From 2d5be643e2294488347c2809949d0eb487349c7d Mon Sep 17 00:00:00 2001 From: Diego Vazquez Date: Tue, 13 Feb 2024 09:48:46 -0300 Subject: [PATCH 1/2] Adding imported token field to analytics in the send flow --- src/analytics/Properties.tsx | 2 + src/send/SendConfirmation.tsx | 1 + src/send/saga.test.ts | 1 + src/send/saga.ts | 1 + src/tokens/saga.test.ts | 95 +++++++++++++++++++++++++++++++++++ 5 files changed, 100 insertions(+) diff --git a/src/analytics/Properties.tsx b/src/analytics/Properties.tsx index 58b959855cf..af16063962d 100644 --- a/src/analytics/Properties.tsx +++ b/src/analytics/Properties.tsx @@ -559,6 +559,7 @@ interface SendEventsProperties { networkId: NetworkId | null tokenId: string commentLength: number + isTokenManuallyImported: boolean } [SendEvents.send_secure_start]: { @@ -595,6 +596,7 @@ interface SendEventsProperties { tokenAddress: string | undefined tokenId: string networkId: string + isTokenManuallyImported: boolean } [SendEvents.send_tx_error]: { error: string diff --git a/src/send/SendConfirmation.tsx b/src/send/SendConfirmation.tsx index 9f14385936f..03c860e4eac 100644 --- a/src/send/SendConfirmation.tsx +++ b/src/send/SendConfirmation.tsx @@ -242,6 +242,7 @@ function SendConfirmation(props: Props) { networkId: tokenInfo?.networkId ?? null, tokenId, commentLength: comment.length, + isTokenManuallyImported: !!tokenInfo?.isManuallyImported, }) dispatch( diff --git a/src/send/saga.test.ts b/src/send/saga.test.ts index 714cb74027d..b4be1eb1bb3 100644 --- a/src/send/saga.test.ts +++ b/src/send/saga.test.ts @@ -121,6 +121,7 @@ describe(sendPaymentSaga, () => { tokenAddress: '0x874069Fa1Eb16D44d622F2e0Ca25eeA172369bC1'.toLowerCase(), tokenId: mockCusdTokenId, networkId: 'celo-alfajores', + isTokenManuallyImported: false, }) }) diff --git a/src/send/saga.ts b/src/send/saga.ts index 83ee3bf65dc..fb963a3879f 100644 --- a/src/send/saga.ts +++ b/src/send/saga.ts @@ -208,6 +208,7 @@ function* sendPayment( tokenAddress: tokenInfo.address ?? undefined, tokenId: tokenInfo.tokenId, networkId: tokenInfo.networkId, + isTokenManuallyImported: !!tokenInfo?.isManuallyImported, }) } catch (err) { const error = ensureError(err) diff --git a/src/tokens/saga.test.ts b/src/tokens/saga.test.ts index 4a47cdaa6e4..845e9de5731 100644 --- a/src/tokens/saga.test.ts +++ b/src/tokens/saga.test.ts @@ -329,6 +329,8 @@ describe(fetchImportedTokenBalances, () => { name: 'TestToken', symbol: 'TT', isManuallyImported: true, + priceUsd: null, + lastKnownPriceUsd: null, }, [mockPoofTokenId]: { address: mockPoofAddress, @@ -339,6 +341,8 @@ describe(fetchImportedTokenBalances, () => { name: 'PoofToken', symbol: 'Poof', isManuallyImported: true, + priceUsd: null, + lastKnownPriceUsd: null, }, [mockUSDCTokenId]: { address: mockUSDCAddress, @@ -350,6 +354,8 @@ describe(fetchImportedTokenBalances, () => { name: 'USD Coin', symbol: 'USDC', isManuallyImported: true, + priceUsd: null, + lastKnownPriceUsd: null, }, } @@ -381,14 +387,103 @@ describe(fetchImportedTokenBalances, () => { [mockTestTokenTokenId]: { ...mockImportedTokens[mockTestTokenTokenId], balance: new BigNumber(0.000000001).toFixed(), + priceUsd: undefined, }, [mockPoofTokenId]: { ...mockImportedTokens[mockPoofTokenId], balance: new BigNumber(0.0005).toFixed(), + priceUsd: undefined, }, [mockUSDCTokenId]: { ...mockImportedTokens[mockUSDCTokenId], balance: new BigNumber(10).toFixed(), + priceUsd: undefined, + }, + }) + }) +}) + +describe(fetchImportedTokenBalances, () => { + it('returns token balances for multiple chains', async () => { + const mockImportedTokens = { + [mockTestTokenTokenId]: { + address: mockTestTokenAddress, + decimals: 18, + tokenId: mockTestTokenTokenId, + networkId: NetworkId['celo-alfajores'], + balance: new BigNumber(100), + name: 'TestToken', + symbol: 'TT', + isManuallyImported: true, + priceUsd: null, + lastKnownPriceUsd: null, + }, + [mockPoofTokenId]: { + address: mockPoofAddress, + decimals: 18, + tokenId: mockPoofTokenId, + networkId: NetworkId['celo-alfajores'], + balance: new BigNumber(100), + name: 'PoofToken', + symbol: 'Poof', + isManuallyImported: true, + priceUsd: null, + lastKnownPriceUsd: null, + }, + [mockUSDCTokenId]: { + address: mockUSDCAddress, + decimals: 8, + tokenId: mockUSDCTokenId, + showZeroBalance: true, + networkId: NetworkId['ethereum-sepolia'], + balance: new BigNumber(100), + name: 'USD Coin', + symbol: 'USDC', + isManuallyImported: true, + priceUsd: null, + lastKnownPriceUsd: null, + }, + } + + const mockKnownTokenBalances = { + [mockPoofTokenId]: { + tokenId: mockPoofTokenId, + balance: '500000000000000', + }, + } + + // @ts-ignore + jest.mocked(getContract).mockImplementation((_args: any) => { + return { + read: { + balanceOf: (_argsArray: any) => { + return BigInt(1000000000) + }, + }, + } + }) + + const result = await fetchImportedTokenBalances( + mockAccount, + Object.values(mockImportedTokens), + mockKnownTokenBalances + ) + + expect(result).toEqual({ + [mockTestTokenTokenId]: { + ...mockImportedTokens[mockTestTokenTokenId], + balance: new BigNumber(0.000000001).toFixed(), + priceUsd: undefined, + }, + [mockPoofTokenId]: { + ...mockImportedTokens[mockPoofTokenId], + balance: new BigNumber(0.0005).toFixed(), + priceUsd: undefined, + }, + [mockUSDCTokenId]: { + ...mockImportedTokens[mockUSDCTokenId], + balance: new BigNumber(10).toFixed(), + priceUsd: undefined, }, }) }) From 5638c38b3823da2394c1307c743f75eb3a1cfbed Mon Sep 17 00:00:00 2001 From: Diego Vazquez Date: Wed, 14 Feb 2024 11:12:11 -0300 Subject: [PATCH 2/2] Fix bad merge in tests --- src/tokens/saga.test.ts | 86 ----------------------------------------- 1 file changed, 86 deletions(-) diff --git a/src/tokens/saga.test.ts b/src/tokens/saga.test.ts index 845e9de5731..772f3ac29fb 100644 --- a/src/tokens/saga.test.ts +++ b/src/tokens/saga.test.ts @@ -403,92 +403,6 @@ describe(fetchImportedTokenBalances, () => { }) }) -describe(fetchImportedTokenBalances, () => { - it('returns token balances for multiple chains', async () => { - const mockImportedTokens = { - [mockTestTokenTokenId]: { - address: mockTestTokenAddress, - decimals: 18, - tokenId: mockTestTokenTokenId, - networkId: NetworkId['celo-alfajores'], - balance: new BigNumber(100), - name: 'TestToken', - symbol: 'TT', - isManuallyImported: true, - priceUsd: null, - lastKnownPriceUsd: null, - }, - [mockPoofTokenId]: { - address: mockPoofAddress, - decimals: 18, - tokenId: mockPoofTokenId, - networkId: NetworkId['celo-alfajores'], - balance: new BigNumber(100), - name: 'PoofToken', - symbol: 'Poof', - isManuallyImported: true, - priceUsd: null, - lastKnownPriceUsd: null, - }, - [mockUSDCTokenId]: { - address: mockUSDCAddress, - decimals: 8, - tokenId: mockUSDCTokenId, - showZeroBalance: true, - networkId: NetworkId['ethereum-sepolia'], - balance: new BigNumber(100), - name: 'USD Coin', - symbol: 'USDC', - isManuallyImported: true, - priceUsd: null, - lastKnownPriceUsd: null, - }, - } - - const mockKnownTokenBalances = { - [mockPoofTokenId]: { - tokenId: mockPoofTokenId, - balance: '500000000000000', - }, - } - - // @ts-ignore - jest.mocked(getContract).mockImplementation((_args: any) => { - return { - read: { - balanceOf: (_argsArray: any) => { - return BigInt(1000000000) - }, - }, - } - }) - - const result = await fetchImportedTokenBalances( - mockAccount, - Object.values(mockImportedTokens), - mockKnownTokenBalances - ) - - expect(result).toEqual({ - [mockTestTokenTokenId]: { - ...mockImportedTokens[mockTestTokenTokenId], - balance: new BigNumber(0.000000001).toFixed(), - priceUsd: undefined, - }, - [mockPoofTokenId]: { - ...mockImportedTokens[mockPoofTokenId], - balance: new BigNumber(0.0005).toFixed(), - priceUsd: undefined, - }, - [mockUSDCTokenId]: { - ...mockImportedTokens[mockUSDCTokenId], - balance: new BigNumber(10).toFixed(), - priceUsd: undefined, - }, - }) - }) -}) - describe(tokenAmountInSmallestUnit, () => { it('returns correct value', async () => { expect(tokenAmountInSmallestUnit(new BigNumber(10), 5)).toEqual('1000000')