diff --git a/lib/services/coins/ethereum/ethereum_wallet.dart b/lib/services/coins/ethereum/ethereum_wallet.dart index f099cc3d9..e30e03aba 100644 --- a/lib/services/coins/ethereum/ethereum_wallet.dart +++ b/lib/services/coins/ethereum/ethereum_wallet.dart @@ -191,24 +191,24 @@ class EthereumWallet extends CoinServiceAPI { } @override - // TODO: implement balanceMinusMaxFee - Future get balanceMinusMaxFee => throw UnimplementedError(); + Future get balanceMinusMaxFee async => + (await availableBalance) - + (Decimal.fromInt((await maxFee)) / + Decimal.fromInt(Constants.satsPerCoin(coin))) + .toDecimal(); @override Future confirmSend({required Map txData}) async { - final gasPrice = await _client.getGasPrice(); final int chainId = await _client.getNetworkId(); - - print("GAS PRICE IS $gasPrice"); - print("AMOUNT TO SEND IS ${txData['fee']}"); - final amount = txData['recipientAmt']; final decimalAmount = Format.satoshisToAmount(amount as int, coin: Coin.ethereum); final bigIntAmount = amountToBigInt(decimalAmount.toDouble()); + final tx = Transaction.Transaction( to: EthereumAddress.fromHex(txData['address'] as String), - gasPrice: EtherAmount.fromUnitAndValue(EtherUnit.gwei, txData['fee']), + gasPrice: + EtherAmount.fromUnitAndValue(EtherUnit.wei, txData['feeInWei']), maxGas: _gasLimit, value: EtherAmount.inWei(bigIntAmount)); final transaction = @@ -259,9 +259,9 @@ class EthereumWallet extends CoinServiceAPI { GasTracker fees = await getGasOracle(); final feesMap = fees.data; return FeeObject( - numberOfBlocksFast: 3, + numberOfBlocksFast: 1, numberOfBlocksAverage: 3, - numberOfBlocksSlow: 1, + numberOfBlocksSlow: 3, fast: feesMap['fast'] as int, medium: feesMap['standard'] as int, slow: feesMap['slow'] as int); @@ -279,6 +279,7 @@ class EthereumWallet extends CoinServiceAPI { } } + //Full rescan is not needed for ETH since we have a balance @override Future fullRescan( int maxUnusedAddressGap, int maxNumberOfIndexesToCheck) { @@ -327,7 +328,6 @@ class EthereumWallet extends CoinServiceAPI { await _prefs.init(); final String mnemonic = bip39.generateMnemonic(strength: 256); _credentials = EthPrivateKey.fromHex(StringToHex.toHexString(mnemonic)); - await _secureStore.write(key: '${_walletId}_mnemonic', value: mnemonic); //Store credentials in secure store @@ -367,8 +367,11 @@ class EthereumWallet extends CoinServiceAPI { bool refreshMutex = false; @override - // TODO: implement maxFee - Future get maxFee => throw UnimplementedError(); + Future get maxFee async { + final fee = (await fees).fast; + final feeEstimate = await estimateFeeFor(0, fee); + return feeEstimate; + } @override Future> get mnemonic => _getMnemonicList(); @@ -407,18 +410,14 @@ class EthereumWallet extends CoinServiceAPI { } @override - // TODO: implement pendingBalance + // TODO: implement pendingBalance - Not needed since we don't use UTXOs to get a balance Future get pendingBalance => throw UnimplementedError(); - // Future transactionFee(int satoshiAmount) {} - @override Future> prepareSend( {required String address, required int satoshiAmount, Map? args}) async { - print("CALLING PREPARE SEND"); - print(args); final feeRateType = args?["feeRate"]; int fee = 0; final feeObject = await fees; @@ -433,13 +432,12 @@ class EthereumWallet extends CoinServiceAPI { fee = feeObject.slow; break; } - final feeEstimate = await estimateFeeFor(satoshiAmount, fee); - print("FEE ESTIMATE IS $feeEstimate"); - final gasPrice = await _client.getGasPrice(); + final feeEstimate = await estimateFeeFor(satoshiAmount, fee); Map txData = { "fee": feeEstimate, + "feeInWei": fee, "address": address, "recipientAmt": satoshiAmount, }; @@ -682,8 +680,6 @@ class EthereumWallet extends CoinServiceAPI { await Future.wait([ newTxData, feeObj, - - /// TODO - GET fee object allTxsToWatch, ]); GlobalEventBus.instance @@ -769,7 +765,6 @@ class EthereumWallet extends CoinServiceAPI { } @override - // TODO: Check difference between total and available balance for eth Future get totalBalance async { EtherAmount ethBalance = await _client.getBalance(_credentials.address); return Decimal.parse(ethBalance.getValueInUnit(EtherUnit.ether).toString()); @@ -783,7 +778,7 @@ class EthereumWallet extends CoinServiceAPI { TransactionData? cachedTxData; @override - // TODO: implement unspentOutputs + // TODO: implement unspentOutputs - NOT NEEDED, ETH DOES NOT USE UTXOs Future> get unspentOutputs => throw UnimplementedError(); @override