WIP eth fees

This commit is contained in:
julian 2023-03-29 12:49:12 -06:00
parent ac0c65e26b
commit bfeb3e0d30
4 changed files with 22 additions and 60 deletions

View file

@ -245,7 +245,7 @@ class EthereumWallet extends CoinServiceAPI with WalletCache, WalletDB {
@override
Future<int> estimateFeeFor(int satoshiAmount, int feeRate) async {
final fee = estimateFee(feeRate, _gasLimit, 18);
final fee = estimateFee(feeRate, _gasLimit, coin.decimals);
return Format.decimalAmountToSatoshis(Decimal.parse(fee.toString()), coin);
}
@ -258,10 +258,7 @@ class EthereumWallet extends CoinServiceAPI with WalletCache, WalletDB {
}
@override
Future<FeeObject> get fees => _feeObject ??= _getFees();
Future<FeeObject>? _feeObject;
Future<FeeObject> _getFees() => EthereumAPI.getFees();
Future<FeeObject> get fees => EthereumAPI.getFees();
//Full rescan is not needed for ETH since we have a balance
@override
@ -758,13 +755,13 @@ class EthereumWallet extends CoinServiceAPI with WalletCache, WalletDB {
GlobalEventBus.instance
.fire(RefreshPercentChangedEvent(0.50, walletId));
final feeObj = _getFees();
// final feeObj = _getFees();
GlobalEventBus.instance
.fire(RefreshPercentChangedEvent(0.60, walletId));
GlobalEventBus.instance
.fire(RefreshPercentChangedEvent(0.70, walletId));
_feeObject = Future(() => feeObj);
// _feeObject = Future(() => feeObj);
GlobalEventBus.instance
.fire(RefreshPercentChangedEvent(0.80, walletId));
@ -772,7 +769,7 @@ class EthereumWallet extends CoinServiceAPI with WalletCache, WalletDB {
await Future.wait([
updateBalance(),
newTxDataFuture,
feeObj,
// feeObj,
allTxsToWatch,
]);
GlobalEventBus.instance

View file

@ -34,12 +34,6 @@ class EthereumResponse<T> {
abstract class EthereumAPI {
static String get stackBaseServer => DefaultNodes.ethereum.host;
// static const etherscanApi =
// "https://api.etherscan.io/api"; //TODO - Once our server has abi functionality update
static const gasTrackerUrl =
"https://blockscout.com/eth/mainnet/api/v1/gas-price-oracle";
static Future<EthereumResponse<List<EthTxDTO>>> getEthTransactions(
String address) async {
try {
@ -336,10 +330,15 @@ abstract class EthereumAPI {
}
static Future<GasTracker> getGasOracle() async {
final response = await get(Uri.parse(gasTrackerUrl));
final response = await get(
Uri.parse(
"https://api.etherscan.io/api?module=gastracker&action=gasoracle&apikey=EG6J7RJIQVSTP2BS59D3TY2G55YHS5F2HP",
),
);
if (response.statusCode == 200) {
return GasTracker.fromJson(
json.decode(response.body) as Map<String, dynamic>);
final json = jsonDecode(response.body) as Map;
return GasTracker.fromJson(json["result"] as Map<String, dynamic>);
} else {
throw Exception('Failed to load gas oracle');
}

View file

@ -105,16 +105,11 @@ class EthTokenWallet extends ChangeNotifier with EthTokenCache {
.findFirst();
Future<int> estimateFeeFor(int satoshiAmount, int feeRate) async {
final fee = estimateFee(feeRate, _gasLimit, tokenContract.decimals);
final fee = estimateFee(feeRate, _gasLimit, coin.decimals);
return Format.decimalAmountToSatoshis(Decimal.parse(fee.toString()), coin);
}
Future<FeeObject> get fees => _feeObject ??= _getFees();
Future<FeeObject>? _feeObject;
Future<FeeObject> _getFees() async {
return await EthereumAPI.getFees();
}
Future<FeeObject> get fees => EthereumAPI.getFees();
Future<EthContract> _updateTokenABI({
required EthContract forContract,

View file

@ -4,40 +4,11 @@ import 'package:bip32/bip32.dart' as bip32;
import 'package:bip39/bip39.dart' as bip39;
import "package:hex/hex.dart";
class AddressTransaction {
final String message;
final List<dynamic> result;
final String status;
const AddressTransaction({
required this.message,
required this.result,
required this.status,
});
factory AddressTransaction.fromJson(List<dynamic> json) {
return AddressTransaction(
message: "",
result: json,
status: "",
);
}
@override
String toString() {
return "AddressTransaction: {"
"\n\t message: $message,"
"\n\t status: $status,"
"\n\t result: $result,"
"\n}";
}
}
class GasTracker {
final double average;
final double fast;
final double slow;
// final Map<String, dynamic> data;
// gwei
final int average;
final int fast;
final int slow;
const GasTracker({
required this.average,
@ -47,9 +18,9 @@ class GasTracker {
factory GasTracker.fromJson(Map<String, dynamic> json) {
return GasTracker(
average: json['average'] as double,
fast: json['fast'] as double,
slow: json['slow'] as double,
average: int.parse(json['ProposeGasPrice'] as String),
fast: int.parse(json['FastGasPrice'] as String),
slow: int.parse(json['SafeGasPrice'] as String),
);
}
}