Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

devop: switch solana asset handler to helius #578

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/extension/src/providers/ethereum/libs/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class API implements ProviderAPIInterface {
name: 'Unknown',
symbol: 'UNKNWN',
decimals: 18,
icon: undefined,
};
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ export default (
(obj, cur) => ({ ...obj, [cur.contract]: cur }),
{},
);

const marketData = new MarketData();

const marketInfo = supportedNetworks[networkName].cgPlatform
Expand Down Expand Up @@ -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',
Expand All @@ -350,7 +352,6 @@ export default (
});
});
}

return assets;
});
};
1 change: 1 addition & 0 deletions packages/extension/src/providers/ethereum/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export interface ERC20TokenInfo {
name: string;
symbol: string;
decimals: number;
icon?: string;
}
export interface JsonRpcRequest {
id: string;
Expand Down
65 changes: 36 additions & 29 deletions packages/extension/src/providers/solana/libs/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class API implements ProviderAPIInterface {
return getSolAddress(pubkey);
}

async init(): Promise<void> { }
async init(): Promise<void> {}

/**
* Returns null if the transaction hasn't been received by the node
Expand All @@ -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
Expand Down Expand Up @@ -66,39 +66,47 @@ class API implements ProviderAPIInterface {
}

getTokenInfo = async (contractAddress: string): Promise<SPLTokenInfo> => {
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<string, TokenDetails> = {};
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<string, TokenDetails>;
let decimals = 9;
kvhnuke marked this conversation as resolved.
Show resolved Hide resolved
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
? tokenResponse.result.content.metadata.name
: tokenResponse.result.content.metadata.symbol,
symbol: tokenResponse.result.content.metadata.symbol,
decimals: tokenResponse.result.token_info.decimals,
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
Expand All @@ -115,7 +123,6 @@ class API implements ProviderAPIInterface {
symbol: 'UNKNWN',
decimals,
icon: undefined,
cgId: undefined,
};
};
}
Expand Down
4 changes: 1 addition & 3 deletions packages/extension/src/providers/solana/types/sol-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading