Skip to content

Commit

Permalink
feat: update keys to use address instead of symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
Space-Bean committed Jul 14, 2024
1 parent 137e2d9 commit 68eaa50
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 26 deletions.
4 changes: 2 additions & 2 deletions projects/dex-ui/src/components/Liquidity/AddLiquidity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ const AddLiquidityContent = ({
toast.error(error);
setIsSubmitting(false);
}
invalidate(queryKeys.tokenBalance(token1.symbol));
invalidate(queryKeys.tokenBalance(token2.symbol));
invalidate(queryKeys.tokenBalance(token1.address));
invalidate(queryKeys.tokenBalance(token2.address));
invalidate(queryKeys.lpSummaryAll);

}
Expand Down
8 changes: 4 additions & 4 deletions projects/dex-ui/src/components/Swap/TokenInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ export const TokenInput: FC<TokenInput> = ({
}, []);

const handleClickMax = useCallback(() => {
const val = balance?.[token.symbol].toHuman() ?? "";
const val = balance?.[token.address]?.toHuman() ?? "";
handleAmountChange(val);
}, [balance, handleAmountChange, token.symbol]);
}, [balance, handleAmountChange, token.address]);

if (loading) return <LoadingContainer width={width} data-trace="true" />;

Expand All @@ -110,7 +110,7 @@ export const TokenInput: FC<TokenInput> = ({
inputRef={inputRef}
allowNegative={allowNegative}
canChangeValue={!!canChangeValue}
max={clamp ? balance?.[token.symbol] : undefined}
max={clamp ? balance?.[token.address] : undefined}
/>
<TokenPicker
token={token}
Expand All @@ -126,7 +126,7 @@ export const TokenInput: FC<TokenInput> = ({
<BalanceRow>
<Balance onClick={handleClickMax}>
{balanceLabel}:{" "}
{isBalanceLoading ? <Spinner size={12} /> : balance?.[token.symbol].toHuman("short")}
{isBalanceLoading ? <Spinner size={12} /> : balance?.[token.address]?.toHuman("short")}
</Balance>
</BalanceRow>
)}
Expand Down
38 changes: 18 additions & 20 deletions projects/dex-ui/src/tokens/useLPPositionSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export const useLPPositionSummary = () => {

const lpTokenIndex = Math.floor(i / CALLS_PER_TOKEN);
const lpToken = lpTokens[lpTokenIndex];
let balance = balances?.[lpToken.symbol] || {
let balance = balances?.[lpToken.address] || {
external: TokenValue.ZERO,
internal: TokenValue.ZERO
};
Expand All @@ -113,30 +113,31 @@ export const useLPPositionSummary = () => {
if (lpTokens[lpTokenIndex]) {
balance.external = lpTokens[lpTokenIndex].fromBlockchain(res[i]) || TokenValue.ZERO;
}
setQueryData(queryKeys.tokenBalance(lpToken.symbol), (oldData: TokenBalanceCache) => {
if (!oldData) return { [lpToken.symbol]: balance.external };
return { ...oldData, [lpToken.symbol]: balance.external };
setQueryData(queryKeys.tokenBalance(lpToken.address), (oldData: TokenBalanceCache) => {
if (!oldData) return { [lpToken.address]: balance.external };
return { ...oldData, [lpToken.address]: balance.external };
})
setQueryData(queryKeys.tokenBalancesAll, (oldData: TokenBalanceCache) => {
if (!oldData) return { [lpToken.symbol]: balance.external };
return { ...oldData, [lpToken.symbol]: balance.external };
if (!oldData) return { [lpToken.address]: balance.external };
return { ...oldData, [lpToken.address]: balance.external };
})

} else {
if (lpTokens[lpTokenIndex]) {
balance.internal = lpTokens[lpTokenIndex].fromBlockchain(res[i]);
setQueryData(queryKeys.tokenBalanceInternal(lpToken.symbol), (oldData: TokenBalanceCache) => {
if (!oldData) return { [lpToken.symbol]: balance.internal };
return { ...oldData, [lpToken.symbol]: balance.internal };
setQueryData(queryKeys.tokenBalanceInternal(lpToken.address), (oldData: TokenBalanceCache) => {
if (!oldData) return { [lpToken.address]: balance.internal };
return { ...oldData, [lpToken.address]: balance.internal };
})
}
}

balances[lpToken.symbol] = balance;
balances[lpToken.address] = balance;
}

return balances;
},
enabled: !!address && !!lpTokens.length,

/**
* Token balances are cached for 30 seconds, refetch value every 30 seconds,
Expand All @@ -152,21 +153,18 @@ export const useLPPositionSummary = () => {

// Combine silo, internal & external balances & update state
useEffect(() => {
console.log("balanceData: ", balanceData);
// console.log("balanceData: ", balanceData);
// console.log("lpTokens: ", lpTokens);
if (!lpTokens.length || !balanceData || !siloBalances) return;

console.log("siloBalances: ", siloBalances);

// console.log("lptokens: ", lpTokens);

const map = lpTokens.reduce<TokenMap<LPBalanceSummary>>((memo, curr) => {
const siloBalance = siloBalances[curr.symbol] || TokenValue.ZERO;
const internalExternal = balanceData?.[curr.symbol] || {
const siloBalance = siloBalances[curr.address] || TokenValue.ZERO;
const internalExternal = balanceData?.[curr.address] || {
external: TokenValue.ZERO,
internal: TokenValue.ZERO
};

memo[curr.symbol] = {
memo[curr.address] = {
silo: siloBalance,
internal: internalExternal.internal,
external: internalExternal.external,
Expand All @@ -191,8 +189,8 @@ export const useLPPositionSummary = () => {
*/
const getPositionWithWell = useCallback(
(well: Well | undefined) => {
if (!well?.lpToken?.symbol) return undefined;
return positions?.[well.lpToken.symbol];
if (!well?.lpToken?.address) return undefined;
return positions?.[well.lpToken.address];
},
[positions]
);
Expand Down

0 comments on commit 68eaa50

Please sign in to comment.