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
+72
View File
@@ -0,0 +1,72 @@
import Wallet from 'ethereumjs-wallet'
import { sleepMs } from '.'
import { BzzToken } from '../models/BzzToken'
import { DaiToken } from '../models/DaiToken'
import { getWalletFromPrivateKeyString } from './identity'
import { Rpc } from './rpc'
export class WalletAddress {
private constructor(public address: string, public bzz: BzzToken, public dai: DaiToken) {}
static async make(address: string): Promise<WalletAddress> {
const bzz = new BzzToken(await Rpc._eth_getBalanceERC20(address))
const dai = new DaiToken(await Rpc._eth_getBalance(address))
return new WalletAddress(address, bzz, dai)
}
public async refresh(): Promise<WalletAddress> {
this.bzz = new BzzToken(await Rpc._eth_getBalanceERC20(this.address))
this.dai = new DaiToken(await Rpc._eth_getBalance(this.address))
return this
}
}
export class ResolvedWallet {
public address: string
public privateKey: string
private constructor(public wallet: Wallet, public bzz: BzzToken, public dai: DaiToken) {
this.address = wallet.getAddressString()
this.privateKey = wallet.getPrivateKeyString()
}
static async make(privateKeyOrWallet: string | Wallet): Promise<ResolvedWallet> {
const wallet =
typeof privateKeyOrWallet === 'string' ? getWalletFromPrivateKeyString(privateKeyOrWallet) : privateKeyOrWallet
const address = wallet.getAddressString()
const bzz = new BzzToken(await Rpc._eth_getBalanceERC20(address))
const dai = new DaiToken(await Rpc._eth_getBalance(address))
return new ResolvedWallet(wallet, bzz, dai)
}
public async refresh(): Promise<ResolvedWallet> {
this.bzz = new BzzToken(await Rpc._eth_getBalanceERC20(this.address))
this.dai = new DaiToken(await Rpc._eth_getBalance(this.address))
return this
}
public async transfer(
destination: string,
jsonRpcProvider = 'https://gno.getblock.io/mainnet/?api_key=d7b92d96-9784-49a8-a800-b3edd1647fc7',
): Promise<void> {
const DUMMY_GAS_PRICE = '300000000000000'
if (this.bzz.toDecimal.gt(0.1)) {
await Rpc.sendBzzTransaction(this.privateKey, destination, this.bzz.toString, jsonRpcProvider)
await sleepMs(5_000)
}
if (this.dai.toBigNumber.gt(DUMMY_GAS_PRICE)) {
await Rpc.sendNativeTransaction(
this.privateKey,
destination,
this.dai.toBigNumber.minus(DUMMY_GAS_PRICE).toString(),
jsonRpcProvider,
)
}
}
}