From 2e0b02766e4e2e6281c6f29c9453918fb0cfeef8 Mon Sep 17 00:00:00 2001 From: OmarHatem Date: Fri, 21 Jul 2023 21:28:56 +0300 Subject: [PATCH] Fix sending erc20 fix block explorer issue --- cw_ethereum/lib/ethereum_wallet.dart | 3 +++ lib/core/address_validator.dart | 21 +++++++++++-------- .../transaction_details_view_model.dart | 4 ++++ 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/cw_ethereum/lib/ethereum_wallet.dart b/cw_ethereum/lib/ethereum_wallet.dart index b7b852979..e57b7fbfd 100644 --- a/cw_ethereum/lib/ethereum_wallet.dart +++ b/cw_ethereum/lib/ethereum_wallet.dart @@ -175,6 +175,9 @@ abstract class EthereumWalletBase gas: _priorityFees[_credentials.priority!.raw], priority: _credentials.priority!, currency: _credentials.currency, + contractAddress: _credentials.currency is Erc20Token + ? (_credentials.currency as Erc20Token).contractAddress + : null, ); return pendingEthereumTransaction; diff --git a/lib/core/address_validator.dart b/lib/core/address_validator.dart index 6522b2756..f2a235363 100644 --- a/lib/core/address_validator.dart +++ b/lib/core/address_validator.dart @@ -2,6 +2,7 @@ import 'package:bitcoin_flutter/bitcoin_flutter.dart' as bitcoin; import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/core/validator.dart'; import 'package:cw_core/crypto_currency.dart'; +import 'package:cw_core/erc20_token.dart'; class AddressValidator extends TextValidator { AddressValidator({required CryptoCurrency type}) @@ -14,6 +15,9 @@ class AddressValidator extends TextValidator { length: getLength(type)); static String getPattern(CryptoCurrency type) { + if (type is Erc20Token) { + return '0x[0-9a-zA-Z]'; + } switch (type) { case CryptoCurrency.xmr: return '^4[0-9a-zA-Z]{94}\$|^8[0-9a-zA-Z]{94}\$|^[0-9a-zA-Z]{106}\$'; @@ -117,17 +121,14 @@ class AddressValidator extends TextValidator { } static List? getLength(CryptoCurrency type) { + if (type is Erc20Token) { + return [42]; + } switch (type) { case CryptoCurrency.xmr: return null; case CryptoCurrency.ada: return null; - case CryptoCurrency.avaxc: - return [42]; - case CryptoCurrency.bch: - return [42]; - case CryptoCurrency.bnb: - return [42]; case CryptoCurrency.btc: return null; case CryptoCurrency.dash: @@ -168,6 +169,9 @@ class AddressValidator extends TextValidator { case CryptoCurrency.dydx: case CryptoCurrency.steth: case CryptoCurrency.shib: + case CryptoCurrency.avaxc: + case CryptoCurrency.bch: + case CryptoCurrency.bnb: return [42]; case CryptoCurrency.ltc: return [34, 43, 63]; @@ -205,11 +209,8 @@ class AddressValidator extends TextValidator { case CryptoCurrency.xusd: return [98, 99, 106]; case CryptoCurrency.btt: - return [34]; case CryptoCurrency.bttc: - return [34]; case CryptoCurrency.doge: - return [34]; case CryptoCurrency.firo: return [34]; case CryptoCurrency.hbar: @@ -260,6 +261,8 @@ class AddressValidator extends TextValidator { return '([^0-9a-zA-Z]|^)^L[a-zA-Z0-9]{26,33}([^0-9a-zA-Z]|\$)' '|([^0-9a-zA-Z]|^)[LM][a-km-zA-HJ-NP-Z1-9]{26,33}([^0-9a-zA-Z]|\$)' '|([^0-9a-zA-Z]|^)ltc[a-zA-Z0-9]{26,45}([^0-9a-zA-Z]|\$)'; + case CryptoCurrency.eth: + return '0x[0-9a-zA-Z]{42}'; default: return null; } diff --git a/lib/view_model/transaction_details_view_model.dart b/lib/view_model/transaction_details_view_model.dart index 9a392330b..bb6008754 100644 --- a/lib/view_model/transaction_details_view_model.dart +++ b/lib/view_model/transaction_details_view_model.dart @@ -114,6 +114,8 @@ abstract class TransactionDetailsViewModelBase with Store { return 'https://blockchair.com/litecoin/transaction/${txId}'; case WalletType.haven: return 'https://explorer.havenprotocol.org/search?value=${txId}'; + case WalletType.ethereum: + return 'https://etherscan.io/tx/${txId}'; default: return ''; } @@ -129,6 +131,8 @@ abstract class TransactionDetailsViewModelBase with Store { return S.current.view_transaction_on + 'Blockchair.com'; case WalletType.haven: return S.current.view_transaction_on + 'explorer.havenprotocol.org'; + case WalletType.ethereum: + return S.current.view_transaction_on + 'etherscan.io'; default: return ''; }