From 12fb3a4f3d943a3d7d31af0326e9b87a0c14a0c4 Mon Sep 17 00:00:00 2001 From: Alex Freska Date: Tue, 7 May 2024 08:24:45 -0400 Subject: [PATCH] fix: walletd events update --- .changeset/gentle-zoos-love.md | 6 +++ .changeset/quiet-starfishes-matter.md | 5 +++ .changeset/six-fishes-check.md | 5 +++ apps/walletd/contexts/events/columns.tsx | 38 +++++++++++++++++++ apps/walletd/contexts/events/index.tsx | 22 +++++++---- apps/walletd/contexts/events/types.ts | 5 +++ .../src/components/Table/TableRow.tsx | 1 + libs/walletd-types/src/types.ts | 9 +++-- 8 files changed, 79 insertions(+), 12 deletions(-) create mode 100644 .changeset/gentle-zoos-love.md create mode 100644 .changeset/quiet-starfishes-matter.md create mode 100644 .changeset/six-fishes-check.md diff --git a/.changeset/gentle-zoos-love.md b/.changeset/gentle-zoos-love.md new file mode 100644 index 000000000..044c8b5f6 --- /dev/null +++ b/.changeset/gentle-zoos-love.md @@ -0,0 +1,6 @@ +--- +'walletd': minor +'@siafoundation/walletd-types': minor +--- + +Updated wallet events to include maturityHeight and renamed val to data. Closes https://github.com/SiaFoundation/walletd/issues/114 diff --git a/.changeset/quiet-starfishes-matter.md b/.changeset/quiet-starfishes-matter.md new file mode 100644 index 000000000..64fec85fc --- /dev/null +++ b/.changeset/quiet-starfishes-matter.md @@ -0,0 +1,5 @@ +--- +'walletd': minor +--- + +Pending transaction event rows are now more opaque. diff --git a/.changeset/six-fishes-check.md b/.changeset/six-fishes-check.md new file mode 100644 index 000000000..49181c48d --- /dev/null +++ b/.changeset/six-fishes-check.md @@ -0,0 +1,5 @@ +--- +'walletd': minor +--- + +The events list now shows the maturity height, transactions that have not reached this height are more opaque and shown as locked. Closes https://github.com/SiaFoundation/walletd/issues/115 diff --git a/apps/walletd/contexts/events/columns.tsx b/apps/walletd/contexts/events/columns.tsx index 658a86520..d5bc18e54 100644 --- a/apps/walletd/contexts/events/columns.tsx +++ b/apps/walletd/contexts/events/columns.tsx @@ -5,9 +5,11 @@ import { LoadingDots, ValueScFiat, ValueSf, + Tooltip, } from '@siafoundation/design-system' import { humanDate } from '@siafoundation/units' import { CellContext, EventData, TableColumnId } from './types' +import { Locked16, Unlocked16 } from '@carbon/icons-react' type EventsTableColumn = TableColumn & { fixed?: boolean @@ -93,6 +95,42 @@ export const columns: EventsTableColumn[] = [ ) }, }, + { + id: 'maturityHeight', + label: 'maturity height', + category: 'general', + render: ({ data: { pending, maturityHeight, isMature } }) => { + if (pending) { + return ( + + + + ) + } + if (!maturityHeight) { + return null + } + return ( + + + {isMature ? : } + {maturityHeight.toLocaleString()} + + + ) + }, + }, { id: 'timestamp', label: 'timestamp', diff --git a/apps/walletd/contexts/events/index.tsx b/apps/walletd/contexts/events/index.tsx index dc2a93a65..18ab6d851 100644 --- a/apps/walletd/contexts/events/index.tsx +++ b/apps/walletd/contexts/events/index.tsx @@ -61,21 +61,23 @@ export function useEventsMain() { timestamp: 0, pending: true, type: e.type, + isMature: false, amount: new BigNumber(e.received).minus(e.sent), + className: 'opacity-50', })) const dataEvents: EventData[] = responseEvents.data.map((e, index) => { let amountSc = new BigNumber(0) let amountSf = 0 if (e.type === 'transaction') { const inputsScTotal = - e.val?.siacoinInputs?.reduce((acc, o) => { + e.data?.siacoinInputs?.reduce((acc, o) => { if (e.relevant.includes(o.siacoinOutput.address)) { return acc.plus(o.siacoinOutput.value) } return acc }, new BigNumber(0)) || new BigNumber(0) const outputsScTotal = - e.val?.siacoinOutputs?.reduce((acc, o) => { + e.data?.siacoinOutputs?.reduce((acc, o) => { if (e.relevant.includes(o.siacoinOutput.address)) { return acc.plus(o.siacoinOutput.value) } @@ -84,14 +86,14 @@ export function useEventsMain() { amountSc = outputsScTotal.minus(inputsScTotal) const inputsSfTotal = - e.val?.siafundInputs?.reduce((acc, o) => { + e.data?.siafundInputs?.reduce((acc, o) => { if (e.relevant.includes(o.siafundElement.siafundOutput.address)) { return acc + o.siafundElement.siafundOutput.value } return acc }, 0) || 0 const outputsSfTotal = - e.val?.siafundOutputs?.reduce((acc, o) => { + e.data?.siafundOutputs?.reduce((acc, o) => { if (e.relevant.includes(o.siafundOutput.address)) { return acc + o.siafundOutput.value } @@ -101,26 +103,30 @@ export function useEventsMain() { } if (e.type === 'miner payout') { - amountSc = new BigNumber(e.val.siacoinOutput.siacoinOutput.value) + amountSc = new BigNumber(e.data.siacoinOutput.siacoinOutput.value) } if (e.type === 'foundation subsidy') { - amountSc = new BigNumber(e.val.siacoinOutput.siacoinOutput.value) + amountSc = new BigNumber(e.data.siacoinOutput.siacoinOutput.value) } + const isMature = e.maturityHeight <= e.index.height const res: EventData = { id: e.id, type: e.type, + className: isMature ? '' : 'opacity-50', timestamp: new Date(e.timestamp).getTime(), + maturityHeight: e.maturityHeight, + isMature, height: e.index.height, pending: false, amountSc, amountSf, } if (e.type === 'transaction') { - res.fee = new BigNumber(e.val.fee) + res.fee = new BigNumber(e.data.fee) } if (e.type === 'contract payout') { - res.contractId = e.val.fileContract.id + res.contractId = e.data.fileContract.id } return res }) diff --git a/apps/walletd/contexts/events/types.ts b/apps/walletd/contexts/events/types.ts index b6b617ad5..5854d19a6 100644 --- a/apps/walletd/contexts/events/types.ts +++ b/apps/walletd/contexts/events/types.ts @@ -9,12 +9,15 @@ export type EventData = { transactionId?: string timestamp: number height?: number + maturityHeight?: number + isMature?: boolean pending: boolean type: string fee?: BigNumber amountSc?: BigNumber amountSf?: number contractId?: string + className?: string } export type TableColumnId = @@ -23,6 +26,7 @@ export type TableColumnId = | 'transactionId' | 'type' | 'height' + | 'maturityHeight' | 'timestamp' | 'amount' | 'fee' @@ -35,6 +39,7 @@ export const columnsDefaultVisible: TableColumnId[] = [ 'transactionId', 'type', 'height', + 'maturityHeight', 'timestamp', 'amount', 'fee', diff --git a/libs/design-system/src/components/Table/TableRow.tsx b/libs/design-system/src/components/Table/TableRow.tsx index ab482aedb..cf936b92f 100644 --- a/libs/design-system/src/components/Table/TableRow.tsx +++ b/libs/design-system/src/components/Table/TableRow.tsx @@ -91,6 +91,7 @@ export function createTableRow< className={cx( 'border-b border-gray-200/50 dark:border-graydark-100', data.onClick ? 'cursor-pointer' : '', + data.className, className )} > diff --git a/libs/walletd-types/src/types.ts b/libs/walletd-types/src/types.ts index 02543377e..2d635ccbd 100644 --- a/libs/walletd-types/src/types.ts +++ b/libs/walletd-types/src/types.ts @@ -39,6 +39,7 @@ export type WalletEventBase = { id: Hash256 timestamp: string index: ChainIndex + maturityHeight: number relevant: Address[] } @@ -67,7 +68,7 @@ export type WalletHostAnnouncement = { export type WalletEventTransaction = WalletEventBase & { type: 'transaction' - val: { + data: { siacoinInputs?: SiacoinElement[] siacoinOutputs?: SiacoinElement[] siafundInputs?: WalletSiafundInput[] @@ -81,14 +82,14 @@ export type WalletEventTransaction = WalletEventBase & { export type WalletEventMinerPayout = WalletEventBase & { type: 'miner payout' - val: { + data: { siacoinOutput: SiacoinElement } } export type WalletEventContractPayout = WalletEventBase & { type: 'contract payout' - val: { + data: { fileContract: FileContractElement siacoinOutput: SiacoinElement missed: boolean @@ -101,7 +102,7 @@ export type WalletEventSiafundClaim = WalletEventBase & { export type WalletEventFoundationSubsidy = WalletEventBase & { type: 'foundation subsidy' - val: { + data: { siacoinOutput: SiacoinElement } }