-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use token registry for non existing images (#430)
- Loading branch information
1 parent
80f88ba
commit b0da934
Showing
6 changed files
with
101 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { useContext } from 'react' | ||
import { TokenListContext } from '../storage/TokenListProvider' | ||
|
||
export const useTokenList = () => { | ||
return useContext(TokenListContext) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { | ||
TokenListProvider as Provider, | ||
TokenInfo, | ||
ENV, | ||
} from '@solana/spl-token-registry' | ||
import React, { ReactNode, useEffect, useState } from 'react' | ||
|
||
export const TokenListContext = React.createContext< | ||
Map<string, TokenInfo> | undefined | ||
>(undefined) | ||
|
||
export const TokenListProvider = ({ children }: { children: ReactNode }) => { | ||
const [tokenMap, setTokenMap] = useState<Map<string, TokenInfo>>(new Map()) | ||
|
||
useEffect(() => { | ||
new Provider().resolve().then((tokens) => { | ||
const tokenList = tokens.filterByChainId(ENV.MainnetBeta).getList() | ||
|
||
setTokenMap( | ||
tokenList.reduce((map, item) => { | ||
map.set(item.address, item) | ||
return map | ||
}, new Map()), | ||
) | ||
}) | ||
}, [setTokenMap]) | ||
|
||
return ( | ||
<TokenListContext.Provider value={tokenMap}> | ||
{children} | ||
</TokenListContext.Provider> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3813,6 +3813,13 @@ | |
js-sha3 "^0.8.0" | ||
typescript-collections "^1.3.3" | ||
|
||
"@solana/spl-token-registry@^0.2.4574": | ||
version "0.2.4574" | ||
resolved "https://registry.yarnpkg.com/@solana/spl-token-registry/-/spl-token-registry-0.2.4574.tgz#13f4636b7bec90d2bb43bbbb83512cd90d2ce257" | ||
integrity sha512-JzlfZmke8Rxug20VT/VpI2XsXlsqMlcORIUivF+Yucj7tFi7A0dXG7h+2UnD0WaZJw8BrUz2ABNkUnv89vbv1A== | ||
dependencies: | ||
cross-fetch "3.0.6" | ||
|
||
"@solana/[email protected]": | ||
version "0.3.6" | ||
resolved "https://registry.yarnpkg.com/@solana/spl-token/-/spl-token-0.3.6.tgz#35473ad2ed71fe91e5754a2ac72901e1b8b26a42" | ||
|
@@ -7029,6 +7036,13 @@ create-require@^1.1.0: | |
resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333" | ||
integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ== | ||
|
||
[email protected]: | ||
version "3.0.6" | ||
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.0.6.tgz#3a4040bc8941e653e0e9cf17f29ebcd177d3365c" | ||
integrity sha512-KBPUbqgFjzWlVcURG+Svp9TlhA5uliYtiNx/0r8nv0pdypeQCRJ9IaSIc3q/x3q8t3F75cHuwxVql1HFGHCNJQ== | ||
dependencies: | ||
node-fetch "2.6.1" | ||
|
||
cross-fetch@^3.1.5: | ||
version "3.1.5" | ||
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.1.5.tgz#e1389f44d9e7ba767907f7af8454787952ab534f" | ||
|
@@ -12021,6 +12035,11 @@ node-fetch@2, node-fetch@^2.2.0, node-fetch@^2.6.0, node-fetch@^2.6.1, node-fetc | |
dependencies: | ||
whatwg-url "^5.0.0" | ||
|
||
[email protected]: | ||
version "2.6.1" | ||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052" | ||
integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw== | ||
|
||
[email protected]: | ||
version "2.6.7" | ||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad" | ||
|