diff --git a/README.md b/README.md index a38c7e358..adf7e770b 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ The `explorer` user interface, a Sia blockchain explorer interface that powers [ The Sia web libraries provide developers with convenient TypeScript SDKs for using Sia core types, blockchain utilities, data fetching, daemon-specific React hooks, and components for common functionality such as Siacoin/fiat input fields, transaction lists, files, and more. -- [@siafoundation/react-core](libs/react-core) - Core Sia types and library methods. +- [@siafoundation/react-core](libs/react-core) - Core library for building React hooks for interacting with a Sia daemon. - [@siafoundation/react-renterd](libs/react-renterd) - React hooks for interacting with `renterd`. - [@siafoundation/react-hostd](libs/react-hostd) - React hooks for interacting with `hostd`. - [@siafoundation/react-walletd](libs/react-walletd) - React hooks for interacting with `walletd`. @@ -50,6 +50,7 @@ The Sia web libraries provide developers with convenient TypeScript SDKs for usi - [@siafoundation/data-sources](libs/data-sources) - Data sources used for stats on the website. - [@siafoundation/fonts](libs/fonts) - Next font configuration for use across apps. - [@siafoundation/units](libs/units) - Methods and types for converting and displaying units. +- [@siafoundation/types](libs/types) - Core Sia types and library methods. ## Internal diff --git a/apps/hostd/contexts/contracts/types.ts b/apps/hostd/contexts/contracts/types.ts index f6c5cc878..6e6d7ae05 100644 --- a/apps/hostd/contexts/contracts/types.ts +++ b/apps/hostd/contexts/contracts/types.ts @@ -4,7 +4,7 @@ import { Signature, UnlockConditions, SiacoinOutput, -} from '@siafoundation/react-core' +} from '@siafoundation/types' import { ContractFilterSortField, ContractStatus, diff --git a/apps/hostd/contexts/transactions/index.tsx b/apps/hostd/contexts/transactions/index.tsx index 9bd4b9e91..d08b19995 100644 --- a/apps/hostd/contexts/transactions/index.tsx +++ b/apps/hostd/contexts/transactions/index.tsx @@ -15,7 +15,7 @@ import { useDialog } from '../dialog' import BigNumber from 'bignumber.js' import { useRouter } from 'next/router' import { useSiascanUrl } from '../../hooks/useSiascanUrl' -import { Transaction } from '@siafoundation/react-core' +import { Transaction } from '@siafoundation/types' const defaultLimit = 50 const filters = [] diff --git a/apps/renterd/contexts/transactions/index.tsx b/apps/renterd/contexts/transactions/index.tsx index 5a8ab54df..8314b7dfc 100644 --- a/apps/renterd/contexts/transactions/index.tsx +++ b/apps/renterd/contexts/transactions/index.tsx @@ -16,7 +16,7 @@ import { useDialog } from '../dialog' import BigNumber from 'bignumber.js' import { useRouter } from 'next/router' import { useSiascanUrl } from '../../hooks/useSiascanUrl' -import { Transaction } from '@siafoundation/react-core' +import { Transaction } from '@siafoundation/types' const defaultLimit = 50 const filters = [] diff --git a/apps/walletd/dialogs/WalletSendLedgerDialog/useFundAndSign.tsx b/apps/walletd/dialogs/WalletSendLedgerDialog/useFundAndSign.tsx index e9b324b33..91ec45d09 100644 --- a/apps/walletd/dialogs/WalletSendLedgerDialog/useFundAndSign.tsx +++ b/apps/walletd/dialogs/WalletSendLedgerDialog/useFundAndSign.tsx @@ -1,4 +1,4 @@ -import { Transaction } from '@siafoundation/react-core' +import { Transaction } from '@siafoundation/types' import { useCallback } from 'react' import { SendParams } from '../_sharedWalletSend/types' diff --git a/apps/walletd/dialogs/WalletSendLedgerDialog/useSendForm.tsx b/apps/walletd/dialogs/WalletSendLedgerDialog/useSendForm.tsx index 32ecd3c16..d50386859 100644 --- a/apps/walletd/dialogs/WalletSendLedgerDialog/useSendForm.tsx +++ b/apps/walletd/dialogs/WalletSendLedgerDialog/useSendForm.tsx @@ -10,7 +10,7 @@ import { } from '@siafoundation/design-system' import { DeviceConnectForm } from '../DeviceConnectForm' import { useLedger } from '../../contexts/ledger' -import { Transaction } from '@siafoundation/react-core' +import { Transaction } from '@siafoundation/types' import { LedgerSignTxn } from './LedgerSignTxn' import { useSign } from './useSign' import { useBroadcast } from '../_sharedWalletSend/useBroadcast' diff --git a/apps/walletd/dialogs/WalletSendLedgerDialog/useSign.tsx b/apps/walletd/dialogs/WalletSendLedgerDialog/useSign.tsx index cf030f90c..84db2330f 100644 --- a/apps/walletd/dialogs/WalletSendLedgerDialog/useSign.tsx +++ b/apps/walletd/dialogs/WalletSendLedgerDialog/useSign.tsx @@ -1,4 +1,4 @@ -import { Transaction } from '@siafoundation/react-core' +import { Transaction } from '@siafoundation/types' import { useWalletOutputs } from '@siafoundation/react-walletd' import { useWallets } from '../../contexts/wallets' import { useCallback } from 'react' diff --git a/apps/walletd/dialogs/_sharedWalletSend/useBroadcast.tsx b/apps/walletd/dialogs/_sharedWalletSend/useBroadcast.tsx index 2af523548..cfc6e3047 100644 --- a/apps/walletd/dialogs/_sharedWalletSend/useBroadcast.tsx +++ b/apps/walletd/dialogs/_sharedWalletSend/useBroadcast.tsx @@ -1,4 +1,4 @@ -import { Transaction } from '@siafoundation/react-core' +import { Transaction } from '@siafoundation/types' import { useTxPoolBroadcast } from '@siafoundation/react-walletd' import { useCallback } from 'react' diff --git a/apps/walletd/dialogs/_sharedWalletSend/useCancel.tsx b/apps/walletd/dialogs/_sharedWalletSend/useCancel.tsx index 0a31d1b53..1d018a6ae 100644 --- a/apps/walletd/dialogs/_sharedWalletSend/useCancel.tsx +++ b/apps/walletd/dialogs/_sharedWalletSend/useCancel.tsx @@ -1,4 +1,4 @@ -import { Transaction } from '@siafoundation/react-core' +import { Transaction } from '@siafoundation/types' import { useWalletRelease } from '@siafoundation/react-walletd' import { useWallets } from '../../contexts/wallets' import { useCallback } from 'react' diff --git a/apps/walletd/lib/sign.ts b/apps/walletd/lib/sign.ts index 60438dd0d..256a2b505 100644 --- a/apps/walletd/lib/sign.ts +++ b/apps/walletd/lib/sign.ts @@ -4,7 +4,7 @@ import { SiafundElement, SiafundInput, Transaction, -} from '@siafoundation/react-core' +} from '@siafoundation/types' import { stripPrefix } from '@siafoundation/design-system' import { AddressData } from '../contexts/addresses/types' diff --git a/apps/walletd/lib/signLedger.ts b/apps/walletd/lib/signLedger.ts index 8908c1cf0..78d7971ac 100644 --- a/apps/walletd/lib/signLedger.ts +++ b/apps/walletd/lib/signLedger.ts @@ -2,7 +2,7 @@ import { SiacoinElement, SiafundElement, Transaction, -} from '@siafoundation/react-core' +} from '@siafoundation/types' import { getWalletWasm } from './wasm' import { AddressData } from '../contexts/addresses/types' import { LedgerDevice } from '../contexts/ledger/types' diff --git a/apps/walletd/lib/signSeed.ts b/apps/walletd/lib/signSeed.ts index 94fd72106..015f2677d 100644 --- a/apps/walletd/lib/signSeed.ts +++ b/apps/walletd/lib/signSeed.ts @@ -3,7 +3,7 @@ import { SiacoinElement, Transaction, SiafundElement, -} from '@siafoundation/react-core' +} from '@siafoundation/types' import { getWalletWasm } from './wasm' import { AddressData } from '../contexts/addresses/types' import { addUnlockConditionsAndSignatures, getToSignMetadata } from './sign' diff --git a/apps/walletd/lib/testMocks.ts b/apps/walletd/lib/testMocks.ts index 425420502..679ef9e3e 100644 --- a/apps/walletd/lib/testMocks.ts +++ b/apps/walletd/lib/testMocks.ts @@ -1,6 +1,6 @@ import Sia from '@siacentral/ledgerjs-sia' import { LedgerDevice } from '../contexts/ledger/types' -import { Transaction } from '@siafoundation/react-core' +import { Transaction } from '@siafoundation/types' export function getMockDevice() { return { diff --git a/apps/walletd/lib/wasm.ts b/apps/walletd/lib/wasm.ts index a3f794f7f..909f7b609 100644 --- a/apps/walletd/lib/wasm.ts +++ b/apps/walletd/lib/wasm.ts @@ -1,4 +1,4 @@ -import { Transaction, UnlockConditions } from '@siafoundation/react-core' +import { Transaction, UnlockConditions } from '@siafoundation/types' import { initWasmGo } from './wasm_exec_mod' interface WalletWASM { diff --git a/libs/design-system/package.json b/libs/design-system/package.json index 2c0b75abe..0ae2b07ee 100644 --- a/libs/design-system/package.json +++ b/libs/design-system/package.json @@ -7,6 +7,7 @@ "@siafoundation/react-icons": "^0.1.0", "@siafoundation/react-core": "^0.15.0", "@siafoundation/units": "^0.1.3", + "@siafoundation/types": "^0.0.1", "@visx/group": "2.17.0", "@visx/react-spring": "2.18.0", "@visx/glyph": "2.17.0", diff --git a/libs/design-system/src/app/TransactionDetailsDialog.tsx b/libs/design-system/src/app/TransactionDetailsDialog.tsx index b8a9af69c..a08b41945 100644 --- a/libs/design-system/src/app/TransactionDetailsDialog.tsx +++ b/libs/design-system/src/app/TransactionDetailsDialog.tsx @@ -5,7 +5,7 @@ import { humanDate } from '@siafoundation/units' import BigNumber from 'bignumber.js' import { Dialog } from '../core/Dialog' import { getTitleId } from '../lib/utils' -import { Transaction } from '@siafoundation/react-core' +import { Transaction } from '@siafoundation/types' import { getTxTypeLabel, TxType } from '../lib/entityTypes' import { upperFirst } from 'lodash' diff --git a/libs/design-system/src/app/TxPoolList.tsx b/libs/design-system/src/app/TxPoolList.tsx index 5893e8b67..dea432413 100644 --- a/libs/design-system/src/app/TxPoolList.tsx +++ b/libs/design-system/src/app/TxPoolList.tsx @@ -1,6 +1,6 @@ import { EntityList } from '../components/EntityList' import { getTransactionTotals, getTransactionType } from '../lib/entityTypes' -import { Transaction } from '@siafoundation/react-core' +import { Transaction } from '@siafoundation/types' type Props = { isLoading?: boolean diff --git a/libs/design-system/src/lib/entityTypes.ts b/libs/design-system/src/lib/entityTypes.ts index 9f4dc4230..607d0ff91 100644 --- a/libs/design-system/src/lib/entityTypes.ts +++ b/libs/design-system/src/lib/entityTypes.ts @@ -1,4 +1,4 @@ -import { Transaction } from '@siafoundation/react-core' +import { Transaction } from '@siafoundation/types' import BigNumber from 'bignumber.js' export type EntityType = diff --git a/libs/react-core/package.json b/libs/react-core/package.json index bcf5a3415..e97804662 100644 --- a/libs/react-core/package.json +++ b/libs/react-core/package.json @@ -1,6 +1,6 @@ { "name": "@siafoundation/react-core", - "description": "Core Sia types and library methods.", + "description": "Core library for building React hooks for interacting with a Sia daemon.", "version": "0.15.0", "license": "MIT", "dependencies": { diff --git a/libs/react-core/src/index.ts b/libs/react-core/src/index.ts index 4085b4b51..bdc615be7 100644 --- a/libs/react-core/src/index.ts +++ b/libs/react-core/src/index.ts @@ -1,5 +1,4 @@ export * from './types' -export * from './siaTypes' export * from './utils' export * from './usePost' export * from './usePut' diff --git a/libs/react-hostd/package.json b/libs/react-hostd/package.json index 265287c6e..9aef034ef 100644 --- a/libs/react-hostd/package.json +++ b/libs/react-hostd/package.json @@ -5,6 +5,7 @@ "license": "MIT", "dependencies": { "@siafoundation/react-core": "^0.15.0", + "@siafoundation/types": "^0.0.1", "swr": "^2.1.1" }, "types": "./src/index.d.ts" diff --git a/libs/react-hostd/src/api.ts b/libs/react-hostd/src/api.ts index 0271e9801..221f7a419 100644 --- a/libs/react-hostd/src/api.ts +++ b/libs/react-hostd/src/api.ts @@ -6,17 +6,19 @@ import { HookArgsSwr, HookArgsCallback, HookArgsWithPayloadSwr, - FileContractID, - PublicKey, getTestnetZenBlockHeight, getMainnetBlockHeight, - Currency, usePutSwr, useDeleteFunc, delay, - TransactionID, usePatchFunc, } from '@siafoundation/react-core' +import { + FileContractID, + PublicKey, + Currency, + TransactionID, +} from '@siafoundation/types' import useSWR from 'swr' import { Contract, ContractStatus, WalletTransaction } from './siaTypes' diff --git a/libs/react-hostd/src/siaTypes.ts b/libs/react-hostd/src/siaTypes.ts index 13a08cfcb..6121d2e23 100644 --- a/libs/react-hostd/src/siaTypes.ts +++ b/libs/react-hostd/src/siaTypes.ts @@ -6,7 +6,7 @@ import { Signature, Currency, FileContractID, -} from '@siafoundation/react-core' +} from '@siafoundation/types' export interface WalletTransaction { id: string diff --git a/libs/react-renterd/package.json b/libs/react-renterd/package.json index 057064c35..ce6818724 100644 --- a/libs/react-renterd/package.json +++ b/libs/react-renterd/package.json @@ -5,6 +5,7 @@ "license": "MIT", "dependencies": { "@siafoundation/react-core": "^0.15.0", + "@siafoundation/types": "^0.0.1", "swr": "^2.1.1", "lodash": "^4.17.21" }, diff --git a/libs/react-renterd/src/bus.ts b/libs/react-renterd/src/bus.ts index 63e270a73..e2527aba7 100644 --- a/libs/react-renterd/src/bus.ts +++ b/libs/react-renterd/src/bus.ts @@ -8,18 +8,20 @@ import { HookArgsSwr, HookArgsCallback, HookArgsWithPayloadSwr, - Currency, - PublicKey, - Transaction, getMainnetBlockHeight, getTestnetZenBlockHeight, delay, +} from '@siafoundation/react-core' +import { + Currency, + PublicKey, + Transaction, FileContractRevision, OutputID, CoveredFields, FileContractID, Block, -} from '@siafoundation/react-core' +} from '@siafoundation/types' import { ConsensusState, Contract, diff --git a/libs/react-renterd/src/siaTypes.ts b/libs/react-renterd/src/siaTypes.ts index a1d7e2c76..7cce404bc 100644 --- a/libs/react-renterd/src/siaTypes.ts +++ b/libs/react-renterd/src/siaTypes.ts @@ -6,7 +6,7 @@ import { EncryptionKey, PublicKey, TransactionSignature, -} from '@siafoundation/react-core' +} from '@siafoundation/types' export type ConsensusState = { blockHeight: number diff --git a/libs/react-walletd/package.json b/libs/react-walletd/package.json index 8010eedbc..beffdb807 100644 --- a/libs/react-walletd/package.json +++ b/libs/react-walletd/package.json @@ -5,6 +5,7 @@ "license": "MIT", "dependencies": { "@siafoundation/react-core": "^0.15.0", + "@siafoundation/types": "^0.0.1", "swr": "^2.1.1" }, "types": "./src/index.d.ts" diff --git a/libs/react-walletd/src/api.ts b/libs/react-walletd/src/api.ts index 09322c973..520a2a1a3 100644 --- a/libs/react-walletd/src/api.ts +++ b/libs/react-walletd/src/api.ts @@ -9,6 +9,8 @@ import { getMainnetBlockHeight, getTestnetZenBlockHeight, useDeleteFunc, +} from '@siafoundation/react-core' +import { Currency, BlockHeight, ChainIndex, @@ -17,7 +19,7 @@ import { SiacoinElement, SiafundElement, Transaction, -} from '@siafoundation/react-core' +} from '@siafoundation/types' import { ConsensusState, ConsensusNetwork, diff --git a/libs/react-walletd/src/siaTypes.ts b/libs/react-walletd/src/siaTypes.ts index 7fd0c1a3d..550436a58 100644 --- a/libs/react-walletd/src/siaTypes.ts +++ b/libs/react-walletd/src/siaTypes.ts @@ -7,7 +7,7 @@ import { SiafundElementAndClaim, SiafundElement, FileContractElement, -} from '@siafoundation/react-core' +} from '@siafoundation/types' export type ConsensusNetwork = { name: 'mainnet' | 'zen' diff --git a/libs/types/.babelrc b/libs/types/.babelrc new file mode 100644 index 000000000..1ea870ead --- /dev/null +++ b/libs/types/.babelrc @@ -0,0 +1,12 @@ +{ + "presets": [ + [ + "@nx/react/babel", + { + "runtime": "automatic", + "useBuiltIns": "usage" + } + ] + ], + "plugins": [] +} diff --git a/libs/types/.eslintrc.json b/libs/types/.eslintrc.json new file mode 100644 index 000000000..1e06b264c --- /dev/null +++ b/libs/types/.eslintrc.json @@ -0,0 +1,13 @@ +{ + "extends": ["plugin:@nx/react", "../../.eslintrc.json"], + "ignorePatterns": ["!**/*"], + "overrides": [ + { + "files": ["*.json"], + "parser": "jsonc-eslint-parser", + "rules": { + "@nx/dependency-checks": "error" + } + } + ] +} diff --git a/libs/types/CHANGELOG.md b/libs/types/CHANGELOG.md new file mode 100644 index 000000000..85ee4ce19 --- /dev/null +++ b/libs/types/CHANGELOG.md @@ -0,0 +1 @@ +# @siafoundation/types diff --git a/libs/types/README.md b/libs/types/README.md new file mode 100644 index 000000000..60b7b4016 --- /dev/null +++ b/libs/types/README.md @@ -0,0 +1,7 @@ +# types + +Core Sia types and library methods. + +## Running unit tests + +Run `nx test types` to execute the unit tests via [Jest](https://jestjs.io). diff --git a/libs/types/jest.config.ts b/libs/types/jest.config.ts new file mode 100644 index 000000000..7a7b41544 --- /dev/null +++ b/libs/types/jest.config.ts @@ -0,0 +1,10 @@ +/* eslint-disable */ +export default { + displayName: 'types', + preset: '../../jest.preset.js', + transform: { + '^.+\\.[tj]sx?$': ['babel-jest', { presets: ['@nx/react/babel'] }], + }, + moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], + coverageDirectory: '../../coverage/libs/types', +} diff --git a/libs/types/package.json b/libs/types/package.json new file mode 100644 index 000000000..522be2c5d --- /dev/null +++ b/libs/types/package.json @@ -0,0 +1,8 @@ +{ + "name": "@siafoundation/types", + "description": "Core Sia types and library methods.", + "version": "0.0.1", + "license": "MIT", + "dependencies": {}, + "types": "./src/index.d.ts" +} diff --git a/libs/types/project.json b/libs/types/project.json new file mode 100644 index 000000000..3723deae6 --- /dev/null +++ b/libs/types/project.json @@ -0,0 +1,48 @@ +{ + "name": "types", + "$schema": "../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "libs/types/src", + "projectType": "library", + "tags": [], + "targets": { + "build": { + "executor": "@nrwl/rollup:rollup", + "outputs": ["{options.outputPath}"], + "options": { + "outputPath": "dist/libs/types", + "tsConfig": "libs/types/tsconfig.lib.json", + "project": "libs/types/package.json", + "entryFile": "libs/types/src/index.ts", + "external": ["react/jsx-runtime"], + "rollupConfig": "@nx/react/plugins/bundle-rollup", + "compiler": "swc", + "assets": [ + { + "glob": "libs/types/*.md", + "input": ".", + "output": "." + } + ] + }, + "configurations": {} + }, + "lint": { + "executor": "@nx/linter:eslint", + "outputs": ["{options.outputFile}"], + "options": { + "lintFilePatterns": [ + "libs/types/**/*.{ts,tsx,js,jsx}", + "libs/types/package.json" + ] + } + }, + "test": { + "executor": "@nx/jest:jest", + "outputs": ["{workspaceRoot}/coverage/libs/types"], + "options": { + "jestConfig": "libs/types/jest.config.ts", + "passWithNoTests": true + } + } + } +} diff --git a/libs/react-core/src/siaTypes.ts b/libs/types/src/index.ts similarity index 97% rename from libs/react-core/src/siaTypes.ts rename to libs/types/src/index.ts index 5b6f83d81..d3ab50c98 100644 --- a/libs/react-core/src/siaTypes.ts +++ b/libs/types/src/index.ts @@ -13,11 +13,6 @@ export type SiacoinOutputID = Hash256 export type SiafundOutputID = Hash256 export type Address = string -// export type SiaPublicKey = { -// algorithm: string -// key?: string -// } - export type UnlockConditions = { timelock: number publicKeys?: PublicKey[] diff --git a/libs/types/tsconfig.json b/libs/types/tsconfig.json new file mode 100644 index 000000000..4c089585e --- /dev/null +++ b/libs/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/types/tsconfig.lib.json b/libs/types/tsconfig.lib.json new file mode 100644 index 000000000..621db72d7 --- /dev/null +++ b/libs/types/tsconfig.lib.json @@ -0,0 +1,23 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "types": ["node"] + }, + "files": [ + "../../node_modules/@nx/react/typings/cssmodule.d.ts", + "../../node_modules/@nx/react/typings/image.d.ts" + ], + "exclude": [ + "**/*.spec.ts", + "**/*.test.ts", + "**/*.spec.tsx", + "**/*.test.tsx", + "**/*.spec.js", + "**/*.test.js", + "**/*.spec.jsx", + "**/*.test.jsx", + "jest.config.ts" + ], + "include": ["**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx"] +} diff --git a/libs/types/tsconfig.spec.json b/libs/types/tsconfig.spec.json new file mode 100644 index 000000000..a85d573fc --- /dev/null +++ b/libs/types/tsconfig.spec.json @@ -0,0 +1,20 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "module": "commonjs", + "types": ["jest", "node"] + }, + "include": [ + "**/*.test.ts", + "**/*.spec.ts", + "**/*.test.tsx", + "**/*.spec.tsx", + "**/*.test.js", + "**/*.spec.js", + "**/*.test.jsx", + "**/*.spec.jsx", + "**/*.d.ts", + "jest.config.ts" + ] +} diff --git a/tsconfig.base.json b/tsconfig.base.json index aaff91b24..bc9fc4aa1 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -15,6 +15,7 @@ "skipDefaultLibCheck": true, "baseUrl": ".", "paths": { + "@siafoundation/types": ["libs/types/src/index.ts"], "@siafoundation/data-sources": ["libs/data-sources/src/index.ts"], "@siafoundation/design-system": ["libs/design-system/src/index.ts"], "@siafoundation/react-core": ["libs/react-core/src/index.ts"],