feat: switch token list to Solana strategy (#21292)

This commit is contained in:
Josh
2021-11-15 17:54:31 -08:00
committed by GitHub
parent 398af132a5
commit bea61e9543
3 changed files with 927 additions and 21 deletions

View File

@@ -4,6 +4,7 @@ import {
TokenInfoMap,
TokenInfo,
TokenListContainer,
Strategy,
} from "@solana/spl-token-registry";
import { Cluster, clusterSlug, useCluster } from "providers/cluster";
@@ -18,19 +19,21 @@ export function TokenRegistryProvider({ children }: ProviderProps) {
const { cluster } = useCluster();
React.useEffect(() => {
new TokenListProvider().resolve().then((tokens: TokenListContainer) => {
const tokenList =
cluster === Cluster.Custom
? []
: tokens.filterByClusterSlug(clusterSlug(cluster)).getList();
new TokenListProvider()
.resolve(Strategy.Solana)
.then((tokens: TokenListContainer) => {
const tokenList =
cluster === Cluster.Custom
? []
: tokens.filterByClusterSlug(clusterSlug(cluster)).getList();
setTokenRegistry(
tokenList.reduce((map: TokenInfoMap, item: TokenInfo) => {
map.set(item.address, item);
return map;
}, new Map())
);
});
setTokenRegistry(
tokenList.reduce((map: TokenInfoMap, item: TokenInfo) => {
map.set(item.address, item);
return map;
}, new Map())
);
});
}, [cluster]);
return (