fix: all wallet flows to use ethers (#395)
* fix: all wallet flows to use only ethers libraries * feat: remove ethereumjs-wallet * fix: remove the buggy `/wallet` bee call and use provider
This commit is contained in:
+30
-24
@@ -1,23 +1,27 @@
|
||||
import Wallet from 'ethereumjs-wallet'
|
||||
import { providers, Wallet } from 'ethers'
|
||||
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) {}
|
||||
private constructor(
|
||||
public address: string,
|
||||
public bzz: BzzToken,
|
||||
public dai: DaiToken,
|
||||
public provider: providers.JsonRpcProvider,
|
||||
) {}
|
||||
|
||||
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))
|
||||
static async make(address: string, provider: providers.JsonRpcProvider): Promise<WalletAddress> {
|
||||
const bzz = new BzzToken(await Rpc._eth_getBalanceERC20(address, provider))
|
||||
const dai = new DaiToken(await Rpc._eth_getBalance(address, provider))
|
||||
|
||||
return new WalletAddress(address, bzz, dai)
|
||||
return new WalletAddress(address, bzz, dai, provider)
|
||||
}
|
||||
|
||||
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))
|
||||
this.bzz = new BzzToken(await Rpc._eth_getBalanceERC20(this.address, this.provider))
|
||||
this.dai = new DaiToken(await Rpc._eth_getBalance(this.address, this.provider))
|
||||
|
||||
return this
|
||||
}
|
||||
@@ -27,32 +31,34 @@ 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()
|
||||
private constructor(
|
||||
public wallet: Wallet,
|
||||
public bzz: BzzToken,
|
||||
public dai: DaiToken,
|
||||
public provider: providers.JsonRpcProvider,
|
||||
) {
|
||||
this.address = wallet.address
|
||||
this.privateKey = wallet.privateKey
|
||||
}
|
||||
|
||||
static async make(privateKeyOrWallet: string | Wallet): Promise<ResolvedWallet> {
|
||||
static async make(privateKeyOrWallet: string | Wallet, provider: providers.JsonRpcProvider): 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))
|
||||
typeof privateKeyOrWallet === 'string' ? new Wallet(privateKeyOrWallet, provider) : privateKeyOrWallet
|
||||
const address = wallet.address
|
||||
const bzz = new BzzToken(await Rpc._eth_getBalanceERC20(address, provider))
|
||||
const dai = new DaiToken(await Rpc._eth_getBalance(address, provider))
|
||||
|
||||
return new ResolvedWallet(wallet, bzz, dai)
|
||||
return new ResolvedWallet(wallet, bzz, dai, provider)
|
||||
}
|
||||
|
||||
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))
|
||||
this.bzz = new BzzToken(await Rpc._eth_getBalanceERC20(this.address, this.provider))
|
||||
this.dai = new DaiToken(await Rpc._eth_getBalance(this.address, this.provider))
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
public async transfer(
|
||||
destination: string,
|
||||
jsonRpcProvider = 'https://gno.getblock.io/mainnet/?api_key=d7b92d96-9784-49a8-a800-b3edd1647fc7',
|
||||
): Promise<void> {
|
||||
public async transfer(destination: string, jsonRpcProvider: string): Promise<void> {
|
||||
const DUMMY_GAS_PRICE = '300000000000000'
|
||||
|
||||
if (this.bzz.toDecimal.gt(0.1)) {
|
||||
|
||||
Reference in New Issue
Block a user