From 3947500eba23f2e694784662964b177f03ee344a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Jedli=C4=8Dka?= Date: Fri, 19 May 2023 08:14:07 +0200 Subject: [PATCH] show parsed amount values in transfers table --- src/components/transfers/TransfersTable.tsx | 18 +++++++++++++----- src/model/main-squid/mainSquidTransfer.ts | 3 ++- src/model/transfer.ts | 4 +++- src/services/transfersService.ts | 12 ++++++++---- src/utils/uniq.ts | 16 ++++++++++++++++ 5 files changed, 42 insertions(+), 11 deletions(-) diff --git a/src/components/transfers/TransfersTable.tsx b/src/components/transfers/TransfersTable.tsx index 18dbf81a..d17582ce 100644 --- a/src/components/transfers/TransfersTable.tsx +++ b/src/components/transfers/TransfersTable.tsx @@ -1,9 +1,14 @@ -import { PaginatedResource } from "../../model/paginatedResource"; -import { Transfer } from "../../model/transfer"; import { Chip } from "@mui/material"; + import CrossIcon from "../../assets/cross-icon.png"; import CheckIcon from "../../assets/check-icon.png"; + +import { PaginatedResource } from "../../model/paginatedResource"; +import { Transfer } from "../../model/transfer"; +import { getNetwork } from "../../services/networksService"; + import { AccountAddress } from "../AccountAddress"; +import { Currency } from "../Currency"; import { ItemsTable, ItemsTableAttribute } from "../ItemsTable"; import { Link } from "../Link"; import { Time } from "../Time"; @@ -70,9 +75,12 @@ function TransfersTable(props: TransfersTableProps) { - <> - {transfer.amount} - + } /> "latest"); const transfers = await addExtrinsicsInfo(network, itemsWithRuntimeSpec); @@ -132,14 +134,16 @@ async function getArchiveExtrinsicsInfo(network: string, extrinsicHashes: string }, {} as Record); } -function unifyMainSquidTransfer(transfer: MainSquidTransfer): Omit { +function unifyMainSquidTransfer(transfer: MainSquidTransfer, networkName: string): Omit { + const network = getNetwork(networkName); + return { ...transfer, accountPublicKey: transfer.account.publicKey, blockNumber: transfer.transfer.blockNumber, timestamp: transfer.transfer.timestamp, extrinsicHash: transfer.transfer.extrinsicHash, - amount: transfer.transfer.amount, + amount: rawAmountToDecimal(network, transfer.transfer.amount), success: transfer.transfer.success, fromPublicKey: transfer.transfer.from.publicKey, toPublicKey: transfer.transfer.to.publicKey, diff --git a/src/utils/uniq.ts b/src/utils/uniq.ts index 39e96729..1f08816a 100644 --- a/src/utils/uniq.ts +++ b/src/utils/uniq.ts @@ -1,3 +1,19 @@ export function uniq(array: T[]) { return Array.from(new Set(array)); } + +export function uniqBy(array: T[], propGetter: (it: T) => any) { + const result = []; + + const set = new Set(); + for (const item of array) { + const prop = propGetter(item); + + if(!set.has(prop)) { + set.add(prop); + result.push(item); + } + } + + return result; +}