diff --git a/.changeset/rare-scissors-wait.md b/.changeset/rare-scissors-wait.md new file mode 100644 index 000000000..14dc44843 --- /dev/null +++ b/.changeset/rare-scissors-wait.md @@ -0,0 +1,5 @@ +--- +'explorer': patch +--- + +Fixed a bug in the average fiat storage cost calculation. diff --git a/libs/units/src/storage.spec.ts b/libs/units/src/storage.spec.ts index 61bda4b08..44fcf3a37 100644 --- a/libs/units/src/storage.spec.ts +++ b/libs/units/src/storage.spec.ts @@ -4,6 +4,15 @@ test('storage', () => { expect(getStorageCost({ price: (1e9).toString() })).toEqual('4.320 SC/TB') }) +test('storage fiat', () => { + expect( + getStorageCost({ + exchange: { currency: { prefix: '$' }, rate: '2' }, + price: (1e9).toString(), + }) + ).toEqual('$8.64/TB') +}) + test('download', () => { expect(getDownloadCost({ price: (1e9).toString() })).toEqual('1.000 mS/TB') }) diff --git a/libs/units/src/storage.ts b/libs/units/src/storage.ts index 39db28250..60fa4a5ca 100644 --- a/libs/units/src/storage.ts +++ b/libs/units/src/storage.ts @@ -1,10 +1,9 @@ import { TBToBytes } from './bytes' -import { monthsToBlocks } from './blockTime' import { SiaCentralHost } from '@siafoundation/sia-central-types' import BigNumber from 'bignumber.js' import { humanSiacoin, toSiacoins } from './currency' import { humanBytes, humanSpeed } from './humanUnits' -import { valuePerTBPerMonthToPerBytePerBlock } from './valuePer' +import { valuePerBytePerBlockToPerTBPerMonth } from './valuePer' type Hastings = string @@ -20,14 +19,16 @@ type Props = { export function getStorageCost({ price, exchange }: Props) { return exchange - ? `${exchange.currency.prefix}${toSiacoins( - valuePerTBPerMonthToPerBytePerBlock(new BigNumber(price)) + ? `${exchange.currency.prefix}${valuePerBytePerBlockToPerTBPerMonth( + toSiacoins(price) ) .times(exchange.rate || 1) .toFormat(2)}/TB` : `${humanSiacoin( - new BigNumber(price).times(TBToBytes(1)).times(monthsToBlocks(1)), - { fixed: 3 } + valuePerBytePerBlockToPerTBPerMonth(new BigNumber(price)), + { + fixed: 3, + } )}/TB` }