Skip to content

Commit

Permalink
refactor: exchange rates and time helpers package organization
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Aug 22, 2024
1 parent 5f34c9a commit 57a47d0
Show file tree
Hide file tree
Showing 93 changed files with 183 additions and 172 deletions.
6 changes: 6 additions & 0 deletions .changeset/forty-suns-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@siafoundation/design-system': minor
'@siafoundation/units': minor
---

Time conversion helpers were moved from design-system to units package.
5 changes: 5 additions & 0 deletions .changeset/funny-ravens-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@siafoundation/design-system': minor
---

Fiat components requiring exchange rate now use the generic useExchangeRate hook rather than useSiascanExchangeRate directly.
6 changes: 6 additions & 0 deletions .changeset/short-cows-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@siafoundation/design-system': minor
'@siafoundation/react-core': minor
---

Exchange rate hooks were moved from design-system to react-core.
3 changes: 1 addition & 2 deletions apps/hostd/components/Config/AnnounceButton.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
Button,
Paragraph,
minutesInMilliseconds,
triggerErrorToast,
triggerSuccessToast,
} from '@siafoundation/design-system'
Expand All @@ -13,7 +12,7 @@ import {
useHostState,
useTxPoolFee,
} from '@siafoundation/hostd-react'
import { humanSiacoin } from '@siafoundation/units'
import { humanSiacoin, minutesInMilliseconds } from '@siafoundation/units'
import { useCallback } from 'react'
import BigNumber from 'bignumber.js'

Expand Down
2 changes: 1 addition & 1 deletion apps/hostd/config/swr.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { secondsInMilliseconds } from '@siafoundation/design-system'
import { secondsInMilliseconds } from '@siafoundation/units'

export const defaultDatasetRefreshInterval = secondsInMilliseconds(15)
2 changes: 1 addition & 1 deletion apps/hostd/contexts/config/useForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getFields } from './fields'
import useLocalStorageState from 'use-local-storage-state'
import { useHostState } from '@siafoundation/hostd-react'
import { useAutoCalculatedFields } from './useAutoCalculatedFields'
import { useExchangeRate } from '@siafoundation/design-system'
import { useExchangeRate } from '@siafoundation/react-core'

export function useForm() {
const form = useHookForm({
Expand Down
2 changes: 1 addition & 1 deletion apps/hostd/contexts/config/useOnValid.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
triggerSuccessToast,
triggerErrorToast,
minutesInMilliseconds,
} from '@siafoundation/design-system'
import { useCallback } from 'react'
import { SettingsData } from './types'
Expand All @@ -12,6 +11,7 @@ import {
useSettingsPinnedUpdate,
useSettingsUpdate,
} from '@siafoundation/hostd-react'
import { minutesInMilliseconds } from '@siafoundation/units'

export function useOnValid({
resources,
Expand Down
2 changes: 1 addition & 1 deletion apps/hostd/contexts/config/useResources.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { minutesInMilliseconds } from '@siafoundation/design-system'
import {
useSettings,
useSettingsDdnsUpdate,
useSettingsPinned,
} from '@siafoundation/hostd-react'
import { minutesInMilliseconds } from '@siafoundation/units'

export function useResources() {
const settings = useSettings({
Expand Down
2 changes: 1 addition & 1 deletion apps/hostd/contexts/metrics/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import {
formatChartData,
getDataIntervalLabelFormatter,
getTimeRange,
secondsInMilliseconds,
ValueScFiat,
} from '@siafoundation/design-system'
import {
MiBToBytes,
humanBytes,
humanNumber,
humanSiacoin,
secondsInMilliseconds,
} from '@siafoundation/units'
import { useCallback, useMemo } from 'react'
import { chartConfigs } from '../../config/charts'
Expand Down
2 changes: 1 addition & 1 deletion apps/hostd/contexts/metrics/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
daysInMilliseconds,
hoursInMilliseconds,
minutesInMilliseconds,
} from '@siafoundation/design-system'
} from '@siafoundation/units'

export type RevenueKeys =
| 'rpcPotential'
Expand Down
2 changes: 1 addition & 1 deletion apps/hostd/contexts/metrics/useNowAtInterval.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from 'react'
import { DataInterval, getDataIntervalInMs } from './types'
import { hoursInMilliseconds } from '@siafoundation/design-system'
import { hoursInMilliseconds } from '@siafoundation/units'

// now timestamp updated every interval
// used to reset the time range and keep the graph up to date
Expand Down
2 changes: 1 addition & 1 deletion apps/hostd/contexts/transactions/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
daysInMilliseconds,
useDatasetEmptyState,
useServerFilters,
useTableState,
Expand All @@ -20,6 +19,7 @@ import {
getEventContractId,
getEventFee,
getEventTxType,
daysInMilliseconds,
} from '@siafoundation/units'
import {
CellContext,
Expand Down
2 changes: 1 addition & 1 deletion apps/hostd/contexts/volumes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
useTableState,
useDatasetEmptyState,
secondsInMilliseconds,
} from '@siafoundation/design-system'
import { VolumeMeta } from '@siafoundation/hostd-types'
import { useVolumes as useVolumesData } from '@siafoundation/hostd-react'
Expand All @@ -10,6 +9,7 @@ import { columnsDefaultVisible, TableColumnId } from './types'
import { columns } from './columns'
import { useDataset } from './dataset'
import { defaultDatasetRefreshInterval } from '../../config/swr'
import { secondsInMilliseconds } from '@siafoundation/units'

function useVolumesMain() {
const {
Expand Down
2 changes: 1 addition & 1 deletion apps/hostd/hooks/useSyncStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
useConsensusTipState,
useIndexTip,
} from '@siafoundation/hostd-react'
import { hoursInMilliseconds } from '@siafoundation/design-system'
import { hoursInMilliseconds } from '@siafoundation/units'

export function useSyncStatus() {
const { isUnlockedAndAuthedRoute } = useAppSettings()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {
weeksInMilliseconds,
monthsInMilliseconds,
yearsInMilliseconds,
ClientFilterItem,
} from '@siafoundation/design-system'
} from '@siafoundation/units'
import { ClientFilterItem } from '@siafoundation/design-system'
import { ContractData } from '../../../../../contexts/contracts/types'
import { CommandGroup, CommandItemSearch } from '../../../../CmdRoot/Item'
import { Page } from '../../../../CmdRoot/types'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {
weeksInMilliseconds,
monthsInMilliseconds,
yearsInMilliseconds,
ClientFilterItem,
} from '@siafoundation/design-system'
} from '@siafoundation/units'
import { ClientFilterItem } from '@siafoundation/design-system'
import { ContractData } from '../../../../../contexts/contracts/types'
import { CommandGroup, CommandItemSearch } from '../../../../CmdRoot/Item'
import { Page } from '../../../../CmdRoot/types'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {
weeksInMilliseconds,
monthsInMilliseconds,
yearsInMilliseconds,
ClientFilterItem,
} from '@siafoundation/design-system'
} from '@siafoundation/units'
import { ClientFilterItem } from '@siafoundation/design-system'
import { ContractData } from '../../../../../contexts/contracts/types'
import { CommandGroup, CommandItemSearch } from '../../../../CmdRoot/Item'
import { Page } from '../../../../CmdRoot/types'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import {
Separator,
Text,
Tooltip,
minutesInMilliseconds,
} from '@siafoundation/design-system'
import { useObjectStats } from '@siafoundation/renterd-react'
import { humanBytes } from '@siafoundation/units'
import { humanBytes, minutesInMilliseconds } from '@siafoundation/units'

export function FilesStatsMenuSize() {
const stats = useObjectStats({
Expand Down
2 changes: 1 addition & 1 deletion apps/renterd/components/Hosts/HostContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
DropdownMenuLeftSlot,
DropdownMenuLabel,
Text,
secondsInMilliseconds,
truncate,
copyToClipboard,
} from '@siafoundation/design-system'
Expand All @@ -32,6 +31,7 @@ import { useBlocklistUpdate } from '../../hooks/useBlocklistUpdate'
import { addressContainsFilter } from '../Contracts/ContractsFilterAddressDialog'
import { publicKeyContainsFilter } from '../Contracts/ContractsFilterPublicKeyDialog'
import { filterPublicKeyEquals } from './HostsFilterPublicKeyDialog'
import { secondsInMilliseconds } from '@siafoundation/units'

type Props = {
address: string
Expand Down
3 changes: 1 addition & 2 deletions apps/renterd/components/Hosts/HostMap/Globe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import { useEffect, useRef, useCallback, useMemo } from 'react'
import { GlobeMethods } from 'react-globe.gl'
import { getHostLabel } from './utils'
import { useElementSize } from 'usehooks-ts'
import { useTryUntil } from '@siafoundation/react-core'
import { useTryUntil, useExchangeRate } from '@siafoundation/react-core'
import earthDarkContrast from '../../../assets/earth-dark-contrast.png'
import earthTopology from '../../../assets/earth-topology.png'
import { GlobeDyn } from './GlobeDyn'
import { HostDataWithLocation } from '../../../contexts/hosts/types'
import BigNumber from 'bignumber.js'
import { getHostStatus } from '../../../contexts/hosts/status'
import { useExchangeRate } from '@siafoundation/design-system'

export type Commands = {
moveToLocation: (
Expand Down
2 changes: 1 addition & 1 deletion apps/renterd/config/swr.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { secondsInMilliseconds } from '@siafoundation/design-system'
import { secondsInMilliseconds } from '@siafoundation/units'

export const defaultDatasetRefreshInterval = secondsInMilliseconds(15)
2 changes: 1 addition & 1 deletion apps/renterd/contexts/app/useAutopilot.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { secondsInMilliseconds } from '@siafoundation/design-system'
import { secondsInMilliseconds } from '@siafoundation/units'
import { useAutopilotState } from '@siafoundation/renterd-react'
import { useEffect, useState } from 'react'

Expand Down
3 changes: 1 addition & 2 deletions apps/renterd/contexts/config/fields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import {
ConfigFields,
Link,
Text,
hoursInDays,
secondsInMinutes,
toFixedMaxString,
} from '@siafoundation/design-system'
import { hoursInDays, secondsInMinutes } from '@siafoundation/units'
import BigNumber from 'bignumber.js'
import React from 'react'
import {
Expand Down
4 changes: 2 additions & 2 deletions apps/renterd/contexts/config/transformDown.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import {
nanosecondsInDays,
nanosecondsInMinutes,
toFixedMaxBigNumber,
toFixedMaxString,
} from '@siafoundation/design-system'
Expand All @@ -20,6 +18,8 @@ import {
valuePerPeriodToPerMonth,
valuePerOneToPerMillion,
weeksToBlocks,
nanosecondsInDays,
nanosecondsInMinutes,
} from '@siafoundation/units'
import BigNumber from 'bignumber.js'
import {
Expand Down
6 changes: 2 additions & 4 deletions apps/renterd/contexts/config/transformUp.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import {
daysInNanoseconds,
minutesInNanoseconds,
} from '@siafoundation/design-system'
import {
AutopilotConfig,
ContractSetSettings,
Expand All @@ -17,6 +13,8 @@ import {
valuePerTBPerMonthToPerBytePerBlock,
valuePerMonthToPerPeriod,
valuePerMillionToPerOne,
daysInNanoseconds,
minutesInNanoseconds,
} from '@siafoundation/units'
import {
AutopilotData,
Expand Down
7 changes: 5 additions & 2 deletions apps/renterd/contexts/config/useAllowanceDerivedPricing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { UseFormReturn } from 'react-hook-form'
import BigNumber from 'bignumber.js'
import useSWR from 'swr'
import axios from 'axios'
import { minutesInMilliseconds } from '@siafoundation/design-system'
import {
calculateIdealAllowance,
derivePricingFromAllowance,
Expand All @@ -17,7 +16,11 @@ import {
storageWeight,
uploadWeight,
} from './deriveAllowanceConfig'
import { fiatToSiacoin, siacoinToFiat } from '@siafoundation/units'
import {
fiatToSiacoin,
siacoinToFiat,
minutesInMilliseconds,
} from '@siafoundation/units'

export function useForexExchangeRate({
form,
Expand Down
2 changes: 1 addition & 1 deletion apps/renterd/contexts/config/useResources.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { minutesInMilliseconds } from '@siafoundation/design-system'
import {
useAutopilotConfig,
useSettingContractSet,
Expand All @@ -11,6 +10,7 @@ import { useSyncContractSet } from './useSyncContractSet'
import { useAppSettings } from '@siafoundation/react-core'
import { useSiaCentralHostsNetworkAverages } from '@siafoundation/sia-central-react'
import { useApp } from '../app'
import { minutesInMilliseconds } from '@siafoundation/units'

export function useResources() {
const app = useApp()
Expand Down
2 changes: 1 addition & 1 deletion apps/renterd/contexts/contracts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
useDatasetEmptyState,
useClientFilters,
useClientFilteredDataset,
daysInMilliseconds,
} from '@siafoundation/design-system'
import { useRouter } from 'next/router'
import {
Expand Down Expand Up @@ -38,6 +37,7 @@ import { defaultDatasetRefreshInterval } from '../../config/swr'
import { useDataset } from './dataset'
import { useFilteredStats } from './useFilteredStats'
import { useAutopilot } from '../app/useAutopilot'
import { daysInMilliseconds } from '@siafoundation/units'

const defaultLimit = 50

Expand Down
3 changes: 1 addition & 2 deletions apps/renterd/contexts/contracts/useContractMetrics.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
daysInMilliseconds,
Chart,
formatChartData,
computeChartStats,
Expand All @@ -12,7 +11,7 @@ import { useMetricsContract } from '@siafoundation/renterd-react'
import { useMemo } from 'react'
import BigNumber from 'bignumber.js'
import { ChartContractCategory, ChartContractKey } from './types'
import { humanSiacoin } from '@siafoundation/units'
import { humanSiacoin, daysInMilliseconds } from '@siafoundation/units'
import { getTimeClampedToNearest5min } from './utils'

export function useContractMetrics({
Expand Down
2 changes: 1 addition & 1 deletion apps/renterd/contexts/contracts/useContractSetMetrics.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
daysInMilliseconds,
Chart,
formatChartData,
computeChartStats,
Expand All @@ -13,6 +12,7 @@ import {
import { useMemo } from 'react'
import { ChartContractSetCategory, ChartContractSetKey } from './types'
import { getTimeClampedToNearest5min } from './utils'
import { daysInMilliseconds } from '@siafoundation/units'

export function useContractSetMetrics() {
// don't use exact times, round to 5 minutes so that swr can cache
Expand Down
2 changes: 1 addition & 1 deletion apps/renterd/contexts/contracts/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { minutesInMilliseconds } from '@siafoundation/design-system'
import { minutesInMilliseconds } from '@siafoundation/units'

export function getTimeClampedToNearest5min(t: number) {
const granularity = minutesInMilliseconds(5)
Expand Down
7 changes: 2 additions & 5 deletions apps/renterd/contexts/filesManager/uploads.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
minutesInMilliseconds,
triggerErrorToast,
} from '@siafoundation/design-system'
import { triggerErrorToast } from '@siafoundation/design-system'
import { Bucket } from '@siafoundation/renterd-types'
import {
useBuckets,
Expand All @@ -21,7 +18,7 @@ import {
join,
} from '../../lib/paths'
import { MultipartUpload } from '../../lib/multipartUpload'
import { MiBToBytes } from '@siafoundation/units'
import { MiBToBytes, minutesInMilliseconds } from '@siafoundation/units'
import { useMutate } from '@siafoundation/react-core'
import { useWarnActiveUploadsOnClose } from './useWarnActiveUploadsOnClose'

Expand Down
Loading

0 comments on commit 57a47d0

Please sign in to comment.