diff --git a/.changeset/ten-geckos-rest.md b/.changeset/ten-geckos-rest.md index 710b6b10d..eaf4080c6 100644 --- a/.changeset/ten-geckos-rest.md +++ b/.changeset/ten-geckos-rest.md @@ -1,7 +1,5 @@ --- '@siafoundation/e2e': minor -'@siafoundation/sia-central-mock': minor -'@siafoundation/walletd-mock': minor --- Upgraded playwright dependencies. diff --git a/README.md b/README.md index c1a62b4a0..4bf3f6d14 100644 --- a/README.md +++ b/README.md @@ -35,9 +35,6 @@ The Sia web libraries provide developers with convenient TypeScript SDKs for usi - [@siafoundation/explored-react](libs/explored-react) - React hooks for interacting with `explored`. - [@siafoundation/explored-types](libs/explored-types) - Types for `explored`. - [@siafoundation/design-system](libs/design-system) - React-based design system used across Sia apps and websites. -- [@siafoundation/sia-central-types](libs/sia-central-types) - Types for the Sia Central API. -- [@siafoundation/sia-central-js](libs/sia-central-js) - SDK for interacting with the Sia Central API. -- [@siafoundation/sia-central-react](libs/sia-central-react) - React hooks for interacting with the Sia Central API. - [@siafoundation/units](libs/units) - Methods and types for converting and displaying units. - [@siafoundation/types](libs/types) - Core Sia types and library methods. - [@siafoundation/react-core](libs/react-core) - Core library for building React hooks for interacting with a Sia daemon. @@ -73,8 +70,6 @@ The Sia web libraries provide developers with convenient TypeScript SDKs for usi - [explorer-e2e](apps/explorer-e2e) - App for testing explorer. - [e2e](libs/e2e) - Shared e2e testing code. - [@siafoundation/clusterd](libs/clusterd) - Methods for controlling `clusterd` in e2e testing. -- [@siafoundation/walletd-mock](libs/walletd-mock) - `walletd` data and API mock library for testing. -- [@siafoundation/sia-central-mock](libs/sia-central-mock) - Sia Central data and API mock library for testing. ## Development diff --git a/apps/hostd-e2e/src/fixtures/beforeTest.ts b/apps/hostd-e2e/src/fixtures/beforeTest.ts index 10aa42b00..951ee4a66 100644 --- a/apps/hostd-e2e/src/fixtures/beforeTest.ts +++ b/apps/hostd-e2e/src/fixtures/beforeTest.ts @@ -1,4 +1,3 @@ -import { mockApiSiaCentralHostsNetworkAverages } from '@siafoundation/sia-central-mock' import { login } from './login' import { Page } from 'playwright' import { @@ -11,11 +10,12 @@ import { clickIf, setCurrencyDisplay, mockApiSiaScanExchangeRates, + mockApiSiaScanHostMetrics, } from '@siafoundation/e2e' export async function beforeTest(page: Page, { renterdCount = 0 } = {}) { await mockApiSiaScanExchangeRates({ page }) - await mockApiSiaCentralHostsNetworkAverages({ page }) + await mockApiSiaScanHostMetrics({ page }) await setupCluster({ hostdCount: 1, renterdCount }) const hostdNode = clusterd.nodes.find((n) => n.type === 'hostd') await hostdWaitForContracts({ hostdNode, renterdCount }) diff --git a/apps/hostd/components/CmdRoot/AppCmdGroup.tsx b/apps/hostd/components/CmdRoot/AppCmdGroup.tsx index 4419c2e64..c53569a0c 100644 --- a/apps/hostd/components/CmdRoot/AppCmdGroup.tsx +++ b/apps/hostd/components/CmdRoot/AppCmdGroup.tsx @@ -46,12 +46,12 @@ export function AppCmdGroup({ currentPage, parentPage }: Props) { currentPage={currentPage} commandPage={commandPage} onSelect={() => { - setExternalDataSettings({ siaCentral: !settings.siaCentral }) + setExternalDataSettings({ siascan: !settings.siascan }) closeDialog() }} > - {(settings.siaCentral ? 'Disable' : 'Enable') + - ' external API - Sia Central exchange rates'} + {(settings.siascan ? 'Disable' : 'Enable') + + ' external API - Siascan exchange rates'} n.type === 'renterd') await renterdWaitForContracts({ renterdNode, hostdCount }) diff --git a/apps/renterd-e2e/src/specs/externalData.spec.ts b/apps/renterd-e2e/src/specs/externalData.spec.ts index 3b794dfd5..63f416a4e 100644 --- a/apps/renterd-e2e/src/specs/externalData.spec.ts +++ b/apps/renterd-e2e/src/specs/externalData.spec.ts @@ -2,11 +2,6 @@ import { test, expect } from '@playwright/test' import { afterTest } from '../fixtures/beforeTest' import { clusterd, setupCluster } from '@siafoundation/clusterd' import { login } from '../fixtures/login' -import { - mockApiSiaCentralHostsNetworkAverages, - mockApiSiaCentralHostsNetworkAveragesHanging, - mockApiSiaCentralHostsNetworkAveragesUnroute, -} from '@siafoundation/sia-central-mock' import { configResetBasicSettings } from '../fixtures/configResetSettings' import { expectTextInputByName, @@ -15,11 +10,14 @@ import { mockApiSiaScanExchangeRatesUnroute, mockApiSiaScanExchangeRatesHanging, fillSelectInputByName, + mockApiSiaScanHostMetrics, + mockApiSiaScanHostMetricsUnroute, + mockApiSiaScanHostMetricsHanging, } from '@siafoundation/e2e' test.beforeEach(async ({ page }) => { await mockApiSiaScanExchangeRates({ page }) - await mockApiSiaCentralHostsNetworkAverages({ page }) + await mockApiSiaScanHostMetrics({ page }) await setupCluster({ renterdCount: 1 }) const renterdNode = clusterd.nodes.find((n) => n.type === 'renterd') await login({ @@ -83,8 +81,8 @@ test('configuration shows not-enabled message when exchange rates API hangs', as test('configuration does not show network averages when sia central API hangs', async ({ page, }) => { - await mockApiSiaCentralHostsNetworkAveragesUnroute({ page }) - await mockApiSiaCentralHostsNetworkAveragesHanging({ page }) + await mockApiSiaScanHostMetricsUnroute({ page }) + await mockApiSiaScanHostMetricsHanging({ page }) await page.reload() await fillSelectInputByName(page, 'pinnedCurrency', 'usd') @@ -120,8 +118,8 @@ test('configuration does not show network averages when sia central API hangs', page.getByTestId('maxDownloadPriceTBGroup').getByText('Network average') ).toBeHidden() - await mockApiSiaCentralHostsNetworkAveragesUnroute({ page }) - await mockApiSiaCentralHostsNetworkAverages({ page }) + await mockApiSiaScanHostMetricsUnroute({ page }) + await mockApiSiaScanHostMetrics({ page }) await page.reload() // Regular field should be shown. diff --git a/apps/renterd/components/CmdRoot/AppCmdGroup.tsx b/apps/renterd/components/CmdRoot/AppCmdGroup.tsx index c420a7ce7..3f835155b 100644 --- a/apps/renterd/components/CmdRoot/AppCmdGroup.tsx +++ b/apps/renterd/components/CmdRoot/AppCmdGroup.tsx @@ -46,12 +46,12 @@ export function AppCmdGroup({ currentPage, parentPage }: Props) { currentPage={currentPage} commandPage={commandPage} onSelect={() => { - setExternalDataSettings({ siaCentral: !settings.siaCentral }) + setExternalDataSettings({ siascan: !settings.siascan }) closeDialog() }} > - {(settings.siaCentral ? 'Disable' : 'Enable') + - ' external API - Sia Central exchange rates'} + {(settings.siascan ? 'Disable' : 'Enable') + + ' external API - Siascan exchange rates'} rates - ? `$${new BigNumber(host.settings?.storage_price || 0) + ? `$${new BigNumber(host.settings?.storageprice || 0) .times(TBToBytes(1)) .times(monthsToBlocks(1)) .div(1e24) .times(rates?.usd || 1) .toFixed(2)}/TB` : `${humanSiacoin( - new BigNumber(host.settings?.storage_price || 0) + new BigNumber(host.settings?.storageprice || 0) .times(TBToBytes(1)) .times(monthsToBlocks(1)), { fixed: 0 } @@ -57,13 +55,13 @@ export function HostItem({ const downloadCost = useMemo( () => rates - ? `$${new BigNumber(host.settings?.download_price || 0) + ? `$${new BigNumber(host.settings?.downloadbandwidthprice || 0) .times(TBToBytes(1)) .div(1e24) .times(rates?.usd || 1) .toFixed(2)}/TB` : `${humanSiacoin( - new BigNumber(host.settings?.download_price || 0).times( + new BigNumber(host.settings?.downloadbandwidthprice || 0).times( TBToBytes(1) ), { fixed: 0 } @@ -74,13 +72,15 @@ export function HostItem({ const uploadCost = useMemo( () => rates - ? `$${new BigNumber(host.settings?.upload_price || 0) + ? `$${new BigNumber(host.settings?.uploadbandwidthprice || 0) .times(TBToBytes(1)) .div(1e24) .times(rates?.usd || 1) .toFixed(2)}/TB` : `${humanSiacoin( - new BigNumber(host.settings?.upload_price || 0).times(TBToBytes(1)), + new BigNumber(host.settings?.uploadbandwidthprice || 0).times( + TBToBytes(1) + ), { fixed: 0 } )}/TB`, [rates, host] @@ -91,7 +91,7 @@ export function HostItem({ content={
- {countryCodeEmoji(host.country_code)} {host.country_code} + {countryCodeEmoji(host.countryCode)} {host.countryCode}
@@ -105,17 +105,6 @@ export function HostItem({ upload
-
- - {humanBytes(host.settings?.total_storage || 0)} - - - {getDownloadSpeed(host)} - - - {getUploadSpeed(host)} - -
{storageCost} @@ -130,7 +119,7 @@ export function HostItem({
} - key={host.public_key} + key={host.publicKey} > { - if (!settings.siaCentral) { + if (!settings.siascan) { openDialog('settings') return } diff --git a/apps/renterd/contexts/config/transform.spec.ts b/apps/renterd/contexts/config/transform.spec.ts index 2887dad36..c5ac8cbac 100644 --- a/apps/renterd/contexts/config/transform.spec.ts +++ b/apps/renterd/contexts/config/transform.spec.ts @@ -375,11 +375,6 @@ describe('tansforms', () => { gouging: { data: gouging }, pinned: { data: pinned }, upload: { data: upload }, - appSettings: { - settings: { - siaCentral: false, - }, - }, }, renterdState: { network: 'mainnet' as const, diff --git a/apps/renterd/contexts/config/useAverages.tsx b/apps/renterd/contexts/config/useAverages.tsx index 0ecfcf53c..3912de613 100644 --- a/apps/renterd/contexts/config/useAverages.tsx +++ b/apps/renterd/contexts/config/useAverages.tsx @@ -6,10 +6,10 @@ import { valuePerByteToPerTB, valuePerOneToPerMillion, } from '@siafoundation/units' -import { useSiaCentralHostsNetworkAverages } from '@siafoundation/sia-central-react' +import { useExternalHostMetrics } from '@siafoundation/design-system' export function useAverages() { - const siaCentralAverages = useSiaCentralHostsNetworkAverages({ + const siascanAverages = useExternalHostMetrics({ config: { swr: { revalidateOnFocus: false, @@ -18,58 +18,56 @@ export function useAverages() { }) const storageAverage = useMemo( () => - siaCentralAverages.data + siascanAverages.data ? new BigNumber( valuePerBytePerBlockToPerTBPerMonth( - toSiacoins(siaCentralAverages.data.settings.storage_price) + toSiacoins(siascanAverages.data.settings.storageprice) ).toFixed(0) ) : undefined, - [siaCentralAverages.data] + [siascanAverages.data] ) const uploadAverage = useMemo( () => - siaCentralAverages.data + siascanAverages.data ? new BigNumber( valuePerByteToPerTB( - toSiacoins(siaCentralAverages.data.settings.upload_price) + toSiacoins(siascanAverages.data.settings.uploadbandwidthprice) ).toFixed(0) ) : undefined, - [siaCentralAverages.data] + [siascanAverages.data] ) const downloadAverage = useMemo( () => - siaCentralAverages.data + siascanAverages.data ? new BigNumber( valuePerByteToPerTB( - toSiacoins(siaCentralAverages.data.settings.download_price) + toSiacoins(siascanAverages.data.settings.downloadbandwidthprice) ).toFixed(0) ) : undefined, - [siaCentralAverages.data] + [siascanAverages.data] ) const contractAverage = useMemo( () => - siaCentralAverages.data + siascanAverages.data ? new BigNumber( - toSiacoins(siaCentralAverages.data.settings.contract_price).toFixed( - 0 - ) + toSiacoins(siascanAverages.data.settings.contractprice).toFixed(0) ) : undefined, - [siaCentralAverages.data] + [siascanAverages.data] ) const rpcAverage = useMemo( () => - siaCentralAverages.data + siascanAverages.data ? valuePerOneToPerMillion( - toSiacoins(siaCentralAverages.data.settings.base_rpc_price) + toSiacoins(siascanAverages.data.settings.baserpcprice) ) : undefined, - [siaCentralAverages.data] + [siascanAverages.data] ) const averages = useMemo(() => { diff --git a/apps/renterd/contexts/config/useResources.tsx b/apps/renterd/contexts/config/useResources.tsx index 095ea2dd0..910455202 100644 --- a/apps/renterd/contexts/config/useResources.tsx +++ b/apps/renterd/contexts/config/useResources.tsx @@ -1,4 +1,4 @@ -import { useAppSettings, SWRError } from '@siafoundation/react-core' +import { SWRError } from '@siafoundation/react-core' import { AutopilotConfig, AutopilotState, @@ -53,8 +53,6 @@ export function useResources() { }, }) - const appSettings = useAppSettings() - // Resources required to intialize form. const resources: ResourcesMaybeLoaded = useMemo( () => ({ @@ -78,11 +76,6 @@ export function useResources() { data: upload.data, error: upload.error, }, - appSettings: { - settings: { - siaCentral: appSettings.settings.siaCentral, - }, - }, }), [ autopilotState.data, @@ -95,7 +88,6 @@ export function useResources() { pinned.error, upload.data, upload.error, - appSettings.settings.siaCentral, ] ) @@ -106,7 +98,6 @@ export function useResources() { gouging, pinned, upload, - appSettings, } } @@ -162,11 +153,6 @@ export type ResourcesMaybeLoaded = { data?: SettingsUpload error?: SWRError } - appSettings: { - settings: { - siaCentral: boolean - } - } } export type ResourcesRequiredLoaded = { @@ -190,9 +176,4 @@ export type ResourcesRequiredLoaded = { data: SettingsUpload error?: undefined } - appSettings: { - settings: { - siaCentral: boolean - } - } } diff --git a/apps/renterd/contexts/contracts/dataset.tsx b/apps/renterd/contexts/contracts/dataset.tsx index 67985c436..21ea1d488 100644 --- a/apps/renterd/contexts/contracts/dataset.tsx +++ b/apps/renterd/contexts/contracts/dataset.tsx @@ -2,13 +2,13 @@ import { useContracts as useContractsData } from '@siafoundation/renterd-react' import { useMemo } from 'react' import BigNumber from 'bignumber.js' import { ContractData, ContractDataWithoutPrunable } from './types' -import { useSiaCentralHosts } from '@siafoundation/sia-central-react' import { useSyncStatus } from '../../hooks/useSyncStatus' import { blockHeightToTime } from '@siafoundation/units' import { defaultDatasetRefreshInterval } from '../../config/swr' import { usePrunableContractSizes } from './usePrunableContractSizes' import { Maybe } from '@siafoundation/types' import { maybeFromNullishArrayResponse } from '@siafoundation/react-core' +import { useExternalHostsList } from '@siafoundation/design-system' export function useDataset() { const response = useContractsData({ @@ -18,8 +18,16 @@ export function useDataset() { }, }, }) - const geo = useSiaCentralHosts() - const geoHosts = useMemo(() => geo.data?.hosts || [], [geo.data]) + const geo = useExternalHostsList({ + params: { + sortBy: 'storage_price', + dir: 'asc', + }, + payload: { + online: true, + }, + }) + const geoHosts = useMemo(() => geo.data || [], [geo.data]) const syncStatus = useSyncStatus() const currentHeight = syncStatus.isSynced @@ -45,7 +53,7 @@ export function useDataset() { id: c.id, state: c.state, hostKey: c.hostKey, - location: geoHosts.find((h) => h.public_key === c.hostKey)?.location, + location: geoHosts.find((h) => h.publicKey === c.hostKey)?.location, timeline: startTime, usability: c.usability, startTime, diff --git a/apps/renterd/contexts/hosts/dataset.ts b/apps/renterd/contexts/hosts/dataset.ts index 041448210..c98f93658 100644 --- a/apps/renterd/contexts/hosts/dataset.ts +++ b/apps/renterd/contexts/hosts/dataset.ts @@ -8,10 +8,10 @@ import { useHosts, } from '@siafoundation/renterd-react' import { ContractData } from '../contracts/types' -import { SiaCentralHost } from '@siafoundation/sia-central-types' import { Maybe } from '@siafoundation/types' import { objectEntries } from '@siafoundation/design-system' import { maybeFromNullishArrayResponse } from '@siafoundation/react-core' +import { ExplorerHost } from '@siafoundation/explored-types' export function useDataset({ response, @@ -26,7 +26,7 @@ export function useDataset({ allowlist: ReturnType blocklist: ReturnType isAllowlistActive: boolean - geoHosts: SiaCentralHost[] + geoHosts: ExplorerHost[] }) { return useMemo>(() => { const data = maybeFromNullishArrayResponse(response.data) @@ -36,7 +36,7 @@ export function useDataset({ return undefined } return data.map((host) => { - const sch = geoHosts.find((gh) => gh.public_key === host.publicKey) + const sch = geoHosts.find((gh) => gh.publicKey === host.publicKey) return { ...getHostFields(host, allContracts), ...getAllowedFields({ @@ -47,7 +47,7 @@ export function useDataset({ }), ...getAutopilotFields(host.checks), location: sch?.location, - countryCode: sch?.country_code, + countryCode: sch?.countryCode, // selectable onClick: () => null, isSelected: false, diff --git a/apps/renterd/contexts/hosts/index.tsx b/apps/renterd/contexts/hosts/index.tsx index 632d054c0..519430451 100644 --- a/apps/renterd/contexts/hosts/index.tsx +++ b/apps/renterd/contexts/hosts/index.tsx @@ -2,6 +2,7 @@ import { triggerToast, truncate, useDatasetState, + useExternalHostsList, useMultiSelect, usePaginationOffset, useServerFilters, @@ -18,7 +19,6 @@ import { HostsPayload, HostsUsabilityMode, } from '@siafoundation/renterd-types' -import { useSiaCentralHosts } from '@siafoundation/sia-central-react' import { createContext, useCallback, @@ -91,22 +91,23 @@ function useHostsMain() { const isAllowlistActive = !!allowlist.data?.length const { settings } = useAppSettings() - const geo = useSiaCentralHosts({ - disabled: !settings.siaCentral, - config: { - swr: { - revalidateOnFocus: false, - }, + const geo = useExternalHostsList({ + params: { + sortBy: 'storage_price', + dir: 'asc', + }, + payload: { + online: true, }, }) useEffect(() => { - if (!settings.siaCentral) { + if (!settings.siascan) { setViewMode('list') } - }, [settings.siaCentral]) + }, [settings.siascan]) - const geoHosts = useMemo(() => geo.data?.hosts || [], [geo.data]) + const geoHosts = useMemo(() => geo.data || [], [geo.data]) const cmdRef = useRef(emptyCommands) diff --git a/apps/walletd-e2e/src/fixtures/beforeTest.ts b/apps/walletd-e2e/src/fixtures/beforeTest.ts index 0f5a0459e..01eca7fa1 100644 --- a/apps/walletd-e2e/src/fixtures/beforeTest.ts +++ b/apps/walletd-e2e/src/fixtures/beforeTest.ts @@ -1,6 +1,5 @@ import { login } from './login' import { Page } from 'playwright' -import { mockApiSiaCentralHostsNetworkAverages } from '@siafoundation/sia-central-mock' import { clusterd, mine, @@ -11,6 +10,7 @@ import { Bus } from '@siafoundation/renterd-js' import { setCurrencyDisplay, mockApiSiaScanExchangeRates, + mockApiSiaScanHostMetrics, } from '@siafoundation/e2e' export async function beforeTest( @@ -18,7 +18,7 @@ export async function beforeTest( { siafundAddr }: { siafundAddr?: string } = {} ) { await mockApiSiaScanExchangeRates({ page }) - await mockApiSiaCentralHostsNetworkAverages({ page }) + await mockApiSiaScanHostMetrics({ page }) await setupCluster({ walletdCount: 1, renterdCount: 1, diff --git a/apps/walletd/lib/mocks/mockConsensusNetwork.ts b/apps/walletd/lib/mocks/mockConsensusNetwork.ts new file mode 100644 index 000000000..0e6071db3 --- /dev/null +++ b/apps/walletd/lib/mocks/mockConsensusNetwork.ts @@ -0,0 +1,55 @@ +import { ConsensusNetwork } from '@siafoundation/types' +import { Page } from 'playwright' + +export function getMockConsensusNetworkResponse(): ConsensusNetwork { + return { + name: 'zen', + initialCoinbase: '300000000000000000000000000000', + minimumCoinbase: '300000000000000000000000000000', + initialTarget: + '0000000100000000000000000000000000000000000000000000000000000000', + hardforkDevAddr: { + height: 1, + oldAddress: + '000000000000000000000000000000000000000000000000000000000000000089eb0d6a8a69', + newAddress: + '000000000000000000000000000000000000000000000000000000000000000089eb0d6a8a69', + }, + hardforkTax: { + height: 2, + }, + hardforkStorageProof: { + height: 5, + }, + hardforkOak: { + height: 10, + fixHeight: 12, + genesisTimestamp: '2023-01-13T03:53:20-05:00', + }, + hardforkASIC: { + height: 20, + oakTime: 10000000000000, + oakTarget: + '0000000100000000000000000000000000000000000000000000000000000000', + }, + hardforkFoundation: { + height: 30, + primaryAddress: + '053b2def3cbdd078c19d62ce2b4f0b1a3c5e0ffbeeff01280efb1f8969b2f5bb4fdc680f0807', + failsafeAddress: + '000000000000000000000000000000000000000000000000000000000000000089eb0d6a8a69', + }, + hardforkV2: { + allowHeight: 100000, + requireHeight: 102000, + }, + } +} + +export async function mockApiConsensusNetwork({ page }: { page: Page }) { + const json = getMockConsensusNetworkResponse() + await page.route('**/api/consensus/network*', async (route) => { + await route.fulfill({ json }) + }) + return json +} diff --git a/apps/walletd/lib/mocks/mockConsensusTipState.ts b/apps/walletd/lib/mocks/mockConsensusTipState.ts new file mode 100644 index 000000000..8f4ddd351 --- /dev/null +++ b/apps/walletd/lib/mocks/mockConsensusTipState.ts @@ -0,0 +1,66 @@ +import { ConsensusState } from '@siafoundation/types' +import { Page } from 'playwright' + +export function getMockConsensusTipStateResponse(): ConsensusState { + return { + index: { + height: 61676, + id: '00000010d5da9002b9640d920d9eb9f7502c5c3b2a796ecf800a103920bea96f', + }, + prevTimestamps: [ + // This timestamp being recent is used to represent a "synced" state + new Date().toISOString(), + '2024-03-25T17:33:24-04:00', + '2024-03-25T17:18:32-04:00', + '2024-03-25T17:07:59-04:00', + '2024-03-25T17:04:15-04:00', + '2024-03-25T16:50:56-04:00', + '2024-03-25T16:38:22-04:00', + '2024-03-25T16:38:12-04:00', + '2024-03-25T16:36:56-04:00', + '2024-03-25T16:35:17-04:00', + '2024-03-25T16:33:59-04:00', + '2024-03-25T16:31:16-04:00', + ], + depth: '000000000001aa096ddebfbf467c56faba46eb4b3e53e72c775bf9ab202a4890', + childTarget: + '0000005a6c49bca6186415827e15b13371c3de541dd64b7cf36a519b5128b2f8', + siafundPool: '88386728360671853873752300000', + oakTime: 127103000000000, + oakTarget: + '0000000024d11bd550a6acf3718192825fa2cef5582314db8e92c4f4e5efbf4c', + foundationPrimaryAddress: + '053b2def3cbdd078c19d62ce2b4f0b1a3c5e0ffbeeff01280efb1f8969b2f5bb4fdc680f0807', + foundationFailsafeAddress: + '000000000000000000000000000000000000000000000000000000000000000089eb0d6a8a69', + totalWork: '169134658088983', + difficulty: '47498615', + oakWork: '29864374508', + elements: { + numLeaves: 304383, + trees: [ + '6d5fedd2f6d71cad5fc7bb35ef8bad6631c63e1323142e2a4825314b77f87d1e', + '16e0c70194d2e41a21fe070ff936551b2379df8054890b95bada3c6b6a0ed3f7', + '73defbf6af352d9401698492c407662b8feb62ba82e92028bf9bf0103f261844', + 'e22d4da6204096eef1eb0fc217c8900dce1040312cc721b9b6b3fc2be7a77da8', + '4a9860d3e3ccf6cf434ed94d485b4385c62c443fd18e539998bd817a3ebed772', + '6cd1e1d71a0796980193bcbb1adff069ef3f70fd12749d9e877b2bd0c8d561d1', + '7aa0bdb94da13c43abd9446f77638d3e6e2ae4c36c5224a76433044c56db906c', + '66c119cf5cb9ca3a174637c751988f03300e0375b43d22c82df7145841515d38', + 'ce8a94296e60887232915d6801a9246827661d329de47a08f25a6a3884809037', + '8aa7872a63ef37e1ca8e4211700daf96068ce2cc215d4e2ab45434b5ffcab818', + '3f0175c94ed31190e6da23e80d6167e2da619b460e27798750491163dbe5677b', + '9f120f6489c3e3a324cd51a6f8f9dd033930688095f4440dc5f8511692b4efc1', + ], + }, + attestations: 0, + } +} + +export async function mockApiConsensusTipState({ page }: { page: Page }) { + const json = getMockConsensusTipStateResponse() + await page.route('**/api/consensus/tipstate*', async (route) => { + await route.fulfill({ json }) + }) + return json +} diff --git a/apps/walletd/lib/mocks/mockSeedWallet.ts b/apps/walletd/lib/mocks/mockSeedWallet.ts new file mode 100644 index 000000000..64d698408 --- /dev/null +++ b/apps/walletd/lib/mocks/mockSeedWallet.ts @@ -0,0 +1,300 @@ +import { + Wallet, + WalletAddress, + WalletBalanceResponse, + WalletConstructV2TransactionResponse, + WalletFundSiacoinResponse, + WalletOutputsSiacoinResponse, + WalletOutputsSiafundResponse, +} from '@siafoundation/walletd-types' +import { toHastings } from '@siafoundation/units' +import { getMockConsensusNetworkResponse } from './mockConsensusNetwork' +import { getMockConsensusTipStateResponse } from './mockConsensusTipState' + +export function getMockScenarioSeedWallet() { + const mnemonic = + 'ridge business wish transfer home glove office salt wealth baby journey diary' + + const receiveAddress = + '5739945c21e60afd70eaf97ccd33ea27836e0219212449f39e4b38acaa8b3119aa4150a9ef0f' + const changeAddress = + '170173c40ca0f39f9618da30af14c390c7ce70248a3662a7a5d3d5a8a31c9fbfa2071e9f6518' + + const newWallet: Wallet = { + id: '100', + name: 'test send wallet', + description: 'wallet description', + dateCreated: new Date().toISOString(), + lastUpdated: new Date().toISOString(), + metadata: { + type: 'seed', + mnemonicHash: + '251cc9d01333287e9c9f39fc4749095a28a3970348a6106244848d2c414a908bc81ae4982911435a045a407fb305b69e51d05ce6f9b47ef1750c1e74ca299a48', + }, + } + + const walletBalanceResponse: WalletBalanceResponse = { + siacoins: toHastings('100').toString(), + immatureSiacoins: toHastings('10').toString(), + siafunds: 10, + } + + const walletOutputsSiacoinResponse: WalletOutputsSiacoinResponse = { + basis: { + height: 0, + id: '0', + }, + outputs: [ + { + id: 'aa3e781330c9b3991e0141807df1327fadf114ca6c37acb9e58004f942d91dfb', + leafIndex: 304248, + merkleProof: [ + '0a7a4c392f78899e3c38c5cd9e6a673b2c7afec97930af539af9c8e20209aa78', + 'a1e074dc48634a234b7366a0d7ab19cd05e3e698e1d44bf07e24d75ae0c65b3c', + '44d107342962e2068d289ce090c87b7bf0c847f734bdfad10db5546e402c3ad7', + '64ea3e65ecd5ebc1c0ce014673148060855ce550571208b6303b8e2a83e33451', + '19e37bf7747c6d8c7b87d2474dbbd3a8f5b26d89642f8e1af4b9b02abdfb2ea6', + '1fc2ac9f70211a3be6f334db14feb8b327458aee49d3539770640cbdec9b4a5f', + 'defbbc18c64349f11e75537955861ececce0fadf10baec456f6c74b024820af1', + '87d27ff868ca3b1dce59ae754eaec48239718e81e2e6f3b7b418f5a00362bcf7', + '93d823c55fbd09de462a8e355921433b3693d63de58ea8e2780a2c2ffabd0fee', + 'a68820d6b79b2735b15c69d0fc26b11252bb27f22b9088559ed13f9420f5dda1', + '1bbcead690290291ea9628214a121ef783411693975171803bf5716a3a6ff19b', + ], + siacoinOutput: { + value: '1000000000000000000000000', + address: + 'f2dbf56b5b0c698d7fbf43f646c76169d84e597e8b37fada97348beeecaa812d400ac4ce7981', + }, + maturityHeight: 0, + }, + { + id: '32e430158591b4073a6834e9f4c4b67162e348844f569f4e472896bb72efb724', + leafIndex: 305723, + merkleProof: [ + '8c02aeec48de589ce497ebe72fb8b527cfe022ef513fcfdc56745c84832f00ec', + '1bf63b9959e60272fd7a48a8cecd4120a852c0e14557ea27ccad6ea2071e70b3', + '21b7e1606e9fd677059c58a1a687682182f71ce09e071431dcaff823a3a5d49e', + 'e81ac37d3b4db6166dc1bb10ebfa49f57cbf99aababd36ee4e3e5e12082dc6dc', + 'ecc307c6c3e505d97ccf821938e5e5702ef0130d33c991ca95735f7d9706a4b8', + '9560060ee399793f102e092afdfdbdd33692706256955e8390af552de0addfc0', + ], + siacoinOutput: { + value: '97988210000000000000000000', + address: + 'f2dbf56b5b0c698d7fbf43f646c76169d84e597e8b37fada97348beeecaa812d400ac4ce7981', + }, + maturityHeight: 0, + }, + ], + } + + const walletOutputsSiafundResponse: WalletOutputsSiafundResponse = { + basis: { + height: 0, + id: '0', + }, + outputs: [], + } + + const walletFundResponse: WalletFundSiacoinResponse = { + basis: { + height: 0, + id: '0', + }, + transaction: { + siacoinInputs: [ + { + parentID: + 'aa3e781330c9b3991e0141807df1327fadf114ca6c37acb9e58004f942d91dfb', + unlockConditions: { + timelock: 0, + publicKeys: null, + signaturesRequired: 1, + }, + }, + { + parentID: + '32e430158591b4073a6834e9f4c4b67162e348844f569f4e472896bb72efb724', + unlockConditions: { + timelock: 0, + publicKeys: null, + signaturesRequired: 1, + }, + }, + ], + siacoinOutputs: [ + { + value: '1000000000000000000000000', + address: + '90c6057cdd2463eca61f83796e83152dbba28b6cb9a74831a043833051ec9f422726bfff2ee8', + }, + { + value: '97984280000000000000000000', + address: + 'f2dbf56b5b0c698d7fbf43f646c76169d84e597e8b37fada97348beeecaa812d400ac4ce7981', + }, + ], + minerFees: ['3930000000000000000000'], + }, + toSign: [ + 'aa3e781330c9b3991e0141807df1327fadf114ca6c37acb9e58004f942d91dfb', + '32e430158591b4073a6834e9f4c4b67162e348844f569f4e472896bb72efb724', + ], + dependsOn: null, + } + + const walletConstructV2Response: WalletConstructV2TransactionResponse = { + id: '0', + basis: { + height: 0, + id: '0', + }, + transaction: { + siacoinInputs: [ + { + parent: { + id: 'aa3e781330c9b3991e0141807df1327fadf114ca6c37acb9e58004f942d91dfb', + maturityHeight: 0, + siacoinOutput: { + value: '1000000000000000000000000', + address: + '90c6057cdd2463eca61f83796e83152dbba28b6cb9a74831a043833051ec9f422726bfff2ee8', + }, + leafIndex: 304248, + merkleProof: [ + '0a7a4c392f78899e3c38c5cd9e6a673b2c7afec97930af539af9c8e20209aa78', + 'a1e074dc48634a234b7366a0d7ab19cd05e3e698e1d44bf07e24d75ae0c65b3c', + ], + }, + satisfiedPolicy: { + policy: { + type: 'uc', + policy: { + timelock: 0, + publicKeys: [ + 'ed25519:ee122b2169bdae5776b55609e384e0c58372cd5c529d4edc9b9918b26f8e5535', + ], + signaturesRequired: 1, + }, + }, + }, + }, + { + parent: { + id: '32e430158591b4073a6834e9f4c4b67162e348844f569f4e472896bb72efb724', + maturityHeight: 0, + siacoinOutput: { + value: '97984280000000000000000000', + address: + 'f2dbf56b5b0c698d7fbf43f646c76169d84e597e8b37fada97348beeecaa812d400ac4ce7981', + }, + leafIndex: 305723, + merkleProof: [ + '8c02aeec48de589ce497ebe72fb8b527cfe022ef513fcfdc56745c84832f00ec', + '1bf63b9959e60272fd7a48a8cecd4120a852c0e14557ea27ccad6ea2071e70b3', + ], + }, + satisfiedPolicy: { + policy: { + type: 'uc', + policy: { + timelock: 0, + publicKeys: [ + 'ed25519:ee122b2169bdae5776b55609e384e0c58372cd5c529d4edc9b9918b26f8e5535', + ], + signaturesRequired: 1, + }, + }, + }, + }, + ], + siacoinOutputs: [ + { + value: '1000000000000000000000000', + address: + '90c6057cdd2463eca61f83796e83152dbba28b6cb9a74831a043833051ec9f422726bfff2ee8', + }, + { + value: '97984280000000000000000000', + address: + 'f2dbf56b5b0c698d7fbf43f646c76169d84e597e8b37fada97348beeecaa812d400ac4ce7981', + }, + ], + minerFee: '3930000000000000000000', + }, + estimatedFee: '0', + } + + const walletAddressesResponse: WalletAddress[] = [ + { + address: + 'f2dbf56b5b0c698d7fbf43f646c76169d84e597e8b37fada97348beeecaa812d400ac4ce7981', + description: '', + spendPolicy: { + type: 'uc', + policy: { + timelock: 0, + signaturesRequired: 1, + publicKeys: [ + 'ed25519:ee122b2169bdae5776b55609e384e0c58372cd5c529d4edc9b9918b26f8e5535', + ], + }, + }, + metadata: { + index: 0, + }, + }, + { + address: + '90c6057cdd2463eca61f83796e83152dbba28b6cb9a74831a043833051ec9f422726bfff2ee8', + description: '', + spendPolicy: { + type: 'uc', + policy: { + timelock: 0, + signaturesRequired: 1, + publicKeys: [ + 'ed25519:624d6d477a8f4ceac873e6dd9138740f9322cb34a24246f96f9d64c021172f43', + ], + }, + }, + metadata: { + index: 1, + }, + }, + { + address: + '170173c40ca0f39f9618da30af14c390c7ce70248a3662a7a5d3d5a8a31c9fbfa2071e9f6518', + description: '', + spendPolicy: { + type: 'uc', + policy: { + timelock: 0, + signaturesRequired: 1, + publicKeys: [ + 'ed25519:65cac661a4acf36847c0aa67cbc6956e3449fd82a7430cfd673ea7fedbfcf5fa', + ], + }, + }, + metadata: { + index: 2, + }, + }, + ] + + return { + consensusState: getMockConsensusTipStateResponse(), + consensusNetwork: getMockConsensusNetworkResponse(), + mnemonic, + receiveAddress, + changeAddress, + newWallet, + walletBalanceResponse, + walletOutputsSiacoinResponse, + walletOutputsSiafundResponse, + walletFundResponse, + walletConstructV2Response, + walletAddressesResponse, + } +} diff --git a/apps/walletd/lib/signLedgerV1.spec.ts b/apps/walletd/lib/signLedgerV1.spec.ts index c1577308c..5ae95d71d 100644 --- a/apps/walletd/lib/signLedgerV1.spec.ts +++ b/apps/walletd/lib/signLedgerV1.spec.ts @@ -1,7 +1,7 @@ import { initSDK } from '@siafoundation/sdk' import { signTransactionLedgerV1 } from './signLedgerV1' import { getMockAddresses, getMockDevice } from './testMocks' -import { getMockScenarioSeedWallet } from '@siafoundation/walletd-mock' +import { getMockScenarioSeedWallet } from './mocks/mockSeedWallet' beforeEach(async () => { await initSDK() diff --git a/apps/walletd/lib/signSeedV1.spec.ts b/apps/walletd/lib/signSeedV1.spec.ts index 38fcd358d..a04ca38b9 100644 --- a/apps/walletd/lib/signSeedV1.spec.ts +++ b/apps/walletd/lib/signSeedV1.spec.ts @@ -1,6 +1,6 @@ import { signTransactionSeedV1 } from './signSeedV1' import { initSDK } from '@siafoundation/sdk' -import { getMockScenarioSeedWallet } from '@siafoundation/walletd-mock' +import { getMockScenarioSeedWallet } from './mocks/mockSeedWallet' import { getMockAddresses } from './testMocks' beforeEach(async () => { diff --git a/apps/walletd/lib/signSeedV2.spec.ts b/apps/walletd/lib/signSeedV2.spec.ts index 81aa4542f..5b8413346 100644 --- a/apps/walletd/lib/signSeedV2.spec.ts +++ b/apps/walletd/lib/signSeedV2.spec.ts @@ -1,6 +1,6 @@ import { signTransactionSeedV2 } from './signSeedV2' import { initSDK } from '@siafoundation/sdk' -import { getMockScenarioSeedWallet } from '@siafoundation/walletd-mock' +import { getMockScenarioSeedWallet } from './mocks/mockSeedWallet' import { getMockAddresses } from './testMocks' beforeEach(async () => { diff --git a/apps/website/components/HostMap/Globe.tsx b/apps/website/components/HostMap/Globe.tsx index a983bb85f..89fca7eb5 100644 --- a/apps/website/components/HostMap/Globe.tsx +++ b/apps/website/components/HostMap/Globe.tsx @@ -11,15 +11,15 @@ import dynamic from 'next/dynamic' import { GlobeMethods } from 'react-globe.gl' import { random, sortBy } from '@technically/lodash' import { getHostLabel } from './utils' -import { SiaCentralPartialHost } from '../../content/geoHosts' import { getAssetUrl } from '../../content/assets' import { useTheme } from 'next-themes' import { useElementSize } from 'usehooks-ts' +import { ExplorerPartialHost } from '../../content/geoHosts' type Props = { - activeHost?: SiaCentralPartialHost + activeHost?: ExplorerPartialHost selectActiveHost: (public_key: string) => void - hosts: SiaCentralPartialHost[] + hosts: ExplorerPartialHost[] rates: { usd: string } @@ -27,8 +27,8 @@ type Props = { type Route = { distance: number - src: SiaCentralPartialHost - dst: SiaCentralPartialHost + src: ExplorerPartialHost + dst: ExplorerPartialHost } const GlobeGl = dynamic(() => import('./GlobeGl'), { @@ -44,7 +44,7 @@ const ReactGlobe = forwardRef(function ReactGlobe( function GlobeComponent({ activeHost, hosts, rates, selectActiveHost }: Props) { const globeEl = useRef(null) - const moveToHost = useCallback((host: SiaCentralPartialHost) => { + const moveToHost = useCallback((host: ExplorerPartialHost) => { globeEl.current?.pointOfView( { lat: host.location[0] - 8, @@ -118,7 +118,7 @@ function GlobeComponent({ activeHost, hosts, rates, selectActiveHost }: Props) { let routes: Route[] = [] for (let i = 0; i < hosts.length; i++) { const host = hosts[i] - if (activeHost.public_key === host.public_key) { + if (activeHost.publicKey === host.publicKey) { continue } const distance = distanceBetweenHosts(activeHost, host) @@ -176,26 +176,26 @@ function GlobeComponent({ activeHost, hosts, rates, selectActiveHost }: Props) { : [`rgba(187, 229, 201, 0.10)`, `rgba(187, 229, 201, 0.10)`] } onArcClick={(r: Route) => { - selectActiveHost(r.dst.public_key) + selectActiveHost(r.dst.publicKey) }} arcsTransitionDuration={0} pointsData={hosts} - pointLat={(h: SiaCentralPartialHost) => h.location[0]} - pointLng={(h: SiaCentralPartialHost) => h.location[1]} - pointLabel={(h: SiaCentralPartialHost) => + pointLat={(h: ExplorerPartialHost) => h.location[0]} + pointLng={(h: ExplorerPartialHost) => h.location[1]} + pointLabel={(h: ExplorerPartialHost) => getHostLabel({ host: h, rates }) } pointAltitude={0} - pointColor={(h: SiaCentralPartialHost) => - h.public_key === activeHost.public_key + pointColor={(h: ExplorerPartialHost) => + h.publicKey === activeHost?.publicKey ? 'rgba(0,255,0,1)' : 'rgba(0,255,0,1)' } - pointRadius={(h: SiaCentralPartialHost) => - h.public_key === activeHost.public_key ? 0.6 : 0.2 + pointRadius={(h: ExplorerPartialHost) => + h.publicKey === activeHost?.publicKey ? 0.6 : 0.2 } - onPointClick={(h: SiaCentralPartialHost) => { - selectActiveHost(h.public_key) + onPointClick={(h: ExplorerPartialHost) => { + selectActiveHost(h.publicKey) }} pointsMerge={false} /> @@ -206,8 +206,8 @@ function GlobeComponent({ activeHost, hosts, rates, selectActiveHost }: Props) { export const Globe = memo(GlobeComponent) function distanceBetweenHosts( - h1: SiaCentralPartialHost, - h2: SiaCentralPartialHost + h1: ExplorerPartialHost, + h2: ExplorerPartialHost ) { return Math.sqrt( Math.pow(h1.location[0] - h2.location[0], 2) + @@ -215,15 +215,12 @@ function distanceBetweenHosts( ) } -function doesIncludeActiveHost( - route: Route, - activeHost?: SiaCentralPartialHost -) { +function doesIncludeActiveHost(route: Route, activeHost?: ExplorerPartialHost) { if (!activeHost) { return false } return ( - route.dst.public_key === activeHost.public_key || - route.src.public_key === activeHost.public_key + route.dst.publicKey === activeHost.publicKey || + route.src.publicKey === activeHost.publicKey ) } diff --git a/apps/website/components/HostMap/HostItem.tsx b/apps/website/components/HostMap/HostItem.tsx index 3d8eabcb4..28051f541 100644 --- a/apps/website/components/HostMap/HostItem.tsx +++ b/apps/website/components/HostMap/HostItem.tsx @@ -9,20 +9,18 @@ import { } from '@siafoundation/design-system' import { cx } from 'class-variance-authority' import BigNumber from 'bignumber.js' -import { SiaCentralPartialHost } from '../../content/geoHosts' +import { ExplorerPartialHost } from '../../content/geoHosts' import { Launch16 } from '@siafoundation/react-icons' import { monthsToBlocks, TBToBytes, humanBytes, humanSiacoin, - getDownloadSpeed, - getUploadSpeed, } from '@siafoundation/units' type Props = { - host: SiaCentralPartialHost - activeHost?: SiaCentralPartialHost + host: ExplorerPartialHost + activeHost?: ExplorerPartialHost setRef?: (el: HTMLButtonElement) => void selectActiveHost: (public_key: string) => void rates: { @@ -40,14 +38,14 @@ export function HostItem({ const storageCost = useMemo( () => rates - ? `$${new BigNumber(host.settings.storage_price) + ? `$${new BigNumber(host.settings.storageprice) .times(TBToBytes(1)) .times(monthsToBlocks(1)) .div(1e24) .times(rates?.usd || 1) .toFixed(2)}/TB` : `${humanSiacoin( - new BigNumber(host.settings.storage_price) + new BigNumber(host.settings.storageprice) .times(TBToBytes(1)) .times(monthsToBlocks(1)), { fixed: 0 } @@ -58,13 +56,15 @@ export function HostItem({ const downloadCost = useMemo( () => rates - ? `$${new BigNumber(host.settings.download_price) + ? `$${new BigNumber(host.settings.downloadbandwidthprice) .times(TBToBytes(1)) .div(1e24) .times(rates?.usd || 1) .toFixed(2)}/TB` : `${humanSiacoin( - new BigNumber(host.settings.download_price).times(TBToBytes(1)), + new BigNumber(host.settings.downloadbandwidthprice).times( + TBToBytes(1) + ), { fixed: 0 } )}/TB`, [rates, host] @@ -73,13 +73,15 @@ export function HostItem({ const uploadCost = useMemo( () => rates - ? `$${new BigNumber(host.settings.upload_price) + ? `$${new BigNumber(host.settings.uploadbandwidthprice) .times(TBToBytes(1)) .div(1e24) .times(rates?.usd || 1) .toFixed(2)}/TB` : `${humanSiacoin( - new BigNumber(host.settings.upload_price).times(TBToBytes(1)), + new BigNumber(host.settings.uploadbandwidthprice).times( + TBToBytes(1) + ), { fixed: 0 } )}/TB`, [rates, host] @@ -96,14 +98,14 @@ export function HostItem({ weight="bold" className="text-start" > - {countryCodeEmoji(host.country_code)} {host.country_code} + {countryCodeEmoji(host.countryCode)} {host.countryCode} @@ -120,17 +122,6 @@ export function HostItem({ upload
-
- - {humanBytes(host.settings.total_storage)} - - - {getDownloadSpeed(host)} - - - {getUploadSpeed(host)} - -
{storageCost} @@ -145,7 +136,7 @@ export function HostItem({
} - key={host.public_key} + key={host.publicKey} >