eth gas tracker fixes and token send tweaks

This commit is contained in:
julian 2023-04-11 15:34:17 -06:00
parent e2cc371f99
commit b5a58064ac
4 changed files with 22 additions and 39 deletions

View file

@ -342,7 +342,9 @@ class FeeDropDownChild extends ConsumerWidget {
), ),
if (feeObject != null) if (feeObject != null)
Text( Text(
estimatedTimeToBeIncludedInNextBlock( manager.coin == Coin.ethereum
? ""
: estimatedTimeToBeIncludedInNextBlock(
Constants.targetBlockTimeInSeconds(manager.coin), Constants.targetBlockTimeInSeconds(manager.coin),
feeRateType == FeeRateType.fast feeRateType == FeeRateType.fast
? feeObject!.numberOfBlocksFast ? feeObject!.numberOfBlocksFast

View file

@ -503,7 +503,7 @@ abstract class EthereumAPI {
if (json["success"] == true) { if (json["success"] == true) {
return EthereumResponse( return EthereumResponse(
GasTracker.fromJson( GasTracker.fromJson(
Map<String, dynamic>.from(json["result"] as Map), Map<String, dynamic>.from(json["result"]["result"] as Map),
), ),
null, null,
); );

View file

@ -90,30 +90,10 @@ class EthTokenWallet extends ChangeNotifier with EthTokenCache {
final myAddress = await currentReceivingAddress; final myAddress = await currentReceivingAddress;
final myWeb3Address = web3dart.EthereumAddress.fromHex(myAddress); final myWeb3Address = web3dart.EthereumAddress.fromHex(myAddress);
final est = await client.estimateGas(
sender: myWeb3Address,
to: web3dart.EthereumAddress.fromHex(address),
data: _sendFunction
.encodeCall([web3dart.EthereumAddress.fromHex(address), amount.raw]),
gasPrice: web3dart.EtherAmount.fromUnitAndValue(
web3dart.EtherUnit.wei,
fee,
),
amountOfGas: BigInt.from(_gasLimit),
);
final nonce = args?["nonce"] as int? ?? final nonce = args?["nonce"] as int? ??
await client.getTransactionCount(myWeb3Address, await client.getTransactionCount(myWeb3Address,
atBlock: const web3dart.BlockNum.pending()); atBlock: const web3dart.BlockNum.pending());
final nResponse = await EthereumAPI.getAddressNonce(address: myAddress);
print("==============================================================");
print("TOKEN client.estimateGas: $est");
print("TOKEN estimateFeeFor : $feeEstimate");
print("TOKEN nonce custom response: $nResponse");
print("TOKEN actual nonce : $nonce");
print("==============================================================");
final tx = web3dart.Transaction.callContract( final tx = web3dart.Transaction.callContract(
contract: _deployedContract, contract: _deployedContract,
function: _sendFunction, function: _sendFunction,
@ -179,7 +159,7 @@ class EthTokenWallet extends ChangeNotifier with EthTokenCache {
// precision may be lost here hence the following amountString // precision may be lost here hence the following amountString
amount: (txData["recipientAmt"] as Amount).raw.toInt(), amount: (txData["recipientAmt"] as Amount).raw.toInt(),
amountString: (txData["recipientAmt"] as Amount).toJsonString(), amountString: (txData["recipientAmt"] as Amount).toJsonString(),
fee: txData["fee"] as int, fee: (txData["fee"] as Amount).raw.toInt(),
height: null, height: null,
isCancelled: false, isCancelled: false,
isLelantus: false, isLelantus: false,

View file

@ -15,7 +15,7 @@ class GasTracker {
final int numberOfBlocksAverage; final int numberOfBlocksAverage;
final int numberOfBlocksSlow; final int numberOfBlocksSlow;
final int timestamp; final String lastBlock;
const GasTracker({ const GasTracker({
required this.average, required this.average,
@ -24,19 +24,20 @@ class GasTracker {
required this.numberOfBlocksFast, required this.numberOfBlocksFast,
required this.numberOfBlocksAverage, required this.numberOfBlocksAverage,
required this.numberOfBlocksSlow, required this.numberOfBlocksSlow,
required this.timestamp, required this.lastBlock,
}); });
factory GasTracker.fromJson(Map<String, dynamic> json) { factory GasTracker.fromJson(Map<String, dynamic> json) {
final targetTime = Constants.targetBlockTimeInSeconds(Coin.ethereum); final targetTime = Constants.targetBlockTimeInSeconds(Coin.ethereum);
return GasTracker( return GasTracker(
average: Decimal.parse(json["average"]["price"].toString()), fast: Decimal.parse(json["FastGasPrice"].toString()),
fast: Decimal.parse(json["fast"]["price"].toString()), average: Decimal.parse(json["ProposeGasPrice"].toString()),
slow: Decimal.parse(json["slow"]["price"].toString()), slow: Decimal.parse(json["SafeGasPrice"].toString()),
numberOfBlocksAverage: (json["average"]["time"] as int) ~/ targetTime, // TODO fix hardcoded
numberOfBlocksFast: (json["fast"]["time"] as int) ~/ targetTime, numberOfBlocksFast: 30 ~/ targetTime,
numberOfBlocksSlow: (json["slow"]["time"] as int) ~/ targetTime, numberOfBlocksAverage: 180 ~/ targetTime,
timestamp: json["timestamp"] as int, numberOfBlocksSlow: 240 ~/ targetTime,
lastBlock: json["LastBlock"] as String,
); );
} }
} }