Skip to content

Commit d6bd8d8

Browse files
committed
refactor: request api, renterd and sia central sdks
1 parent f97a2c6 commit d6bd8d8

Some content is hidden

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

66 files changed

+375
-603
lines changed

.changeset/breezy-bees-design.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@siafoundation/renterd-js': minor
3+
'@siafoundation/request': minor
4+
---
5+
6+
The request API has been updated to return [data, error, response].

.changeset/chilly-pants-provide.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'explorer': minor
3+
'website': minor
4+
---
5+
6+
The site now uses the updated Sia Central SDK.

.changeset/odd-pets-fix.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@siafoundation/sia-central-js': minor
3+
---
4+
5+
The SDK has been updated to use the request library.

apps/explorer/app/address/[id]/opengraph-image.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { getSiaCentralAddress } from '@siafoundation/sia-central-js'
21
import { humanSiacoin, humanSiafund } from '@siafoundation/units'
32
import { getOGImage } from '../../../components/OGImageEntity'
4-
import { siaCentralApi } from '../../../config'
3+
import { siaCentral } from '../../../config/siaCentral'
54
import { truncate } from '@siafoundation/design-system'
65

76
export const revalidate = 0
@@ -16,13 +15,10 @@ export const contentType = 'image/png'
1615

1716
export default async function Image({ params }) {
1817
const id = params?.id as string
19-
const { data: a } = await getSiaCentralAddress({
18+
const [a] = await siaCentral.address({
2019
params: {
2120
id,
2221
},
23-
config: {
24-
api: siaCentralApi,
25-
},
2622
})
2723

2824
if (!a) {

apps/explorer/app/address/[id]/page.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { getSiaCentralAddress } from '@siafoundation/sia-central-js'
21
import { Address } from '../../../components/Address'
32
import { Metadata } from 'next'
43
import { routes } from '../../../config/routes'
54
import { buildMetadata } from '../../../lib/utils'
6-
import { siaCentralApi } from '../../../config'
5+
import { siaCentral } from '../../../config/siaCentral'
76
import { notFound } from 'next/navigation'
87
import { truncate } from '@siafoundation/design-system'
98

@@ -23,17 +22,14 @@ export const revalidate = 0
2322

2423
export default async function Page({ params }) {
2524
const id = params?.id as string
26-
const { data: a, error } = await getSiaCentralAddress({
25+
const [a, error] = await siaCentral.address({
2726
params: {
2827
id,
2928
},
30-
config: {
31-
api: siaCentralApi,
32-
},
3329
})
3430

3531
if (error) {
36-
throw Error(error)
32+
throw error
3733
}
3834

3935
if (a?.unspent_siacoins == undefined) {

apps/explorer/app/block/[id]/opengraph-image.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { getSiaCentralBlock } from '@siafoundation/sia-central-js'
21
import { humanDate } from '@siafoundation/units'
32
import { getOGImage } from '../../../components/OGImageEntity'
4-
import { siaCentralApi } from '../../../config'
3+
import { siaCentral } from '../../../config/siaCentral'
54
import { truncate } from '@siafoundation/design-system'
65

76
export const revalidate = 0
@@ -16,13 +15,10 @@ export const contentType = 'image/png'
1615

1716
export default async function Image({ params }) {
1817
const id = params?.id as string
19-
const { data: b } = await getSiaCentralBlock({
18+
const [b] = await siaCentral.block({
2019
params: {
2120
id,
2221
},
23-
config: {
24-
api: siaCentralApi,
25-
},
2622
})
2723

2824
if (!b || !b.block) {

apps/explorer/app/block/[id]/page.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import { getTitleId } from '@siafoundation/design-system'
22
import { Block } from '../../../components/Block'
33
import { routes } from '../../../config/routes'
44
import { Metadata } from 'next'
5-
import { getSiaCentralBlock } from '@siafoundation/sia-central-js'
65
import { buildMetadata } from '../../../lib/utils'
7-
import { siaCentralApi } from '../../../config'
6+
import { siaCentral } from '../../../config/siaCentral'
87
import { notFound } from 'next/navigation'
98

109
export function generateMetadata({ params }): Metadata {
@@ -34,17 +33,14 @@ export const revalidate = 0
3433

3534
export default async function Page({ params }) {
3635
const id = params?.id as string
37-
const { data: b, error } = await getSiaCentralBlock({
36+
const [b, error] = await siaCentral.block({
3837
params: {
3938
id,
4039
},
41-
config: {
42-
api: siaCentralApi,
43-
},
4440
})
4541

4642
if (error) {
47-
throw Error(error)
43+
throw error
4844
}
4945

5046
if (!b?.block) {

apps/explorer/app/contract/[id]/opengraph-image.tsx

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
import {
2-
getSiaCentralContract,
3-
getSiaCentralExchangeRates,
4-
} from '@siafoundation/sia-central-js'
51
import { humanBytes, humanDate } from '@siafoundation/units'
62
import { getOGImage } from '../../../components/OGImageEntity'
7-
import { siaCentralApi } from '../../../config'
3+
import { siaCentral } from '../../../config/siaCentral'
84
import { truncate } from '@siafoundation/design-system'
95
import { lowerCase } from '@technically/lodash'
106
import { siacoinToFiat } from '../../../lib/currency'
@@ -25,18 +21,15 @@ const currency = currencyOptions.find((c) => c.id === 'usd') as CurrencyOption
2521
export default async function Image({ params }) {
2622
const id = params?.id as string
2723

28-
const [{ data: c }, { data: r }] = await Promise.all([
29-
getSiaCentralContract({
24+
const [[c], [r]] = await Promise.all([
25+
siaCentral.contract({
3026
params: {
3127
id,
3228
},
33-
config: {
34-
api: siaCentralApi,
35-
},
3629
}),
37-
getSiaCentralExchangeRates({
38-
config: {
39-
api: siaCentralApi,
30+
siaCentral.exchangeRates({
31+
params: {
32+
currencies: 'sc',
4033
},
4134
}),
4235
])

apps/explorer/app/contract/[id]/page.tsx

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import { SiaCentralContract } from '@siafoundation/sia-central-types'
2-
import {
3-
getSiaCentralContract,
4-
getSiaCentralExchangeRates,
5-
getSiaCentralTransaction,
6-
} from '@siafoundation/sia-central-js'
72
import { ContractView } from '../../../components/ContractView'
83
import { Metadata } from 'next'
94
import { routes } from '../../../config/routes'
105
import { buildMetadata } from '../../../lib/utils'
11-
import { siaCentralApi } from '../../../config'
6+
import { siaCentral } from '../../../config/siaCentral'
127
import { notFound } from 'next/navigation'
138
import { truncate } from '@siafoundation/design-system'
149

@@ -28,50 +23,42 @@ export const revalidate = 0
2823

2924
export default async function Page({ params }) {
3025
const id = params?.id as string
31-
const [{ data: c, error }, { data: r }] = await Promise.all([
32-
getSiaCentralContract({
26+
const [[c, error], [r]] = await Promise.all([
27+
siaCentral.contract({
3328
params: {
3429
id,
3530
},
36-
config: {
37-
api: siaCentralApi,
38-
},
3931
}),
40-
getSiaCentralExchangeRates({
41-
config: {
42-
api: siaCentralApi,
32+
siaCentral.exchangeRates({
33+
params: {
34+
currencies: 'sc',
4335
},
4436
}),
4537
])
4638

4739
if (error) {
48-
throw Error(error)
40+
throw error
4941
}
5042

51-
if (!c?.contract) {
43+
const contract = c?.contract
44+
45+
if (!contract) {
5246
return notFound()
5347
}
5448

55-
const contract = c.contract
5649
const formationTxnId = getFormationTxnId(contract)
5750
const finalRevisionTxnId = contract?.transaction_id || ''
5851

59-
const [{ data: ft }, { data: rt }] = await Promise.all([
60-
getSiaCentralTransaction({
52+
const [[ft], [rt]] = await Promise.all([
53+
siaCentral.transaction({
6154
params: {
6255
id: formationTxnId,
6356
},
64-
config: {
65-
api: siaCentralApi,
66-
},
6757
}),
68-
getSiaCentralTransaction({
58+
siaCentral.transaction({
6959
params: {
7060
id: finalRevisionTxnId,
7161
},
72-
config: {
73-
api: siaCentralApi,
74-
},
7562
}),
7663
])
7764

apps/explorer/app/host/[id]/opengraph-image.tsx

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import {
2-
getSiaCentralExchangeRates,
3-
getSiaCentralHost,
4-
} from '@siafoundation/sia-central-js'
51
import { getOGImage } from '../../../components/OGImageEntity'
6-
import { siaCentralApi } from '../../../config'
2+
import { siaCentral } from '../../../config/siaCentral'
73
import {
84
getDownloadCost,
95
getDownloadSpeed,
@@ -29,18 +25,15 @@ export const contentType = 'image/png'
2925

3026
export default async function Image({ params }) {
3127
const id = params?.id as string
32-
const [{ data: h }, { data: r }] = await Promise.all([
33-
getSiaCentralHost({
28+
const [[h], [r]] = await Promise.all([
29+
siaCentral.host({
3430
params: {
3531
id,
3632
},
37-
config: {
38-
api: siaCentralApi,
39-
},
4033
}),
41-
getSiaCentralExchangeRates({
42-
config: {
43-
api: siaCentralApi,
34+
siaCentral.exchangeRates({
35+
params: {
36+
currencies: 'sc',
4437
},
4538
}),
4639
])

apps/explorer/app/host/[id]/page.tsx

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
import {
2-
getSiaCentralExchangeRates,
3-
getSiaCentralHost,
4-
} from '@siafoundation/sia-central-js'
51
import { Metadata } from 'next'
62
import { routes } from '../../../config/routes'
73
import { buildMetadata } from '../../../lib/utils'
84
import { Host } from '../../../components/Host'
9-
import { siaCentralApi } from '../../../config'
105
import { notFound } from 'next/navigation'
116
import { truncate } from '@siafoundation/design-system'
7+
import { siaCentral } from '../../../config/siaCentral'
128

139
export function generateMetadata({ params }): Metadata {
1410
const id = decodeURIComponent((params?.id as string) || '')
@@ -26,24 +22,21 @@ export const revalidate = 0
2622

2723
export default async function Page({ params }) {
2824
const id = params?.id as string
29-
const [{ data: h, error }, { data: r }] = await Promise.all([
30-
getSiaCentralHost({
25+
const [[h, error], [r]] = await Promise.all([
26+
siaCentral.host({
3127
params: {
3228
id,
3329
},
34-
config: {
35-
api: siaCentralApi,
36-
},
3730
}),
38-
getSiaCentralExchangeRates({
39-
config: {
40-
api: siaCentralApi,
31+
siaCentral.exchangeRates({
32+
params: {
33+
currencies: 'sc',
4134
},
4235
}),
4336
])
4437

4538
if (error) {
46-
throw Error(error)
39+
throw error
4740
}
4841

4942
if (!h?.host) {

apps/explorer/app/opengraph-image.tsx

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import {
2-
getSiaCentralBlockLatest,
3-
getSiaCentralHostsNetworkMetrics,
4-
} from '@siafoundation/sia-central-js'
51
import { getOGImage } from '../components/OGImage'
6-
import { network, siaCentralApi } from '../config'
2+
import { network } from '../config'
73
import { humanBytes } from '@siafoundation/units'
84
import { PreviewValue } from '../components/OGImage/Preview'
5+
import { siaCentral } from '../config/siaCentral'
96

107
export const revalidate = 0
118

@@ -18,20 +15,12 @@ export const size = {
1815
export const contentType = 'image/png'
1916

2017
export default async function Image() {
21-
const [{ data: metrics }, { data: latestBlock }] = await Promise.all([
22-
getSiaCentralHostsNetworkMetrics({
23-
config: {
24-
api: siaCentralApi,
25-
},
26-
}),
27-
getSiaCentralBlockLatest({
28-
config: {
29-
api: siaCentralApi,
30-
},
31-
}),
18+
const [[metrics], [latestBlock]] = await Promise.all([
19+
siaCentral.hostsNetworkMetrics(),
20+
siaCentral.blockLatest(),
3221
])
3322

34-
const lastBlockHeight = Number(latestBlock?.block.height || 0)
23+
const lastBlockHeight = Number(latestBlock?.block?.height || 0)
3524

3625
const values: PreviewValue[] = []
3726
if (latestBlock) {

0 commit comments

Comments
 (0)