Skip to content

Commit

Permalink
feat: walletd send siafunds
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Nov 28, 2023
1 parent f1da1d9 commit ccf9e17
Show file tree
Hide file tree
Showing 50 changed files with 1,992 additions and 1,713 deletions.
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
74 changes: 13 additions & 61 deletions apps/walletd/contexts/events/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,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 @@ -68,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 Down Expand Up @@ -133,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 @@ -157,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" />
},
},
]
51 changes: 29 additions & 22 deletions apps/walletd/contexts/events/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import {
useServerFilters,
} from '@siafoundation/design-system'
import {
WalletEventMinerPayout,
WalletEventTransaction,
useWalletEvents,
useWalletSubscribe,
useWalletTxPool,
Expand Down Expand Up @@ -76,7 +74,8 @@ 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,
Expand All @@ -87,27 +86,35 @@ export function useEventsMain() {
let amountSf = 0
if (e.type === 'transaction') {
const inputsScTotal =
e.val?.siacoinInputs?.reduce(
(acc, o) => acc.plus(o.siacoinOutput.value),
new BigNumber(0)
) || new BigNumber(0)
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) => acc.plus(o.siacoinOutput.value),
new BigNumber(0)
) || new BigNumber(0)
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) => acc + o.siafundElement.siafundOutput.value,
0
) || 0
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) => acc + o.siafundOutput.value,
0
) || 0
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
}

Expand All @@ -131,9 +138,9 @@ export function useEventsMain() {
if ('fileContract' in e.val) {
res.contractId = e.val.fileContract.id
}
if ('transactionID' in e.val) {
res.id += e.val.transactionID
res.transactionId = e.val.transactionID
if ('id' in e.val) {
res.id += e.val.id
res.transactionId = e.val.id
}
return res
})
Expand Down
4 changes: 3 additions & 1 deletion apps/walletd/contexts/events/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@ import BigNumber from 'bignumber.js'

export type EventData = {
id: string
transactionId?: string
timestamp: number
height?: number
pending: boolean
type: string
fee?: BigNumber
amountSc?: BigNumber
amountSf?: number
transactionId?: string
contractId?: string
}

export type TableColumnId =
// | 'actions'
// | 'id'
| 'transactionId'
| 'type'
| 'height'
| 'timestamp'
Expand All @@ -27,6 +28,7 @@ export type TableColumnId =
export const columnsDefaultVisible: TableColumnId[] = [
// 'actions',
// 'id',
'transactionId',
'type',
'height',
'timestamp',
Expand Down
12 changes: 2 additions & 10 deletions apps/walletd/dialogs/WalletAddressesGenerateLedgerDialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,6 @@ export function WalletAddressesGenerateLedgerDialog({
return indiciesWithAddresses
}, [existingAddresses, indices])

const newIncompleteAddresses = useMemo(
() =>
Object.entries(indiciesWithAddresses)
.filter(([index, item]) => item.isNew && !item.address)
.map(([index, item]) => item),
[indiciesWithAddresses]
)

const newGeneratedAddresses = useMemo(
() =>
Object.entries(indiciesWithAddresses)
Expand Down Expand Up @@ -287,15 +279,15 @@ export function WalletAddressesGenerateLedgerDialog({
})

const onSubmit = useCallback(async () => {
if (newIncompleteAddresses.length === 0) {
if (newGeneratedAddresses.length === 0) {
triggerErrorToast(
'Add and generate addresses with your Ledger device to continue.'
)
return
}
await saveAddresses()
closeAndReset()
}, [newIncompleteAddresses, saveAddresses, closeAndReset])
}, [newGeneratedAddresses, saveAddresses, closeAndReset])

return (
<Dialog
Expand Down
Loading

0 comments on commit ccf9e17

Please sign in to comment.