From ff7678d3d681915c06d677dc5f37d96b6800e6bb Mon Sep 17 00:00:00 2001 From: Alex Freska Date: Sun, 14 Apr 2024 20:32:44 +0200 Subject: [PATCH] refactor: split out sia-central-types --- .../src/core/SiacoinField.spec.tsx | 2 +- libs/{sia-central => sia-central-js}/.babelrc | 0 .../.eslintrc.json | 2 +- .../CHANGELOG.md | 2 +- libs/sia-central-js/README.md | 7 ++++ .../jest.config.ts | 4 +- .../package.json | 5 ++- .../project.json | 20 ++++----- .../rollup.config.js | 0 libs/sia-central-js/src/address.ts | 18 ++++++++ .../src/block.ts} | 15 +++---- .../src/blockLatest.ts} | 10 ++--- .../src/blocks.ts} | 16 +++---- .../src/contract.ts} | 15 +++---- libs/sia-central-js/src/exchangeRates.ts | 16 +++++++ .../src/fetch.ts | 0 .../src/host.ts} | 16 +++---- .../src/hosts.ts} | 19 +++------ .../src/hostsNetworkAverages.ts} | 10 ++--- .../sia-central-js/src/hostsNetworkMetrics.ts | 16 +++++++ libs/sia-central-js/src/index.ts | 12 ++++++ libs/sia-central-js/src/search.ts | 18 ++++++++ .../src/transaction.ts} | 16 +++---- .../tsconfig.json | 0 .../tsconfig.lib.json | 0 .../tsconfig.spec.json | 0 libs/sia-central-mock/package.json | 4 +- .../src/siaCentralExchangeRates.ts | 2 +- libs/sia-central-react/package.json | 4 +- .../src/useSiaCentralAddress.tsx | 2 +- .../src/useSiaCentralBlock.tsx | 2 +- .../src/useSiaCentralBlockLatest.tsx | 2 +- .../src/useSiaCentralBlocks.tsx | 2 +- .../src/useSiaCentralContract.tsx | 2 +- .../src/useSiaCentralExchangeRates.tsx | 2 +- .../src/useSiaCentralHost.tsx | 2 +- .../src/useSiaCentralHosts.tsx | 2 +- .../src/useSiaCentralHostsNetworkAverages.tsx | 2 +- .../src/useSiaCentralHostsNetworkMetrics.tsx | 2 +- .../src/useSiaCentralSearch.tsx | 2 +- .../src/useSiaCentralTransaction.tsx | 2 +- libs/sia-central-types/.babelrc | 12 ++++++ libs/sia-central-types/.eslintrc.json | 21 ++++++++++ libs/sia-central-types/README.md | 3 ++ libs/sia-central-types/jest.config.ts | 17 ++++++++ libs/sia-central-types/package.json | 8 ++++ libs/sia-central-types/project.json | 42 +++++++++++++++++++ libs/sia-central-types/rollup.config.js | 18 ++++++++ .../src/address.ts} | 15 +------ libs/sia-central-types/src/block.ts | 10 +++++ libs/sia-central-types/src/blockLatest.ts | 6 +++ libs/sia-central-types/src/blocks.ts | 11 +++++ libs/sia-central-types/src/config.ts | 1 + libs/sia-central-types/src/contract.ts | 10 +++++ .../src/exchangeRates.ts} | 14 ------- libs/sia-central-types/src/host.ts | 11 +++++ libs/sia-central-types/src/hosts.ts | 14 +++++++ .../src/hostsNetworkAverages.ts | 6 +++ .../src/hostsNetworkMetrics.ts} | 14 +------ libs/sia-central-types/src/index.ts | 14 +++++++ .../src/search.ts} | 14 ------- libs/sia-central-types/src/transaction.ts | 11 +++++ .../src/types.ts} | 2 - libs/sia-central-types/tsconfig.json | 25 +++++++++++ libs/sia-central-types/tsconfig.lib.json | 22 ++++++++++ libs/sia-central-types/tsconfig.spec.json | 19 +++++++++ libs/sia-central/README.md | 7 ---- libs/sia-central/src/index.ts | 13 ------ libs/units/package.json | 10 ++--- libs/units/src/storage.ts | 2 +- tsconfig.base.json | 15 ++++--- 71 files changed, 457 insertions(+), 203 deletions(-) rename libs/{sia-central => sia-central-js}/.babelrc (100%) rename libs/{sia-central => sia-central-js}/.eslintrc.json (84%) rename libs/{sia-central => sia-central-js}/CHANGELOG.md (93%) create mode 100644 libs/sia-central-js/README.md rename libs/{sia-central => sia-central-js}/jest.config.ts (80%) rename libs/{sia-central => sia-central-js}/package.json (58%) rename libs/{sia-central => sia-central-js}/project.json (56%) rename libs/{sia-central => sia-central-js}/rollup.config.js (100%) create mode 100644 libs/sia-central-js/src/address.ts rename libs/{sia-central/src/siaCentralBlock.tsx => sia-central-js/src/block.ts} (61%) rename libs/{sia-central/src/siaCentralBlockLatest.tsx => sia-central-js/src/blockLatest.ts} (61%) rename libs/{sia-central/src/siaCentralBlocks.tsx => sia-central-js/src/blocks.ts} (61%) rename libs/{sia-central/src/siaCentralContract.tsx => sia-central-js/src/contract.ts} (60%) create mode 100644 libs/sia-central-js/src/exchangeRates.ts rename libs/{sia-central => sia-central-js}/src/fetch.ts (100%) rename libs/{sia-central/src/siaCentralHost.tsx => sia-central-js/src/host.ts} (58%) rename libs/{sia-central/src/siaCentralHosts.tsx => sia-central-js/src/hosts.ts} (67%) rename libs/{sia-central/src/siaCentralHostsNetworkAverages.tsx => sia-central-js/src/hostsNetworkAverages.ts} (62%) create mode 100644 libs/sia-central-js/src/hostsNetworkMetrics.ts create mode 100644 libs/sia-central-js/src/index.ts create mode 100644 libs/sia-central-js/src/search.ts rename libs/{sia-central/src/siaCentralTransaction.tsx => sia-central-js/src/transaction.ts} (57%) rename libs/{sia-central => sia-central-js}/tsconfig.json (100%) rename libs/{sia-central => sia-central-js}/tsconfig.lib.json (100%) rename libs/{sia-central => sia-central-js}/tsconfig.spec.json (100%) create mode 100644 libs/sia-central-types/.babelrc create mode 100644 libs/sia-central-types/.eslintrc.json create mode 100644 libs/sia-central-types/README.md create mode 100644 libs/sia-central-types/jest.config.ts create mode 100644 libs/sia-central-types/package.json create mode 100644 libs/sia-central-types/project.json create mode 100644 libs/sia-central-types/rollup.config.js rename libs/{sia-central/src/siaCentralAddress.tsx => sia-central-types/src/address.ts} (58%) create mode 100644 libs/sia-central-types/src/block.ts create mode 100644 libs/sia-central-types/src/blockLatest.ts create mode 100644 libs/sia-central-types/src/blocks.ts create mode 100644 libs/sia-central-types/src/config.ts create mode 100644 libs/sia-central-types/src/contract.ts rename libs/{sia-central/src/siaCentralExchangeRates.tsx => sia-central-types/src/exchangeRates.ts} (56%) create mode 100644 libs/sia-central-types/src/host.ts create mode 100644 libs/sia-central-types/src/hosts.ts create mode 100644 libs/sia-central-types/src/hostsNetworkAverages.ts rename libs/{sia-central/src/siaCentralHostsNetworkMetrics.tsx => sia-central-types/src/hostsNetworkMetrics.ts} (53%) create mode 100644 libs/sia-central-types/src/index.ts rename libs/{sia-central/src/siaCentralSearch.tsx => sia-central-types/src/search.ts} (58%) create mode 100644 libs/sia-central-types/src/transaction.ts rename libs/{sia-central/src/types.tsx => sia-central-types/src/types.ts} (99%) create mode 100644 libs/sia-central-types/tsconfig.json create mode 100644 libs/sia-central-types/tsconfig.lib.json create mode 100644 libs/sia-central-types/tsconfig.spec.json delete mode 100644 libs/sia-central/README.md delete mode 100644 libs/sia-central/src/index.ts diff --git a/libs/design-system/src/core/SiacoinField.spec.tsx b/libs/design-system/src/core/SiacoinField.spec.tsx index 218ad04e5..1a78538e8 100644 --- a/libs/design-system/src/core/SiacoinField.spec.tsx +++ b/libs/design-system/src/core/SiacoinField.spec.tsx @@ -8,7 +8,7 @@ import { SiacoinField } from './SiacoinField' import { fireEvent, render, waitFor, act } from '@testing-library/react' import userEvent from '@testing-library/user-event' import { useState } from 'react' -import { SiaCentralExchangeRatesResponse } from '@siafoundation/sia-central' +import { SiaCentralExchangeRatesResponse } from '@siafoundation/sia-central-types' import { setupServer } from 'msw/node' import { HttpResponse, http } from 'msw' diff --git a/libs/sia-central/.babelrc b/libs/sia-central-js/.babelrc similarity index 100% rename from libs/sia-central/.babelrc rename to libs/sia-central-js/.babelrc diff --git a/libs/sia-central/.eslintrc.json b/libs/sia-central-js/.eslintrc.json similarity index 84% rename from libs/sia-central/.eslintrc.json rename to libs/sia-central-js/.eslintrc.json index 1da02672e..12e4c0bb1 100644 --- a/libs/sia-central/.eslintrc.json +++ b/libs/sia-central-js/.eslintrc.json @@ -5,7 +5,7 @@ "@nx/dependency-checks": [ "error", { - "ignoredFiles": ["libs/sia-central/rollup.config.js"] + "ignoredFiles": ["libs/sia-central-js/rollup.config.js"] } ] }, diff --git a/libs/sia-central/CHANGELOG.md b/libs/sia-central-js/CHANGELOG.md similarity index 93% rename from libs/sia-central/CHANGELOG.md rename to libs/sia-central-js/CHANGELOG.md index 2cd2e9d09..2e7ed27ce 100644 --- a/libs/sia-central/CHANGELOG.md +++ b/libs/sia-central-js/CHANGELOG.md @@ -1,4 +1,4 @@ -# @siafoundation/sia-central +# @siafoundation/sia-central-js ## 0.3.3 diff --git a/libs/sia-central-js/README.md b/libs/sia-central-js/README.md new file mode 100644 index 000000000..0e54a0556 --- /dev/null +++ b/libs/sia-central-js/README.md @@ -0,0 +1,7 @@ +# sia-central-js + +Methods and types for interacting with the Sia Central API. + +## Running unit tests + +Run `nx test sia-central-js` to execute the unit tests via [Jest](https://jestjs.io). diff --git a/libs/sia-central/jest.config.ts b/libs/sia-central-js/jest.config.ts similarity index 80% rename from libs/sia-central/jest.config.ts rename to libs/sia-central-js/jest.config.ts index e355f2554..b1b82c844 100644 --- a/libs/sia-central/jest.config.ts +++ b/libs/sia-central-js/jest.config.ts @@ -1,6 +1,6 @@ /* eslint-disable */ export default { - displayName: 'sia-central', + displayName: 'sia-central-js', preset: '../../jest.preset.js', transform: { '^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '@nx/react/plugins/jest', @@ -13,5 +13,5 @@ export default { ], }, moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], - coverageDirectory: '../../coverage/libs/sia-central', + coverageDirectory: '../../coverage/libs/sia-central-js', } diff --git a/libs/sia-central/package.json b/libs/sia-central-js/package.json similarity index 58% rename from libs/sia-central/package.json rename to libs/sia-central-js/package.json index b7e2a2d0f..5fe891726 100644 --- a/libs/sia-central/package.json +++ b/libs/sia-central-js/package.json @@ -1,10 +1,11 @@ { - "name": "@siafoundation/sia-central", + "name": "@siafoundation/sia-central-js", "description": "Methods and types for interacting with the Sia Central API.", "version": "0.3.3", "license": "MIT", "dependencies": { - "@technically/lodash": "^4.17.0" + "@technically/lodash": "^4.17.0", + "@siafoundation/sia-central-types": "0.0.0" }, "types": "./src/index.d.ts" } diff --git a/libs/sia-central/project.json b/libs/sia-central-js/project.json similarity index 56% rename from libs/sia-central/project.json rename to libs/sia-central-js/project.json index d02bc8bf0..a094d9ce0 100644 --- a/libs/sia-central/project.json +++ b/libs/sia-central-js/project.json @@ -1,7 +1,7 @@ { - "name": "sia-central", + "name": "sia-central-js", "$schema": "../../node_modules/nx/schemas/project-schema.json", - "sourceRoot": "libs/sia-central/src", + "sourceRoot": "libs/sia-central-js/src", "projectType": "library", "tags": [], "targets": { @@ -9,17 +9,17 @@ "executor": "@nx/rollup:rollup", "outputs": ["{options.outputPath}"], "options": { - "outputPath": "dist/libs/sia-central", - "tsConfig": "libs/sia-central/tsconfig.lib.json", - "project": "libs/sia-central/package.json", - "entryFile": "libs/sia-central/src/index.ts", + "outputPath": "dist/libs/sia-central-js", + "tsConfig": "libs/sia-central-js/tsconfig.lib.json", + "project": "libs/sia-central-js/package.json", + "entryFile": "libs/sia-central-js/src/index.ts", "external": ["react/jsx-runtime"], "compiler": "tsc", "outputFileName": "index.js", - "rollupConfig": "libs/sia-central/rollup.config.js", + "rollupConfig": "libs/sia-central-js/rollup.config.js", "assets": [ { - "glob": "libs/sia-central/*.md", + "glob": "libs/sia-central-js/*.md", "input": ".", "output": "." } @@ -33,9 +33,9 @@ }, "test": { "executor": "@nx/jest:jest", - "outputs": ["{workspaceRoot}/coverage/libs/sia-central"], + "outputs": ["{workspaceRoot}/coverage/libs/sia-central-js"], "options": { - "jestConfig": "libs/sia-central/jest.config.ts" + "jestConfig": "libs/sia-central-js/jest.config.ts" } } } diff --git a/libs/sia-central/rollup.config.js b/libs/sia-central-js/rollup.config.js similarity index 100% rename from libs/sia-central/rollup.config.js rename to libs/sia-central-js/rollup.config.js diff --git a/libs/sia-central-js/src/address.ts b/libs/sia-central-js/src/address.ts new file mode 100644 index 000000000..6dbd7516b --- /dev/null +++ b/libs/sia-central-js/src/address.ts @@ -0,0 +1,18 @@ +import { runFetch } from './fetch' +import { + api, + SiaCentralAddressParams, + SiaCentralAddressResponse, +} from '@siafoundation/sia-central-types' + +export async function getSiaCentralAddress(args: { + params: SiaCentralAddressParams + config?: { + api: string + } +}) { + const { params, config } = args + return runFetch( + `${config?.api || api}/wallet/addresses/${params.id}` + ) +} diff --git a/libs/sia-central/src/siaCentralBlock.tsx b/libs/sia-central-js/src/block.ts similarity index 61% rename from libs/sia-central/src/siaCentralBlock.tsx rename to libs/sia-central-js/src/block.ts index 6c96816f9..ea2de9d4e 100644 --- a/libs/sia-central/src/siaCentralBlock.tsx +++ b/libs/sia-central-js/src/block.ts @@ -1,14 +1,9 @@ import { runFetch } from './fetch' -import { SiaCentralBlock, api } from './types' - -export type SiaCentralBlockParams = { - id: string -} - -export type SiaCentralBlockResponse = { - message: string - block: SiaCentralBlock -} +import { + api, + SiaCentralBlockParams, + SiaCentralBlockResponse, +} from '@siafoundation/sia-central-types' export async function getSiaCentralBlock(args: { params: SiaCentralBlockParams diff --git a/libs/sia-central/src/siaCentralBlockLatest.tsx b/libs/sia-central-js/src/blockLatest.ts similarity index 61% rename from libs/sia-central/src/siaCentralBlockLatest.tsx rename to libs/sia-central-js/src/blockLatest.ts index 8ba78268c..3ab7194be 100644 --- a/libs/sia-central/src/siaCentralBlockLatest.tsx +++ b/libs/sia-central-js/src/blockLatest.ts @@ -1,10 +1,8 @@ -import { api, SiaCentralBlock } from './types' import { runFetch } from './fetch' - -export type SiaCentralBlockLatestResponse = { - message: string - block: Omit -} +import { + api, + SiaCentralBlockLatestResponse, +} from '@siafoundation/sia-central-types' export async function getSiaCentralBlockLatest(args?: { config?: { diff --git a/libs/sia-central/src/siaCentralBlocks.tsx b/libs/sia-central-js/src/blocks.ts similarity index 61% rename from libs/sia-central/src/siaCentralBlocks.tsx rename to libs/sia-central-js/src/blocks.ts index e38408102..ab2e829af 100644 --- a/libs/sia-central/src/siaCentralBlocks.tsx +++ b/libs/sia-central-js/src/blocks.ts @@ -1,16 +1,10 @@ -import { api, SiaCentralBlock } from './types' +import { + api, + SiaCentralBlocksPayload, + SiaCentralBlocksResponse, +} from '@siafoundation/sia-central-types' import { runFetch } from './fetch' -export type SiaCentralBlocksResponse = { - message: string - blocks: SiaCentralBlock[] -} - -export type SiaCentralBlocksPayload = { - block_ids?: number[] - heights?: number[] -} - export async function getSiaCentralBlocks(args: { payload: SiaCentralBlocksPayload config?: { diff --git a/libs/sia-central/src/siaCentralContract.tsx b/libs/sia-central-js/src/contract.ts similarity index 60% rename from libs/sia-central/src/siaCentralContract.tsx rename to libs/sia-central-js/src/contract.ts index 61863533a..02d4cb6e1 100644 --- a/libs/sia-central/src/siaCentralContract.tsx +++ b/libs/sia-central-js/src/contract.ts @@ -1,14 +1,9 @@ import { runFetch } from './fetch' -import { api, SiaCentralContract } from './types' - -export type SiaCentralContractParams = { - id: string -} - -export type SiaCentralContractResponse = { - message: string - contract: SiaCentralContract -} +import { + api, + SiaCentralContractParams, + SiaCentralContractResponse, +} from '@siafoundation/sia-central-types' export async function getSiaCentralContract(args: { params: SiaCentralContractParams diff --git a/libs/sia-central-js/src/exchangeRates.ts b/libs/sia-central-js/src/exchangeRates.ts new file mode 100644 index 000000000..75fd6cc6e --- /dev/null +++ b/libs/sia-central-js/src/exchangeRates.ts @@ -0,0 +1,16 @@ +import { runFetch } from './fetch' +import { + api, + SiaCentralExchangeRatesResponse, +} from '@siafoundation/sia-central-types' + +export async function getSiaCentralExchangeRates(args?: { + config?: { + api: string + } +}) { + const { config } = args || {} + return runFetch( + `${config?.api || api}/market/exchange-rate?currencies=sc` + ) +} diff --git a/libs/sia-central/src/fetch.ts b/libs/sia-central-js/src/fetch.ts similarity index 100% rename from libs/sia-central/src/fetch.ts rename to libs/sia-central-js/src/fetch.ts diff --git a/libs/sia-central/src/siaCentralHost.tsx b/libs/sia-central-js/src/host.ts similarity index 58% rename from libs/sia-central/src/siaCentralHost.tsx rename to libs/sia-central-js/src/host.ts index 179960b02..ec06c60bf 100644 --- a/libs/sia-central/src/siaCentralHost.tsx +++ b/libs/sia-central-js/src/host.ts @@ -1,15 +1,9 @@ import { runFetch } from './fetch' -import { SiaCentralHost, api } from './types' - -export type SiaCentralHostParams = { - id: string -} - -export type SiaCentralHostResponse = { - message: string - type: string - host: SiaCentralHost -} +import { + api, + SiaCentralHostParams, + SiaCentralHostResponse, +} from '@siafoundation/sia-central-types' export async function getSiaCentralHost(args: { params: SiaCentralHostParams diff --git a/libs/sia-central/src/siaCentralHosts.tsx b/libs/sia-central-js/src/hosts.ts similarity index 67% rename from libs/sia-central/src/siaCentralHosts.tsx rename to libs/sia-central-js/src/hosts.ts index b8b4bf7c7..8e9f3f1b5 100644 --- a/libs/sia-central/src/siaCentralHosts.tsx +++ b/libs/sia-central-js/src/hosts.ts @@ -1,19 +1,10 @@ import { merge } from '@technically/lodash' import { runFetch } from './fetch' -import { SiaCentralHost, api } from './types' - -export type SiaCentralHostsParams = { - limit?: number - page?: number -} - -export type SiaCentralHostsResponse = { - message: string - count: number - total: number - type: string - hosts: SiaCentralHost[] -} +import { + api, + SiaCentralHostsParams, + SiaCentralHostsResponse, +} from '@siafoundation/sia-central-types' export async function getSiaCentralHosts(args?: { params?: SiaCentralHostsParams diff --git a/libs/sia-central/src/siaCentralHostsNetworkAverages.tsx b/libs/sia-central-js/src/hostsNetworkAverages.ts similarity index 62% rename from libs/sia-central/src/siaCentralHostsNetworkAverages.tsx rename to libs/sia-central-js/src/hostsNetworkAverages.ts index e8ef24947..008ec299d 100644 --- a/libs/sia-central/src/siaCentralHostsNetworkAverages.tsx +++ b/libs/sia-central-js/src/hostsNetworkAverages.ts @@ -1,10 +1,8 @@ import { runFetch } from './fetch' -import { SiaCentralNetworkStats, api } from './types' - -export type SiaCentralHostsNetworkAveragesResponse = { - message: string - type: string -} & SiaCentralNetworkStats +import { + api, + SiaCentralHostsNetworkAveragesResponse, +} from '@siafoundation/sia-central-types' export async function getSiaCentralHostsNetworkAverages(args?: { config?: { diff --git a/libs/sia-central-js/src/hostsNetworkMetrics.ts b/libs/sia-central-js/src/hostsNetworkMetrics.ts new file mode 100644 index 000000000..dda6ace05 --- /dev/null +++ b/libs/sia-central-js/src/hostsNetworkMetrics.ts @@ -0,0 +1,16 @@ +import { runFetch } from './fetch' +import { + api, + SiaCentralHostsNetworkMetricsResponse, +} from '@siafoundation/sia-central-types' + +export async function getSiaCentralHostsNetworkMetrics(args?: { + config?: { + api: string + } +}) { + const { config } = args || {} + return runFetch( + `${config?.api || api}/hosts/network/metrics` + ) +} diff --git a/libs/sia-central-js/src/index.ts b/libs/sia-central-js/src/index.ts new file mode 100644 index 000000000..2d5b3ffe9 --- /dev/null +++ b/libs/sia-central-js/src/index.ts @@ -0,0 +1,12 @@ +export * from './address' +export * from './blockLatest' +export * from './block' +export * from './blocks' +export * from './contract' +export * from './host' +export * from './hosts' +export * from './hostsNetworkAverages' +export * from './hostsNetworkMetrics' +export * from './exchangeRates' +export * from './transaction' +export * from './search' diff --git a/libs/sia-central-js/src/search.ts b/libs/sia-central-js/src/search.ts new file mode 100644 index 000000000..657102031 --- /dev/null +++ b/libs/sia-central-js/src/search.ts @@ -0,0 +1,18 @@ +import { runFetch } from './fetch' +import { + api, + SiaCentralSearchParams, + SiaCentralSearchResponse, +} from '@siafoundation/sia-central-types' + +export async function getSiaCentralSearch(args: { + params: SiaCentralSearchParams + config?: { + api: string + } +}) { + const { params, config } = args + return runFetch( + `${config?.api || api}/explorer/search/${params.query}` + ) +} diff --git a/libs/sia-central/src/siaCentralTransaction.tsx b/libs/sia-central-js/src/transaction.ts similarity index 57% rename from libs/sia-central/src/siaCentralTransaction.tsx rename to libs/sia-central-js/src/transaction.ts index ecdb4217e..d99ac64d5 100644 --- a/libs/sia-central/src/siaCentralTransaction.tsx +++ b/libs/sia-central-js/src/transaction.ts @@ -1,16 +1,10 @@ -import { api, SiaCentralTransaction } from './types' +import { + api, + SiaCentralTransactionParams, + SiaCentralTransactionResponse, +} from '@siafoundation/sia-central-types' import { runFetch } from './fetch' -export type SiaCentralTransactionParams = { - id: string -} - -export type SiaCentralTransactionResponse = { - message: string - type?: 'error' - transaction: SiaCentralTransaction -} - export async function getSiaCentralTransaction(args: { params: SiaCentralTransactionParams config?: { diff --git a/libs/sia-central/tsconfig.json b/libs/sia-central-js/tsconfig.json similarity index 100% rename from libs/sia-central/tsconfig.json rename to libs/sia-central-js/tsconfig.json diff --git a/libs/sia-central/tsconfig.lib.json b/libs/sia-central-js/tsconfig.lib.json similarity index 100% rename from libs/sia-central/tsconfig.lib.json rename to libs/sia-central-js/tsconfig.lib.json diff --git a/libs/sia-central/tsconfig.spec.json b/libs/sia-central-js/tsconfig.spec.json similarity index 100% rename from libs/sia-central/tsconfig.spec.json rename to libs/sia-central-js/tsconfig.spec.json diff --git a/libs/sia-central-mock/package.json b/libs/sia-central-mock/package.json index 5e15aebbf..86c7d1870 100644 --- a/libs/sia-central-mock/package.json +++ b/libs/sia-central-mock/package.json @@ -4,8 +4,8 @@ "version": "0.0.0", "license": "MIT", "dependencies": { - "@siafoundation/sia-central": "0.3.3", - "playwright": "^1.42.1" + "playwright": "^1.42.1", + "@siafoundation/sia-central-types": "0.0.0" }, "types": "./src/index.d.ts" } diff --git a/libs/sia-central-mock/src/siaCentralExchangeRates.ts b/libs/sia-central-mock/src/siaCentralExchangeRates.ts index dda0d9be9..a3e0b5ab7 100644 --- a/libs/sia-central-mock/src/siaCentralExchangeRates.ts +++ b/libs/sia-central-mock/src/siaCentralExchangeRates.ts @@ -1,4 +1,4 @@ -import { SiaCentralExchangeRatesResponse } from '@siafoundation/sia-central' +import { SiaCentralExchangeRatesResponse } from '@siafoundation/sia-central-types' import { Page } from 'playwright' export function getMockSiaCentralExchangeRatesResponse(): SiaCentralExchangeRatesResponse { diff --git a/libs/sia-central-react/package.json b/libs/sia-central-react/package.json index e296c3f9b..4382828f3 100644 --- a/libs/sia-central-react/package.json +++ b/libs/sia-central-react/package.json @@ -3,9 +3,9 @@ "description": "React hooks for interacting with the Sia Central API.", "version": "3.0.0", "license": "MIT", - "peerDependencies": { + "dependencies": { "@siafoundation/react-core": "^1.1.0", - "@siafoundation/sia-central": "^0.3.3" + "@siafoundation/sia-central-types": "0.0.0" }, "types": "./src/index.d.ts" } diff --git a/libs/sia-central-react/src/useSiaCentralAddress.tsx b/libs/sia-central-react/src/useSiaCentralAddress.tsx index 7303c48e4..fb74c0393 100644 --- a/libs/sia-central-react/src/useSiaCentralAddress.tsx +++ b/libs/sia-central-react/src/useSiaCentralAddress.tsx @@ -7,7 +7,7 @@ import { api, SiaCentralAddressParams, SiaCentralAddressResponse, -} from '@siafoundation/sia-central' +} from '@siafoundation/sia-central-types' export function useSiaCentralAddress( args?: HookArgsSwr diff --git a/libs/sia-central-react/src/useSiaCentralBlock.tsx b/libs/sia-central-react/src/useSiaCentralBlock.tsx index 0f77e246d..e8240ee25 100644 --- a/libs/sia-central-react/src/useSiaCentralBlock.tsx +++ b/libs/sia-central-react/src/useSiaCentralBlock.tsx @@ -7,7 +7,7 @@ import { api, SiaCentralBlockParams, SiaCentralBlockResponse, -} from '@siafoundation/sia-central' +} from '@siafoundation/sia-central-types' export function useSiaCentralBlock( args?: HookArgsSwr diff --git a/libs/sia-central-react/src/useSiaCentralBlockLatest.tsx b/libs/sia-central-react/src/useSiaCentralBlockLatest.tsx index 65456a09b..34c3b3dd4 100644 --- a/libs/sia-central-react/src/useSiaCentralBlockLatest.tsx +++ b/libs/sia-central-react/src/useSiaCentralBlockLatest.tsx @@ -3,7 +3,7 @@ import { HookArgsSwr, useGetSwr, } from '@siafoundation/react-core' -import { api, SiaCentralBlock } from '@siafoundation/sia-central' +import { api, SiaCentralBlock } from '@siafoundation/sia-central-types' type SiaCentralBlockLatestResponse = { message: string diff --git a/libs/sia-central-react/src/useSiaCentralBlocks.tsx b/libs/sia-central-react/src/useSiaCentralBlocks.tsx index 8a3ec1694..026f6572a 100644 --- a/libs/sia-central-react/src/useSiaCentralBlocks.tsx +++ b/libs/sia-central-react/src/useSiaCentralBlocks.tsx @@ -7,7 +7,7 @@ import { api, SiaCentralBlock, SiaCentralBlocksPayload, -} from '@siafoundation/sia-central' +} from '@siafoundation/sia-central-types' type SiaCentralBlocksResposne = { message: string diff --git a/libs/sia-central-react/src/useSiaCentralContract.tsx b/libs/sia-central-react/src/useSiaCentralContract.tsx index 1eb82bb01..e50df6e58 100644 --- a/libs/sia-central-react/src/useSiaCentralContract.tsx +++ b/libs/sia-central-react/src/useSiaCentralContract.tsx @@ -7,7 +7,7 @@ import { api, SiaCentralContractParams, SiaCentralContractResponse, -} from '@siafoundation/sia-central' +} from '@siafoundation/sia-central-types' export function useSiaCentralContract( args?: HookArgsSwr diff --git a/libs/sia-central-react/src/useSiaCentralExchangeRates.tsx b/libs/sia-central-react/src/useSiaCentralExchangeRates.tsx index cea366bb9..b1f0db9a5 100644 --- a/libs/sia-central-react/src/useSiaCentralExchangeRates.tsx +++ b/libs/sia-central-react/src/useSiaCentralExchangeRates.tsx @@ -6,7 +6,7 @@ import { import { api, SiaCentralExchangeRatesResponse, -} from '@siafoundation/sia-central' +} from '@siafoundation/sia-central-types' export function useSiaCentralExchangeRates( args?: HookArgsSwr diff --git a/libs/sia-central-react/src/useSiaCentralHost.tsx b/libs/sia-central-react/src/useSiaCentralHost.tsx index 3693b0acd..a2b95fb99 100644 --- a/libs/sia-central-react/src/useSiaCentralHost.tsx +++ b/libs/sia-central-react/src/useSiaCentralHost.tsx @@ -7,7 +7,7 @@ import { SiaCentralHostResponse, SiaCentralHostParams, api, -} from '@siafoundation/sia-central' +} from '@siafoundation/sia-central-types' export function useSiaCentralHost( args?: HookArgsSwr diff --git a/libs/sia-central-react/src/useSiaCentralHosts.tsx b/libs/sia-central-react/src/useSiaCentralHosts.tsx index 92d16d453..d79182125 100644 --- a/libs/sia-central-react/src/useSiaCentralHosts.tsx +++ b/libs/sia-central-react/src/useSiaCentralHosts.tsx @@ -3,7 +3,7 @@ import { useAppSettings, HookArgsSwr, } from '@siafoundation/react-core' -import { SiaCentralHostsResponse, api } from '@siafoundation/sia-central' +import { SiaCentralHostsResponse, api } from '@siafoundation/sia-central-types' export function useSiaCentralHosts( args?: HookArgsSwr diff --git a/libs/sia-central-react/src/useSiaCentralHostsNetworkAverages.tsx b/libs/sia-central-react/src/useSiaCentralHostsNetworkAverages.tsx index 89ecccb5a..f96eb5552 100644 --- a/libs/sia-central-react/src/useSiaCentralHostsNetworkAverages.tsx +++ b/libs/sia-central-react/src/useSiaCentralHostsNetworkAverages.tsx @@ -6,7 +6,7 @@ import { import { api, SiaCentralHostsNetworkAveragesResponse, -} from '@siafoundation/sia-central' +} from '@siafoundation/sia-central-types' export function useSiaCentralHostsNetworkAverages( args?: HookArgsSwr diff --git a/libs/sia-central-react/src/useSiaCentralHostsNetworkMetrics.tsx b/libs/sia-central-react/src/useSiaCentralHostsNetworkMetrics.tsx index a053a1d2e..82c407094 100644 --- a/libs/sia-central-react/src/useSiaCentralHostsNetworkMetrics.tsx +++ b/libs/sia-central-react/src/useSiaCentralHostsNetworkMetrics.tsx @@ -6,7 +6,7 @@ import { import { api, SiaCentralHostsNetworkMetricsResponse, -} from '@siafoundation/sia-central' +} from '@siafoundation/sia-central-types' export function useSiaCentralHostsNetworkMetrics( args?: HookArgsSwr diff --git a/libs/sia-central-react/src/useSiaCentralSearch.tsx b/libs/sia-central-react/src/useSiaCentralSearch.tsx index 27bfdec07..f245e1117 100644 --- a/libs/sia-central-react/src/useSiaCentralSearch.tsx +++ b/libs/sia-central-react/src/useSiaCentralSearch.tsx @@ -7,7 +7,7 @@ import { api, SiaCentralSearchParams, SiaCentralSearchResponse, -} from '@siafoundation/sia-central' +} from '@siafoundation/sia-central-types' export function useSiaCentralSearch( args?: HookArgsCallback< diff --git a/libs/sia-central-react/src/useSiaCentralTransaction.tsx b/libs/sia-central-react/src/useSiaCentralTransaction.tsx index 3f3ca0e0a..c3fbd312b 100644 --- a/libs/sia-central-react/src/useSiaCentralTransaction.tsx +++ b/libs/sia-central-react/src/useSiaCentralTransaction.tsx @@ -7,7 +7,7 @@ import { api, SiaCentralTransactionParams, SiaCentralTransactionResponse, -} from '@siafoundation/sia-central' +} from '@siafoundation/sia-central-types' export function useSiaCentralTransaction( args?: HookArgsSwr diff --git a/libs/sia-central-types/.babelrc b/libs/sia-central-types/.babelrc new file mode 100644 index 000000000..1ea870ead --- /dev/null +++ b/libs/sia-central-types/.babelrc @@ -0,0 +1,12 @@ +{ + "presets": [ + [ + "@nx/react/babel", + { + "runtime": "automatic", + "useBuiltIns": "usage" + } + ] + ], + "plugins": [] +} diff --git a/libs/sia-central-types/.eslintrc.json b/libs/sia-central-types/.eslintrc.json new file mode 100644 index 000000000..54f8472e1 --- /dev/null +++ b/libs/sia-central-types/.eslintrc.json @@ -0,0 +1,21 @@ +{ + "extends": ["plugin:@nx/react", "../../.eslintrc.json"], + "ignorePatterns": ["!**/*"], + "rules": { + "@nx/dependency-checks": [ + "error", + { + "ignoredFiles": ["libs/sia-central-types/rollup.config.js"] + } + ] + }, + "overrides": [ + { + "files": ["*.json"], + "parser": "jsonc-eslint-parser", + "rules": { + "@nx/dependency-checks": "error" + } + } + ] +} diff --git a/libs/sia-central-types/README.md b/libs/sia-central-types/README.md new file mode 100644 index 000000000..71c8af024 --- /dev/null +++ b/libs/sia-central-types/README.md @@ -0,0 +1,3 @@ +# sia-central-types + +Types for the Sia Central API. diff --git a/libs/sia-central-types/jest.config.ts b/libs/sia-central-types/jest.config.ts new file mode 100644 index 000000000..0656a1299 --- /dev/null +++ b/libs/sia-central-types/jest.config.ts @@ -0,0 +1,17 @@ +/* eslint-disable */ +export default { + displayName: 'sia-central-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/sia-central-types', +} diff --git a/libs/sia-central-types/package.json b/libs/sia-central-types/package.json new file mode 100644 index 000000000..9629e88e0 --- /dev/null +++ b/libs/sia-central-types/package.json @@ -0,0 +1,8 @@ +{ + "name": "@siafoundation/sia-central-types", + "description": "Types for the Sia Central API.", + "version": "0.0.0", + "license": "MIT", + "dependencies": {}, + "types": "./src/index.d.ts" +} diff --git a/libs/sia-central-types/project.json b/libs/sia-central-types/project.json new file mode 100644 index 000000000..f9a9886b9 --- /dev/null +++ b/libs/sia-central-types/project.json @@ -0,0 +1,42 @@ +{ + "name": "sia-central-types", + "$schema": "../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "libs/sia-central-types/src", + "projectType": "library", + "tags": [], + "targets": { + "build": { + "executor": "@nx/rollup:rollup", + "outputs": ["{options.outputPath}"], + "options": { + "outputPath": "dist/libs/sia-central-types", + "tsConfig": "libs/sia-central-types/tsconfig.lib.json", + "project": "libs/sia-central-types/package.json", + "entryFile": "libs/sia-central-types/src/index.ts", + "external": ["react/jsx-runtime"], + "compiler": "tsc", + "outputFileName": "index.js", + "rollupConfig": "libs/sia-central-types/rollup.config.js", + "assets": [ + { + "glob": "libs/sia-central-types/*.md", + "input": ".", + "output": "." + } + ] + }, + "configurations": {} + }, + "lint": { + "executor": "@nx/eslint:lint", + "outputs": ["{options.outputFile}"] + }, + "test": { + "executor": "@nx/jest:jest", + "outputs": ["{workspaceRoot}/coverage/libs/sia-central-types"], + "options": { + "jestConfig": "libs/sia-central-types/jest.config.ts" + } + } + } +} diff --git a/libs/sia-central-types/rollup.config.js b/libs/sia-central-types/rollup.config.js new file mode 100644 index 000000000..3f5e4e997 --- /dev/null +++ b/libs/sia-central-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/sia-central/src/siaCentralAddress.tsx b/libs/sia-central-types/src/address.ts similarity index 58% rename from libs/sia-central/src/siaCentralAddress.tsx rename to libs/sia-central-types/src/address.ts index b298e766e..1cbdeaff4 100644 --- a/libs/sia-central/src/siaCentralAddress.tsx +++ b/libs/sia-central-types/src/address.ts @@ -1,5 +1,4 @@ -import { runFetch } from './fetch' -import { SiaCentralSiafundOutput, SiaCentralTransaction, api } from './types' +import { SiaCentralSiafundOutput, SiaCentralTransaction } from './types' export type SiaCentralAddressParams = { id: string @@ -22,15 +21,3 @@ export type SiaCentralAddressResponse = { }[] unspent_siafund_outputs?: SiaCentralSiafundOutput[] } - -export async function getSiaCentralAddress(args: { - params: SiaCentralAddressParams - config?: { - api: string - } -}) { - const { params, config } = args - return runFetch( - `${config?.api || api}/wallet/addresses/${params.id}` - ) -} diff --git a/libs/sia-central-types/src/block.ts b/libs/sia-central-types/src/block.ts new file mode 100644 index 000000000..507946d70 --- /dev/null +++ b/libs/sia-central-types/src/block.ts @@ -0,0 +1,10 @@ +import { SiaCentralBlock } from './types' + +export type SiaCentralBlockParams = { + id: string +} + +export type SiaCentralBlockResponse = { + message: string + block: SiaCentralBlock +} diff --git a/libs/sia-central-types/src/blockLatest.ts b/libs/sia-central-types/src/blockLatest.ts new file mode 100644 index 000000000..774927f4e --- /dev/null +++ b/libs/sia-central-types/src/blockLatest.ts @@ -0,0 +1,6 @@ +import { SiaCentralBlock } from './types' + +export type SiaCentralBlockLatestResponse = { + message: string + block: Omit +} diff --git a/libs/sia-central-types/src/blocks.ts b/libs/sia-central-types/src/blocks.ts new file mode 100644 index 000000000..f87441d86 --- /dev/null +++ b/libs/sia-central-types/src/blocks.ts @@ -0,0 +1,11 @@ +import { SiaCentralBlock } from './types' + +export type SiaCentralBlocksResponse = { + message: string + blocks: SiaCentralBlock[] +} + +export type SiaCentralBlocksPayload = { + block_ids?: number[] + heights?: number[] +} diff --git a/libs/sia-central-types/src/config.ts b/libs/sia-central-types/src/config.ts new file mode 100644 index 000000000..6a7a2d516 --- /dev/null +++ b/libs/sia-central-types/src/config.ts @@ -0,0 +1 @@ +export const api = 'https://api.siacentral.com/v2' diff --git a/libs/sia-central-types/src/contract.ts b/libs/sia-central-types/src/contract.ts new file mode 100644 index 000000000..b5b08ea35 --- /dev/null +++ b/libs/sia-central-types/src/contract.ts @@ -0,0 +1,10 @@ +import { SiaCentralContract } from './types' + +export type SiaCentralContractParams = { + id: string +} + +export type SiaCentralContractResponse = { + message: string + contract: SiaCentralContract +} diff --git a/libs/sia-central/src/siaCentralExchangeRates.tsx b/libs/sia-central-types/src/exchangeRates.ts similarity index 56% rename from libs/sia-central/src/siaCentralExchangeRates.tsx rename to libs/sia-central-types/src/exchangeRates.ts index c015e016b..cb9913bd9 100644 --- a/libs/sia-central/src/siaCentralExchangeRates.tsx +++ b/libs/sia-central-types/src/exchangeRates.ts @@ -1,6 +1,3 @@ -import { runFetch } from './fetch' -import { api } from './types' - export type SiaCentralExchangeRates = { sc: { bch: string @@ -26,14 +23,3 @@ export type SiaCentralExchangeRatesResponse = { rates: SiaCentralExchangeRates timestamp: string } - -export async function getSiaCentralExchangeRates(args?: { - config?: { - api: string - } -}) { - const { config } = args || {} - return runFetch( - `${config?.api || api}/market/exchange-rate?currencies=sc` - ) -} diff --git a/libs/sia-central-types/src/host.ts b/libs/sia-central-types/src/host.ts new file mode 100644 index 000000000..17891589a --- /dev/null +++ b/libs/sia-central-types/src/host.ts @@ -0,0 +1,11 @@ +import { SiaCentralHost } from './types' + +export type SiaCentralHostParams = { + id: string +} + +export type SiaCentralHostResponse = { + message: string + type: string + host: SiaCentralHost +} diff --git a/libs/sia-central-types/src/hosts.ts b/libs/sia-central-types/src/hosts.ts new file mode 100644 index 000000000..d27de8100 --- /dev/null +++ b/libs/sia-central-types/src/hosts.ts @@ -0,0 +1,14 @@ +import { SiaCentralHost } from './types' + +export type SiaCentralHostsParams = { + limit?: number + page?: number +} + +export type SiaCentralHostsResponse = { + message: string + count: number + total: number + type: string + hosts: SiaCentralHost[] +} diff --git a/libs/sia-central-types/src/hostsNetworkAverages.ts b/libs/sia-central-types/src/hostsNetworkAverages.ts new file mode 100644 index 000000000..79fb28dd1 --- /dev/null +++ b/libs/sia-central-types/src/hostsNetworkAverages.ts @@ -0,0 +1,6 @@ +import { SiaCentralNetworkStats } from './types' + +export type SiaCentralHostsNetworkAveragesResponse = { + message: string + type: string +} & SiaCentralNetworkStats diff --git a/libs/sia-central/src/siaCentralHostsNetworkMetrics.tsx b/libs/sia-central-types/src/hostsNetworkMetrics.ts similarity index 53% rename from libs/sia-central/src/siaCentralHostsNetworkMetrics.tsx rename to libs/sia-central-types/src/hostsNetworkMetrics.ts index 28ed742ba..b5a4b8c68 100644 --- a/libs/sia-central/src/siaCentralHostsNetworkMetrics.tsx +++ b/libs/sia-central-types/src/hostsNetworkMetrics.ts @@ -1,5 +1,4 @@ -import { runFetch } from './fetch' -import { SiaCentralNetworkStats, api } from './types' +import { SiaCentralNetworkStats } from './types' export type SiaCentralHostsNetworkMetricsResponse = { message: string @@ -16,14 +15,3 @@ export type SiaCentralHostsNetworkMetricsResponse = { total_hosts: number } } - -export async function getSiaCentralHostsNetworkMetrics(args?: { - config?: { - api: string - } -}) { - const { config } = args || {} - return runFetch( - `${config?.api || api}/hosts/network/metrics` - ) -} diff --git a/libs/sia-central-types/src/index.ts b/libs/sia-central-types/src/index.ts new file mode 100644 index 000000000..7b55efa41 --- /dev/null +++ b/libs/sia-central-types/src/index.ts @@ -0,0 +1,14 @@ +export * from './types' +export * from './config' +export * from './address' +export * from './blockLatest' +export * from './block' +export * from './blocks' +export * from './contract' +export * from './host' +export * from './hosts' +export * from './hostsNetworkAverages' +export * from './hostsNetworkMetrics' +export * from './exchangeRates' +export * from './transaction' +export * from './search' diff --git a/libs/sia-central/src/siaCentralSearch.tsx b/libs/sia-central-types/src/search.ts similarity index 58% rename from libs/sia-central/src/siaCentralSearch.tsx rename to libs/sia-central-types/src/search.ts index 0718f7353..dcb0cdf3d 100644 --- a/libs/sia-central/src/siaCentralSearch.tsx +++ b/libs/sia-central-types/src/search.ts @@ -1,11 +1,9 @@ -import { runFetch } from './fetch' import { SiaCentralBlock, SiaCentralContract, SiaCentralHost, SiaCentralTransaction, SiaCentralUnlockHash, - api, } from './types' export type SiaCentralSearchParams = { @@ -20,15 +18,3 @@ export type SiaCentralSearchResponse = { hosts?: SiaCentralHost[] unlock_hashes?: SiaCentralUnlockHash[] } - -export async function getSiaCentralSearch(args: { - params: SiaCentralSearchParams - config?: { - api: string - } -}) { - const { params, config } = args - return runFetch( - `${config?.api || api}/explorer/search/${params.query}` - ) -} diff --git a/libs/sia-central-types/src/transaction.ts b/libs/sia-central-types/src/transaction.ts new file mode 100644 index 000000000..4253aba1a --- /dev/null +++ b/libs/sia-central-types/src/transaction.ts @@ -0,0 +1,11 @@ +import { SiaCentralTransaction } from './types' + +export type SiaCentralTransactionParams = { + id: string +} + +export type SiaCentralTransactionResponse = { + message: string + type?: 'error' + transaction: SiaCentralTransaction +} diff --git a/libs/sia-central/src/types.tsx b/libs/sia-central-types/src/types.ts similarity index 99% rename from libs/sia-central/src/types.tsx rename to libs/sia-central-types/src/types.ts index 9c048a653..3d8387f55 100644 --- a/libs/sia-central/src/types.tsx +++ b/libs/sia-central-types/src/types.ts @@ -1,5 +1,3 @@ -export const api = 'https://api.siacentral.com/v2' - export type SiaCentralNetworkStats = { settings: { max_download_batch_size: number diff --git a/libs/sia-central-types/tsconfig.json b/libs/sia-central-types/tsconfig.json new file mode 100644 index 000000000..4c089585e --- /dev/null +++ b/libs/sia-central-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/sia-central-types/tsconfig.lib.json b/libs/sia-central-types/tsconfig.lib.json new file mode 100644 index 000000000..d73537814 --- /dev/null +++ b/libs/sia-central-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/sia-central-types/tsconfig.spec.json b/libs/sia-central-types/tsconfig.spec.json new file mode 100644 index 000000000..503e9a83d --- /dev/null +++ b/libs/sia-central-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/libs/sia-central/README.md b/libs/sia-central/README.md deleted file mode 100644 index c2dc55cb3..000000000 --- a/libs/sia-central/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# sia-central - -Methods and types for interacting with the Sia Central API. - -## Running unit tests - -Run `nx test sia-central` to execute the unit tests via [Jest](https://jestjs.io). diff --git a/libs/sia-central/src/index.ts b/libs/sia-central/src/index.ts deleted file mode 100644 index 1e542e702..000000000 --- a/libs/sia-central/src/index.ts +++ /dev/null @@ -1,13 +0,0 @@ -export * from './types' -export * from './siaCentralAddress' -export * from './siaCentralBlockLatest' -export * from './siaCentralBlock' -export * from './siaCentralBlocks' -export * from './siaCentralContract' -export * from './siaCentralHost' -export * from './siaCentralHosts' -export * from './siaCentralHostsNetworkAverages' -export * from './siaCentralHostsNetworkMetrics' -export * from './siaCentralExchangeRates' -export * from './siaCentralTransaction' -export * from './siaCentralSearch' diff --git a/libs/units/package.json b/libs/units/package.json index 4cfdd79d7..5125403e4 100644 --- a/libs/units/package.json +++ b/libs/units/package.json @@ -3,14 +3,12 @@ "description": "Methods and types for interacting with the Sia Central API.", "version": "3.0.0", "license": "MIT", - "peerDependencies": { - "@siafoundation/sia-central": "^0.3.3", - "@siafoundation/react-core": "^1.1.0", - "bignumber.js": "^9.0.2" - }, "dependencies": { + "@siafoundation/react-core": "^1.1.0", + "bignumber.js": "^9.0.2", "@technically/lodash": "^4.17.0", - "blakejs": "^1.2.1" + "blakejs": "^1.2.1", + "@siafoundation/sia-central-types": "0.0.0" }, "types": "./src/index.d.ts" } diff --git a/libs/units/src/storage.ts b/libs/units/src/storage.ts index c3d6a64f0..9327abfbe 100644 --- a/libs/units/src/storage.ts +++ b/libs/units/src/storage.ts @@ -1,6 +1,6 @@ import { TBToBytes } from './bytes' import { monthsToBlocks } from './blockTime' -import { SiaCentralHost } from '@siafoundation/sia-central' +import { SiaCentralHost } from '@siafoundation/sia-central-types' import BigNumber from 'bignumber.js' import { humanSiacoin } from './currency' import { humanBytes, humanSpeed } from './humanUnits' diff --git a/tsconfig.base.json b/tsconfig.base.json index d06c15812..b78eaf5e7 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -25,19 +25,22 @@ "@siafoundation/react-icons": ["libs/react-icons/src/index.ts"], "@siafoundation/renterd-types": ["libs/renterd-types/src/index.ts"], "@siafoundation/renterd-react": ["libs/renterd-react/src/index.ts"], - "@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 "@siafoundation/sdk": ["dist/libs/sdk/index.esm.js"], - "@siafoundation/sia-central": ["libs/sia-central/src/index.ts"], + "@siafoundation/sia-central-types": [ + "libs/sia-central-types/src/index.ts" + ], + "@siafoundation/sia-central-js": ["libs/sia-central-js/src/index.ts"], + "@siafoundation/sia-central-react": [ + "libs/sia-central-react/src/index.ts" + ], + "@siafoundation/sia-central-mock": ["libs/sia-central-mock/src/index.ts"], "@siafoundation/types": ["libs/types/src/index.ts"], "@siafoundation/units": ["libs/units/src/index.ts"], - "@siafoundation/walletd-mock": ["libs/walletd-mock/src/index.ts"], - "@siafoundation/sia-central-mock": ["libs/sia-central-mock/src/index.ts"] + "@siafoundation/walletd-mock": ["libs/walletd-mock/src/index.ts"] } }, "exclude": ["node_modules", "tmp"]