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

Commit 32fe801

Browse files
committed
fix: fee exceed in send crypto & tx recording number conversion
1 parent 46382eb commit 32fe801

File tree

2 files changed

+34
-23
lines changed

2 files changed

+34
-23
lines changed

lib/common/utils/formatter.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Formatter {
4444

4545
static String convertWeiToEth(String inputString, int tokenDecimal) {
4646
// 10^18 = 1000000000000000000 but we want to have up to 2 digits accuracy
47-
if (double.parse(inputString).toDouble() < 10000000000000000) {
47+
if (double.parse(inputString).toDouble() < 1000000000000000) {
4848
return '0';
4949
}
5050
final valueDouble = double.parse(inputString).toDouble() / pow(10, 18);

lib/features/portfolio/subfeatures/token/send_token/send_crypto/send_crypto_presenter.dart

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -150,23 +150,25 @@ class SendCryptoPresenter extends CompletePresenter<SendCryptoState> {
150150

151151
double sumBalance = token.balance! - double.parse(amount);
152152
estimatedGasFee = await _estimatedFee(recipientAddress);
153-
sumBalance -= estimatedGasFee?.gasFee ?? 0.0;
154-
final estimatedFee = estimatedGasFee == null
155-
? '--'
156-
: Validation.isExpoNumber(estimatedGasFee.gasFee.toString())
157-
? '0.000'
158-
: estimatedGasFee.gasFee.toString();
159-
160-
final result = await showTransactionDialog(context!,
161-
amount: amount,
162-
balance: sumBalance.toString(),
163-
token: token,
164-
network: state.network?.label ?? '--',
165-
from: state.account!.address,
166-
to: recipient,
167-
estimatedFee: estimatedFee,
168-
onTap: (transactionType) => _nextTransactionStep(transactionType),
169-
networkSymbol: state.network?.symbol ?? '--');
153+
if (estimatedGasFee != null) {
154+
sumBalance -= estimatedGasFee.gasFee;
155+
final estimatedFee = estimatedGasFee == null
156+
? '--'
157+
: Validation.isExpoNumber(estimatedGasFee.gasFee.toString())
158+
? '0.000'
159+
: estimatedGasFee.gasFee.toString();
160+
161+
final result = await showTransactionDialog(context!,
162+
amount: amount,
163+
balance: sumBalance.toString(),
164+
token: token,
165+
network: state.network?.label ?? '--',
166+
from: state.account!.address,
167+
to: recipient,
168+
estimatedFee: estimatedFee,
169+
onTap: (transactionType) => _nextTransactionStep(transactionType),
170+
networkSymbol: state.network?.symbol ?? '--');
171+
}
170172
}
171173

172174
String? checkAmountCeiling() {
@@ -203,7 +205,11 @@ class SendCryptoPresenter extends CompletePresenter<SendCryptoState> {
203205

204206
return gasFee;
205207
} catch (e, s) {
206-
addError(e, s);
208+
if (e is RPCError) {
209+
String errorMessage = e.message;
210+
errorMessage = changeErrorMessage(errorMessage);
211+
addError(errorMessage);
212+
}
207213
} finally {
208214
loading = false;
209215
}
@@ -229,7 +235,7 @@ class SendCryptoPresenter extends CompletePresenter<SendCryptoState> {
229235
hash: res,
230236
status: TransactionStatus.pending,
231237
type: TransactionType.sent,
232-
value: amount.getValueInUnit(EtherUnit.wei).toString(),
238+
value: amount.getValueInUnitBI(EtherUnit.wei).toString(),
233239
token: token,
234240
timeStamp: DateTime.now());
235241

@@ -249,16 +255,21 @@ class SendCryptoPresenter extends CompletePresenter<SendCryptoState> {
249255
BottomFlowDialog.of(context!).close();
250256
}
251257
String errorMessage = e.message;
252-
if (e.message.contains('gas required exceeds allowance')) {
253-
errorMessage = translate('insufficient_balance_for_fee') ?? e.message;
254-
}
258+
errorMessage = changeErrorMessage(errorMessage);
255259
addError(errorMessage);
256260
}
257261
} finally {
258262
loading = false;
259263
}
260264
}
261265

266+
String changeErrorMessage(String message) {
267+
if (message.contains('gas required exceeds allowance')) {
268+
return translate('insufficient_balance_for_fee') ?? message;
269+
}
270+
return message;
271+
}
272+
262273
@override
263274
Future<void> dispose() async {
264275
super.dispose();

0 commit comments

Comments
 (0)