dev
dart 61 lines 2.03 KB
Raw
1 import 'package:cw_core/crypto_currency.dart';
2
3 class EVMChainMnemonicIsIncorrectException implements Exception {
4 @override
5 String toString() =>
6 'EVM mnemonic has incorrect format. Mnemonic should contain 12 or 24 words separated by space.';
7 }
8
9 class EVMChainTransactionCreationException implements Exception {
10 final String exceptionMessage;
11
12 EVMChainTransactionCreationException(CryptoCurrency currency)
13 : exceptionMessage = 'Wrong balance. Not enough ${currency.title} on your balance.';
14
15 EVMChainTransactionCreationException.fromMessage(this.exceptionMessage);
16
17 @override
18 String toString() => exceptionMessage;
19 }
20
21 class EVMChainTransactionFeesException implements Exception {
22 final String exceptionMessage;
23
24 EVMChainTransactionFeesException(String message) : exceptionMessage = message;
25
26 EVMChainTransactionFeesException.fromCurrency(String currency)
27 : exceptionMessage =
28 'Transaction failed due to insufficient $currency balance to cover the fees.';
29
30 @override
31 String toString() => exceptionMessage;
32 }
33
34 class InsufficientGasFeeException implements Exception {
35 final String exceptionMessage;
36 final BigInt? requiredGasFee;
37 final BigInt? currentBalance;
38
39 InsufficientGasFeeException({
40 this.requiredGasFee,
41 this.currentBalance,
42 }) : exceptionMessage = _buildMessage(requiredGasFee, currentBalance);
43
44 static String _buildMessage(BigInt? requiredGasFee, BigInt? currentBalance) {
45 const baseMessage = 'Insufficient ETH for gas fees.';
46 const addEthMessage = ' Please add ETH to your wallet to cover transaction fees.';
47
48 if (requiredGasFee != null) {
49 final requiredEth = (requiredGasFee / BigInt.from(10).pow(18)).toStringAsFixed(8);
50 final balanceInfo = currentBalance != null
51 ? ', Available: ${(currentBalance / BigInt.from(10).pow(18)).toStringAsFixed(8)} ETH'
52 : '';
53 return '$baseMessage Required: ~$requiredEth ETH$balanceInfo.$addEthMessage';
54 }
55
56 return '$baseMessage$addEthMessage';
57 }
58
59 @override
60 String toString() => exceptionMessage;
61 }