chore: update bee-js to 0.8.1 version (#78)

* chore: upgrade to bee-js 0.8.1

* refactor: removed toString on number types, Token now accepts numbers

* test: removed fromBZZbaseUnit test, makeBigNumber accepts number now

* chore: fix logic error when displaying Cashout button
This commit is contained in:
Vojtech Simetka
2021-04-23 11:43:48 +02:00
committed by GitHub
parent d77e184d6a
commit a0f1d1c50a
16 changed files with 276 additions and 210 deletions
+5 -16
View File
@@ -1,21 +1,7 @@
import BigNumber from 'bignumber.js'
import { fromBZZbaseUnit, isInteger, makeBigNumber } from './index'
import { isInteger, makeBigNumber } from './index'
describe('utils', () => {
describe('fromBZZbaseUnit', () => {
const values = [
{ bzz: 0, baseUnits: 0 },
{ bzz: 0.1, baseUnits: 1e15 },
{ bzz: 0.9, baseUnits: 9e15 },
]
values.forEach(({ bzz, baseUnits }) => {
test(`converting ${bzz} => ${baseUnits}`, () => {
expect(fromBZZbaseUnit(baseUnits)).toBe(bzz)
})
})
})
describe('isInteger', () => {
const correctValues = [
BigInt(0),
@@ -52,8 +38,11 @@ describe('utils', () => {
new BigNumber('1'),
new BigNumber('0'),
new BigNumber('-1'),
0,
1,
-1,
]
const wrongValues = [new Function(), 0, 1]
const wrongValues = [new Function()]
correctValues.forEach(v => {
test(`testing ${v}`, () => {
+5 -19
View File
@@ -1,22 +1,5 @@
import { BigNumber } from 'bignumber.js'
/**
* @deprecated Should be removed in favour of Token class
*/
const BZZ_BASE_UNIT = 1e16
/**
* Convert from base units of BZZ token to BZZ
* @deprecated This should only be used for displaying values, it's unsafe and should be replaced with Token class
*
* @param amount Amount in base units of BZZ token
*
* @returns amount in BZZ
*/
export const fromBZZbaseUnit = (amount: number): number => {
return amount / BZZ_BASE_UNIT
}
/**
* Test if value is an integer
*
@@ -37,12 +20,15 @@ export function isInteger(value: unknown): value is BigNumber | bigint {
*
* @returns BigNumber - but it may still be NaN or Infinite
*/
export function makeBigNumber(value: BigNumber | bigint | string): BigNumber | never {
export function makeBigNumber(value: BigNumber | BigInt | number | string): BigNumber | never {
if (BigNumber.isBigNumber(value)) return value
if (typeof value === 'string') return new BigNumber(value)
if (typeof value === 'bigint') return new BigNumber(value.toString())
throw new TypeError('Not a BigNumber or BigNumber convertible value')
// FIXME: bee-js still returns some values as numbers and even outside of SAFE INTEGER bounds
if (typeof value === 'number' /* && Number.isSafeInteger(value)*/) return new BigNumber(value)
throw new TypeError(`Not a BigNumber or BigNumber convertible value. Type: ${typeof value} value: ${value}`)
}