Skip to content

Commit

Permalink
Fix checking token info
Browse files Browse the repository at this point in the history
  • Loading branch information
Lbqds committed Aug 21, 2024
1 parent 4a65c9b commit 5dda69c
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions bridge_ui/src/utils/alephium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async function fetchTokenList(): Promise<TokenList> {
return tokenList
}

async function getTokenFromTokenList(tokenId: string): Promise<TokenInfo | undefined> {
async function getTokenFromTokenList(tokenId: string): Promise<TokenInfo & { nameOnChain?: string; symbolOnChain?: string } | undefined> {
if (tokenListCache !== undefined) {
let result = tokenListCache.tokens.find((t) => t.id.toLowerCase() === tokenId.toLowerCase())
if (result === undefined) { // update the cache
Expand Down Expand Up @@ -200,23 +200,23 @@ export async function getAlephiumTokenLogoURI(tokenId: string): Promise<string |
}

export async function getAndCheckLocalTokenInfo(provider: NodeProvider, tokenId: string): Promise<TokenInfo> {
const localTokenInfo = await getLocalTokenInfo(provider, tokenId)
const onChainTokenInfo = await getLocalTokenInfo(provider, tokenId)
if (CLUSTER === 'devnet' || tokenId === ALPH_TOKEN_ID) {
return localTokenInfo
return onChainTokenInfo
}

const tokenInfo = await getTokenFromTokenList(tokenId)
if (tokenInfo === undefined) {
throw new Error(i18n.t('Token {{ tokenId }} does not exists in the token-list', { tokenId }))
}
if (
tokenInfo.name !== localTokenInfo.name ||
tokenInfo.symbol !== localTokenInfo.symbol ||
tokenInfo.decimals !== localTokenInfo.decimals
(tokenInfo.name === onChainTokenInfo.name || tokenInfo.nameOnChain === onChainTokenInfo.name) &&
(tokenInfo.symbol === onChainTokenInfo.symbol || tokenInfo.symbolOnChain === onChainTokenInfo.symbol) &&
(tokenInfo.decimals === onChainTokenInfo.decimals)
) {
throw new Error(i18n.t('Invalid token info, expected: {{ localTokenInfo }}, have: {{ tokenInfo }}', { localTokenInfo, tokenInfo }))
return onChainTokenInfo
}
return localTokenInfo
throw new Error(i18n.t('Invalid token info, expected: {{ localTokenInfo }}, have: {{ tokenInfo }}', { localTokenInfo: onChainTokenInfo, tokenInfo }))
}

export async function getAlephiumTokenWrappedInfo(tokenId: string, provider: NodeProvider): Promise<WormholeWrappedInfo> {
Expand Down

0 comments on commit 5dda69c

Please sign in to comment.