Skip to content

Commit

Permalink
Lookup token symbol from token id when displaying out-of-balance erro…
Browse files Browse the repository at this point in the history
…r message
  • Loading branch information
h0ngcha0 committed Oct 23, 2024
1 parent 1e34951 commit e34c4c7
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/extension/src/shared/transactions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { BaseTokenWithBalance } from "../token/type"
import { BigNumber } from "ethers"
import { addTokenToBalances, getBalances } from "../token/balance"
import i18n from "../../i18n"
import { tokenListStore } from "../token/storage"

export type Status = 'NOT_RECEIVED' | 'RECEIVED' | 'PENDING' | 'ACCEPTED_ON_MEMPOOL' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_CHAIN' | 'REJECTED' | 'REMOVED_FROM_MEMPOOL';

Expand Down Expand Up @@ -225,7 +226,11 @@ export async function tryBuildTransactions(
}

const [firstMissingTokenId, firstMissingAmount] = missingBalances.entries().next().value;
const tokenSymbol = firstMissingTokenId === ALPH_TOKEN_ID ? 'ALPH' : firstMissingTokenId;
const tokenListTokens = await tokenListStore.get()
const tokenSymbol = firstMissingTokenId === ALPH_TOKEN_ID ?
'ALPH' : tokenListTokens.tokens.find(token =>
token.id === firstMissingTokenId && token.networkId === selectedAccount.networkId
)?.symbol ?? firstMissingTokenId
const expectedStr = firstMissingAmount.toString();
const haveStr = (tokensWithBalance.find(t => t.id === firstMissingTokenId)?.balance || '0').toString();
const errorMsg = i18n.t("Insufficient token {{ tokenSymbol }}, expected at least {{ expectedStr }}, got {{ haveStr }}", { tokenSymbol, expectedStr, haveStr })
Expand Down

0 comments on commit e34c4c7

Please sign in to comment.