Skip to content

Commit

Permalink
refactor: split out sia-central-types
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Apr 15, 2024
1 parent 16a20ef commit ff7678d
Show file tree
Hide file tree
Showing 71 changed files with 457 additions and 203 deletions.
2 changes: 1 addition & 1 deletion libs/design-system/src/core/SiacoinField.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"@nx/dependency-checks": [
"error",
{
"ignoredFiles": ["libs/sia-central/rollup.config.js"]
"ignoredFiles": ["libs/sia-central-js/rollup.config.js"]
}
]
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @siafoundation/sia-central
# @siafoundation/sia-central-js

## 0.3.3

Expand Down
7 changes: 7 additions & 0 deletions libs/sia-central-js/README.md
Original file line number Diff line number Diff line change
@@ -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).
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -13,5 +13,5 @@ export default {
],
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage/libs/sia-central',
coverageDirectory: '../../coverage/libs/sia-central-js',
}
Original file line number Diff line number Diff line change
@@ -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"
}
20 changes: 10 additions & 10 deletions libs/sia-central/project.json → libs/sia-central-js/project.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
{
"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": {
"build": {
"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": "."
}
Expand All @@ -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"
}
}
}
Expand Down
File renamed without changes.
18 changes: 18 additions & 0 deletions libs/sia-central-js/src/address.ts
Original file line number Diff line number Diff line change
@@ -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<SiaCentralAddressResponse>(
`${config?.api || api}/wallet/addresses/${params.id}`
)
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { api, SiaCentralBlock } from './types'
import { runFetch } from './fetch'

export type SiaCentralBlockLatestResponse = {
message: string
block: Omit<SiaCentralBlock, 'transactions'>
}
import {
api,
SiaCentralBlockLatestResponse,
} from '@siafoundation/sia-central-types'

export async function getSiaCentralBlockLatest(args?: {
config?: {
Expand Down
Original file line number Diff line number Diff line change
@@ -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?: {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 16 additions & 0 deletions libs/sia-central-js/src/exchangeRates.ts
Original file line number Diff line number Diff line change
@@ -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<SiaCentralExchangeRatesResponse>(
`${config?.api || api}/market/exchange-rate?currencies=sc`
)
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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?: {
Expand Down
16 changes: 16 additions & 0 deletions libs/sia-central-js/src/hostsNetworkMetrics.ts
Original file line number Diff line number Diff line change
@@ -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<SiaCentralHostsNetworkMetricsResponse>(
`${config?.api || api}/hosts/network/metrics`
)
}
12 changes: 12 additions & 0 deletions libs/sia-central-js/src/index.ts
Original file line number Diff line number Diff line change
@@ -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'
18 changes: 18 additions & 0 deletions libs/sia-central-js/src/search.ts
Original file line number Diff line number Diff line change
@@ -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<SiaCentralSearchResponse>(
`${config?.api || api}/explorer/search/${params.query}`
)
}
Original file line number Diff line number Diff line change
@@ -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?: {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions libs/sia-central-mock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
2 changes: 1 addition & 1 deletion libs/sia-central-mock/src/siaCentralExchangeRates.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions libs/sia-central-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
2 changes: 1 addition & 1 deletion libs/sia-central-react/src/useSiaCentralAddress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
api,
SiaCentralAddressParams,
SiaCentralAddressResponse,
} from '@siafoundation/sia-central'
} from '@siafoundation/sia-central-types'

export function useSiaCentralAddress(
args?: HookArgsSwr<SiaCentralAddressParams, SiaCentralAddressResponse>
Expand Down
2 changes: 1 addition & 1 deletion libs/sia-central-react/src/useSiaCentralBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
api,
SiaCentralBlockParams,
SiaCentralBlockResponse,
} from '@siafoundation/sia-central'
} from '@siafoundation/sia-central-types'

export function useSiaCentralBlock(
args?: HookArgsSwr<SiaCentralBlockParams, SiaCentralBlockResponse>
Expand Down
Loading

0 comments on commit ff7678d

Please sign in to comment.