Skip to content

Commit

Permalink
refactor(renterd): migrate to events apis and remove other deprecated…
Browse files Browse the repository at this point in the history
… apis
  • Loading branch information
alexfreska committed Sep 17, 2024
1 parent 978b70a commit 64d82fc
Show file tree
Hide file tree
Showing 26 changed files with 582 additions and 312 deletions.
5 changes: 5 additions & 0 deletions .changeset/beige-cycles-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'renterd': minor
---

The transactions list now includes more details such as specific transaction types and maturity height for locked siacoin.
7 changes: 7 additions & 0 deletions .changeset/cold-poems-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@siafoundation/renterd-js': minor
'@siafoundation/renterd-react': minor
'@siafoundation/renterd-types': minor
---

Removed deprecated wallet transactions and pending transactions APIs.
5 changes: 5 additions & 0 deletions .changeset/fifty-dots-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@siafoundation/design-system': minor
---

Authed layout, wallet balance, and wallet layout actions now require immature balance value.
7 changes: 7 additions & 0 deletions .changeset/poor-berries-sin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@siafoundation/renterd-js': minor
'@siafoundation/renterd-react': minor
'@siafoundation/renterd-types': minor
---

Added wallet events and pending events APIs.
7 changes: 7 additions & 0 deletions .changeset/silent-icons-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@siafoundation/renterd-js': minor
'@siafoundation/renterd-react': minor
'@siafoundation/renterd-types': minor
---

Removed deprecated wallet discard, fund, sign, and outputs APIs.
2 changes: 1 addition & 1 deletion apps/hostd/contexts/transactions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function useTransactionsMain() {
sortField,
sortDirection,
resetDefaultColumnVisibility,
} = useTableState('walletd/v0/events', {
} = useTableState('hostd/v0/events', {
columns,
columnsDefaultVisible,
sortOptions,
Expand Down
88 changes: 59 additions & 29 deletions apps/renterd-e2e/src/specs/wallet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import BigNumber from 'bignumber.js'
import { setSwitchByLabel } from '../fixtures/switchValue'

test.beforeEach(async ({ page }) => {
await beforeTest(page, false)
await beforeTest(page)
})

test('send siacoin with include fee off', async ({ page }) => {
Expand Down Expand Up @@ -66,20 +66,35 @@ test('send siacoin with include fee off', async ({ page }) => {
await expect(sendDialog.getByTestId('transactionId')).toBeVisible()

// List.
// TODO: Add this after we migrate to the new events API.
// await sendDialog.getByRole('button', { name: 'Close' }).click()
// await expect(page.getByTestId('eventsTable')).toBeVisible()
// await expect(
// page.getByTestId('eventsTable').locator('tbody tr').first()
// ).toBeVisible()
// await expect(
// page
// .getByTestId('eventsTable')
// .locator('tbody tr')
// .first()
// .getByTestId('amount')
// .getByText(`-${amountWithFeeString}`)
// ).toBeVisible()
await sendDialog.getByRole('button', { name: 'Close' }).click()
await expect(page.getByTestId('eventsTable')).toBeVisible()
await expect(
page.getByTestId('eventsTable').locator('tbody tr').first()
).toBeVisible()
await expect(
page
.getByTestId('eventsTable')
.locator('tbody tr')
.first()
.getByTestId('amount')
.getByText(`-${amountWithFeeString}`)
).toBeVisible()
await expect(
page
.getByTestId('eventsTable')
.locator('tbody tr')
.first()
.getByTestId('type')
.getByText('siacoin transfer')
).toBeVisible()
await expect(
page
.getByTestId('eventsTable')
.locator('tbody tr')
.first()
.getByTestId('fee')
.getByText('12.000 mS')
).toBeVisible()
})

test('send siacoin with include fee on', async ({ page }) => {
Expand Down Expand Up @@ -139,18 +154,33 @@ test('send siacoin with include fee on', async ({ page }) => {
await expect(sendDialog.getByTestId('transactionId')).toBeVisible()

// List.
// TODO: Add this after we migrate to the new events API.
// await sendDialog.getByRole('button', { name: 'Close' }).click()
// await expect(page.getByTestId('eventsTable')).toBeVisible()
// await expect(
// page.getByTestId('eventsTable').locator('tbody tr').first()
// ).toBeVisible()
// await expect(
// page
// .getByTestId('eventsTable')
// .locator('tbody tr')
// .first()
// .getByTestId('amount')
// .getByText(`-${amountWithFeeString}`)
// ).toBeVisible()
await sendDialog.getByRole('button', { name: 'Close' }).click()
await expect(page.getByTestId('eventsTable')).toBeVisible()
await expect(
page.getByTestId('eventsTable').locator('tbody tr').first()
).toBeVisible()
await expect(
page
.getByTestId('eventsTable')
.locator('tbody tr')
.first()
.getByTestId('amount')
.getByText(`-${amountString}`)
).toBeVisible()
await expect(
page
.getByTestId('eventsTable')
.locator('tbody tr')
.first()
.getByTestId('type')
.getByText('siacoin transfer')
).toBeVisible()
await expect(
page
.getByTestId('eventsTable')
.locator('tbody tr')
.first()
.getByTestId('fee')
.getByText('12.000 mS')
).toBeVisible()
})
1 change: 1 addition & 0 deletions apps/renterd/components/RenterdAuthedLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export function RenterdAuthedLayout(
spendable: new BigNumber(wallet.data.spendable),
confirmed: new BigNumber(wallet.data.confirmed),
unconfirmed: new BigNumber(wallet.data.unconfirmed),
immature: new BigNumber(wallet.data.immature),
}
}
{...props}
Expand Down
15 changes: 15 additions & 0 deletions apps/renterd/components/Wallet/StateError.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Text } from '@siafoundation/design-system'
import { MisuseOutline32 } from '@siafoundation/react-icons'

export function StateError() {
return (
<div className="flex flex-col gap-10 justify-center items-center h-[400px]">
<Text>
<MisuseOutline32 className="scale-[200%]" />
</Text>
<Text color="subtle" className="text-center max-w-[500px]">
Error fetching transactions.
</Text>
</div>
)
}
15 changes: 15 additions & 0 deletions apps/renterd/components/Wallet/StateNoneMatching.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Text } from '@siafoundation/design-system'
import { Filter32 } from '@siafoundation/react-icons'

export function StateNoneMatching() {
return (
<div className="flex flex-col gap-10 justify-center items-center h-[400px]">
<Text>
<Filter32 className="scale-[200%]" />
</Text>
<Text color="subtle" className="text-center max-w-[500px]">
No transactions matching filters.
</Text>
</div>
)
}
15 changes: 15 additions & 0 deletions apps/renterd/components/Wallet/StateNoneYet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Text } from '@siafoundation/design-system'
import { Money32 } from '@siafoundation/react-icons'

export function StateNoneYet() {
return (
<div className="flex flex-col gap-10 justify-center items-center h-[400px]">
<Text>
<Money32 className="scale-[200%]" />
</Text>
<Text color="subtle" className="text-center max-w-[500px]">
The wallet has no transactions yet.
</Text>
</div>
)
}
13 changes: 12 additions & 1 deletion apps/renterd/components/Wallet/WalletFilterBar.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { WalletSyncWarning } from '@siafoundation/design-system'
import {
PaginatorUnknownTotal,
WalletSyncWarning,
} from '@siafoundation/design-system'
import { useSyncStatus } from '../../hooks/useSyncStatus'
import { useTransactions } from '../../contexts/transactions'

export function WalletFilterBar() {
const { isSynced, syncPercent, isWalletSynced, walletScanPercent } =
useSyncStatus()
const { offset, limit, pageCount, dataState } = useTransactions()
return (
<div className="flex gap-2 w-full">
<WalletSyncWarning
Expand All @@ -13,6 +18,12 @@ export function WalletFilterBar() {
walletScanPercent={walletScanPercent}
/>
<div className="flex-1" />
<PaginatorUnknownTotal
offset={offset}
limit={limit}
pageTotal={pageCount}
isLoading={dataState === 'loading'}
/>
</div>
)
}
57 changes: 39 additions & 18 deletions apps/renterd/components/Wallet/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
BalanceEvolution,
EntityList,
PaginatorUnknownTotal,
Table,
WalletLayoutActions,
} from '@siafoundation/design-system'
import { useWallet } from '@siafoundation/renterd-react'
Expand All @@ -11,18 +10,32 @@ import BigNumber from 'bignumber.js'
import { RenterdSidenav } from '../RenterdSidenav'
import { RenterdAuthedLayout } from '../RenterdAuthedLayout'
import { useSyncStatus } from '../../hooks/useSyncStatus'
import { EmptyState } from './EmptyState'
import { useTransactions } from '../../contexts/transactions'
import { WalletFilterBar } from './WalletFilterBar'
import { StateNoneMatching } from './StateNoneMatching'
import { StateNoneYet } from './StateNoneYet'
import { StateError } from './StateError'

export function Wallet() {
const { openDialog } = useDialog()
const wallet = useWallet()
const { dataset, offset, limit, pageCount, dataState, balances, metrics } =
useTransactions()
const { isSynced, syncPercent, isWalletSynced, walletScanPercent } =
const { isSynced, isWalletSynced, syncPercent, walletScanPercent } =
useSyncStatus()

const {
balances,
metrics,
dataset,
dataState,
columns,
cellContext,
sortableColumns,
sortDirection,
sortField,
toggleSort,
defaultPageSize,
} = useTransactions()

return (
<RenterdAuthedLayout
routes={routes}
Expand All @@ -41,6 +54,7 @@ export function Wallet() {
spendable: new BigNumber(wallet.data.spendable),
unconfirmed: new BigNumber(wallet.data.unconfirmed),
confirmed: new BigNumber(wallet.data.confirmed),
immature: new BigNumber(wallet.data.immature),
}
: undefined
}
Expand All @@ -50,7 +64,7 @@ export function Wallet() {
}
stats={<WalletFilterBar />}
>
<div className="p-6 flex flex-col gap-5">
<div className="flex flex-col gap-4 px-6 py-7 min-w-fit">
{balances?.length ? (
<BalanceEvolution
// see comment above
Expand All @@ -59,19 +73,26 @@ export function Wallet() {
isLoading={metrics.isValidating}
/>
) : null}
<EntityList
title="Transactions"
<Table
testId="eventsTable"
isLoading={dataState === 'loading'}
dataset={dataset}
emptyState={<EmptyState />}
actions={
<PaginatorUnknownTotal
offset={offset}
limit={limit}
pageTotal={pageCount}
isLoading={dataState === 'loading'}
/>
emptyState={
dataState === 'noneMatchingFilters' ? (
<StateNoneMatching />
) : dataState === 'noneYet' ? (
<StateNoneYet />
) : dataState === 'error' ? (
<StateError />
) : null
}
pageSize={defaultPageSize}
data={dataset}
context={cellContext}
columns={columns}
sortableColumns={sortableColumns}
sortDirection={sortDirection}
sortField={sortField}
toggleSort={toggleSort}
/>
</div>
</RenterdAuthedLayout>
Expand Down
Loading

0 comments on commit 64d82fc

Please sign in to comment.