fix: get current price from chain state (#286)

* fix: get current price from chain state

* refactor: do not allow optional currentPrice
This commit is contained in:
Cafe137
2022-01-20 15:49:41 +01:00
committed by GitHub
parent 63e79ae2aa
commit bc82e67561
3 changed files with 29 additions and 6 deletions
+5 -2
View File
@@ -1,3 +1,4 @@
import { NumberString } from '@ethersphere/bee-js'
import { BigNumber } from 'bignumber.js'
/**
@@ -186,6 +187,8 @@ export function convertAmountToSeconds(amount: number): number {
return amount / 10 / 1
}
export function calculateStampPrice(depth: number, amount: number): number {
return (amount * 2 ** (depth - 16) * 2) / 1e16
export function calculateStampPrice(depth: number, amount: number, currentPrice: NumberString): number {
const price = parseInt(currentPrice, 10)
return (amount * 2 ** (depth - 16) * price) / 1e16
}