Skip to content

Commit 825e581

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

Some content is hidden

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

68 files changed

+534
-674
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: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
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'
5+
import { to } from '@siafoundation/request'
66

77
export const revalidate = 0
88

@@ -16,14 +16,13 @@ export const contentType = 'image/png'
1616

1717
export default async function Image({ params }) {
1818
const id = params?.id as string
19-
const { data: a } = await getSiaCentralAddress({
20-
params: {
21-
id,
22-
},
23-
config: {
24-
api: siaCentralApi,
25-
},
26-
})
19+
const [a] = await to(
20+
siaCentral.address({
21+
params: {
22+
id,
23+
},
24+
})
25+
)
2726

2827
if (!a) {
2928
return getOGImage(

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
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'
8+
import { to } from '@siafoundation/request'
99

1010
export function generateMetadata({ params }): Metadata {
1111
const id = decodeURIComponent((params?.id as string) || '')
@@ -23,17 +23,16 @@ export const revalidate = 0
2323

2424
export default async function Page({ params }) {
2525
const id = params?.id as string
26-
const { data: a, error } = await getSiaCentralAddress({
27-
params: {
28-
id,
29-
},
30-
config: {
31-
api: siaCentralApi,
32-
},
33-
})
26+
const [a, error] = await to(
27+
siaCentral.address({
28+
params: {
29+
id,
30+
},
31+
})
32+
)
3433

3534
if (error) {
36-
throw Error(error)
35+
throw error
3736
}
3837

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

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
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'
5+
import { to } from '@siafoundation/request'
66

77
export const revalidate = 0
88

@@ -16,14 +16,13 @@ export const contentType = 'image/png'
1616

1717
export default async function Image({ params }) {
1818
const id = params?.id as string
19-
const { data: b } = await getSiaCentralBlock({
20-
params: {
21-
id,
22-
},
23-
config: {
24-
api: siaCentralApi,
25-
},
26-
})
19+
const [b] = await to(
20+
siaCentral.block({
21+
params: {
22+
id,
23+
},
24+
})
25+
)
2726

2827
if (!b || !b.block) {
2928
return getOGImage(

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ 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'
8+
import { to } from '@siafoundation/request'
99

1010
export function generateMetadata({ params }): Metadata {
1111
const id = decodeURIComponent((params?.id as string) || '')
@@ -34,17 +34,16 @@ export const revalidate = 0
3434

3535
export default async function Page({ params }) {
3636
const id = params?.id as string
37-
const { data: b, error } = await getSiaCentralBlock({
38-
params: {
39-
id,
40-
},
41-
config: {
42-
api: siaCentralApi,
43-
},
44-
})
37+
const [b, error] = await to(
38+
siaCentral.block({
39+
params: {
40+
id,
41+
},
42+
})
43+
)
4544

4645
if (error) {
47-
throw Error(error)
46+
throw error
4847
}
4948

5049
if (!b?.block) {

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

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
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'
117
import { CurrencyOption, currencyOptions } from '@siafoundation/react-core'
8+
import { to } from '@siafoundation/request'
129

1310
export const revalidate = 0
1411

@@ -25,20 +22,21 @@ const currency = currencyOptions.find((c) => c.id === 'usd') as CurrencyOption
2522
export default async function Image({ params }) {
2623
const id = params?.id as string
2724

28-
const [{ data: c }, { data: r }] = await Promise.all([
29-
getSiaCentralContract({
30-
params: {
31-
id,
32-
},
33-
config: {
34-
api: siaCentralApi,
35-
},
36-
}),
37-
getSiaCentralExchangeRates({
38-
config: {
39-
api: siaCentralApi,
40-
},
41-
}),
25+
const [[c], [r]] = await Promise.all([
26+
to(
27+
siaCentral.contract({
28+
params: {
29+
id,
30+
},
31+
})
32+
),
33+
to(
34+
siaCentral.exchangeRates({
35+
params: {
36+
currencies: 'sc',
37+
},
38+
})
39+
),
4240
])
4341

4442
if (!c || !c.contract) {

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

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
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'
9+
import { to } from '@siafoundation/request'
1410

1511
export function generateMetadata({ params }): Metadata {
1612
const id = decodeURIComponent((params?.id as string) || '')
@@ -28,51 +24,51 @@ export const revalidate = 0
2824

2925
export default async function Page({ params }) {
3026
const id = params?.id as string
31-
const [{ data: c, error }, { data: r }] = await Promise.all([
32-
getSiaCentralContract({
33-
params: {
34-
id,
35-
},
36-
config: {
37-
api: siaCentralApi,
38-
},
39-
}),
40-
getSiaCentralExchangeRates({
41-
config: {
42-
api: siaCentralApi,
43-
},
44-
}),
27+
const [[c, error], [r]] = await Promise.all([
28+
to(
29+
siaCentral.contract({
30+
params: {
31+
id,
32+
},
33+
})
34+
),
35+
to(
36+
siaCentral.exchangeRates({
37+
params: {
38+
currencies: 'sc',
39+
},
40+
})
41+
),
4542
])
4643

4744
if (error) {
48-
throw Error(error)
45+
throw error
4946
}
5047

51-
if (!c?.contract) {
48+
const contract = c?.contract
49+
50+
if (!contract) {
5251
return notFound()
5352
}
5453

55-
const contract = c.contract
5654
const formationTxnId = getFormationTxnId(contract)
5755
const finalRevisionTxnId = contract?.transaction_id || ''
5856

59-
const [{ data: ft }, { data: rt }] = await Promise.all([
60-
getSiaCentralTransaction({
61-
params: {
62-
id: formationTxnId,
63-
},
64-
config: {
65-
api: siaCentralApi,
66-
},
67-
}),
68-
getSiaCentralTransaction({
69-
params: {
70-
id: finalRevisionTxnId,
71-
},
72-
config: {
73-
api: siaCentralApi,
74-
},
75-
}),
57+
const [[ft], [rt]] = await Promise.all([
58+
to(
59+
siaCentral.transaction({
60+
params: {
61+
id: formationTxnId,
62+
},
63+
})
64+
),
65+
to(
66+
siaCentral.transaction({
67+
params: {
68+
id: finalRevisionTxnId,
69+
},
70+
})
71+
),
7672
])
7773

7874
const formationTransaction = ft?.transaction

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

Lines changed: 17 additions & 19 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,
@@ -14,6 +10,7 @@ import {
1410
} from '@siafoundation/units'
1511
import { truncate } from '@siafoundation/design-system'
1612
import { CurrencyOption, currencyOptions } from '@siafoundation/react-core'
13+
import { to } from '@siafoundation/request'
1714

1815
export const revalidate = 0
1916

@@ -29,20 +26,21 @@ export const contentType = 'image/png'
2926

3027
export default async function Image({ params }) {
3128
const id = params?.id as string
32-
const [{ data: h }, { data: r }] = await Promise.all([
33-
getSiaCentralHost({
34-
params: {
35-
id,
36-
},
37-
config: {
38-
api: siaCentralApi,
39-
},
40-
}),
41-
getSiaCentralExchangeRates({
42-
config: {
43-
api: siaCentralApi,
44-
},
45-
}),
29+
const [[h], [r]] = await Promise.all([
30+
to(
31+
siaCentral.host({
32+
params: {
33+
id,
34+
},
35+
})
36+
),
37+
to(
38+
siaCentral.exchangeRates({
39+
params: {
40+
currencies: 'sc',
41+
},
42+
})
43+
),
4644
])
4745

4846
if (!h || !h.host) {

0 commit comments

Comments
 (0)