From 8d5cc2c5c33ac638676e9412de4157054d38dad5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Leszczyk?= Date: Wed, 18 Sep 2024 14:24:05 +0200 Subject: [PATCH] fix: bridge initiated from core web (#48) --- .../handlers/avalanche_bridgeAsset.test.ts | 16 +++++++++------- .../bridge/handlers/avalanche_bridgeAsset.ts | 11 ++++++----- src/pages/ApproveAction/BridgeTransferAsset.tsx | 2 +- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/background/services/bridge/handlers/avalanche_bridgeAsset.test.ts b/src/background/services/bridge/handlers/avalanche_bridgeAsset.test.ts index 63c14d2e..782287a8 100644 --- a/src/background/services/bridge/handlers/avalanche_bridgeAsset.test.ts +++ b/src/background/services/bridge/handlers/avalanche_bridgeAsset.test.ts @@ -421,13 +421,15 @@ describe('background/services/bridge/handlers/avalanche_bridgeAsset', () => { const balanceServiceMock = { getBalancesForNetworks: jest.fn().mockResolvedValueOnce({ - [43113]: { - C_address: { - WETH: { - symbol: 'WETH', - type: TokenType.ERC20, - balance: new BN(100), - decimals: 1, + tokens: { + [43113]: { + C_address: { + WETH: { + symbol: 'WETH', + type: TokenType.ERC20, + balance: new BN(100), + decimals: 1, + }, }, }, }, diff --git a/src/background/services/bridge/handlers/avalanche_bridgeAsset.ts b/src/background/services/bridge/handlers/avalanche_bridgeAsset.ts index 80ecab60..26d894f7 100644 --- a/src/background/services/bridge/handlers/avalanche_bridgeAsset.ts +++ b/src/background/services/bridge/handlers/avalanche_bridgeAsset.ts @@ -163,10 +163,11 @@ export class AvalancheBridgeAsset extends DAppRequestHandler } // get the correct balance information for the asset - const balances = await this.balanceAggregatorService.getBalancesForNetworks( - [sourceNetwork.chainId], - [activeAccount] - ); + const { tokens } = + await this.balanceAggregatorService.getBalancesForNetworks( + [sourceNetwork.chainId], + [activeAccount] + ); const balanceAddress = sourceNetwork && isBitcoinNetwork(sourceNetwork) @@ -179,7 +180,7 @@ export class AvalancheBridgeAsset extends DAppRequestHandler findTokenForAsset( asset.symbol, asset.nativeNetwork, - Object.values(balances?.[sourceNetwork.chainId]?.[balanceAddress] ?? {}) + Object.values(tokens?.[sourceNetwork.chainId]?.[balanceAddress] ?? {}) ); const action: Action = { diff --git a/src/pages/ApproveAction/BridgeTransferAsset.tsx b/src/pages/ApproveAction/BridgeTransferAsset.tsx index dc489ab1..a47278a4 100644 --- a/src/pages/ApproveAction/BridgeTransferAsset.tsx +++ b/src/pages/ApproveAction/BridgeTransferAsset.tsx @@ -41,7 +41,7 @@ export function BridgeTransferAsset({ GasFeeModifier.INSTANT ); - const tokenPrice = displayData.token.priceInCurrency; + const tokenPrice = displayData?.token?.priceInCurrency; const fiatValue: Big | undefined = typeof tokenPrice === 'number' ? new Big(displayData.amountStr).times(tokenPrice)