Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

walletd upgrades and refactor, send siafund support #422

Merged
merged 2 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/famous-owls-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@siafoundation/react-walletd': minor
---

Refactor types to match latest core changes.
5 changes: 5 additions & 0 deletions .changeset/quick-rats-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'walletd': minor
---

Ledger wallets now support sending siafunds.
5 changes: 5 additions & 0 deletions .changeset/rare-rings-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'walletd': minor
---

Seed wallets now support sending siafunds.
5 changes: 5 additions & 0 deletions .changeset/shaggy-bulldogs-smell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'walletd': minor
---

Event balances are now calculated with only relevant transaction components.
5 changes: 5 additions & 0 deletions .changeset/weak-peas-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'walletd': minor
---

The ledger generate addresses dialog now shows a close action if no new addresses have been generated.
6 changes: 5 additions & 1 deletion apps/walletd/components/Node/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export function Node() {
})
const { openDialog } = useDialog()

const transactionCount = txPool.data
? txPool.data.transactions.length + txPool.data.v2Transactions.length
: 0

return (
<WalletdAuthedLayout
routes={routes}
Expand All @@ -46,7 +50,7 @@ export function Node() {
// comment={!state.data?.synced ? 'Syncing' : undefined}
/>
<DatumCard label="Connected peers" value={peers.data?.length} />
<DatumCard label="Transactions in pool" value={txPool.data?.length} />
<DatumCard label="Transactions in pool" value={transactionCount} />
</div>
<div className="flex flex-wrap gap-7">
<div className="flex-1">
Expand Down
4 changes: 2 additions & 2 deletions apps/walletd/components/Wallet/WalletActionsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ export function WalletActionsMenu() {
variant="accent"
onClick={() => {
if (wallet?.type === 'seed') {
openDialog('walletSendSiacoinSeed', {
openDialog('walletSendSeed', {
walletId,
})
} else if (wallet?.type === 'ledger') {
openDialog('walletSendSiacoinLedger', {
openDialog('walletSendLedger', {
walletId,
})
}
Expand Down
34 changes: 15 additions & 19 deletions apps/walletd/contexts/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ import {
AddressRemoveDialogParams,
} from '../dialogs/AddressRemoveDialog'
import {
WalletSendSiacoinSeedDialog,
WalletSendSiacoinSeedDialogParams,
WalletSendSeedDialog,
WalletSendSeedDialogParams,
} from '../dialogs/WalletSendSiacoinSeedDialog'
import {
WalletSendSiacoinLedgerDialog,
WalletSendSiacoinLedgerDialogParams,
} from '../dialogs/WalletSendSiacoinLedgerDialog'
WalletSendLedgerDialog,
WalletSendLedgerDialogParams,
} from '../dialogs/WalletSendLedgerDialog'
import {
WalletUnlockDialog,
WalletUnlockDialogParams,
Expand All @@ -75,8 +75,8 @@ import {
type DialogParams = {
cmdk?: void
settings?: WalletdSettingsDialogParams
walletSendSiacoinSeed?: WalletSendSiacoinSeedDialogParams
walletSendSiacoinLedger?: WalletSendSiacoinLedgerDialogParams
walletSendSeed?: WalletSendSeedDialogParams
walletSendLedger?: WalletSendLedgerDialogParams
transactionDetails?: void
addressUpdate?: AddressUpdateDialogParams
addressRemove?: AddressRemoveDialogParams
Expand Down Expand Up @@ -255,22 +255,18 @@ export function Dialogs() {
}
onOpenChange={(val) => (val ? openDialog(dialog) : closeDialog())}
/>
<WalletSendSiacoinSeedDialog
open={dialog === 'walletSendSiacoinSeed'}
params={params['walletSendSiacoinSeed']}
<WalletSendSeedDialog
open={dialog === 'walletSendSeed'}
params={params['walletSendSeed']}
onOpenChange={(val) =>
val
? openDialog(dialog, params['walletSendSiacoinSeed'])
: closeDialog()
val ? openDialog(dialog, params['walletSendSeed']) : closeDialog()
}
/>
<WalletSendSiacoinLedgerDialog
open={dialog === 'walletSendSiacoinLedger'}
params={params['walletSendSiacoinLedger']}
<WalletSendLedgerDialog
open={dialog === 'walletSendLedger'}
params={params['walletSendLedger']}
onOpenChange={(val) =>
val
? openDialog(dialog, params['walletSendSiacoinLedger'])
: closeDialog()
val ? openDialog(dialog, params['walletSendLedger']) : closeDialog()
}
/>
<ConfirmDialog
Expand Down
88 changes: 24 additions & 64 deletions apps/walletd/contexts/events/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ValueCopyable,
LoadingDots,
ValueScFiat,
ValueSf,
} from '@siafoundation/design-system'
import { humanDate } from '@siafoundation/sia-js'
import { EventData, TableColumnId } from './types'
Expand Down Expand Up @@ -32,6 +33,19 @@ export const columns: EventsTableColumn[] = [
// )
// },
// },
{
id: 'transactionId',
label: 'transaction ID',
category: 'general',
render: ({ data: { transactionId } }) => {
if (!transactionId) {
return null
}
return (
<ValueCopyable size="12" value={transactionId} label="transaction ID" />
)
},
},
{
id: 'type',
label: 'type',
Expand Down Expand Up @@ -67,21 +81,6 @@ export const columns: EventsTableColumn[] = [
)
},
},
{
id: 'maturityHeight',
label: 'maturity height',
category: 'general',
render: ({ data: { maturityHeight } }) => {
if (!maturityHeight) {
return null
}
return (
<Text size="12" ellipsis>
{maturityHeight.toLocaleString()}
</Text>
)
},
},
{
id: 'timestamp',
label: 'timestamp',
Expand All @@ -106,11 +105,18 @@ export const columns: EventsTableColumn[] = [
label: 'amount',
category: 'general',
contentClassName: 'w-[120px] justify-end',
render: ({ data: { amount } }) => {
if (!amount) {
render: ({ data: { amountSc, amountSf } }) => {
if (!amountSc) {
return null
}
return <ValueScFiat displayBoth size="12" value={amount} />
return (
<div className="flex flex-col gap-2">
{!amountSc.isZero() && (
<ValueScFiat displayBoth size="12" value={amountSc} />
)}
{!!amountSf && <ValueSf size="12" value={amountSf} />}
</div>
)
},
},
{
Expand All @@ -125,19 +131,6 @@ export const columns: EventsTableColumn[] = [
return <ValueScFiat displayBoth size="12" variant="value" value={fee} />
},
},
{
id: 'transactionId',
label: 'transaction ID',
category: 'general',
render: ({ data: { transactionId } }) => {
if (!transactionId) {
return null
}
return (
<ValueCopyable size="12" value={transactionId} label="transaction ID" />
)
},
},
{
id: 'contractId',
label: 'contract ID',
Expand All @@ -149,37 +142,4 @@ export const columns: EventsTableColumn[] = [
return <ValueCopyable size="12" value={contractId} label="contract ID" />
},
},
{
id: 'outputId',
label: 'output ID',
category: 'general',
render: ({ data: { outputId } }) => {
if (!outputId) {
return null
}
return <ValueCopyable size="12" value={outputId} label="output ID" />
},
},
{
id: 'netAddress',
label: 'net address',
category: 'general',
render: ({ data: { netAddress } }) => {
if (!netAddress) {
return null
}
return <ValueCopyable size="12" value={netAddress} type="ip" />
},
},
{
id: 'publicKey',
label: 'public key',
category: 'general',
render: ({ data: { publicKey } }) => {
if (!publicKey) {
return null
}
return <ValueCopyable size="12" value={publicKey} label="public key" />
},
},
]
80 changes: 47 additions & 33 deletions apps/walletd/contexts/events/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,26 +74,52 @@ export function useEventsMain() {
return null
}
const dataTxPool: EventData[] = responseTxPool.data.map((e) => ({
id: e.ID,
id: e.id,
transactionId: e.id,
timestamp: 0,
pending: true,
type: e.type,
amount: new BigNumber(e.received).minus(e.sent),
}))
const dataEvents: EventData[] = responseEvents.data.map((e, index) => {
let amount = new BigNumber(0)
if (e.type === 'siacoin transfer') {
const inputsTotal =
e.val?.inputs?.reduce(
(acc, o) => acc.plus(o.value),
new BigNumber(0)
) || new BigNumber(0)
const outputsTotal =
e.val?.outputs?.reduce(
(acc, o) => acc.plus(o.value),
new BigNumber(0)
) || new BigNumber(0)
amount = outputsTotal.minus(inputsTotal)
let amountSc = new BigNumber(0)
let amountSf = 0
if (e.type === 'transaction') {
const inputsScTotal =
e.val?.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) => {
if (e.relevant.includes(o.siacoinOutput.address)) {
return acc.plus(o.siacoinOutput.value)
}
return acc
}, new BigNumber(0)) || new BigNumber(0)
amountSc = outputsScTotal.minus(inputsScTotal)

const inputsSfTotal =
e.val?.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) => {
if (e.relevant.includes(o.siafundOutput.address)) {
return acc + o.siafundOutput.value
}
return acc
}, 0) || 0
amountSf = outputsSfTotal - inputsSfTotal
}

if (e.type === 'miner payout') {
amountSc = new BigNumber(e.val.siacoinOutput.siacoinOutput.value)
}

const id = String(index)
Expand All @@ -103,30 +129,18 @@ export function useEventsMain() {
timestamp: new Date(e.timestamp).getTime(),
height: e.index.height,
pending: false,
amount,
}
if ('maturityHeight' in e.val) {
res.maturityHeight = e.val.maturityHeight
amountSc,
amountSf,
}
if ('fee' in e.val) {
res.fee = new BigNumber(e.val.fee)
}
if ('contractID' in e.val) {
res.contractId = e.val.contractID
}
if ('transactionID' in e.val) {
res.id += e.val.transactionID
res.transactionId = e.val.transactionID
}
if ('outputID' in e.val) {
res.id += e.val.outputID
res.outputId = e.val.outputID
}
if ('netAddress' in e.val) {
res.netAddress = e.val.netAddress
if ('fileContract' in e.val) {
res.contractId = e.val.fileContract.id
}
if ('publicKey' in e.val) {
res.publicKey = e.val.publicKey
if ('id' in e.val) {
res.id += e.val.id
res.transactionId = e.val.id
}
return res
})
Expand Down
Loading