From 9f4088b2223ec06d338d7f43a68e5425148039f6 Mon Sep 17 00:00:00 2001 From: Roman Petriv Date: Mon, 18 Sep 2023 14:30:15 +0300 Subject: [PATCH] fix: show unknown token when transfer has no token --- .../app/src/composables/useTransaction.ts | 20 ++++------ .../tests/composables/useTransaction.spec.ts | 39 ++++++++++++++++--- 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/packages/app/src/composables/useTransaction.ts b/packages/app/src/composables/useTransaction.ts index 8fbe09d5c6..078e883e08 100644 --- a/packages/app/src/composables/useTransaction.ts +++ b/packages/app/src/composables/useTransaction.ts @@ -8,8 +8,6 @@ import useContext from "./useContext"; import type { TransactionLogEntry } from "./useEventLog"; import type { Hash, NetworkOrigin } from "@/types"; -import { ETH_TOKEN } from "@/utils/constants"; - export type TransactionStatus = "included" | "committed" | "proved" | "verified" | "failed" | "indexing"; type TokenInfo = { address: Hash; @@ -234,16 +232,14 @@ function mapTransfers(transfers: Api.Response.Transfer[]): TokenTransfer[] { fromNetwork: getTransferNetworkOrigin(item, "from"), toNetwork: getTransferNetworkOrigin(item, "to"), type: item.type, - tokenInfo: item.token - ? ({ - address: item.token.l2Address, - l1Address: item.token.l1Address, - l2Address: item.token.l2Address, - decimals: item.token.decimals, - name: item.token.name, - symbol: item.token.symbol, - } as TokenInfo) - : ETH_TOKEN, + tokenInfo: { + address: item.tokenAddress, + l1Address: item.token?.l1Address, + l2Address: item.tokenAddress, + decimals: item.token?.decimals || 0, + name: item.token?.name, + symbol: item.token?.symbol, + } as TokenInfo, })); } diff --git a/packages/app/tests/composables/useTransaction.spec.ts b/packages/app/tests/composables/useTransaction.spec.ts index 5f4ce4af79..ccb7780c2b 100644 --- a/packages/app/tests/composables/useTransaction.spec.ts +++ b/packages/app/tests/composables/useTransaction.spec.ts @@ -8,6 +8,8 @@ import useTransaction, { getTransferNetworkOrigin } from "@/composables/useTrans import type { Context } from "@/composables/useContext"; +import { ETH_TOKEN } from "@/utils/constants"; + const logs = [ { address: "0x000000000000000000000000000000000000800A", @@ -104,10 +106,10 @@ vi.mock("ohmyfetch", async () => { blockNumber: 1162235, transactionHash: "0x9c526cc47ca2d3f72b7997a61d890d72951a283fa05d08df058ff8a629cffa3c", amount: "1561368069251910", - tokenAddress: null, + tokenAddress: ETH_TOKEN.address, type: "fee", fields: null, - token: null, + token: ETH_TOKEN, }, { from: "0x0000000000000000000000000000000000008001", @@ -115,9 +117,20 @@ vi.mock("ohmyfetch", async () => { blockNumber: 1162235, transactionHash: "0x9c526cc47ca2d3f72b7997a61d890d72951a283fa05d08df058ff8a629cffa3c", amount: "116665569251910", - tokenAddress: null, + tokenAddress: ETH_TOKEN.address, type: "refund", fields: null, + token: ETH_TOKEN, + }, + { + from: "0x08d211E22dB19741FF25838A22e4e696FeE7eD36", + to: "0x08d211E22dB19741FF25838A22e4e696FeE7eD36", + blockNumber: 1162235, + transactionHash: "0x9c526cc47ca2d3f72b7997a61d890d72951a283fa05d08df058ff8a629cffa3c", + amount: "1", + tokenAddress: "0x1bAbcaeA2e4BE1f1e1A149c454806F2D21d7f47D", + type: "transfer", + fields: null, token: null, }, { @@ -143,10 +156,10 @@ vi.mock("ohmyfetch", async () => { blockNumber: 1162235, transactionHash: "0x9c526cc47ca2d3f72b7997a61d890d72951a283fa05d08df058ff8a629cffa3c", amount: "867466250000000", - tokenAddress: null, + tokenAddress: ETH_TOKEN.address, type: "refund", fields: null, - token: null, + token: ETH_TOKEN, }, ], meta: { @@ -451,6 +464,22 @@ describe("useTransaction:", () => { }, ], transfers: [ + { + amount: "1", + from: "0x08d211E22dB19741FF25838A22e4e696FeE7eD36", + to: "0x08d211E22dB19741FF25838A22e4e696FeE7eD36", + fromNetwork: "L2", + toNetwork: "L2", + type: "transfer", + tokenInfo: { + address: "0x1bAbcaeA2e4BE1f1e1A149c454806F2D21d7f47D", + l1Address: undefined, + l2Address: "0x1bAbcaeA2e4BE1f1e1A149c454806F2D21d7f47D", + decimals: 0, + name: undefined, + symbol: undefined, + }, + }, { amount: "12", from: "0x08d211E22dB19741FF25838A22e4e696FeE7eD36",