Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: request api, renterd and sia central sdks #588

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/chilly-pants-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'explorer': minor
'website': minor
---

The site now uses the updated Sia Central SDK.
5 changes: 5 additions & 0 deletions .changeset/odd-pets-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@siafoundation/sia-central-js': minor
---

The SDK has been updated to use the request library.
19 changes: 9 additions & 10 deletions apps/explorer/app/address/[id]/opengraph-image.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { getSiaCentralAddress } from '@siafoundation/sia-central-js'
import { humanSiacoin, humanSiafund } from '@siafoundation/units'
import { getOGImage } from '../../../components/OGImageEntity'
import { siaCentralApi } from '../../../config'
import { siaCentral } from '../../../config/siaCentral'
import { truncate } from '@siafoundation/design-system'
import { to } from '@siafoundation/request'

export const revalidate = 0

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

export default async function Image({ params }) {
const id = params?.id as string
const { data: a } = await getSiaCentralAddress({
params: {
id,
},
config: {
api: siaCentralApi,
},
})
const [a] = await to(
siaCentral.address({
params: {
id,
},
})
)

if (!a) {
return getOGImage(
Expand Down
21 changes: 10 additions & 11 deletions apps/explorer/app/address/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { getSiaCentralAddress } from '@siafoundation/sia-central-js'
import { Address } from '../../../components/Address'
import { Metadata } from 'next'
import { routes } from '../../../config/routes'
import { buildMetadata } from '../../../lib/utils'
import { siaCentralApi } from '../../../config'
import { siaCentral } from '../../../config/siaCentral'
import { notFound } from 'next/navigation'
import { truncate } from '@siafoundation/design-system'
import { to } from '@siafoundation/request'

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

export default async function Page({ params }) {
const id = params?.id as string
const { data: a, error } = await getSiaCentralAddress({
params: {
id,
},
config: {
api: siaCentralApi,
},
})
const [a, error] = await to(
siaCentral.address({
params: {
id,
},
})
)

if (error) {
throw Error(error)
throw error
}

if (a?.unspent_siacoins == undefined) {
Expand Down
19 changes: 9 additions & 10 deletions apps/explorer/app/block/[id]/opengraph-image.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { getSiaCentralBlock } from '@siafoundation/sia-central-js'
import { humanDate } from '@siafoundation/units'
import { getOGImage } from '../../../components/OGImageEntity'
import { siaCentralApi } from '../../../config'
import { siaCentral } from '../../../config/siaCentral'
import { truncate } from '@siafoundation/design-system'
import { to } from '@siafoundation/request'

export const revalidate = 0

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

export default async function Image({ params }) {
const id = params?.id as string
const { data: b } = await getSiaCentralBlock({
params: {
id,
},
config: {
api: siaCentralApi,
},
})
const [b] = await to(
siaCentral.block({
params: {
id,
},
})
)

if (!b || !b.block) {
return getOGImage(
Expand Down
21 changes: 10 additions & 11 deletions apps/explorer/app/block/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { getTitleId } from '@siafoundation/design-system'
import { Block } from '../../../components/Block'
import { routes } from '../../../config/routes'
import { Metadata } from 'next'
import { getSiaCentralBlock } from '@siafoundation/sia-central-js'
import { buildMetadata } from '../../../lib/utils'
import { siaCentralApi } from '../../../config'
import { siaCentral } from '../../../config/siaCentral'
import { notFound } from 'next/navigation'
import { to } from '@siafoundation/request'

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

export default async function Page({ params }) {
const id = params?.id as string
const { data: b, error } = await getSiaCentralBlock({
params: {
id,
},
config: {
api: siaCentralApi,
},
})
const [b, error] = await to(
siaCentral.block({
params: {
id,
},
})
)

if (error) {
throw Error(error)
throw error
}

if (!b?.block) {
Expand Down
36 changes: 17 additions & 19 deletions apps/explorer/app/contract/[id]/opengraph-image.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import {
getSiaCentralContract,
getSiaCentralExchangeRates,
} from '@siafoundation/sia-central-js'
import { humanBytes, humanDate } from '@siafoundation/units'
import { getOGImage } from '../../../components/OGImageEntity'
import { siaCentralApi } from '../../../config'
import { siaCentral } from '../../../config/siaCentral'
import { truncate } from '@siafoundation/design-system'
import { lowerCase } from '@technically/lodash'
import { siacoinToFiat } from '../../../lib/currency'
import { CurrencyOption, currencyOptions } from '@siafoundation/react-core'
import { to } from '@siafoundation/request'

export const revalidate = 0

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

const [{ data: c }, { data: r }] = await Promise.all([
getSiaCentralContract({
params: {
id,
},
config: {
api: siaCentralApi,
},
}),
getSiaCentralExchangeRates({
config: {
api: siaCentralApi,
},
}),
const [[c], [r]] = await Promise.all([
to(
siaCentral.contract({
params: {
id,
},
})
),
to(
siaCentral.exchangeRates({
params: {
currencies: 'sc',
},
})
),
])

if (!c || !c.contract) {
Expand Down
76 changes: 36 additions & 40 deletions apps/explorer/app/contract/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { SiaCentralContract } from '@siafoundation/sia-central-types'
import {
getSiaCentralContract,
getSiaCentralExchangeRates,
getSiaCentralTransaction,
} from '@siafoundation/sia-central-js'
import { ContractView } from '../../../components/ContractView'
import { Metadata } from 'next'
import { routes } from '../../../config/routes'
import { buildMetadata } from '../../../lib/utils'
import { siaCentralApi } from '../../../config'
import { siaCentral } from '../../../config/siaCentral'
import { notFound } from 'next/navigation'
import { truncate } from '@siafoundation/design-system'
import { to } from '@siafoundation/request'

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

export default async function Page({ params }) {
const id = params?.id as string
const [{ data: c, error }, { data: r }] = await Promise.all([
getSiaCentralContract({
params: {
id,
},
config: {
api: siaCentralApi,
},
}),
getSiaCentralExchangeRates({
config: {
api: siaCentralApi,
},
}),
const [[c, error], [r]] = await Promise.all([
to(
siaCentral.contract({
params: {
id,
},
})
),
to(
siaCentral.exchangeRates({
params: {
currencies: 'sc',
},
})
),
])

if (error) {
throw Error(error)
throw error
}

if (!c?.contract) {
const contract = c?.contract

if (!contract) {
return notFound()
}

const contract = c.contract
const formationTxnId = getFormationTxnId(contract)
const finalRevisionTxnId = contract?.transaction_id || ''

const [{ data: ft }, { data: rt }] = await Promise.all([
getSiaCentralTransaction({
params: {
id: formationTxnId,
},
config: {
api: siaCentralApi,
},
}),
getSiaCentralTransaction({
params: {
id: finalRevisionTxnId,
},
config: {
api: siaCentralApi,
},
}),
const [[ft], [rt]] = await Promise.all([
to(
siaCentral.transaction({
params: {
id: formationTxnId,
},
})
),
to(
siaCentral.transaction({
params: {
id: finalRevisionTxnId,
},
})
),
])

const formationTransaction = ft?.transaction
Expand Down
36 changes: 17 additions & 19 deletions apps/explorer/app/host/[id]/opengraph-image.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import {
getSiaCentralExchangeRates,
getSiaCentralHost,
} from '@siafoundation/sia-central-js'
import { getOGImage } from '../../../components/OGImageEntity'
import { siaCentralApi } from '../../../config'
import { siaCentral } from '../../../config/siaCentral'
import {
getDownloadCost,
getDownloadSpeed,
Expand All @@ -14,6 +10,7 @@ import {
} from '@siafoundation/units'
import { truncate } from '@siafoundation/design-system'
import { CurrencyOption, currencyOptions } from '@siafoundation/react-core'
import { to } from '@siafoundation/request'

export const revalidate = 0

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

export default async function Image({ params }) {
const id = params?.id as string
const [{ data: h }, { data: r }] = await Promise.all([
getSiaCentralHost({
params: {
id,
},
config: {
api: siaCentralApi,
},
}),
getSiaCentralExchangeRates({
config: {
api: siaCentralApi,
},
}),
const [[h], [r]] = await Promise.all([
to(
siaCentral.host({
params: {
id,
},
})
),
to(
siaCentral.exchangeRates({
params: {
currencies: 'sc',
},
})
),
])

if (!h || !h.host) {
Expand Down
Loading
Loading