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 6cc16c3
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 35 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/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 shown as locked. Closes https://github.com/SiaFoundation/walletd/issues/115
59 changes: 40 additions & 19 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 All @@ -22,23 +24,6 @@ export const columns: EventsTableColumn[] = [
// cellClassName: 'w-[50px] !pl-2 !pr-4 [&+*]:!pl-0',
// render: ({ data: { name } }) => null,
// },
// {
// id: 'id',
// label: 'ID',
// category: 'general',
// fixed: true,
// render: ({ data: { id }, context }) => {
// return (
// <ValueCopyable
// size="12"
// maxLength={20}
// value={id}
// type="transaction"
// siascanUrl={context.siascanUrl}
// />
// )
// },
// },
{
id: 'transactionId',
label: 'transaction ID',
Expand Down Expand Up @@ -75,7 +60,8 @@ export const columns: EventsTableColumn[] = [
id: 'height',
label: 'height',
category: 'general',
render: ({ data: { height, pending } }) => {
contentClassName: 'justify-end',
render: ({ data: { height, pending, maturityHeight, isMature } }) => {
if (pending) {
return (
<Text size="12" ellipsis>
Expand All @@ -86,8 +72,42 @@ export const columns: EventsTableColumn[] = [
if (!height) {
return null
}
if (height && maturityHeight && maturityHeight > height) {
return (
<Tooltip
content={
isMature
? 'The maturity height has been reached.'
: 'The maturity height has not been reached, therefore the output is still locked.'
}
>
<div className="flex flex-col gap-[5px]">
<div className="flex justify-end">
<Text
size="12"
font="mono"
ellipsis
color={isMature ? 'green' : 'red'}
className="flex gap-1 items-center"
>
{isMature ? <Unlocked16 /> : <Locked16 />}
{maturityHeight.toLocaleString()}
</Text>
</div>
<div className="flex justify-between items-end gap-1">
<div className="pl-[8px] pb-[6px]">
<div className="border-l border-b border-gray-800 dark:border-graydark-800 h-[20px] w-[7px]" />
</div>
<Text size="12" font="mono" color="subtle" ellipsis>
{height.toLocaleString()}
</Text>
</div>
</div>
</Tooltip>
)
}
return (
<Text size="12" ellipsis>
<Text size="12" font="mono" ellipsis>
{height.toLocaleString()}
</Text>
)
Expand All @@ -97,6 +117,7 @@ export const columns: EventsTableColumn[] = [
id: 'timestamp',
label: 'timestamp',
category: 'general',
contentClassName: 'justify-end',
render: ({ data: { timestamp, pending } }) => {
if (pending) {
return (
Expand Down
30 changes: 20 additions & 10 deletions apps/walletd/contexts/events/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import {
useDatasetEmptyState,
useServerFilters,
} from '@siafoundation/design-system'
import { useWalletEvents, useWalletTxPool } from '@siafoundation/walletd-react'
import {
useNodeState,
useWalletEvents,
useWalletTxPool,
} from '@siafoundation/walletd-react'
import { createContext, useContext, useMemo } from 'react'
import {
CellContext,
Expand All @@ -17,6 +21,7 @@ import { useRouter } from 'next/router'
import BigNumber from 'bignumber.js'
import { useSiascanUrl } from '../../hooks/useSiascanUrl'
import { defaultDatasetRefreshInterval } from '../../config/swr'
import { useSyncStatus } from '../../hooks/useSyncStatus'

const defaultLimit = 100

Expand Down Expand Up @@ -52,6 +57,7 @@ export function useEventsMain() {
},
})

const syncStatus = useSyncStatus()
const dataset = useMemo<EventData[] | null>(() => {
if (!responseEvents.data || !responseTxPool.data) {
return null
Expand All @@ -61,21 +67,22 @@ export function useEventsMain() {
timestamp: 0,
pending: true,
type: e.type,
isMature: false,
amount: new BigNumber(e.received).minus(e.sent),
}))
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 +91,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,31 +108,34 @@ 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 <= syncStatus.nodeBlockHeight
const res: EventData = {
id: e.id,
type: e.type,
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
})
return [...dataTxPool.reverse(), ...dataEvents]
}, [responseEvents.data, responseTxPool.data])
}, [responseEvents.data, responseTxPool.data, syncStatus.nodeBlockHeight])

const {
configurableColumns,
Expand Down
5 changes: 3 additions & 2 deletions apps/walletd/contexts/events/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ 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 =
// | 'actions'
// | 'id'
| 'transactionId'
| 'type'
| 'height'
Expand All @@ -31,7 +33,6 @@ export type TableColumnId =

export const columnsDefaultVisible: TableColumnId[] = [
// 'actions',
// 'id',
'transactionId',
'type',
'height',
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
1 change: 1 addition & 0 deletions libs/design-system/src/core/Separator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const styles = cva(['m-0 flex-shrink-0 cursor-default'], {
horizontal: 'border-b',
},
color: {
contrast: 'border-gray-700 dark:border-graydark-700',
subtle: 'border-gray-300 dark:border-graydark-300',
verySubtle: 'border-gray-100 dark:border-graydark-100',
panel: 'border-gray-100 dark:border-graydark-400/50',
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 6cc16c3

Please sign in to comment.