From 1181518830664c01124bb246ccceb47f9b989dcf Mon Sep 17 00:00:00 2001 From: kvhnuke <10602065+kvhnuke@users.noreply.github.com> Date: Tue, 17 Dec 2024 14:01:16 -0800 Subject: [PATCH 1/4] devop: switch solana asset handler to helius --- .../src/providers/ethereum/libs/api.ts | 1 + .../libs/assets-handlers/assetinfo-mew.ts | 7 ++- .../libs/assets-handlers/solanachain.ts | 3 + .../src/providers/ethereum/types/index.ts | 1 + .../src/providers/solana/libs/api.ts | 59 ++++++++++--------- .../src/providers/solana/types/sol-token.ts | 4 +- 6 files changed, 40 insertions(+), 35 deletions(-) diff --git a/packages/extension/src/providers/ethereum/libs/api.ts b/packages/extension/src/providers/ethereum/libs/api.ts index a923daf42..9e8f34a09 100644 --- a/packages/extension/src/providers/ethereum/libs/api.ts +++ b/packages/extension/src/providers/ethereum/libs/api.ts @@ -76,6 +76,7 @@ class API implements ProviderAPIInterface { name: 'Unknown', symbol: 'UNKNWN', decimals: 18, + icon: undefined, }; } }; diff --git a/packages/extension/src/providers/ethereum/libs/assets-handlers/assetinfo-mew.ts b/packages/extension/src/providers/ethereum/libs/assets-handlers/assetinfo-mew.ts index 85803b768..5ff6cc7e1 100644 --- a/packages/extension/src/providers/ethereum/libs/assets-handlers/assetinfo-mew.ts +++ b/packages/extension/src/providers/ethereum/libs/assets-handlers/assetinfo-mew.ts @@ -231,7 +231,6 @@ export default ( (obj, cur) => ({ ...obj, [cur.contract]: cur }), {}, ); - const marketData = new MarketData(); const marketInfo = supportedNetworks[networkName].cgPlatform @@ -336,7 +335,10 @@ export default ( balancef: formatFloatingPointValue(userBalance).value, balanceUSD: 0, balanceUSDf: formatFiatValue('0').value, - icon: tokenInfo[unknownTokens[idx]]?.logoURI || network.icon, + icon: + tokenInfo[unknownTokens[idx]]?.logoURI || + tInfo.icon || + network.icon, name: tInfo.name, symbol: tInfo.symbol, value: '0', @@ -350,7 +352,6 @@ export default ( }); }); } - return assets; }); }; diff --git a/packages/extension/src/providers/ethereum/libs/assets-handlers/solanachain.ts b/packages/extension/src/providers/ethereum/libs/assets-handlers/solanachain.ts index 6d01483c5..9f67877c6 100644 --- a/packages/extension/src/providers/ethereum/libs/assets-handlers/solanachain.ts +++ b/packages/extension/src/providers/ethereum/libs/assets-handlers/solanachain.ts @@ -34,6 +34,9 @@ const getBalances = (network: BaseNetwork, address: string) => { (acc.account.data as any).parsed.info.tokenAmount.amount, ); if (balance === '0x0') return; + if ((acc.account.data as any).parsed.info.tokenAmount.decimals === 0) + // skip tokens with 0 decimals because it is an NFT + return; const contract = (acc.account.data as any).parsed.info.mint; if (!balanceObj[contract]) balanceObj[contract] = toBN(0); balanceObj[contract] = balanceObj[contract].add(toBN(balance)); diff --git a/packages/extension/src/providers/ethereum/types/index.ts b/packages/extension/src/providers/ethereum/types/index.ts index 87e3522bb..a9ee4d084 100644 --- a/packages/extension/src/providers/ethereum/types/index.ts +++ b/packages/extension/src/providers/ethereum/types/index.ts @@ -60,6 +60,7 @@ export interface ERC20TokenInfo { name: string; symbol: string; decimals: number; + icon?: string; } export interface JsonRpcRequest { id: string; diff --git a/packages/extension/src/providers/solana/libs/api.ts b/packages/extension/src/providers/solana/libs/api.ts index 2893cbdae..a5c9a028b 100644 --- a/packages/extension/src/providers/solana/libs/api.ts +++ b/packages/extension/src/providers/solana/libs/api.ts @@ -23,7 +23,7 @@ class API implements ProviderAPIInterface { return getSolAddress(pubkey); } - async init(): Promise { } + async init(): Promise {} /** * Returns null if the transaction hasn't been received by the node @@ -33,7 +33,7 @@ class API implements ProviderAPIInterface { const tx = await this.web3.getTransaction(hash, { maxSupportedTransactionVersion: 0, commitment: 'confirmed', - }) + }); if (!tx) { // Transaction hasn't been picked up by the node @@ -66,39 +66,41 @@ class API implements ProviderAPIInterface { } getTokenInfo = async (contractAddress: string): Promise => { - interface TokenDetails { - address: string; - decimals: number; - name: string; - symbol: string; - logoURI: string; - extensions?: { coingeckoId: string }; - } - const allTokensResponse = await cacheFetch( + const tokenResponse: { + result?: { + token_info: { + symbol: string; + decimals: number; + }; + content: { + files: { uri: string }[]; + metadata: { + name: string; + symbol: string; + }; + }; + }; + } = await cacheFetch( { - url: 'https://raw.githubusercontent.com/solflare-wallet/token-list/refs/heads/master/solana-tokenlist.json', - postProcess: (data: any) => { - const allTokens = data.tokens as TokenDetails[]; - const tObj: Record = {}; - allTokens.forEach(t => { - tObj[t.address] = t; - }); - return tObj; + url: this.node, + post: { + jsonrpc: '2.0', + id: 1, + method: 'getAsset', + params: { + id: contractAddress, + }, }, }, 6 * 60 * 60 * 1000, ); - const allTokens = allTokensResponse as Record; let decimals = 9; - if (allTokens[contractAddress]) { + if (tokenResponse.result) { return { - name: allTokens[contractAddress].name, - symbol: allTokens[contractAddress].symbol, - decimals: allTokens[contractAddress].decimals, - icon: allTokens[contractAddress].logoURI, - cgId: allTokens[contractAddress].extensions?.coingeckoId - ? allTokens[contractAddress].extensions?.coingeckoId - : undefined, + name: tokenResponse.result.content.metadata.name, + symbol: tokenResponse.result.content.metadata.symbol, + decimals: tokenResponse.result.token_info.decimals, + icon: `https://img.mewapi.io/?image=${tokenResponse.result.content.files[0].uri}`, }; } else { await this.web3 @@ -115,7 +117,6 @@ class API implements ProviderAPIInterface { symbol: 'UNKNWN', decimals, icon: undefined, - cgId: undefined, }; }; } diff --git a/packages/extension/src/providers/solana/types/sol-token.ts b/packages/extension/src/providers/solana/types/sol-token.ts index 5a905c673..c86586cf6 100644 --- a/packages/extension/src/providers/solana/types/sol-token.ts +++ b/packages/extension/src/providers/solana/types/sol-token.ts @@ -3,10 +3,8 @@ import SolanaAPI from '@/providers/bitcoin/libs/api'; import { ERC20TokenInfo } from '@/providers/ethereum/types'; export interface SPLTokenInfo extends ERC20TokenInfo { - icon: string | undefined; - cgId: string | undefined; + cgId?: string; } - export interface SolTokenOptions extends BaseTokenOptions { contract: string; } From 8a6ef06906309d2806f3c23e1a1610941677785b Mon Sep 17 00:00:00 2001 From: kvhnuke <10602065+kvhnuke@users.noreply.github.com> Date: Tue, 17 Dec 2024 14:09:22 -0800 Subject: [PATCH 2/4] fix: 0 decimal nft --- .../ethereum/libs/assets-handlers/solanachain.ts | 3 --- packages/extension/src/providers/solana/libs/api.ts | 10 ++++++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/extension/src/providers/ethereum/libs/assets-handlers/solanachain.ts b/packages/extension/src/providers/ethereum/libs/assets-handlers/solanachain.ts index 9f67877c6..6d01483c5 100644 --- a/packages/extension/src/providers/ethereum/libs/assets-handlers/solanachain.ts +++ b/packages/extension/src/providers/ethereum/libs/assets-handlers/solanachain.ts @@ -34,9 +34,6 @@ const getBalances = (network: BaseNetwork, address: string) => { (acc.account.data as any).parsed.info.tokenAmount.amount, ); if (balance === '0x0') return; - if ((acc.account.data as any).parsed.info.tokenAmount.decimals === 0) - // skip tokens with 0 decimals because it is an NFT - return; const contract = (acc.account.data as any).parsed.info.mint; if (!balanceObj[contract]) balanceObj[contract] = toBN(0); balanceObj[contract] = balanceObj[contract].add(toBN(balance)); diff --git a/packages/extension/src/providers/solana/libs/api.ts b/packages/extension/src/providers/solana/libs/api.ts index a5c9a028b..deffac6de 100644 --- a/packages/extension/src/providers/solana/libs/api.ts +++ b/packages/extension/src/providers/solana/libs/api.ts @@ -97,10 +97,16 @@ class API implements ProviderAPIInterface { let decimals = 9; if (tokenResponse.result) { return { - name: tokenResponse.result.content.metadata.name, + name: tokenResponse.result.content.metadata.name + ? tokenResponse.result.content.metadata.name + : tokenResponse.result.content.metadata.symbol, symbol: tokenResponse.result.content.metadata.symbol, decimals: tokenResponse.result.token_info.decimals, - icon: `https://img.mewapi.io/?image=${tokenResponse.result.content.files[0].uri}`, + icon: + tokenResponse.result.content.files && + tokenResponse.result.content.files.length > 0 + ? `https://img.mewapi.io/?image=${tokenResponse.result.content.files[0].uri}` + : undefined, }; } else { await this.web3 From eb53d2b8444d34ef47710fd70a6b416abca55131 Mon Sep 17 00:00:00 2001 From: kvhnuke <10602065+kvhnuke@users.noreply.github.com> Date: Tue, 17 Dec 2024 15:23:51 -0800 Subject: [PATCH 3/4] devop: change error messaage --- .../bitcoin/ui/send-transaction/components/send-alert.vue | 4 +++- .../src/providers/bitcoin/ui/send-transaction/index.vue | 5 +++-- .../src/providers/ethereum/ui/send-transaction/index.vue | 6 +++--- .../src/providers/kadena/ui/send-transaction/index.vue | 2 +- .../src/providers/solana/ui/send-transaction/index.vue | 2 +- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/extension/src/providers/bitcoin/ui/send-transaction/components/send-alert.vue b/packages/extension/src/providers/bitcoin/ui/send-transaction/components/send-alert.vue index 8ba300e2c..e62d46777 100644 --- a/packages/extension/src/providers/bitcoin/ui/send-transaction/components/send-alert.vue +++ b/packages/extension/src/providers/bitcoin/ui/send-transaction/components/send-alert.vue @@ -1,7 +1,8 @@