Skip to content

Commit

Permalink
refactor: useVaultDepositParams, find by address only
Browse files Browse the repository at this point in the history
(cherry picked from commit 2eb6f77)
  • Loading branch information
D-Ig authored and dimlbc committed Nov 1, 2024
1 parent 09a3d64 commit 46f1da1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,13 @@ describe('useVaultDepositParams', () => {
})

it('should return deposit params for custom token deposit when deposit token is presented in vault composition', () => {
const poolComposition = [{ tokenName: USDC_BASE.symbol, isDeposit: true }]
const poolComposition = [
{
tokenName: USDC_BASE.symbol,
isDeposit: true,
tokenAddress: USDC_BASE.address,
},
]
vi.mocked(useSendTokenInput).mockReturnValue([
USDC_BASE,
] as unknown as ReturnType<typeof useSendTokenInput>)
Expand All @@ -118,7 +124,13 @@ describe('useVaultDepositParams', () => {
})

it('should return deposit params for custom token deposit when deposit token is not presented in vault composition', () => {
const poolComposition = [{ tokenName: WETH_BASE.symbol, isDeposit: true }]
const poolComposition = [
{
tokenName: WETH_BASE.symbol,
isDeposit: true,
tokenAddress: WETH_BASE.address,
},
]
vi.mocked(useSendTokenInput).mockReturnValue([
USDC_BASE,
] as unknown as ReturnType<typeof useSendTokenInput>)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,10 @@ const getVaultDepositTokenAddress = (
if (!availableDepositOptions.length) {
return null
}
const fallbackToken = availableDepositOptions.find(
({ tokenName, tokenAddress }) =>
Object.values(FALLBACK_ASSETS_MAP[chainId] ?? {}).some(
(fallbackToken) =>
fallbackToken.symbol === tokenName ||
isEqualAddress(fallbackToken.address, tokenAddress),
),
const fallbackToken = availableDepositOptions.find(({ tokenAddress }) =>
Object.values(FALLBACK_ASSETS_MAP[chainId] ?? {}).some((fallbackToken) =>
isEqualAddress(fallbackToken.address, tokenAddress),
),
)

return fallbackToken?.tokenAddress ?? availableDepositOptions[0]?.tokenAddress
Expand Down Expand Up @@ -80,9 +77,7 @@ export const useVaultDepositParams = (): VaultDepositParams => {
}

const depositTokenPresentedInVault = availableDepositOptions.find(
({ tokenName, tokenAddress }) =>
tokenName === sendToken.symbol ||
isEqualAddress(tokenAddress, sendToken.address),
({ tokenAddress }) => isEqualAddress(tokenAddress, sendToken.address),
)

// Step 2: Check if the token is presented in the vault
Expand Down

0 comments on commit 46f1da1

Please sign in to comment.