From d2d159f8e46ca935ccb87877ed2999d5a34e3355 Mon Sep 17 00:00:00 2001 From: Alex Freska Date: Sun, 14 Apr 2024 20:04:22 +0200 Subject: [PATCH] refactor: split out walletd-types --- .changeset/clean-hairs-tell.md | 5 + apps/walletd-e2e/src/fixtures/createWallet.ts | 6 +- .../src/specs/seedSendSiacoin.spec.ts | 2 +- apps/walletd/contexts/addresses/dataset.tsx | 4 +- apps/walletd/contexts/addresses/types.ts | 2 +- apps/walletd/contexts/wallets/index.tsx | 6 +- apps/walletd/contexts/wallets/types.ts | 2 +- .../dialogs/WalletAddLedgerDialog/index.tsx | 5 +- .../dialogs/WalletAddNewDialog/index.tsx | 3 +- .../dialogs/WalletAddRecoverDialog/index.tsx | 3 +- .../dialogs/WalletAddWatchDialog/index.tsx | 3 +- .../dialogs/WalletAddressesAddDialog.tsx | 6 +- .../index.tsx | 6 +- .../index.tsx | 6 +- apps/walletd/lib/testMocks.ts | 2 +- libs/walletd-mock/package.json | 4 +- libs/walletd-mock/src/mocks/consensusTip.ts | 2 +- libs/walletd-mock/src/mocks/defaults.ts | 2 +- libs/walletd-mock/src/mocks/peers.ts | 2 +- libs/walletd-mock/src/mocks/rescan.ts | 2 +- libs/walletd-mock/src/mocks/wallet.ts | 8 +- .../walletd-mock/src/mocks/walletAddresses.ts | 2 +- libs/walletd-mock/src/mocks/walletBalance.ts | 2 +- libs/walletd-mock/src/mocks/walletEvents.ts | 2 +- .../src/mocks/walletFundSiacoin.ts | 6 +- .../src/mocks/walletFundSiafund.ts | 6 +- .../src/mocks/walletOutputsSiacoin.ts | 2 +- .../src/mocks/walletOutputsSiafund.ts | 2 +- libs/walletd-mock/src/mocks/walletRelease.ts | 4 +- libs/walletd-mock/src/mocks/walletTxPool.ts | 2 +- libs/walletd-mock/src/mocks/wallets.ts | 2 +- libs/walletd-mock/src/scenarios/seedWallet.ts | 6 +- libs/walletd-react/package.json | 6 +- libs/walletd-react/src/api.ts | 282 +++++++++--------- libs/walletd-react/src/index.ts | 1 - libs/walletd-types/.babelrc | 12 + libs/walletd-types/.eslintrc.json | 21 ++ libs/walletd-types/README.md | 3 + libs/walletd-types/jest.config.ts | 17 ++ libs/walletd-types/package.json | 10 + libs/walletd-types/project.json | 42 +++ libs/walletd-types/rollup.config.js | 18 ++ libs/walletd-types/src/api.ts | 189 ++++++++++++ libs/walletd-types/src/index.ts | 2 + .../src/types.ts} | 0 libs/walletd-types/tsconfig.json | 25 ++ libs/walletd-types/tsconfig.lib.json | 22 ++ libs/walletd-types/tsconfig.spec.json | 19 ++ tsconfig.base.json | 1 + 49 files changed, 578 insertions(+), 209 deletions(-) create mode 100644 .changeset/clean-hairs-tell.md create mode 100644 libs/walletd-types/.babelrc create mode 100644 libs/walletd-types/.eslintrc.json create mode 100644 libs/walletd-types/README.md create mode 100644 libs/walletd-types/jest.config.ts create mode 100644 libs/walletd-types/package.json create mode 100644 libs/walletd-types/project.json create mode 100644 libs/walletd-types/rollup.config.js create mode 100644 libs/walletd-types/src/api.ts create mode 100644 libs/walletd-types/src/index.ts rename libs/{walletd-react/src/siaTypes.ts => walletd-types/src/types.ts} (100%) create mode 100644 libs/walletd-types/tsconfig.json create mode 100644 libs/walletd-types/tsconfig.lib.json create mode 100644 libs/walletd-types/tsconfig.spec.json diff --git a/.changeset/clean-hairs-tell.md b/.changeset/clean-hairs-tell.md new file mode 100644 index 000000000..6d79daf18 --- /dev/null +++ b/.changeset/clean-hairs-tell.md @@ -0,0 +1,5 @@ +--- +'@siafoundation/walletd-types': minor +--- + +Introduced new library for walletd types. diff --git a/apps/walletd-e2e/src/fixtures/createWallet.ts b/apps/walletd-e2e/src/fixtures/createWallet.ts index 7c157b0d9..623ef908b 100644 --- a/apps/walletd-e2e/src/fixtures/createWallet.ts +++ b/apps/walletd-e2e/src/fixtures/createWallet.ts @@ -4,9 +4,9 @@ import { Wallet, WalletAddressesResponse, WalletBalanceResponse, - WalletFundResponse, + WalletFundSiacoinResponse, WalletOutputsSiacoinResponse, -} from '@siafoundation/walletd-react' +} from '@siafoundation/walletd-types' export async function createWallet({ page, @@ -21,7 +21,7 @@ export async function createWallet({ responses?: { balance?: WalletBalanceResponse outputsSiacoin?: WalletOutputsSiacoinResponse - fund?: WalletFundResponse + fundSiacoin?: WalletFundSiacoinResponse addresses?: WalletAddressesResponse } expects?: { diff --git a/apps/walletd-e2e/src/specs/seedSendSiacoin.spec.ts b/apps/walletd-e2e/src/specs/seedSendSiacoin.spec.ts index a89d309e3..385d42fb7 100644 --- a/apps/walletd-e2e/src/specs/seedSendSiacoin.spec.ts +++ b/apps/walletd-e2e/src/specs/seedSendSiacoin.spec.ts @@ -87,7 +87,7 @@ test('errors if the input to sign is not found on the transaction', async ({ mnemonic, responses: { ...getDefaultMockWalletResponses(mocks), - fund: mockFundInvalid, + fundSiacoin: mockFundInvalid, }, expects: { fundSiacoinPost: (data) => diff --git a/apps/walletd/contexts/addresses/dataset.tsx b/apps/walletd/contexts/addresses/dataset.tsx index 59727a9cc..2e2a4fa4a 100644 --- a/apps/walletd/contexts/addresses/dataset.tsx +++ b/apps/walletd/contexts/addresses/dataset.tsx @@ -5,8 +5,8 @@ import { import { WalletAddressMetadata, WalletAddressesResponse, - useWalletAddresses, -} from '@siafoundation/walletd-react' +} from '@siafoundation/walletd-types' +import { useWalletAddresses } from '@siafoundation/walletd-react' import { useMemo } from 'react' import { AddressData } from './types' import { OpenDialog, useDialog } from '../dialog' diff --git a/apps/walletd/contexts/addresses/types.ts b/apps/walletd/contexts/addresses/types.ts index 584759329..7f2ed661d 100644 --- a/apps/walletd/contexts/addresses/types.ts +++ b/apps/walletd/contexts/addresses/types.ts @@ -1,7 +1,7 @@ import { WalletAddress, WalletAddressMetadata, -} from '@siafoundation/walletd-react' +} from '@siafoundation/walletd-types' export type CellContext = { siascanUrl: string diff --git a/apps/walletd/contexts/wallets/index.tsx b/apps/walletd/contexts/wallets/index.tsx index 59f697987..2c450c906 100644 --- a/apps/walletd/contexts/wallets/index.tsx +++ b/apps/walletd/contexts/wallets/index.tsx @@ -4,10 +4,8 @@ import { useClientFilters, useClientFilteredDataset, } from '@siafoundation/design-system' -import { - WalletMetadata, - useWallets as useWalletsData, -} from '@siafoundation/walletd-react' +import { WalletMetadata } from '@siafoundation/walletd-types' +import { useWallets as useWalletsData } from '@siafoundation/walletd-react' import { createContext, useContext, useEffect, useMemo } from 'react' import { WalletData, diff --git a/apps/walletd/contexts/wallets/types.ts b/apps/walletd/contexts/wallets/types.ts index f740cd9a4..e5ef8162f 100644 --- a/apps/walletd/contexts/wallets/types.ts +++ b/apps/walletd/contexts/wallets/types.ts @@ -1,4 +1,4 @@ -import { Wallet, WalletMetadata } from '@siafoundation/walletd-react' +import { Wallet, WalletMetadata } from '@siafoundation/walletd-types' export type WalletData = { id: string diff --git a/apps/walletd/dialogs/WalletAddLedgerDialog/index.tsx b/apps/walletd/dialogs/WalletAddLedgerDialog/index.tsx index 118867cb0..8a85cdae6 100644 --- a/apps/walletd/dialogs/WalletAddLedgerDialog/index.tsx +++ b/apps/walletd/dialogs/WalletAddLedgerDialog/index.tsx @@ -15,9 +15,8 @@ import { useForm } from 'react-hook-form' import { WalletAddressMetadata, WalletMetadata, - useWalletAdd, - useWalletAddressAdd, -} from '@siafoundation/walletd-react' +} from '@siafoundation/walletd-types' +import { useWalletAdd, useWalletAddressAdd } from '@siafoundation/walletd-react' import { useDialog } from '../../contexts/dialog' import { useWallets } from '../../contexts/wallets' import { walletAddTypes } from '../../config/walletTypes' diff --git a/apps/walletd/dialogs/WalletAddNewDialog/index.tsx b/apps/walletd/dialogs/WalletAddNewDialog/index.tsx index 79793ad79..17a018804 100644 --- a/apps/walletd/dialogs/WalletAddNewDialog/index.tsx +++ b/apps/walletd/dialogs/WalletAddNewDialog/index.tsx @@ -13,7 +13,8 @@ import { import { Redo16, Copy16 } from '@siafoundation/react-icons' import { MouseEvent, useCallback, useEffect } from 'react' import { useForm } from 'react-hook-form' -import { WalletMetadata, useWalletAdd } from '@siafoundation/walletd-react' +import { WalletMetadata } from '@siafoundation/walletd-types' +import { useWalletAdd } from '@siafoundation/walletd-react' import { useDialog } from '../../contexts/dialog' import { useWallets } from '../../contexts/wallets' import { walletAddTypes } from '../../config/walletTypes' diff --git a/apps/walletd/dialogs/WalletAddRecoverDialog/index.tsx b/apps/walletd/dialogs/WalletAddRecoverDialog/index.tsx index 766bf41fa..c0e13b439 100644 --- a/apps/walletd/dialogs/WalletAddRecoverDialog/index.tsx +++ b/apps/walletd/dialogs/WalletAddRecoverDialog/index.tsx @@ -12,7 +12,8 @@ import { useCallback } from 'react' import { useForm } from 'react-hook-form' import { useDialog } from '../../contexts/dialog' import { useWallets } from '../../contexts/wallets' -import { WalletMetadata, useWalletAdd } from '@siafoundation/walletd-react' +import { WalletMetadata } from '@siafoundation/walletd-types' +import { useWalletAdd } from '@siafoundation/walletd-react' import { blake2bHex } from 'blakejs' import { SeedLayout } from '../SeedLayout' import { SeedIcon } from '@siafoundation/react-icons' diff --git a/apps/walletd/dialogs/WalletAddWatchDialog/index.tsx b/apps/walletd/dialogs/WalletAddWatchDialog/index.tsx index 25fb586b3..93054abe2 100644 --- a/apps/walletd/dialogs/WalletAddWatchDialog/index.tsx +++ b/apps/walletd/dialogs/WalletAddWatchDialog/index.tsx @@ -11,7 +11,8 @@ import { } from '@siafoundation/design-system' import { useCallback } from 'react' import { useForm } from 'react-hook-form' -import { WalletMetadata, useWalletAdd } from '@siafoundation/walletd-react' +import { WalletMetadata } from '@siafoundation/walletd-types' +import { useWalletAdd } from '@siafoundation/walletd-react' import { useDialog } from '../../contexts/dialog' import { useWallets } from '../../contexts/wallets' import { walletAddTypes } from '../../config/walletTypes' diff --git a/apps/walletd/dialogs/WalletAddressesAddDialog.tsx b/apps/walletd/dialogs/WalletAddressesAddDialog.tsx index 10ffc9913..ac8c7fd4a 100644 --- a/apps/walletd/dialogs/WalletAddressesAddDialog.tsx +++ b/apps/walletd/dialogs/WalletAddressesAddDialog.tsx @@ -9,10 +9,8 @@ import { triggerSuccessToast, useDialogFormHelpers, } from '@siafoundation/design-system' -import { - WalletAddressMetadata, - useWalletAddressAdd, -} from '@siafoundation/walletd-react' +import { WalletAddressMetadata } from '@siafoundation/walletd-types' +import { useWalletAddressAdd } from '@siafoundation/walletd-react' import { useCallback } from 'react' import { useForm } from 'react-hook-form' import { useWallets } from '../contexts/wallets' diff --git a/apps/walletd/dialogs/WalletAddressesGenerateLedgerDialog/index.tsx b/apps/walletd/dialogs/WalletAddressesGenerateLedgerDialog/index.tsx index 9b1f90f6d..ef67f771c 100644 --- a/apps/walletd/dialogs/WalletAddressesGenerateLedgerDialog/index.tsx +++ b/apps/walletd/dialogs/WalletAddressesGenerateLedgerDialog/index.tsx @@ -11,10 +11,8 @@ import { triggerSuccessToast, useDialogFormHelpers, } from '@siafoundation/design-system' -import { - WalletAddressMetadata, - useWalletAddressAdd, -} from '@siafoundation/walletd-react' +import { WalletAddressMetadata } from '@siafoundation/walletd-types' +import { useWalletAddressAdd } from '@siafoundation/walletd-react' import { useCallback, useEffect, useMemo, useState } from 'react' import { useForm } from 'react-hook-form' import { useWallets } from '../../contexts/wallets' diff --git a/apps/walletd/dialogs/WalletAddressesGenerateSeedDialog/index.tsx b/apps/walletd/dialogs/WalletAddressesGenerateSeedDialog/index.tsx index 7b5aae5cd..c2611352d 100644 --- a/apps/walletd/dialogs/WalletAddressesGenerateSeedDialog/index.tsx +++ b/apps/walletd/dialogs/WalletAddressesGenerateSeedDialog/index.tsx @@ -7,10 +7,8 @@ import { triggerSuccessToast, useDialogFormHelpers, } from '@siafoundation/design-system' -import { - WalletAddressMetadata, - useWalletAddressAdd, -} from '@siafoundation/walletd-react' +import { WalletAddressMetadata } from '@siafoundation/walletd-types' +import { useWalletAddressAdd } from '@siafoundation/walletd-react' import { useCallback, useEffect, useState } from 'react' import { useForm } from 'react-hook-form' import { useWallets } from '../../contexts/wallets' diff --git a/apps/walletd/lib/testMocks.ts b/apps/walletd/lib/testMocks.ts index 791b46b29..7f1b39a14 100644 --- a/apps/walletd/lib/testMocks.ts +++ b/apps/walletd/lib/testMocks.ts @@ -1,7 +1,7 @@ import Sia from '@siacentral/ledgerjs-sia' import { LedgerDevice } from '../contexts/ledger/types' import { transformAddressesResponse } from '../contexts/addresses/dataset' -import { Wallet, WalletAddressesResponse } from '@siafoundation/walletd-react' +import { Wallet, WalletAddressesResponse } from '@siafoundation/walletd-types' export function getMockDevice() { return { diff --git a/libs/walletd-mock/package.json b/libs/walletd-mock/package.json index 379614414..d03c99a75 100644 --- a/libs/walletd-mock/package.json +++ b/libs/walletd-mock/package.json @@ -5,10 +5,10 @@ "license": "MIT", "dependencies": { "@siafoundation/types": "0.2.0", - "@siafoundation/walletd-react": "4.0.0", "@siafoundation/sia-central-mock": "0.0.0", "@siafoundation/units": "3.0.0", - "playwright": "^1.42.1" + "playwright": "^1.42.1", + "@siafoundation/walletd-types": "0.0.0" }, "types": "./src/index.d.ts" } diff --git a/libs/walletd-mock/src/mocks/consensusTip.ts b/libs/walletd-mock/src/mocks/consensusTip.ts index b67169761..802192afb 100644 --- a/libs/walletd-mock/src/mocks/consensusTip.ts +++ b/libs/walletd-mock/src/mocks/consensusTip.ts @@ -1,4 +1,4 @@ -import { ConsensusTipResponse } from '@siafoundation/walletd-react' +import { ConsensusTipResponse } from '@siafoundation/walletd-types' import { Page } from 'playwright' export function getMockConsensusTipResponse(): ConsensusTipResponse { diff --git a/libs/walletd-mock/src/mocks/defaults.ts b/libs/walletd-mock/src/mocks/defaults.ts index 0b0f3ba0c..71ac1241e 100644 --- a/libs/walletd-mock/src/mocks/defaults.ts +++ b/libs/walletd-mock/src/mocks/defaults.ts @@ -8,7 +8,7 @@ import { mockApiWallets } from './wallets' import { mockApiTxPoolBroadcast } from './txPoolBroadcast' import { mockApiWallet } from './wallet' import { mockApiRescan } from './rescan' -import { RescanResponse } from '@siafoundation/walletd-react' +import { RescanResponse } from '@siafoundation/walletd-types' type Responses = { rescan?: RescanResponse diff --git a/libs/walletd-mock/src/mocks/peers.ts b/libs/walletd-mock/src/mocks/peers.ts index 0cba2a8e7..20bd6d7d1 100644 --- a/libs/walletd-mock/src/mocks/peers.ts +++ b/libs/walletd-mock/src/mocks/peers.ts @@ -1,4 +1,4 @@ -import { SyncerPeersResponse } from '@siafoundation/walletd-react' +import { SyncerPeersResponse } from '@siafoundation/walletd-types' import { Page } from 'playwright' export function getMockPeersResponse(): SyncerPeersResponse { diff --git a/libs/walletd-mock/src/mocks/rescan.ts b/libs/walletd-mock/src/mocks/rescan.ts index 5ef5f871c..56e4a14b2 100644 --- a/libs/walletd-mock/src/mocks/rescan.ts +++ b/libs/walletd-mock/src/mocks/rescan.ts @@ -1,4 +1,4 @@ -import { RescanResponse } from '@siafoundation/walletd-react' +import { RescanResponse } from '@siafoundation/walletd-types' import { Page } from 'playwright' export function getMockRescanResponse(): RescanResponse { diff --git a/libs/walletd-mock/src/mocks/wallet.ts b/libs/walletd-mock/src/mocks/wallet.ts index 36d519ccf..cdcbc1674 100644 --- a/libs/walletd-mock/src/mocks/wallet.ts +++ b/libs/walletd-mock/src/mocks/wallet.ts @@ -3,9 +3,9 @@ import { Wallet, WalletAddressesResponse, WalletBalanceResponse, - WalletFundResponse, + WalletFundSiacoinResponse, WalletOutputsSiacoinResponse, -} from '@siafoundation/walletd-react' +} from '@siafoundation/walletd-types' import { mockApiWalletBalance } from './walletBalance' import { mockApiWalletAddresses } from './walletAddresses' import { mockApiWalletEvents } from './walletEvents' @@ -27,7 +27,7 @@ export async function mockApiWallet({ responses?: { balance?: WalletBalanceResponse outputsSiacoin?: WalletOutputsSiacoinResponse - fund?: WalletFundResponse + fundSiacoin?: WalletFundSiacoinResponse addresses?: WalletAddressesResponse } expects?: { @@ -59,7 +59,7 @@ export async function mockApiWallet({ await mockApiWalletFundSiacoin({ page, walletId: wallet.id, - response: responses.fund, + response: responses.fundSiacoin, expectPost: expects.fundSiacoinPost, }) await mockApiWalletRelease({ diff --git a/libs/walletd-mock/src/mocks/walletAddresses.ts b/libs/walletd-mock/src/mocks/walletAddresses.ts index 6e4f43d30..d01fccc39 100644 --- a/libs/walletd-mock/src/mocks/walletAddresses.ts +++ b/libs/walletd-mock/src/mocks/walletAddresses.ts @@ -1,7 +1,7 @@ import { WalletAddress, WalletAddressesResponse, -} from '@siafoundation/walletd-react' +} from '@siafoundation/walletd-types' import { Page } from 'playwright' export function getMockWalletAddressesResponse(): WalletAddressesResponse { diff --git a/libs/walletd-mock/src/mocks/walletBalance.ts b/libs/walletd-mock/src/mocks/walletBalance.ts index 2a377bbf0..b49827d00 100644 --- a/libs/walletd-mock/src/mocks/walletBalance.ts +++ b/libs/walletd-mock/src/mocks/walletBalance.ts @@ -1,4 +1,4 @@ -import { WalletBalanceResponse } from '@siafoundation/walletd-react' +import { WalletBalanceResponse } from '@siafoundation/walletd-types' import { toHastings } from '@siafoundation/units' import { Page } from 'playwright' diff --git a/libs/walletd-mock/src/mocks/walletEvents.ts b/libs/walletd-mock/src/mocks/walletEvents.ts index 19d9be345..7d3c445e6 100644 --- a/libs/walletd-mock/src/mocks/walletEvents.ts +++ b/libs/walletd-mock/src/mocks/walletEvents.ts @@ -1,4 +1,4 @@ -import { WalletEventsResponse } from '@siafoundation/walletd-react' +import { WalletEventsResponse } from '@siafoundation/walletd-types' import { Page } from 'playwright' export function getMockWalletEventsResponse(): WalletEventsResponse { diff --git a/libs/walletd-mock/src/mocks/walletFundSiacoin.ts b/libs/walletd-mock/src/mocks/walletFundSiacoin.ts index 6dce84c31..ab48d3514 100644 --- a/libs/walletd-mock/src/mocks/walletFundSiacoin.ts +++ b/libs/walletd-mock/src/mocks/walletFundSiacoin.ts @@ -1,7 +1,7 @@ -import { WalletFundResponse } from '@siafoundation/walletd-react' +import { WalletFundSiacoinResponse } from '@siafoundation/walletd-types' import { Page } from 'playwright' -export function getMockWalletFundSiacoinResponse(): WalletFundResponse { +export function getMockWalletFundSiacoinResponse(): WalletFundSiacoinResponse { return { transaction: { siacoinInputs: [ @@ -54,7 +54,7 @@ export async function mockApiWalletFundSiacoin({ }: { page: Page walletId: string - response?: WalletFundResponse + response?: WalletFundSiacoinResponse expectPost?: (data: string | null) => void }) { const json = response || getMockWalletFundSiacoinResponse() diff --git a/libs/walletd-mock/src/mocks/walletFundSiafund.ts b/libs/walletd-mock/src/mocks/walletFundSiafund.ts index 221a6bee6..a7b4d6d6c 100644 --- a/libs/walletd-mock/src/mocks/walletFundSiafund.ts +++ b/libs/walletd-mock/src/mocks/walletFundSiafund.ts @@ -1,7 +1,7 @@ -import { WalletFundResponse } from '@siafoundation/walletd-react' +import { WalletFundSiafundResponse } from '@siafoundation/walletd-types' import { Page } from 'playwright' -export function getMockWalletFundSiafundResponse(): WalletFundResponse { +export function getMockWalletFundSiafundResponse(): WalletFundSiafundResponse { return { transaction: { minerFees: ['3930000000000000000000'], @@ -19,7 +19,7 @@ export async function mockApiWalletFundSiafund({ }: { page: Page walletId: string - response?: WalletFundResponse + response?: WalletFundSiafundResponse expectPost?: (data: string | null) => void }) { const json = response || getMockWalletFundSiafundResponse() diff --git a/libs/walletd-mock/src/mocks/walletOutputsSiacoin.ts b/libs/walletd-mock/src/mocks/walletOutputsSiacoin.ts index b12257084..29d8bb3d0 100644 --- a/libs/walletd-mock/src/mocks/walletOutputsSiacoin.ts +++ b/libs/walletd-mock/src/mocks/walletOutputsSiacoin.ts @@ -1,4 +1,4 @@ -import { WalletOutputsSiacoinResponse } from '@siafoundation/walletd-react' +import { WalletOutputsSiacoinResponse } from '@siafoundation/walletd-types' import { SiacoinElement } from '@siafoundation/types' import { Page } from 'playwright' diff --git a/libs/walletd-mock/src/mocks/walletOutputsSiafund.ts b/libs/walletd-mock/src/mocks/walletOutputsSiafund.ts index 0af2b802b..9755d1986 100644 --- a/libs/walletd-mock/src/mocks/walletOutputsSiafund.ts +++ b/libs/walletd-mock/src/mocks/walletOutputsSiafund.ts @@ -1,4 +1,4 @@ -import { WalletOutputsSiafundResponse } from '@siafoundation/walletd-react' +import { WalletOutputsSiafundResponse } from '@siafoundation/walletd-types' import { Page } from 'playwright' export function getMockWalletOutputsSiafundResponse(): WalletOutputsSiafundResponse { diff --git a/libs/walletd-mock/src/mocks/walletRelease.ts b/libs/walletd-mock/src/mocks/walletRelease.ts index e281ac7df..a8b723858 100644 --- a/libs/walletd-mock/src/mocks/walletRelease.ts +++ b/libs/walletd-mock/src/mocks/walletRelease.ts @@ -1,4 +1,4 @@ -import { WalletFundResponse } from '@siafoundation/walletd-react' +import { WalletReleaseResponse } from '@siafoundation/walletd-types' import { Page } from 'playwright' export async function mockApiWalletRelease({ @@ -7,7 +7,7 @@ export async function mockApiWalletRelease({ }: { page: Page walletId: string - response?: WalletFundResponse + response?: WalletReleaseResponse }) { await page.route(`**/api/wallets/${walletId}/release*`, async (route) => { await route.fulfill() diff --git a/libs/walletd-mock/src/mocks/walletTxPool.ts b/libs/walletd-mock/src/mocks/walletTxPool.ts index 449cf6e11..88efa64aa 100644 --- a/libs/walletd-mock/src/mocks/walletTxPool.ts +++ b/libs/walletd-mock/src/mocks/walletTxPool.ts @@ -1,4 +1,4 @@ -import { WalletTxPoolResponse } from '@siafoundation/walletd-react' +import { WalletTxPoolResponse } from '@siafoundation/walletd-types' import { Page } from 'playwright' export function getMockWalletTxPoolResponse(): WalletTxPoolResponse { diff --git a/libs/walletd-mock/src/mocks/wallets.ts b/libs/walletd-mock/src/mocks/wallets.ts index 79a4ba705..5da89ea34 100644 --- a/libs/walletd-mock/src/mocks/wallets.ts +++ b/libs/walletd-mock/src/mocks/wallets.ts @@ -1,4 +1,4 @@ -import { Wallet, WalletsResponse } from '@siafoundation/walletd-react' +import { Wallet, WalletsResponse } from '@siafoundation/walletd-types' import { Page } from 'playwright' export function getMockWalletsResponse(): WalletsResponse { diff --git a/libs/walletd-mock/src/scenarios/seedWallet.ts b/libs/walletd-mock/src/scenarios/seedWallet.ts index 3370d03b8..7fd4f178b 100644 --- a/libs/walletd-mock/src/scenarios/seedWallet.ts +++ b/libs/walletd-mock/src/scenarios/seedWallet.ts @@ -3,8 +3,8 @@ import { Wallet, WalletAddress, WalletBalanceResponse, - WalletFundResponse, -} from '@siafoundation/walletd-react' + WalletFundSiacoinResponse, +} from '@siafoundation/walletd-types' import { toHastings } from '@siafoundation/units' import { getMockConsensusNetworkResponse } from '../mocks/consensusNetwork' import { getMockConsensusTipStateResponse } from '../mocks/consensusTipState' @@ -83,7 +83,7 @@ export function getMockScenarioSeedWallet() { const walletOutputsSiafundResponse: SiafundElement[] = [] - const walletFundResponse: WalletFundResponse = { + const walletFundResponse: WalletFundSiacoinResponse = { transaction: { siacoinInputs: [ { diff --git a/libs/walletd-react/package.json b/libs/walletd-react/package.json index 145c8dc9f..06f9de7bf 100644 --- a/libs/walletd-react/package.json +++ b/libs/walletd-react/package.json @@ -3,10 +3,10 @@ "description": "React hooks for interacting with `walletd`.", "version": "4.0.0", "license": "MIT", - "peerDependencies": { + "dependencies": { "@siafoundation/react-core": "^1.1.0", - "@siafoundation/types": "^0.2.0", - "swr": "^2.1.1" + "swr": "^2.1.1", + "@siafoundation/walletd-types": "0.0.0" }, "types": "./src/index.d.ts" } diff --git a/libs/walletd-react/src/api.ts b/libs/walletd-react/src/api.ts index 79918066c..682b925d2 100644 --- a/libs/walletd-react/src/api.ts +++ b/libs/walletd-react/src/api.ts @@ -11,38 +11,77 @@ import { useDeleteFunc, } from '@siafoundation/react-core' import { - ConsensusState, - ConsensusNetwork, - Currency, - BlockHeight, - ChainIndex, - SiacoinOutputID, - SiafundOutputID, - SiacoinElement, - SiafundElement, - Transaction, - V2Transaction, -} from '@siafoundation/types' -import { - PoolTransaction, - WalletEvent, - GatewayPeer, - Wallet, - WalletAddress, - WalletMetadata, -} from './siaTypes' + ConsensusNetworkParams, + ConsensusNetworkResponse, + ConsensusTipParams, + ConsensusTipResponse, + ConsensusTipStateParams, + ConsensusTipStateResponse, + RescanParams, + RescanResponse, + RescanStartParams, + RescanStartPayload, + RescanStartResponse, + StateParams, + StateResponse, + SyncerConnectParams, + SyncerConnectPayload, + SyncerConnectResponse, + SyncerPeersParams, + SyncerPeersResponse, + TxPoolBroadcastParams, + TxPoolBroadcastPayload, + TxPoolBroadcastResponse, + TxPoolFeeParams, + TxPoolFeeResponse, + TxPoolTransactionsParams, + TxPoolTransactionsResponse, + WalletAddParams, + WalletAddPayload, + WalletAddResponse, + WalletAddressAddParams, + WalletAddressAddPayload, + WalletAddressAddResponse, + WalletAddressDeleteParams, + WalletAddressDeletePayload, + WalletAddressDeleteResponse, + WalletAddressesParams, + WalletAddressesResponse, + WalletBalanceParams, + WalletBalanceResponse, + WalletDeleteParams, + WalletDeletePayload, + WalletDeleteResponse, + WalletEventsParams, + WalletEventsResponse, + WalletFundSiacoinParams, + WalletFundSiacoinPayload, + WalletFundSiacoinResponse, + WalletFundSiafundParams, + WalletFundSiafundPayload, + WalletFundSiafundResponse, + WalletOutputsSiacoinParams, + WalletOutputsSiacoinResponse, + WalletOutputsSiafundParams, + WalletOutputsSiafundResponse, + WalletReleaseParams, + WalletReleasePayload, + WalletReleaseResponse, + WalletReserveParams, + WalletReservePayload, + WalletReserveResponse, + WalletTxPoolParams, + WalletTxPoolResponse, + WalletUpdateParams, + WalletUpdatePayload, + WalletUpdateResponse, + WalletsParams, + WalletsResponse, +} from '@siafoundation/walletd-types' // state -export type StateResponse = { - version: string - commit: string - os: string - buildTime: string - startTime: string -} - -export function useNodeState(args?: HookArgsSwr) { +export function useNodeState(args?: HookArgsSwr) { return useGetSwr({ ...args, route: '/state', @@ -51,10 +90,8 @@ export function useNodeState(args?: HookArgsSwr) { // consensus -export type ConsensusTipResponse = ChainIndex - export function useConsensusTip( - args?: HookArgsSwr + args?: HookArgsSwr ) { return useGetSwr({ ...args, @@ -62,10 +99,8 @@ export function useConsensusTip( }) } -export type ConsensusStateResponse = ConsensusState - export function useConsensusTipState( - args?: HookArgsSwr + args?: HookArgsSwr ) { return useGetSwr({ ...args, @@ -73,10 +108,8 @@ export function useConsensusTipState( }) } -export type ConsensusNetworkResponse = ConsensusNetwork - export function useConsensusNetwork( - args?: HookArgsSwr + args?: HookArgsSwr ) { return useGetSwr({ ...args, @@ -112,16 +145,22 @@ export function useEstimatedNetworkBlockHeight(): number { export const syncerPeersKey = '/syncer/peers' -export type SyncerPeersResponse = GatewayPeer[] - -export function useSyncerPeers(args?: HookArgsSwr) { +export function useSyncerPeers( + args?: HookArgsSwr +) { return useGetSwr({ ...args, route: syncerPeersKey, }) } -export function useSyncerConnect(args?: HookArgsCallback) { +export function useSyncerConnect( + args?: HookArgsCallback< + SyncerConnectParams, + SyncerConnectPayload, + SyncerConnectResponse + > +) { return usePostFunc( { ...args, @@ -135,31 +174,25 @@ export function useSyncerConnect(args?: HookArgsCallback) { // txpool -type TxPoolTransactionsResponse = { - transactions: Transaction[] - v2transactions: V2Transaction[] -} - const txPoolTransactionsRoute = '/txpool/transactions' export function useTxPoolTransactions( - args?: HookArgsSwr + args?: HookArgsSwr ) { return useGetSwr({ ...args, route: txPoolTransactionsRoute }) } -export type TxPoolFeeResponse = Currency - -export function useTxPoolFee(args?: HookArgsSwr) { +export function useTxPoolFee( + args?: HookArgsSwr +) { return useGetSwr({ ...args, route: '/txpool/fee' }) } -type TxPoolBroadcastPayload = { - transactions: Transaction[] - v2transactions: V2Transaction[] -} - export function useTxPoolBroadcast( - args?: HookArgsCallback + args?: HookArgsCallback< + TxPoolBroadcastParams, + TxPoolBroadcastPayload, + TxPoolBroadcastResponse + > ) { return usePostFunc( { @@ -182,7 +215,11 @@ export function useTxPoolBroadcast( // rescan export function useRescanStart( - args?: HookArgsCallback + args?: HookArgsCallback< + RescanStartParams, + RescanStartPayload, + RescanStartResponse + > ) { return usePostFunc( { @@ -200,14 +237,9 @@ export function useRescanStart( ) } -export type RescanResponse = { - startIndex: ChainIndex - index: ChainIndex - startTime: string - error?: string -} - -export function useRescanStatus(args?: HookArgsSwr) { +export function useRescanStatus( + args?: HookArgsSwr +) { return useGetSwr({ ...args, route: '/rescan', @@ -218,25 +250,15 @@ export function useRescanStatus(args?: HookArgsSwr) { const walletsRoute = '/wallets' -export type WalletsResponse = Wallet[] - -export function useWallets(args?: HookArgsSwr) { +export function useWallets(args?: HookArgsSwr) { return useGetSwr({ ...args, route: walletsRoute, }) } -type WalletUpdatePayload = { - name: string - description: string - metadata: WalletMetadata -} - -export type WalletAddResponse = Wallet - export function useWalletAdd( - args?: HookArgsCallback + args?: HookArgsCallback ) { return usePostFunc( { @@ -249,11 +271,9 @@ export function useWalletAdd( ) } -export type WalletUpdateResponse = Wallet - export function useWalletUpdate( args?: HookArgsCallback< - { id: string }, + WalletUpdateParams, WalletUpdatePayload, WalletUpdateResponse > @@ -270,7 +290,11 @@ export function useWalletUpdate( } export function useWalletDelete( - args?: HookArgsCallback<{ id: string }, void, never> + args?: HookArgsCallback< + WalletDeleteParams, + WalletDeletePayload, + WalletDeleteResponse + > ) { return useDeleteFunc( { ...args, route: '/wallets/:id' }, @@ -283,11 +307,10 @@ export function useWalletDelete( } // addresses -export type WalletAddressesResponse = WalletAddress[] export const walletAddressesRoute = '/wallets/:id/addresses' export function useWalletAddresses( - args: HookArgsSwr<{ id: string }, WalletAddressesResponse> + args: HookArgsSwr ) { return useGetSwr({ ...args, @@ -295,10 +318,12 @@ export function useWalletAddresses( }) } -export type WalletAddressAddPayload = WalletAddress - export function useWalletAddressAdd( - args?: HookArgsCallback<{ id: string }, WalletAddressAddPayload, void> + args?: HookArgsCallback< + WalletAddressAddParams, + WalletAddressAddPayload, + WalletAddressAddResponse + > ) { return usePutFunc( { @@ -314,7 +339,11 @@ export function useWalletAddressAdd( } export function useWalletAddressDelete( - args?: HookArgsCallback<{ id: string; addr: string }, void, never> + args?: HookArgsCallback< + WalletAddressDeleteParams, + WalletAddressDeletePayload, + WalletAddressDeleteResponse + > ) { return useDeleteFunc( { ...args, route: '/wallets/:id/addresses/:addr' }, @@ -326,15 +355,9 @@ export function useWalletAddressDelete( ) } -export type WalletBalanceResponse = { - siacoins: Currency - immatureSiacoins: Currency - siafunds: number -} - const walletBalanceRoute = '/wallets/:id/balance' export function useWalletBalance( - args: HookArgsSwr<{ id: string }, WalletBalanceResponse> + args: HookArgsSwr ) { return useGetSwr({ ...args, @@ -342,14 +365,9 @@ export function useWalletBalance( }) } -export type WalletEventsResponse = WalletEvent[] - const walletEventsRoute = '/wallets/:id/events' export function useWalletEvents( - args: HookArgsSwr< - { id: string; offset: number; limit: number }, - WalletEventsResponse - > + args: HookArgsSwr ) { return useGetSwr({ ...args, @@ -359,10 +377,8 @@ export function useWalletEvents( const walletTxPoolRoute = '/wallets/:id/txpool' -export type WalletTxPoolResponse = PoolTransaction[] - export function useWalletTxPool( - args: HookArgsSwr<{ id: string }, WalletTxPoolResponse> + args: HookArgsSwr ) { return useGetSwr({ ...args, @@ -370,10 +386,8 @@ export function useWalletTxPool( }) } -export type WalletOutputsSiacoinResponse = SiacoinElement[] - export function useWalletOutputsSiacoin( - args: HookArgsSwr<{ id: string }, WalletOutputsSiacoinResponse> + args: HookArgsSwr ) { return useGetSwr({ ...args, @@ -381,10 +395,8 @@ export function useWalletOutputsSiacoin( }) } -export type WalletOutputsSiafundResponse = SiafundElement[] - export function useWalletOutputsSiafund( - args: HookArgsSwr<{ id: string }, WalletOutputsSiafundResponse> + args: HookArgsSwr ) { return useGetSwr({ ...args, @@ -392,64 +404,42 @@ export function useWalletOutputsSiafund( }) } -export type WalletFundSiacoinPayload = { - transaction: Transaction - amount: Currency - changeAddress: string -} - -export type WalletFundResponse = { - transaction: Transaction - toSign: string[] - dependsOn: Transaction[] | null -} - export function useWalletFundSiacoin( args?: HookArgsCallback< - { id: string }, + WalletFundSiacoinParams, WalletFundSiacoinPayload, - WalletFundResponse + WalletFundSiacoinResponse > ) { return usePostFunc({ ...args, route: '/wallets/:id/fund' }) } -export type WalletFundSiafundPayload = { - transaction: Transaction - amount: number - changeAddress: string - claimAddress: string -} - export function useWalletFundSiafund( args?: HookArgsCallback< - { id: string }, + WalletFundSiafundParams, WalletFundSiafundPayload, - WalletFundResponse + WalletFundSiafundResponse > ) { return usePostFunc({ ...args, route: '/wallets/:id/fundsf' }) } -export type WalletReservePayload = { - siacoinOutputs?: SiacoinOutputID[] - siafundOutputs?: SiafundOutputID[] - duration: number -} - export function useWalletReserve( - args?: HookArgsCallback<{ id: string }, WalletReservePayload, void> + args?: HookArgsCallback< + WalletReserveParams, + WalletReservePayload, + WalletReserveResponse + > ) { return usePostFunc({ ...args, route: '/wallets/:id/reserve' }) } -export type WalletReleasePayload = { - siacoinOutputs?: SiacoinOutputID[] - siafundOutputs?: SiafundOutputID[] -} - export function useWalletRelease( - args?: HookArgsCallback<{ id: string }, WalletReleasePayload, void> + args?: HookArgsCallback< + WalletReleaseParams, + WalletReleasePayload, + WalletReleaseResponse + > ) { return usePostFunc({ ...args, route: '/wallets/:id/release' }) } diff --git a/libs/walletd-react/src/index.ts b/libs/walletd-react/src/index.ts index 74b0328a1..3318fdbc9 100644 --- a/libs/walletd-react/src/index.ts +++ b/libs/walletd-react/src/index.ts @@ -1,2 +1 @@ export * from './api' -export * from './siaTypes' diff --git a/libs/walletd-types/.babelrc b/libs/walletd-types/.babelrc new file mode 100644 index 000000000..1ea870ead --- /dev/null +++ b/libs/walletd-types/.babelrc @@ -0,0 +1,12 @@ +{ + "presets": [ + [ + "@nx/react/babel", + { + "runtime": "automatic", + "useBuiltIns": "usage" + } + ] + ], + "plugins": [] +} diff --git a/libs/walletd-types/.eslintrc.json b/libs/walletd-types/.eslintrc.json new file mode 100644 index 000000000..a269fb3c8 --- /dev/null +++ b/libs/walletd-types/.eslintrc.json @@ -0,0 +1,21 @@ +{ + "extends": ["plugin:@nx/react", "../../.eslintrc.json"], + "ignorePatterns": ["!**/*"], + "rules": { + "@nx/dependency-checks": [ + "error", + { + "ignoredFiles": ["libs/walletd-types/rollup.config.js"] + } + ] + }, + "overrides": [ + { + "files": ["*.json"], + "parser": "jsonc-eslint-parser", + "rules": { + "@nx/dependency-checks": "error" + } + } + ] +} diff --git a/libs/walletd-types/README.md b/libs/walletd-types/README.md new file mode 100644 index 000000000..45a626736 --- /dev/null +++ b/libs/walletd-types/README.md @@ -0,0 +1,3 @@ +# walletd-types + +Types for `walletd`. diff --git a/libs/walletd-types/jest.config.ts b/libs/walletd-types/jest.config.ts new file mode 100644 index 000000000..0330dc724 --- /dev/null +++ b/libs/walletd-types/jest.config.ts @@ -0,0 +1,17 @@ +/* eslint-disable */ +export default { + displayName: 'walletd-types', + preset: '../../jest.preset.js', + transform: { + '^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '@nx/react/plugins/jest', + '^.+\\.[tj]sx?$': [ + 'babel-jest', + { + presets: ['@nx/next/babel'], + plugins: ['@babel/plugin-transform-private-methods'], + }, + ], + }, + moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], + coverageDirectory: '../../coverage/libs/walletd-types', +} diff --git a/libs/walletd-types/package.json b/libs/walletd-types/package.json new file mode 100644 index 000000000..2f7d38633 --- /dev/null +++ b/libs/walletd-types/package.json @@ -0,0 +1,10 @@ +{ + "name": "@siafoundation/walletd-types", + "description": "Types for `walletd`.", + "version": "0.0.0", + "license": "MIT", + "dependencies": { + "@siafoundation/types": "^0.2.0" + }, + "types": "./src/index.d.ts" +} diff --git a/libs/walletd-types/project.json b/libs/walletd-types/project.json new file mode 100644 index 000000000..23f467da8 --- /dev/null +++ b/libs/walletd-types/project.json @@ -0,0 +1,42 @@ +{ + "name": "walletd-types", + "$schema": "../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "libs/walletd-types/src", + "projectType": "library", + "tags": [], + "targets": { + "build": { + "executor": "@nx/rollup:rollup", + "outputs": ["{options.outputPath}"], + "options": { + "outputPath": "dist/libs/walletd-types", + "tsConfig": "libs/walletd-types/tsconfig.lib.json", + "project": "libs/walletd-types/package.json", + "entryFile": "libs/walletd-types/src/index.ts", + "external": ["react/jsx-runtime"], + "compiler": "tsc", + "outputFileName": "index.js", + "rollupConfig": "libs/walletd-types/rollup.config.js", + "assets": [ + { + "glob": "libs/walletd-types/*.md", + "input": ".", + "output": "." + } + ] + }, + "configurations": {} + }, + "lint": { + "executor": "@nx/eslint:lint", + "outputs": ["{options.outputFile}"] + }, + "test": { + "executor": "@nx/jest:jest", + "outputs": ["{workspaceRoot}/coverage/libs/walletd-types"], + "options": { + "jestConfig": "libs/walletd-types/jest.config.ts" + } + } + } +} diff --git a/libs/walletd-types/rollup.config.js b/libs/walletd-types/rollup.config.js new file mode 100644 index 000000000..3f5e4e997 --- /dev/null +++ b/libs/walletd-types/rollup.config.js @@ -0,0 +1,18 @@ +// eslint-disable-next-line @typescript-eslint/no-var-requires +const preserveDirectives = require('rollup-plugin-preserve-directives') + +// https://github.com/rollup/rollup/issues/4699#issuecomment-1465302665 +function getRollupOptions(options) { + return { + ...options, + output: { + ...options.output, + preserveModules: true, + format: 'esm', + sourcemap: true, + }, + plugins: options.plugins.concat(preserveDirectives.default()), + } +} + +module.exports = getRollupOptions diff --git a/libs/walletd-types/src/api.ts b/libs/walletd-types/src/api.ts new file mode 100644 index 000000000..16c97d942 --- /dev/null +++ b/libs/walletd-types/src/api.ts @@ -0,0 +1,189 @@ +import { + ConsensusState, + ConsensusNetwork, + Currency, + BlockHeight, + ChainIndex, + SiacoinOutputID, + SiafundOutputID, + SiacoinElement, + SiafundElement, + Transaction, + V2Transaction, +} from '@siafoundation/types' +import { + PoolTransaction, + WalletEvent, + GatewayPeer, + Wallet, + WalletAddress, + WalletMetadata, +} from './types' + +// state + +export type StateParams = void +export type StateResponse = { + version: string + commit: string + os: string + buildTime: string + startTime: string +} + +// consensus + +export type ConsensusTipParams = void +export type ConsensusTipResponse = ChainIndex + +export type ConsensusTipStateParams = void +export type ConsensusTipStateResponse = ConsensusState + +export type ConsensusNetworkParams = void +export type ConsensusNetworkResponse = ConsensusNetwork + +// syncer + +export type SyncerPeersParams = void +export type SyncerPeersResponse = GatewayPeer[] + +export type SyncerConnectParams = void +export type SyncerConnectPayload = string +export type SyncerConnectResponse = never + +// txpool + +export type TxPoolTransactionsParams = void +export type TxPoolTransactionsResponse = { + transactions: Transaction[] + v2transactions: V2Transaction[] +} + +export type TxPoolFeeParams = void +export type TxPoolFeeResponse = Currency + +export type TxPoolBroadcastParams = void +export type TxPoolBroadcastPayload = { + transactions: Transaction[] + v2transactions: V2Transaction[] +} +export type TxPoolBroadcastResponse = unknown + +// rescan + +export type RescanStartParams = void +export type RescanStartPayload = BlockHeight +export type RescanStartResponse = void + +export type RescanParams = void +export type RescanResponse = { + startIndex: ChainIndex + index: ChainIndex + startTime: string + error?: string +} + +// wallet + +export type WalletsParams = void +export type WalletsResponse = Wallet[] + +export type WalletAddParams = void +export type WalletAddPayload = { + name: string + description: string + metadata: WalletMetadata +} +export type WalletAddResponse = Wallet + +export type WalletUpdateParams = { id: string } +export type WalletUpdatePayload = { + name: string + description: string + metadata: WalletMetadata +} +export type WalletUpdateResponse = Wallet + +export type WalletDeleteParams = { id: string } +export type WalletDeletePayload = void +export type WalletDeleteResponse = never + +// addresses + +export type WalletAddressesParams = { id: string } +export type WalletAddressesResponse = WalletAddress[] + +export type WalletAddressAddParams = { id: string } +export type WalletAddressAddPayload = WalletAddress +export type WalletAddressAddResponse = void + +export type WalletAddressDeleteParams = { id: string; addr: string } +export type WalletAddressDeletePayload = void +export type WalletAddressDeleteResponse = never + +export type WalletBalanceParams = { id: string } +export type WalletBalanceResponse = { + siacoins: Currency + immatureSiacoins: Currency + siafunds: number +} + +export type WalletEventsParams = { id: string; offset: number; limit: number } +export type WalletEventsResponse = WalletEvent[] + +export type WalletTxPoolParams = { id: string } +export type WalletTxPoolResponse = PoolTransaction[] + +export type WalletOutputsSiacoinParams = { id: string } +export type WalletOutputsSiacoinResponse = SiacoinElement[] + +export type WalletOutputsSiafundParams = { id: string } +export type WalletOutputsSiafundResponse = SiafundElement[] + +export type WalletFundSiacoinParams = { + id: string +} +export type WalletFundSiacoinPayload = { + transaction: Transaction + amount: Currency + changeAddress: string +} +export type WalletFundSiacoinResponse = { + transaction: Transaction + toSign: string[] + dependsOn: Transaction[] | null +} + +export type WalletFundSiafundParams = { + id: string +} +export type WalletFundSiafundPayload = { + transaction: Transaction + amount: number + changeAddress: string + claimAddress: string +} +export type WalletFundSiafundResponse = { + transaction: Transaction + toSign: string[] + dependsOn: Transaction[] | null +} + +export type WalletReserveParams = { + id: string +} +export type WalletReservePayload = { + siacoinOutputs?: SiacoinOutputID[] + siafundOutputs?: SiafundOutputID[] + duration: number +} +export type WalletReserveResponse = void + +export type WalletReleaseParams = { + id: string +} +export type WalletReleasePayload = { + siacoinOutputs?: SiacoinOutputID[] + siafundOutputs?: SiafundOutputID[] +} +export type WalletReleaseResponse = void diff --git a/libs/walletd-types/src/index.ts b/libs/walletd-types/src/index.ts new file mode 100644 index 000000000..39a2c95ba --- /dev/null +++ b/libs/walletd-types/src/index.ts @@ -0,0 +1,2 @@ +export * from './api' +export * from './types' diff --git a/libs/walletd-react/src/siaTypes.ts b/libs/walletd-types/src/types.ts similarity index 100% rename from libs/walletd-react/src/siaTypes.ts rename to libs/walletd-types/src/types.ts diff --git a/libs/walletd-types/tsconfig.json b/libs/walletd-types/tsconfig.json new file mode 100644 index 000000000..4c089585e --- /dev/null +++ b/libs/walletd-types/tsconfig.json @@ -0,0 +1,25 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "jsx": "react-jsx", + "allowJs": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "noImplicitOverride": true, + "noPropertyAccessFromIndexSignature": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true + }, + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.lib.json" + }, + { + "path": "./tsconfig.spec.json" + } + ] +} diff --git a/libs/walletd-types/tsconfig.lib.json b/libs/walletd-types/tsconfig.lib.json new file mode 100644 index 000000000..d73537814 --- /dev/null +++ b/libs/walletd-types/tsconfig.lib.json @@ -0,0 +1,22 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "types": [ + "node", + "@nx/react/typings/cssmodule.d.ts", + "@nx/react/typings/image.d.ts" + ] + }, + "exclude": [ + "**/*.spec.ts", + "**/*.test.ts", + "**/*.spec.tsx", + "**/*.test.tsx", + "**/*.spec.js", + "**/*.test.js", + "**/*.spec.jsx", + "**/*.test.jsx" + ], + "include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"] +} diff --git a/libs/walletd-types/tsconfig.spec.json b/libs/walletd-types/tsconfig.spec.json new file mode 100644 index 000000000..503e9a83d --- /dev/null +++ b/libs/walletd-types/tsconfig.spec.json @@ -0,0 +1,19 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "module": "commonjs", + "types": ["jest", "node"] + }, + "include": [ + "src/**/*.test.ts", + "src/**/*.spec.ts", + "src/**/*.test.tsx", + "src/**/*.spec.tsx", + "src/**/*.test.js", + "src/**/*.spec.js", + "src/**/*.test.jsx", + "src/**/*.spec.jsx", + "src/**/*.d.ts" + ] +} diff --git a/tsconfig.base.json b/tsconfig.base.json index 5aa0fc619..d06c15812 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -28,6 +28,7 @@ "@siafoundation/sia-central-react": [ "libs/sia-central-react/src/index.ts" ], + "@siafoundation/walletd-types": ["libs/walletd-types/src/index.ts"], "@siafoundation/walletd-react": ["libs/walletd-react/src/index.ts"], // "buildLibsFromSource": false does not work with the next executor // this is a very annoying workaround