From 7704ec047cce098bb68748ffc58697104df4ce31 Mon Sep 17 00:00:00 2001 From: David Adegoke <64401859+Blazebrain@users.noreply.github.com> Date: Thu, 25 Sep 2025 08:45:22 +0100 Subject: [PATCH] fix: Polygon transactions not coming up in transactions history page (#2537) --- .../lib/ethereum_transaction_info.dart | 2 + cw_ethereum/lib/ethereum_wallet.dart | 1 + cw_evm/lib/evm_chain_transaction_info.dart | 3 + cw_polygon/lib/polygon_transaction_info.dart | 2 + cw_polygon/lib/polygon_wallet.dart | 1 + lib/polygon/cw_polygon.dart | 156 ++++++++++-------- 6 files changed, 92 insertions(+), 73 deletions(-) diff --git a/cw_ethereum/lib/ethereum_transaction_info.dart b/cw_ethereum/lib/ethereum_transaction_info.dart index 7a62c0b6a..610f04315 100644 --- a/cw_ethereum/lib/ethereum_transaction_info.dart +++ b/cw_ethereum/lib/ethereum_transaction_info.dart @@ -14,6 +14,7 @@ class EthereumTransactionInfo extends EVMChainTransactionInfo { required super.confirmations, required super.to, required super.from, + super.contractAddress, super.evmSignatureName, super.exponent, }); @@ -33,6 +34,7 @@ class EthereumTransactionInfo extends EVMChainTransactionInfo { to: data['to'], from: data['from'], evmSignatureName: data['evmSignatureName'], + contractAddress: data['contractAddress'], ); } diff --git a/cw_ethereum/lib/ethereum_wallet.dart b/cw_ethereum/lib/ethereum_wallet.dart index c22be3cb2..b4883570a 100644 --- a/cw_ethereum/lib/ethereum_wallet.dart +++ b/cw_ethereum/lib/ethereum_wallet.dart @@ -105,6 +105,7 @@ class EthereumWallet extends EVMChainWallet { to: transactionModel.to, from: transactionModel.from, evmSignatureName: transactionModel.evmSignatureName, + contractAddress: transactionModel.contractAddress, ); return model; } diff --git a/cw_evm/lib/evm_chain_transaction_info.dart b/cw_evm/lib/evm_chain_transaction_info.dart index fb6cf6b52..d016646ae 100644 --- a/cw_evm/lib/evm_chain_transaction_info.dart +++ b/cw_evm/lib/evm_chain_transaction_info.dart @@ -21,6 +21,7 @@ abstract class EVMChainTransactionInfo extends TransactionInfo { required this.to, required this.from, this.evmSignatureName, + this.contractAddress, }) : amount = ethAmount.toInt(), fee = ethFee.toInt(); @@ -40,6 +41,7 @@ abstract class EVMChainTransactionInfo extends TransactionInfo { final String? to; final String? from; final String? evmSignatureName; + final String? contractAddress; //! Getter to be overridden in child classes String get feeCurrency; @@ -76,5 +78,6 @@ abstract class EVMChainTransactionInfo extends TransactionInfo { 'to': to, 'from': from, 'evmSignatureName': evmSignatureName, + 'contractAddress': contractAddress, }; } diff --git a/cw_polygon/lib/polygon_transaction_info.dart b/cw_polygon/lib/polygon_transaction_info.dart index 1fbe1c5d4..51ca53cb1 100644 --- a/cw_polygon/lib/polygon_transaction_info.dart +++ b/cw_polygon/lib/polygon_transaction_info.dart @@ -14,6 +14,7 @@ class PolygonTransactionInfo extends EVMChainTransactionInfo { required super.confirmations, required super.to, required super.from, + super.contractAddress, super.exponent, }); @@ -31,6 +32,7 @@ class PolygonTransactionInfo extends EVMChainTransactionInfo { tokenSymbol: data['tokenSymbol'] as String, to: data['to'], from: data['from'], + contractAddress: data['contractAddress'], ); } diff --git a/cw_polygon/lib/polygon_wallet.dart b/cw_polygon/lib/polygon_wallet.dart index 8f6a0ad2e..c0055c789 100644 --- a/cw_polygon/lib/polygon_wallet.dart +++ b/cw_polygon/lib/polygon_wallet.dart @@ -102,6 +102,7 @@ class PolygonWallet extends EVMChainWallet { tokenSymbol: transactionModel.tokenSymbol ?? "MATIC", to: transactionModel.to, from: transactionModel.from, + contractAddress: transactionModel.contractAddress, ); return model; } diff --git a/lib/polygon/cw_polygon.dart b/lib/polygon/cw_polygon.dart index 85fd4bf4b..dabda4e5f 100644 --- a/lib/polygon/cw_polygon.dart +++ b/lib/polygon/cw_polygon.dart @@ -14,14 +14,13 @@ class CWPolygon extends Polygon { WalletInfo? walletInfo, String? password, String? passphrase, - }) => - EVMChainNewWalletCredentials( - name: name, - walletInfo: walletInfo, - password: password, - mnemonic: mnemonic, - passphrase: passphrase, - ); + }) => EVMChainNewWalletCredentials( + name: name, + walletInfo: walletInfo, + password: password, + mnemonic: mnemonic, + passphrase: passphrase, + ); @override WalletCredentials createPolygonRestoreWalletFromSeedCredentials({ @@ -29,30 +28,30 @@ class CWPolygon extends Polygon { required String mnemonic, required String password, String? passphrase, - }) => - EVMChainRestoreWalletFromSeedCredentials( - name: name, - password: password, - mnemonic: mnemonic, - passphrase: passphrase, - ); + }) => EVMChainRestoreWalletFromSeedCredentials( + name: name, + password: password, + mnemonic: mnemonic, + passphrase: passphrase, + ); @override WalletCredentials createPolygonRestoreWalletFromPrivateKey({ required String name, required String privateKey, required String password, - }) => - EVMChainRestoreWalletFromPrivateKey(name: name, password: password, privateKey: privateKey); + }) => EVMChainRestoreWalletFromPrivateKey(name: name, password: password, privateKey: privateKey); @override WalletCredentials createPolygonHardwareWalletCredentials({ required String name, required HardwareAccountData hwAccountData, WalletInfo? walletInfo, - }) => - EVMChainRestoreWalletFromHardware( - name: name, hwAccountData: hwAccountData, walletInfo: walletInfo); + }) => EVMChainRestoreWalletFromHardware( + name: name, + hwAccountData: hwAccountData, + walletInfo: walletInfo, + ); @override String getAddress(WalletBase wallet) => (wallet as PolygonWallet).walletAddresses.address; @@ -88,43 +87,47 @@ class CWPolygon extends Polygon { required TransactionPriority priority, required CryptoCurrency currency, int? feeRate, - }) => - EVMChainTransactionCredentials( - outputs - .map((out) => OutputInfo( - fiatAmount: out.fiatAmount, - cryptoAmount: out.cryptoAmount, - address: out.address, - note: out.note, - sendAll: out.sendAll, - extractedAddress: out.extractedAddress, - isParsedAddress: out.isParsedAddress, - formattedCryptoAmount: out.formattedCryptoAmount)) - .toList(), - priority: priority as EVMChainTransactionPriority, - currency: currency, - feeRate: feeRate, - ); + }) => EVMChainTransactionCredentials( + outputs + .map( + (out) => OutputInfo( + fiatAmount: out.fiatAmount, + cryptoAmount: out.cryptoAmount, + address: out.address, + note: out.note, + sendAll: out.sendAll, + extractedAddress: out.extractedAddress, + isParsedAddress: out.isParsedAddress, + formattedCryptoAmount: out.formattedCryptoAmount, + ), + ) + .toList(), + priority: priority as EVMChainTransactionPriority, + currency: currency, + feeRate: feeRate, + ); Object createPolygonTransactionCredentialsRaw( List outputs, { TransactionPriority? priority, required CryptoCurrency currency, required int feeRate, - }) => - EVMChainTransactionCredentials( - outputs, - priority: priority as EVMChainTransactionPriority?, - currency: currency, - feeRate: feeRate, - ); + }) => EVMChainTransactionCredentials( + outputs, + priority: priority as EVMChainTransactionPriority?, + currency: currency, + feeRate: feeRate, + ); @override int formatterPolygonParseAmount(String amount) => EVMChainFormatter.parseEVMChainAmount(amount); @override - double formatterPolygonAmountToDouble( - {TransactionInfo? transaction, BigInt? amount, int exponent = 18}) { + double formatterPolygonAmountToDouble({ + TransactionInfo? transaction, + BigInt? amount, + int exponent = 18, + }) { assert(transaction != null || amount != null); if (transaction != null) { @@ -148,14 +151,11 @@ class CWPolygon extends Polygon { (wallet as PolygonWallet).deleteErc20Token(token as Erc20Token); @override - Future removeTokenTransactionsInHistory( - WalletBase wallet, CryptoCurrency token) => - (wallet as PolygonWallet) - .removeTokenTransactionsInHistory(token as Erc20Token); + Future removeTokenTransactionsInHistory(WalletBase wallet, CryptoCurrency token) => + (wallet as PolygonWallet).removeTokenTransactionsInHistory(token as Erc20Token); @override - Future getErc20Token( - WalletBase wallet, String contractAddress) => + Future getErc20Token(WalletBase wallet, String contractAddress) => (wallet as PolygonWallet).getErc20Token(contractAddress, 'polygon'); @override @@ -169,7 +169,7 @@ class CWPolygon extends Polygon { wallet as PolygonWallet; return wallet.erc20Currencies.firstWhere( - (element) => transaction.tokenSymbol.toLowerCase() == element.symbol.toLowerCase(), + (element) => transaction.contractAddress?.toLowerCase() == element.contractAddress?.toLowerCase(), ); } @@ -178,30 +178,40 @@ class CWPolygon extends Polygon { (wallet as PolygonWallet).updateScanProviderUsageState(isEnabled); @override - Web3Client? getWeb3Client(WalletBase wallet) => - (wallet as PolygonWallet).getWeb3Client(); + Web3Client? getWeb3Client(WalletBase wallet) => (wallet as PolygonWallet).getWeb3Client(); @override - String getTokenAddress(CryptoCurrency asset) => - (asset as Erc20Token).contractAddress; + String getTokenAddress(CryptoCurrency asset) => (asset as Erc20Token).contractAddress; @override - Future createTokenApproval(WalletBase wallet, - BigInt amount, String spender, CryptoCurrency token, TransactionPriority priority) => - (wallet as EVMChainWallet) - .createApprovalTransaction(amount, spender, token, priority as EVMChainTransactionPriority, "POL"); + Future createTokenApproval( + WalletBase wallet, + BigInt amount, + String spender, + CryptoCurrency token, + TransactionPriority priority, + ) => (wallet as EVMChainWallet).createApprovalTransaction( + amount, + spender, + token, + priority as EVMChainTransactionPriority, + "POL", + ); @override - void setLedgerConnection( - WalletBase wallet, ledger.LedgerConnection connection) { - ((wallet as EVMChainWallet).evmChainPrivateKey as EvmLedgerCredentials) - .setLedgerConnection( - connection, wallet.walletInfo.derivationInfo?.derivationPath); + void setLedgerConnection(WalletBase wallet, ledger.LedgerConnection connection) { + ((wallet as EVMChainWallet).evmChainPrivateKey as EvmLedgerCredentials).setLedgerConnection( + connection, + wallet.walletInfo.derivationInfo?.derivationPath, + ); } @override - Future> getHardwareWalletAccounts(LedgerViewModel ledgerVM, - {int index = 0, int limit = 5}) async { + Future> getHardwareWalletAccounts( + LedgerViewModel ledgerVM, { + int index = 0, + int limit = 5, + }) async { final hardwareWalletService = EVMChainHardwareWalletService(ledgerVM.connection); try { return await hardwareWalletService.getAvailableAccounts(index: index, limit: limit); @@ -212,14 +222,14 @@ class CWPolygon extends Polygon { } @override - List getDefaultTokenContractAddresses() => DefaultPolygonErc20Tokens() - .initialPolygonErc20Tokens - .map((e) => e.contractAddress) - .toList(); + List getDefaultTokenContractAddresses() => + DefaultPolygonErc20Tokens().initialPolygonErc20Tokens.map((e) => e.contractAddress).toList(); @override bool isTokenAlreadyAdded(WalletBase wallet, String contractAddress) { final polygonWallet = wallet as PolygonWallet; - return polygonWallet.erc20Currencies.any((element) => element.contractAddress.toLowerCase() == contractAddress.toLowerCase()); + return polygonWallet.erc20Currencies.any( + (element) => element.contractAddress.toLowerCase() == contractAddress.toLowerCase(), + ); } }