-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reduced reads of celo token list json file (#148)
Co-authored-by: LewisB <[email protected]>
- Loading branch information
1 parent
f5f478c
commit 1f03125
Showing
1 changed file
with
16 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,25 @@ | ||
import { useMemo } from 'react'; | ||
import { Token } from '@uniswap/sdk-core'; | ||
import CeloTokenList from '../models/CeloTokenList.json'; | ||
import { SupportedNetwork } from '../models/constants'; | ||
|
||
const populatedTokenList: Record<string, Token> = populateTokenList(); | ||
|
||
function populateTokenList(): Record<string, Token> { | ||
const tokenList: Record<string, Token> = {}; | ||
const sortedList = CeloTokenList.tokens.sort((a, b) => a.symbol.localeCompare(b.symbol)); | ||
sortedList.forEach((token) => { | ||
if (token.chainId !== SupportedNetwork.CELO) { | ||
return; | ||
} | ||
tokenList[token.symbol] = new Token(token.chainId, token.address, token.decimals, token.symbol); | ||
}); | ||
return tokenList; | ||
} | ||
|
||
export function useToken(symbol: string): Token { | ||
return useTokenList()[symbol]; | ||
return populatedTokenList[symbol]; | ||
} | ||
|
||
export function useTokenList(): Record<string, Token> { | ||
return useMemo(() => { | ||
const tokenList: Record<string, Token> = {}; | ||
const sortedList = CeloTokenList.tokens.sort((a, b) => a.symbol.localeCompare(b.symbol)); | ||
sortedList.forEach((token) => { | ||
if (token.chainId !== SupportedNetwork.CELO) { | ||
return; | ||
} | ||
tokenList[token.symbol] = new Token(token.chainId, token.address, token.decimals, token.symbol); | ||
}); | ||
return tokenList; | ||
}, []); | ||
return populatedTokenList; | ||
} |