mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-26 06:08:40 +01:00
* fix: validate EVM restore mnemonics * chore: drop test changes from this PR Removes the test additions/modifications introduced by this branch so the test design is left to the maintainers. Production code is unchanged.
62 lines
2.0 KiB
Dart
62 lines
2.0 KiB
Dart
import 'package:cw_core/crypto_currency.dart';
|
|
|
|
class EVMChainMnemonicIsIncorrectException implements Exception {
|
|
@override
|
|
String toString() =>
|
|
'EVM mnemonic has incorrect format. Mnemonic should contain 12 or 24 words separated by space.';
|
|
}
|
|
|
|
class EVMChainTransactionCreationException implements Exception {
|
|
final String exceptionMessage;
|
|
|
|
EVMChainTransactionCreationException(CryptoCurrency currency)
|
|
: exceptionMessage = 'Wrong balance. Not enough ${currency.title} on your balance.';
|
|
|
|
EVMChainTransactionCreationException.fromMessage(this.exceptionMessage);
|
|
|
|
@override
|
|
String toString() => exceptionMessage;
|
|
}
|
|
|
|
class EVMChainTransactionFeesException implements Exception {
|
|
final String exceptionMessage;
|
|
|
|
EVMChainTransactionFeesException(String message) : exceptionMessage = message;
|
|
|
|
EVMChainTransactionFeesException.fromCurrency(String currency)
|
|
: exceptionMessage =
|
|
'Transaction failed due to insufficient $currency balance to cover the fees.';
|
|
|
|
@override
|
|
String toString() => exceptionMessage;
|
|
}
|
|
|
|
class InsufficientGasFeeException implements Exception {
|
|
final String exceptionMessage;
|
|
final BigInt? requiredGasFee;
|
|
final BigInt? currentBalance;
|
|
|
|
InsufficientGasFeeException({
|
|
this.requiredGasFee,
|
|
this.currentBalance,
|
|
}) : exceptionMessage = _buildMessage(requiredGasFee, currentBalance);
|
|
|
|
static String _buildMessage(BigInt? requiredGasFee, BigInt? currentBalance) {
|
|
const baseMessage = 'Insufficient ETH for gas fees.';
|
|
const addEthMessage = ' Please add ETH to your wallet to cover transaction fees.';
|
|
|
|
if (requiredGasFee != null) {
|
|
final requiredEth = (requiredGasFee / BigInt.from(10).pow(18)).toStringAsFixed(8);
|
|
final balanceInfo = currentBalance != null
|
|
? ', Available: ${(currentBalance / BigInt.from(10).pow(18)).toStringAsFixed(8)} ETH'
|
|
: '';
|
|
return '$baseMessage Required: ~$requiredEth ETH$balanceInfo.$addEthMessage';
|
|
}
|
|
|
|
return '$baseMessage$addEthMessage';
|
|
}
|
|
|
|
@override
|
|
String toString() => exceptionMessage;
|
|
}
|