Skip to content

Commit

Permalink
fix: estimate fee bloc (#1522)
Browse files Browse the repository at this point in the history
* fix: estimate fee

* refactor: estimate fee emit state
  • Loading branch information
ppupha authored Feb 5, 2024
1 parent 3d96c3a commit 0a7f41f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
14 changes: 7 additions & 7 deletions lib/screen/wallet_connect/send/wc_send_transaction_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,15 @@ class WCSendTransactionBloc
final newState = state.clone();
final exchangeRate = await _currencyService.getExchangeRates();
newState.exchangeRate = exchangeRate;
emit(newState);
try {
newState.feeOptionValue = await _ethereumService.estimateFee(
final estimatedFee = await _ethereumService.estimateFee(
persona, event.index, event.address, event.amount, event.data);
final balance = await _ethereumService
.getBalance(await persona.getETHEip55Address(index: event.index));
newState
..feeOptionValue = estimatedFee
..fee = newState.feeOptionValue!.getFee(state.feeOption)
..balance = balance.getInWei;
} on RPCError catch (e) {
log.info('WC Send tx bloc: RPCError: '
'errorCode: ${e.errorCode} '
Expand All @@ -73,11 +78,6 @@ class WCSendTransactionBloc
add(event);
});
}
newState.fee = newState.feeOptionValue!.getFee(state.feeOption);

final balance =
await _ethereumService.getBalance(await persona.getETHEip55Address());
newState.balance = balance.getInWei;
emit(newState);
});

Expand Down
6 changes: 3 additions & 3 deletions lib/screen/wallet_connect/send/wc_send_transaction_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ class _WCSendTransactionPageState extends State<WCSendTransactionPage> {
state.fee != null ? state.fee! + amount.getInWei : null;
final theme = Theme.of(context);
final ethAmountText = '${ethFormatter.format(amount.getInWei)} ETH '
'(${state.exchangeRate.ethToUsd(amount.getInWei)} USD)';
'(${state.exchangeRate?.ethToUsd(amount.getInWei) ?? '-'} USD)';
final ethTotalAmountText = total == null
? '- ETH (- USD)'
: '${ethFormatter.format(total)} ETH'
' (${state.exchangeRate.ethToUsd(total)} USD)';
' (${state.exchangeRate?.ethToUsd(total) ?? '-'} USD)';
return Stack(
children: [
Container(
Expand Down Expand Up @@ -471,7 +471,7 @@ class _WCSendTransactionPageState extends State<WCSendTransactionPage> {
}
final fee = state.feeOptionValue!.getFee(feeOption ?? state.feeOption);
return '${ethFormatter.format(fee)} ETH '
'(${state.exchangeRate.ethToUsd(fee)} USD)';
'(${state.exchangeRate?.ethToUsd(fee) ?? '-'} USD)';
}
}

Expand Down
6 changes: 3 additions & 3 deletions lib/screen/wallet_connect/send/wc_send_transaction_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ class WCSendTransactionRejectEvent extends WCSendTransactionEvent {
WCSendTransactionRejectEvent(
this.peerMeta,
this.requestId, {
this.topic,
required this.isWalletConnect2,
this.topic,
this.isIRL = false,
});
}
Expand All @@ -81,7 +81,7 @@ class WCSendTransactionState {
bool isError = false;
FeeOption feeOption;
FeeOptionValue? feeOptionValue;
CurrencyExchangeRate exchangeRate;
CurrencyExchangeRate? exchangeRate;

WCSendTransactionState({
this.fee,
Expand All @@ -90,7 +90,7 @@ class WCSendTransactionState {
this.isError = false,
this.feeOption = DEFAULT_FEE_OPTION,
this.feeOptionValue,
this.exchangeRate = const CurrencyExchangeRate(eth: "1.0", xtz: "1.0"),
this.exchangeRate,
});

WCSendTransactionState clone() => WCSendTransactionState(
Expand Down

0 comments on commit 0a7f41f

Please sign in to comment.