From 734a51f5dd7541f70a722e5f60900cb6b9cec78c Mon Sep 17 00:00:00 2001 From: likho Date: Thu, 12 Jan 2023 10:09:11 +0200 Subject: [PATCH] WIP: Get gas estimator --- .../coins/ethereum/ethereum_wallet.dart | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/lib/services/coins/ethereum/ethereum_wallet.dart b/lib/services/coins/ethereum/ethereum_wallet.dart index b5e80d0b7..a19148bb6 100644 --- a/lib/services/coins/ethereum/ethereum_wallet.dart +++ b/lib/services/coins/ethereum/ethereum_wallet.dart @@ -71,21 +71,18 @@ class AddressTransaction { } class GasTracker { - final String status; - final String message; - final List result; + final int code; + final String data; const GasTracker({ - required this.status, - required this.message, - required this.result, + required this.code, + required this.data, }); factory GasTracker.fromJson(Map json) { return GasTracker( - status: json['status'] as String, - message: json['message'] as String, - result: json['result'] as List, + code: json['code'] as int, + data: json['data'] as String, ); } } @@ -250,8 +247,10 @@ class EthereumWallet extends CoinServiceAPI { Future? _feeObject; Future _getFees() async { - String feesEndPoint = - "https://api.etherscan.io/api?module=gastracker&action=gasoracle&apikey=5JJW1UH269SV6ZPC78ZZI7H4QVV1A1TQDH"; + GasTracker fees = await getGasOracle(); + if (fees.code == 200) { + print("FEES IS ${fees.data}"); + } return FeeObject( numberOfBlocksFast: 10, numberOfBlocksAverage: 10, @@ -261,6 +260,18 @@ class EthereumWallet extends CoinServiceAPI { slow: 1); } + Future getGasOracle() async { + final response = + await get(Uri.parse("https://beaconcha.in/api/v1/execution/gasnow")); + + if (response.statusCode == 200) { + return GasTracker.fromJson( + json.decode(response.body) as Map); + } else { + throw Exception('Failed to load gas oracle'); + } + } + @override Future fullRescan( int maxUnusedAddressGap, int maxNumberOfIndexesToCheck) {