Skip to content

Commit fbb5703

Browse files
committed
refactor: split out sia-central-types
1 parent a38cf77 commit fbb5703

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+457
-203
lines changed

libs/design-system/src/core/SiacoinField.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { SiacoinField } from './SiacoinField'
88
import { fireEvent, render, waitFor, act } from '@testing-library/react'
99
import userEvent from '@testing-library/user-event'
1010
import { useState } from 'react'
11-
import { SiaCentralExchangeRatesResponse } from '@siafoundation/sia-central'
11+
import { SiaCentralExchangeRatesResponse } from '@siafoundation/sia-central-types'
1212
import { setupServer } from 'msw/node'
1313
import { HttpResponse, http } from 'msw'
1414

File renamed without changes.

libs/sia-central/.eslintrc.json renamed to libs/sia-central-js/.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"@nx/dependency-checks": [
66
"error",
77
{
8-
"ignoredFiles": ["libs/sia-central/rollup.config.js"]
8+
"ignoredFiles": ["libs/sia-central-js/rollup.config.js"]
99
}
1010
]
1111
},

libs/sia-central/CHANGELOG.md renamed to libs/sia-central-js/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# @siafoundation/sia-central
1+
# @siafoundation/sia-central-js
22

33
## 0.3.3
44

libs/sia-central-js/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# sia-central-js
2+
3+
Methods and types for interacting with the Sia Central API.
4+
5+
## Running unit tests
6+
7+
Run `nx test sia-central-js` to execute the unit tests via [Jest](https://jestjs.io).

libs/sia-central/jest.config.ts renamed to libs/sia-central-js/jest.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable */
22
export default {
3-
displayName: 'sia-central',
3+
displayName: 'sia-central-js',
44
preset: '../../jest.preset.js',
55
transform: {
66
'^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '@nx/react/plugins/jest',
@@ -13,5 +13,5 @@ export default {
1313
],
1414
},
1515
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
16-
coverageDirectory: '../../coverage/libs/sia-central',
16+
coverageDirectory: '../../coverage/libs/sia-central-js',
1717
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
2-
"name": "@siafoundation/sia-central",
2+
"name": "@siafoundation/sia-central-js",
33
"description": "Methods and types for interacting with the Sia Central API.",
44
"version": "0.3.3",
55
"license": "MIT",
66
"dependencies": {
7-
"@technically/lodash": "^4.17.0"
7+
"@technically/lodash": "^4.17.0",
8+
"@siafoundation/sia-central-types": "0.0.0"
89
},
910
"types": "./src/index.d.ts"
1011
}

libs/sia-central/project.json renamed to libs/sia-central-js/project.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
{
2-
"name": "sia-central",
2+
"name": "sia-central-js",
33
"$schema": "../../node_modules/nx/schemas/project-schema.json",
4-
"sourceRoot": "libs/sia-central/src",
4+
"sourceRoot": "libs/sia-central-js/src",
55
"projectType": "library",
66
"tags": [],
77
"targets": {
88
"build": {
99
"executor": "@nx/rollup:rollup",
1010
"outputs": ["{options.outputPath}"],
1111
"options": {
12-
"outputPath": "dist/libs/sia-central",
13-
"tsConfig": "libs/sia-central/tsconfig.lib.json",
14-
"project": "libs/sia-central/package.json",
15-
"entryFile": "libs/sia-central/src/index.ts",
12+
"outputPath": "dist/libs/sia-central-js",
13+
"tsConfig": "libs/sia-central-js/tsconfig.lib.json",
14+
"project": "libs/sia-central-js/package.json",
15+
"entryFile": "libs/sia-central-js/src/index.ts",
1616
"external": ["react/jsx-runtime"],
1717
"compiler": "tsc",
1818
"outputFileName": "index.js",
19-
"rollupConfig": "libs/sia-central/rollup.config.js",
19+
"rollupConfig": "libs/sia-central-js/rollup.config.js",
2020
"assets": [
2121
{
22-
"glob": "libs/sia-central/*.md",
22+
"glob": "libs/sia-central-js/*.md",
2323
"input": ".",
2424
"output": "."
2525
}
@@ -33,9 +33,9 @@
3333
},
3434
"test": {
3535
"executor": "@nx/jest:jest",
36-
"outputs": ["{workspaceRoot}/coverage/libs/sia-central"],
36+
"outputs": ["{workspaceRoot}/coverage/libs/sia-central-js"],
3737
"options": {
38-
"jestConfig": "libs/sia-central/jest.config.ts"
38+
"jestConfig": "libs/sia-central-js/jest.config.ts"
3939
}
4040
}
4141
}

libs/sia-central-js/src/address.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { runFetch } from './fetch'
2+
import {
3+
api,
4+
SiaCentralAddressParams,
5+
SiaCentralAddressResponse,
6+
} from '@siafoundation/sia-central-types'
7+
8+
export async function getSiaCentralAddress(args: {
9+
params: SiaCentralAddressParams
10+
config?: {
11+
api: string
12+
}
13+
}) {
14+
const { params, config } = args
15+
return runFetch<SiaCentralAddressResponse>(
16+
`${config?.api || api}/wallet/addresses/${params.id}`
17+
)
18+
}

libs/sia-central/src/siaCentralBlock.tsx renamed to libs/sia-central-js/src/block.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import { runFetch } from './fetch'
2-
import { SiaCentralBlock, api } from './types'
3-
4-
export type SiaCentralBlockParams = {
5-
id: string
6-
}
7-
8-
export type SiaCentralBlockResponse = {
9-
message: string
10-
block: SiaCentralBlock
11-
}
2+
import {
3+
api,
4+
SiaCentralBlockParams,
5+
SiaCentralBlockResponse,
6+
} from '@siafoundation/sia-central-types'
127

138
export async function getSiaCentralBlock(args: {
149
params: SiaCentralBlockParams

libs/sia-central/src/siaCentralBlockLatest.tsx renamed to libs/sia-central-js/src/blockLatest.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import { api, SiaCentralBlock } from './types'
21
import { runFetch } from './fetch'
3-
4-
export type SiaCentralBlockLatestResponse = {
5-
message: string
6-
block: Omit<SiaCentralBlock, 'transactions'>
7-
}
2+
import {
3+
api,
4+
SiaCentralBlockLatestResponse,
5+
} from '@siafoundation/sia-central-types'
86

97
export async function getSiaCentralBlockLatest(args?: {
108
config?: {

libs/sia-central/src/siaCentralBlocks.tsx renamed to libs/sia-central-js/src/blocks.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1-
import { api, SiaCentralBlock } from './types'
1+
import {
2+
api,
3+
SiaCentralBlocksPayload,
4+
SiaCentralBlocksResponse,
5+
} from '@siafoundation/sia-central-types'
26
import { runFetch } from './fetch'
37

4-
export type SiaCentralBlocksResponse = {
5-
message: string
6-
blocks: SiaCentralBlock[]
7-
}
8-
9-
export type SiaCentralBlocksPayload = {
10-
block_ids?: number[]
11-
heights?: number[]
12-
}
13-
148
export async function getSiaCentralBlocks(args: {
159
payload: SiaCentralBlocksPayload
1610
config?: {

libs/sia-central/src/siaCentralContract.tsx renamed to libs/sia-central-js/src/contract.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import { runFetch } from './fetch'
2-
import { api, SiaCentralContract } from './types'
3-
4-
export type SiaCentralContractParams = {
5-
id: string
6-
}
7-
8-
export type SiaCentralContractResponse = {
9-
message: string
10-
contract: SiaCentralContract
11-
}
2+
import {
3+
api,
4+
SiaCentralContractParams,
5+
SiaCentralContractResponse,
6+
} from '@siafoundation/sia-central-types'
127

138
export async function getSiaCentralContract(args: {
149
params: SiaCentralContractParams
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { runFetch } from './fetch'
2+
import {
3+
api,
4+
SiaCentralExchangeRatesResponse,
5+
} from '@siafoundation/sia-central-types'
6+
7+
export async function getSiaCentralExchangeRates(args?: {
8+
config?: {
9+
api: string
10+
}
11+
}) {
12+
const { config } = args || {}
13+
return runFetch<SiaCentralExchangeRatesResponse>(
14+
`${config?.api || api}/market/exchange-rate?currencies=sc`
15+
)
16+
}
File renamed without changes.

libs/sia-central/src/siaCentralHost.tsx renamed to libs/sia-central-js/src/host.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
import { runFetch } from './fetch'
2-
import { SiaCentralHost, api } from './types'
3-
4-
export type SiaCentralHostParams = {
5-
id: string
6-
}
7-
8-
export type SiaCentralHostResponse = {
9-
message: string
10-
type: string
11-
host: SiaCentralHost
12-
}
2+
import {
3+
api,
4+
SiaCentralHostParams,
5+
SiaCentralHostResponse,
6+
} from '@siafoundation/sia-central-types'
137

148
export async function getSiaCentralHost(args: {
159
params: SiaCentralHostParams

libs/sia-central/src/siaCentralHosts.tsx renamed to libs/sia-central-js/src/hosts.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
import { merge } from '@technically/lodash'
22
import { runFetch } from './fetch'
3-
import { SiaCentralHost, api } from './types'
4-
5-
export type SiaCentralHostsParams = {
6-
limit?: number
7-
page?: number
8-
}
9-
10-
export type SiaCentralHostsResponse = {
11-
message: string
12-
count: number
13-
total: number
14-
type: string
15-
hosts: SiaCentralHost[]
16-
}
3+
import {
4+
api,
5+
SiaCentralHostsParams,
6+
SiaCentralHostsResponse,
7+
} from '@siafoundation/sia-central-types'
178

189
export async function getSiaCentralHosts(args?: {
1910
params?: SiaCentralHostsParams

libs/sia-central/src/siaCentralHostsNetworkAverages.tsx renamed to libs/sia-central-js/src/hostsNetworkAverages.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import { runFetch } from './fetch'
2-
import { SiaCentralNetworkStats, api } from './types'
3-
4-
export type SiaCentralHostsNetworkAveragesResponse = {
5-
message: string
6-
type: string
7-
} & SiaCentralNetworkStats
2+
import {
3+
api,
4+
SiaCentralHostsNetworkAveragesResponse,
5+
} from '@siafoundation/sia-central-types'
86

97
export async function getSiaCentralHostsNetworkAverages(args?: {
108
config?: {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { runFetch } from './fetch'
2+
import {
3+
api,
4+
SiaCentralHostsNetworkMetricsResponse,
5+
} from '@siafoundation/sia-central-types'
6+
7+
export async function getSiaCentralHostsNetworkMetrics(args?: {
8+
config?: {
9+
api: string
10+
}
11+
}) {
12+
const { config } = args || {}
13+
return runFetch<SiaCentralHostsNetworkMetricsResponse>(
14+
`${config?.api || api}/hosts/network/metrics`
15+
)
16+
}

libs/sia-central-js/src/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export * from './address'
2+
export * from './blockLatest'
3+
export * from './block'
4+
export * from './blocks'
5+
export * from './contract'
6+
export * from './host'
7+
export * from './hosts'
8+
export * from './hostsNetworkAverages'
9+
export * from './hostsNetworkMetrics'
10+
export * from './exchangeRates'
11+
export * from './transaction'
12+
export * from './search'

libs/sia-central-js/src/search.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { runFetch } from './fetch'
2+
import {
3+
api,
4+
SiaCentralSearchParams,
5+
SiaCentralSearchResponse,
6+
} from '@siafoundation/sia-central-types'
7+
8+
export async function getSiaCentralSearch(args: {
9+
params: SiaCentralSearchParams
10+
config?: {
11+
api: string
12+
}
13+
}) {
14+
const { params, config } = args
15+
return runFetch<SiaCentralSearchResponse>(
16+
`${config?.api || api}/explorer/search/${params.query}`
17+
)
18+
}

libs/sia-central/src/siaCentralTransaction.tsx renamed to libs/sia-central-js/src/transaction.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1-
import { api, SiaCentralTransaction } from './types'
1+
import {
2+
api,
3+
SiaCentralTransactionParams,
4+
SiaCentralTransactionResponse,
5+
} from '@siafoundation/sia-central-types'
26
import { runFetch } from './fetch'
37

4-
export type SiaCentralTransactionParams = {
5-
id: string
6-
}
7-
8-
export type SiaCentralTransactionResponse = {
9-
message: string
10-
type?: 'error'
11-
transaction: SiaCentralTransaction
12-
}
13-
148
export async function getSiaCentralTransaction(args: {
159
params: SiaCentralTransactionParams
1610
config?: {
File renamed without changes.

libs/sia-central-mock/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"version": "0.0.0",
55
"license": "MIT",
66
"dependencies": {
7-
"@siafoundation/sia-central": "0.3.3",
8-
"playwright": "^1.42.1"
7+
"playwright": "^1.42.1",
8+
"@siafoundation/sia-central-types": "0.0.0"
99
},
1010
"types": "./src/index.d.ts"
1111
}

libs/sia-central-mock/src/siaCentralExchangeRates.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SiaCentralExchangeRatesResponse } from '@siafoundation/sia-central'
1+
import { SiaCentralExchangeRatesResponse } from '@siafoundation/sia-central-types'
22
import { Page } from 'playwright'
33

44
export function getMockSiaCentralExchangeRatesResponse(): SiaCentralExchangeRatesResponse {

libs/sia-central-react/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"description": "React hooks for interacting with the Sia Central API.",
44
"version": "3.0.0",
55
"license": "MIT",
6-
"peerDependencies": {
6+
"dependencies": {
77
"@siafoundation/react-core": "^1.1.0",
8-
"@siafoundation/sia-central": "^0.3.3"
8+
"@siafoundation/sia-central-types": "0.0.0"
99
},
1010
"types": "./src/index.d.ts"
1111
}

libs/sia-central-react/src/useSiaCentralAddress.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
api,
88
SiaCentralAddressParams,
99
SiaCentralAddressResponse,
10-
} from '@siafoundation/sia-central'
10+
} from '@siafoundation/sia-central-types'
1111

1212
export function useSiaCentralAddress(
1313
args?: HookArgsSwr<SiaCentralAddressParams, SiaCentralAddressResponse>

libs/sia-central-react/src/useSiaCentralBlock.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
api,
88
SiaCentralBlockParams,
99
SiaCentralBlockResponse,
10-
} from '@siafoundation/sia-central'
10+
} from '@siafoundation/sia-central-types'
1111

1212
export function useSiaCentralBlock(
1313
args?: HookArgsSwr<SiaCentralBlockParams, SiaCentralBlockResponse>

0 commit comments

Comments
 (0)