feat: add light node upgrade top up methods (#372)

* feat: add top up

* chore: remove console.log

* build: add pseudo-missing dependency

* feat: add missing top up components

* fix: crypto route

* feat(wip): add gift wallet logic

* fix: fix gift wallet flows

* feat: simplify flow without fund step

* feat: add loading screens

* fix: remove alert

* fix: prepend http if needed

* fix: fix bug that was reintroduced with merge

* refactor: rename minusEther to minusBaseUnits

* fix: remove unused setStartedAt

* build: remove unused dependency
This commit is contained in:
Cafe137
2022-06-02 09:28:43 +02:00
committed by GitHub
parent 026783924f
commit a768b4ea06
35 changed files with 1196 additions and 215 deletions
+8
View File
@@ -0,0 +1,8 @@
import { BigNumber } from 'bignumber.js'
import { Token } from './Token'
export class BzzToken extends Token {
constructor(amount: BigNumber | string | BigInt) {
super(amount, 16)
}
}
+8
View File
@@ -0,0 +1,8 @@
import { BigNumber } from 'bignumber.js'
import { Token } from './Token'
export class DaiToken extends Token {
constructor(amount: BigNumber | string | BigInt) {
super(amount, 18)
}
}
+11 -2
View File
@@ -13,7 +13,9 @@ export class Token {
constructor(amount: BigNumber | string | BigInt, decimals: digits = BZZ_DECIMALS) {
const a = makeBigNumber(amount)
if (!isInteger(a) || !POSSIBLE_DECIMALS.includes(decimals)) throw new TypeError('Not a valid token values')
if (!isInteger(a) || !POSSIBLE_DECIMALS.includes(decimals)) {
throw new TypeError(`Not a valid token values: ${amount} ${decimals}`)
}
this.amount = a
this.decimals = decimals
@@ -59,7 +61,7 @@ export class Token {
}
toSignificantDigits(digits = 4): string {
const asString = this.toDecimal.toFixed(16)
const asString = this.toDecimal.toFixed(this.decimals)
let indexOfSignificantDigit = -1
let reachedDecimalPoint = false
@@ -78,4 +80,11 @@ export class Token {
return asString.slice(0, indexOfSignificantDigit + digits)
}
minusBaseUnits(amount: string): Token {
return new Token(
this.toBigNumber.minus(new BigNumber(amount).multipliedBy(new BigNumber(10).pow(this.decimals))),
this.decimals,
)
}
}