Skip to content

Commit

Permalink
fix: explorer average storage price fiat
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Aug 22, 2024
1 parent 57a47d0 commit 8f92df3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/rare-scissors-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'explorer': patch
---

Fixed a bug in the average fiat storage cost calculation.
9 changes: 9 additions & 0 deletions libs/units/src/storage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
Expand Down
13 changes: 7 additions & 6 deletions libs/units/src/storage.ts
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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`
}

Expand Down

0 comments on commit 8f92df3

Please sign in to comment.