-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aa949db
commit 5c039dc
Showing
28 changed files
with
191 additions
and
267 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
web/5.35.0 | ||
web/5.35.1 |
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
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
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 |
---|---|---|
@@ -1,38 +1,36 @@ | ||
import { useTokenBalancesQuery } from 'graphql/data/apollo/TokenBalancesProvider' | ||
import { supportedChainIdFromGQLChain } from 'graphql/data/util' | ||
import { useAccount } from 'hooks/useAccount' | ||
import { TokenBalances } from 'lib/hooks/useTokenList/sorting' | ||
import { useMemo } from 'react' | ||
import { PortfolioTokenBalancePartsFragment } from 'uniswap/src/data/graphql/uniswap-data-api/__generated__/types-and-hooks' | ||
import { currencyKeyFromGraphQL } from 'utils/currencyKey' | ||
|
||
/** | ||
* Returns the user's token balances via graphql as a map and list. | ||
*/ | ||
export function useTokenBalances({ cacheOnly }: { cacheOnly?: boolean } = {}): { | ||
export function useTokenBalances(): { | ||
balanceMap: TokenBalances | ||
balanceList: readonly (PortfolioTokenBalancePartsFragment | undefined)[] | ||
loading: boolean | ||
} { | ||
const { data, loading } = useTokenBalancesQuery({ cacheOnly }) | ||
const { chainId } = useAccount() | ||
const { data, loading } = useTokenBalancesQuery() | ||
return useMemo(() => { | ||
const balanceList = data?.portfolios?.[0]?.tokenBalances ?? [] | ||
const balanceMap = | ||
balanceList?.reduce((balanceMap, tokenBalance) => { | ||
if (!tokenBalance?.token) { | ||
return balanceMap | ||
} | ||
|
||
const key = currencyKeyFromGraphQL({ | ||
address: tokenBalance.token.address, | ||
chain: tokenBalance.token.chain, | ||
standard: tokenBalance.token.standard, | ||
}) | ||
if (tokenBalance.denominatedValue?.value !== undefined) { | ||
const usdValue = tokenBalance.denominatedValue?.value | ||
const balance = tokenBalance.quantity | ||
balanceMap[key] = { usdValue, balance: balance ?? 0 } | ||
const address = | ||
tokenBalance?.token?.standard === 'ERC20' | ||
? tokenBalance.token?.address?.toLowerCase() | ||
: tokenBalance?.token?.symbol ?? 'ETH' | ||
if ( | ||
tokenBalance?.token?.chain && | ||
supportedChainIdFromGQLChain(tokenBalance.token?.chain) === chainId && | ||
address | ||
) { | ||
const usdValue = tokenBalance.denominatedValue?.value ?? 0 | ||
const balance = tokenBalance.quantity ?? 0 | ||
balanceMap[address] = { usdValue, balance } | ||
} | ||
return balanceMap | ||
}, {} as TokenBalances) ?? {} | ||
return { balanceMap, balanceList, loading } | ||
}, [data?.portfolios, loading]) | ||
}, [chainId, data?.portfolios, loading]) | ||
} |
Oops, something went wrong.