Skip to content

Commit

Permalink
fix: walletd events update
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed May 7, 2024
1 parent e989296 commit 7d4ba80
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 12 deletions.
6 changes: 6 additions & 0 deletions .changeset/gentle-zoos-love.md
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions .changeset/quiet-starfishes-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'walletd': minor
---

Pending transaction event rows are now more opaque.
5 changes: 5 additions & 0 deletions .changeset/six-fishes-check.md
Original file line number Diff line number Diff line change
@@ -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
38 changes: 38 additions & 0 deletions apps/walletd/contexts/events/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 '@siafoundation/react-icons'

type EventsTableColumn = TableColumn<TableColumnId, EventData, CellContext> & {
fixed?: boolean
Expand Down Expand Up @@ -93,6 +95,42 @@ export const columns: EventsTableColumn[] = [
)
},
},
{
id: 'maturityHeight',
label: 'maturity height',
category: 'general',
render: ({ data: { pending, maturityHeight, isMature } }) => {
if (pending) {
return (
<Text size="12" ellipsis>
<LoadingDots />
</Text>
)
}
if (!maturityHeight) {
return null
}
return (
<Tooltip
content={
isMature
? 'The maturity height has been reached.'
: 'The maturity height has not been reached, therefore the output is still locked.'
}
>
<Text
size="12"
ellipsis
color={isMature ? 'green' : 'red'}
className="flex gap-1 items-center"
>
{isMature ? <Unlocked16 /> : <Locked16 />}
{maturityHeight.toLocaleString()}
</Text>
</Tooltip>
)
},
},
{
id: 'timestamp',
label: 'timestamp',
Expand Down
22 changes: 14 additions & 8 deletions apps/walletd/contexts/events/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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
}
Expand All @@ -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
})
Expand Down
5 changes: 5 additions & 0 deletions apps/walletd/contexts/events/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -23,6 +26,7 @@ export type TableColumnId =
| 'transactionId'
| 'type'
| 'height'
| 'maturityHeight'
| 'timestamp'
| 'amount'
| 'fee'
Expand All @@ -35,6 +39,7 @@ export const columnsDefaultVisible: TableColumnId[] = [
'transactionId',
'type',
'height',
'maturityHeight',
'timestamp',
'amount',
'fee',
Expand Down
2 changes: 2 additions & 0 deletions libs/design-system/src/components/Table/TableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Data = {
id: string
isDraggable?: boolean
isDroppable?: boolean
className?: string
onClick?: () => void
}

Expand Down Expand Up @@ -91,6 +92,7 @@ export function createTableRow<
className={cx(
'border-b border-gray-200/50 dark:border-graydark-100',
data.onClick ? 'cursor-pointer' : '',
data.className,
className
)}
>
Expand Down
9 changes: 5 additions & 4 deletions libs/walletd-types/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export type WalletEventBase = {
id: Hash256
timestamp: string
index: ChainIndex
maturityHeight: number
relevant: Address[]
}

Expand Down Expand Up @@ -67,7 +68,7 @@ export type WalletHostAnnouncement = {

export type WalletEventTransaction = WalletEventBase & {
type: 'transaction'
val: {
data: {
siacoinInputs?: SiacoinElement[]
siacoinOutputs?: SiacoinElement[]
siafundInputs?: WalletSiafundInput[]
Expand All @@ -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
Expand All @@ -101,7 +102,7 @@ export type WalletEventSiafundClaim = WalletEventBase & {

export type WalletEventFoundationSubsidy = WalletEventBase & {
type: 'foundation subsidy'
val: {
data: {
siacoinOutput: SiacoinElement
}
}
Expand Down

0 comments on commit 7d4ba80

Please sign in to comment.