Skip to content

Commit

Permalink
Merge pull request #8 from matter-labs/handle-transfers-with-no-token
Browse files Browse the repository at this point in the history
fix: show unknown token when transfer has no token
  • Loading branch information
Romsters authored Sep 18, 2023
2 parents ee4ea60 + 9f4088b commit c92ce7a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 17 deletions.
20 changes: 8 additions & 12 deletions packages/app/src/composables/useTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
}));
}

Expand Down
39 changes: 34 additions & 5 deletions packages/app/tests/composables/useTransaction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -104,20 +106,31 @@ 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",
to: "0x08d211E22dB19741FF25838A22e4e696FeE7eD36",
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,
},
{
Expand All @@ -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: {
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit c92ce7a

Please sign in to comment.