Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

Commit

Permalink
fix: Sending price details to send tx
Browse files Browse the repository at this point in the history
  • Loading branch information
reasje committed Sep 13, 2023
1 parent cf58dc5 commit 1b18db6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
34 changes: 18 additions & 16 deletions lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,18 @@ class OpenDAppPresenter extends CompletePresenter<OpenDAppState> {
}
}

Future<String?> _sendTransaction(
String to, EtherAmount amount, Uint8List? data,
Future<String?> _sendTransaction(String to, EtherAmount amount,
Uint8List? data, EstimatedGasFee? estimatedGasFee,
{String? from}) async {
loading = true;
try {
final res = await _tokenContractUseCase.sendTransaction(
privateKey: state.account!.privateKey,
to: to,
from: from,
amount: amount,
data: data,
);
privateKey: state.account!.privateKey,
to: to,
from: from,
amount: amount,
data: data,
estimatedGasFee: estimatedGasFee);

return res;
} catch (e, s) {
Expand All @@ -105,7 +105,7 @@ class OpenDAppPresenter extends CompletePresenter<OpenDAppState> {
final amount = amountEther.getValueInUnit(EtherUnit.ether).toString();
final bridgeData = hexToBytes(bridge.data ?? '');
EtherAmount? gasPrice;
EtherAmount? gasFee;
double? gasFee;
EstimatedGasFee? estimatedGasFee;
BigInt? amountOfGas;

Expand All @@ -116,8 +116,12 @@ class OpenDAppPresenter extends CompletePresenter<OpenDAppState> {
if (bridge.gas != null) {
amountOfGas = BigInt.parse(bridge.gas.toString());
gasPrice = gasPrice ?? await _tokenContractUseCase.getGasPrice();
gasFee = EtherAmount.fromBigInt(
EtherUnit.wei, gasPrice.getInWei * amountOfGas);
final gasPriceDouble =
gasPrice.getValueInUnit(EtherUnit.ether).toDouble();
gasFee = gasPriceDouble * amountOfGas.toDouble();

estimatedGasFee =
EstimatedGasFee(gasPrice: gasPrice, gas: amountOfGas, gasFee: gasFee);
} else {
estimatedGasFee = await _estimatedFee(
bridge.from!, bridge.to!, gasPrice, bridgeData, amountOfGas);
Expand All @@ -128,10 +132,7 @@ class OpenDAppPresenter extends CompletePresenter<OpenDAppState> {
}
}

String finalFee = (gasFee?.getInWei != null
? gasFee!.getValueInUnit(EtherUnit.ether)
: (estimatedGasFee?.gasFee ?? 0))
.toString();
String finalFee = estimatedGasFee.gasFee.toString();

if (Validation.isExpoNumber(finalFee)) {
finalFee = '0.0';
Expand All @@ -149,7 +150,8 @@ class OpenDAppPresenter extends CompletePresenter<OpenDAppState> {
symbol: symbol);

if (result != null && result) {
final hash = await _sendTransaction(bridge.to!, amountEther, bridgeData,
final hash = await _sendTransaction(
bridge.to!, amountEther, bridgeData, estimatedGasFee,
from: bridge.from);
if (hash != null) success.call(hash);
} else {
Expand Down

0 comments on commit 1b18db6

Please sign in to comment.