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

refactor: types library #438

Merged
merged 1 commit into from
Dec 8, 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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion apps/hostd/contexts/contracts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
Signature,
UnlockConditions,
SiacoinOutput,
} from '@siafoundation/react-core'
} from '@siafoundation/types'
import {
ContractFilterSortField,
ContractStatus,
Expand Down
2 changes: 1 addition & 1 deletion apps/hostd/contexts/transactions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
2 changes: 1 addition & 1 deletion apps/renterd/contexts/transactions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Transaction } from '@siafoundation/react-core'
import { Transaction } from '@siafoundation/types'
import { useCallback } from 'react'
import { SendParams } from '../_sharedWalletSend/types'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion apps/walletd/dialogs/WalletSendLedgerDialog/useSign.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion apps/walletd/dialogs/_sharedWalletSend/useBroadcast.tsx
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
2 changes: 1 addition & 1 deletion apps/walletd/dialogs/_sharedWalletSend/useCancel.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion apps/walletd/lib/sign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
2 changes: 1 addition & 1 deletion apps/walletd/lib/signLedger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion apps/walletd/lib/signSeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion apps/walletd/lib/testMocks.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion apps/walletd/lib/wasm.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
1 change: 1 addition & 0 deletions libs/design-system/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion libs/design-system/src/app/TransactionDetailsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
2 changes: 1 addition & 1 deletion libs/design-system/src/app/TxPoolList.tsx
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion libs/design-system/src/lib/entityTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Transaction } from '@siafoundation/react-core'
import { Transaction } from '@siafoundation/types'
import BigNumber from 'bignumber.js'

export type EntityType =
Expand Down
2 changes: 1 addition & 1 deletion libs/react-core/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
1 change: 0 additions & 1 deletion libs/react-core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from './types'
export * from './siaTypes'
export * from './utils'
export * from './usePost'
export * from './usePut'
Expand Down
1 change: 1 addition & 0 deletions libs/react-hostd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 6 additions & 4 deletions libs/react-hostd/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
2 changes: 1 addition & 1 deletion libs/react-hostd/src/siaTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Signature,
Currency,
FileContractID,
} from '@siafoundation/react-core'
} from '@siafoundation/types'

export interface WalletTransaction {
id: string
Expand Down
1 change: 1 addition & 0 deletions libs/react-renterd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
10 changes: 6 additions & 4 deletions libs/react-renterd/src/bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion libs/react-renterd/src/siaTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
EncryptionKey,
PublicKey,
TransactionSignature,
} from '@siafoundation/react-core'
} from '@siafoundation/types'

export type ConsensusState = {
blockHeight: number
Expand Down
1 change: 1 addition & 0 deletions libs/react-walletd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion libs/react-walletd/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
getMainnetBlockHeight,
getTestnetZenBlockHeight,
useDeleteFunc,
} from '@siafoundation/react-core'
import {
Currency,
BlockHeight,
ChainIndex,
Expand All @@ -17,7 +19,7 @@ import {
SiacoinElement,
SiafundElement,
Transaction,
} from '@siafoundation/react-core'
} from '@siafoundation/types'
import {
ConsensusState,
ConsensusNetwork,
Expand Down
2 changes: 1 addition & 1 deletion libs/react-walletd/src/siaTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
SiafundElementAndClaim,
SiafundElement,
FileContractElement,
} from '@siafoundation/react-core'
} from '@siafoundation/types'

export type ConsensusNetwork = {
name: 'mainnet' | 'zen'
Expand Down
12 changes: 12 additions & 0 deletions libs/types/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"presets": [
[
"@nx/react/babel",
{
"runtime": "automatic",
"useBuiltIns": "usage"
}
]
],
"plugins": []
}
13 changes: 13 additions & 0 deletions libs/types/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": ["plugin:@nx/react", "../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": "error"
}
}
]
}
1 change: 1 addition & 0 deletions libs/types/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# @siafoundation/types
7 changes: 7 additions & 0 deletions libs/types/README.md
Original file line number Diff line number Diff line change
@@ -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).
10 changes: 10 additions & 0 deletions libs/types/jest.config.ts
Original file line number Diff line number Diff line change
@@ -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',
}
8 changes: 8 additions & 0 deletions libs/types/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
48 changes: 48 additions & 0 deletions libs/types/project.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}
}
5 changes: 0 additions & 5 deletions libs/react-core/src/siaTypes.ts → libs/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down
Loading