CW-551-Refactor-EVM-Chains (#1256)
* feat: Create central package for EVM chains
* chore: Cleanup pubspec and add core evm dependencies
* feat: Replicated core evm chain files, time to start fixing the issues
* feat: Setup evm central package to handle all evm chains
* feat: Link up Polygon and Ethereum wallets to the centra evm package, fix bugs and issues, and optimze for better performance
* feat: Setup and adjust configs to reflect new evm configurations
* Remove unneeded file
* fix: Changes done while re-reviewing entire structure and refactor
* fix: Add evm chain wallet path to imports in configure file
* feat: Adjust implementation of parent class, remove unneeded files, remove windows, linux and mac directories, restructure the evm child classes
* fix: Make EVMChainWallet a central abstract class and adjust accordingly
* fix: Adjust transaction info, restructure EVMWalletChain to be an abstract, adjust external facing interfaces for polygon and ethereum, adjust configuration for ethereum and polygon in configure file
* fix: Testing issues
* fix: Add localization for nft tile and details page texts and add dashes for null responses
* fix: merge conflicts
* Minor fixes for building Monero.com
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
2024-01-30 18:01:48 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
import 'dart:core';
|
|
|
|
import 'dart:developer';
|
2024-02-03 02:00:35 +00:00
|
|
|
import 'package:cw_core/encryption_file_utils.dart';
|
CW-551-Refactor-EVM-Chains (#1256)
* feat: Create central package for EVM chains
* chore: Cleanup pubspec and add core evm dependencies
* feat: Replicated core evm chain files, time to start fixing the issues
* feat: Setup evm central package to handle all evm chains
* feat: Link up Polygon and Ethereum wallets to the centra evm package, fix bugs and issues, and optimze for better performance
* feat: Setup and adjust configs to reflect new evm configurations
* Remove unneeded file
* fix: Changes done while re-reviewing entire structure and refactor
* fix: Add evm chain wallet path to imports in configure file
* feat: Adjust implementation of parent class, remove unneeded files, remove windows, linux and mac directories, restructure the evm child classes
* fix: Make EVMChainWallet a central abstract class and adjust accordingly
* fix: Adjust transaction info, restructure EVMWalletChain to be an abstract, adjust external facing interfaces for polygon and ethereum, adjust configuration for ethereum and polygon in configure file
* fix: Testing issues
* fix: Add localization for nft tile and details page texts and add dashes for null responses
* fix: merge conflicts
* Minor fixes for building Monero.com
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
2024-01-30 18:01:48 +00:00
|
|
|
import 'package:cw_core/pathForWallet.dart';
|
|
|
|
import 'package:cw_core/wallet_info.dart';
|
|
|
|
import 'package:cw_evm/evm_chain_transaction_info.dart';
|
|
|
|
import 'package:mobx/mobx.dart';
|
|
|
|
import 'package:cw_core/transaction_history.dart';
|
|
|
|
|
|
|
|
part 'evm_chain_transaction_history.g.dart';
|
|
|
|
|
|
|
|
abstract class EVMChainTransactionHistory = EVMChainTransactionHistoryBase
|
|
|
|
with _$EVMChainTransactionHistory;
|
|
|
|
|
|
|
|
abstract class EVMChainTransactionHistoryBase
|
|
|
|
extends TransactionHistoryBase<EVMChainTransactionInfo> with Store {
|
2024-02-03 02:00:35 +00:00
|
|
|
EVMChainTransactionHistoryBase(
|
|
|
|
{required this.walletInfo, required String password, required this.encryptionFileUtils})
|
CW-551-Refactor-EVM-Chains (#1256)
* feat: Create central package for EVM chains
* chore: Cleanup pubspec and add core evm dependencies
* feat: Replicated core evm chain files, time to start fixing the issues
* feat: Setup evm central package to handle all evm chains
* feat: Link up Polygon and Ethereum wallets to the centra evm package, fix bugs and issues, and optimze for better performance
* feat: Setup and adjust configs to reflect new evm configurations
* Remove unneeded file
* fix: Changes done while re-reviewing entire structure and refactor
* fix: Add evm chain wallet path to imports in configure file
* feat: Adjust implementation of parent class, remove unneeded files, remove windows, linux and mac directories, restructure the evm child classes
* fix: Make EVMChainWallet a central abstract class and adjust accordingly
* fix: Adjust transaction info, restructure EVMWalletChain to be an abstract, adjust external facing interfaces for polygon and ethereum, adjust configuration for ethereum and polygon in configure file
* fix: Testing issues
* fix: Add localization for nft tile and details page texts and add dashes for null responses
* fix: merge conflicts
* Minor fixes for building Monero.com
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
2024-01-30 18:01:48 +00:00
|
|
|
: _password = password {
|
|
|
|
transactions = ObservableMap<String, EVMChainTransactionInfo>();
|
|
|
|
}
|
|
|
|
|
|
|
|
String _password;
|
|
|
|
|
|
|
|
final WalletInfo walletInfo;
|
2024-02-03 02:00:35 +00:00
|
|
|
final EncryptionFileUtils encryptionFileUtils;
|
CW-551-Refactor-EVM-Chains (#1256)
* feat: Create central package for EVM chains
* chore: Cleanup pubspec and add core evm dependencies
* feat: Replicated core evm chain files, time to start fixing the issues
* feat: Setup evm central package to handle all evm chains
* feat: Link up Polygon and Ethereum wallets to the centra evm package, fix bugs and issues, and optimze for better performance
* feat: Setup and adjust configs to reflect new evm configurations
* Remove unneeded file
* fix: Changes done while re-reviewing entire structure and refactor
* fix: Add evm chain wallet path to imports in configure file
* feat: Adjust implementation of parent class, remove unneeded files, remove windows, linux and mac directories, restructure the evm child classes
* fix: Make EVMChainWallet a central abstract class and adjust accordingly
* fix: Adjust transaction info, restructure EVMWalletChain to be an abstract, adjust external facing interfaces for polygon and ethereum, adjust configuration for ethereum and polygon in configure file
* fix: Testing issues
* fix: Add localization for nft tile and details page texts and add dashes for null responses
* fix: merge conflicts
* Minor fixes for building Monero.com
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
2024-01-30 18:01:48 +00:00
|
|
|
|
|
|
|
//! Method to be overridden by all child classes
|
|
|
|
|
|
|
|
String getTransactionHistoryFileName();
|
|
|
|
|
|
|
|
EVMChainTransactionInfo getTransactionInfo(Map<String, dynamic> val);
|
|
|
|
|
|
|
|
//! Common methods across all child classes
|
|
|
|
|
|
|
|
Future<void> init() async => await _load();
|
|
|
|
|
|
|
|
@override
|
|
|
|
Future<void> save() async {
|
|
|
|
final transactionsHistoryFileNameForWallet = getTransactionHistoryFileName();
|
|
|
|
try {
|
|
|
|
final dirPath = await pathForWalletDir(name: walletInfo.name, type: walletInfo.type);
|
|
|
|
String path = '$dirPath/$transactionsHistoryFileNameForWallet';
|
|
|
|
final data = json.encode({'transactions': transactions});
|
2024-02-03 02:00:35 +00:00
|
|
|
await encryptionFileUtils.write(path: path, password: _password, data: data);
|
CW-551-Refactor-EVM-Chains (#1256)
* feat: Create central package for EVM chains
* chore: Cleanup pubspec and add core evm dependencies
* feat: Replicated core evm chain files, time to start fixing the issues
* feat: Setup evm central package to handle all evm chains
* feat: Link up Polygon and Ethereum wallets to the centra evm package, fix bugs and issues, and optimze for better performance
* feat: Setup and adjust configs to reflect new evm configurations
* Remove unneeded file
* fix: Changes done while re-reviewing entire structure and refactor
* fix: Add evm chain wallet path to imports in configure file
* feat: Adjust implementation of parent class, remove unneeded files, remove windows, linux and mac directories, restructure the evm child classes
* fix: Make EVMChainWallet a central abstract class and adjust accordingly
* fix: Adjust transaction info, restructure EVMWalletChain to be an abstract, adjust external facing interfaces for polygon and ethereum, adjust configuration for ethereum and polygon in configure file
* fix: Testing issues
* fix: Add localization for nft tile and details page texts and add dashes for null responses
* fix: merge conflicts
* Minor fixes for building Monero.com
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
2024-01-30 18:01:48 +00:00
|
|
|
} catch (e, s) {
|
|
|
|
log('Error while saving ${walletInfo.type.name} transaction history: ${e.toString()}');
|
|
|
|
log(s.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void addOne(EVMChainTransactionInfo transaction) => transactions[transaction.id] = transaction;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void addMany(Map<String, EVMChainTransactionInfo> transactions) =>
|
|
|
|
this.transactions.addAll(transactions);
|
|
|
|
|
|
|
|
Future<Map<String, dynamic>> _read() async {
|
|
|
|
final transactionsHistoryFileNameForWallet = getTransactionHistoryFileName();
|
|
|
|
final dirPath = await pathForWalletDir(name: walletInfo.name, type: walletInfo.type);
|
|
|
|
String path = '$dirPath/$transactionsHistoryFileNameForWallet';
|
2024-02-03 02:00:35 +00:00
|
|
|
final content = await encryptionFileUtils.read(path: path, password: _password);
|
CW-551-Refactor-EVM-Chains (#1256)
* feat: Create central package for EVM chains
* chore: Cleanup pubspec and add core evm dependencies
* feat: Replicated core evm chain files, time to start fixing the issues
* feat: Setup evm central package to handle all evm chains
* feat: Link up Polygon and Ethereum wallets to the centra evm package, fix bugs and issues, and optimze for better performance
* feat: Setup and adjust configs to reflect new evm configurations
* Remove unneeded file
* fix: Changes done while re-reviewing entire structure and refactor
* fix: Add evm chain wallet path to imports in configure file
* feat: Adjust implementation of parent class, remove unneeded files, remove windows, linux and mac directories, restructure the evm child classes
* fix: Make EVMChainWallet a central abstract class and adjust accordingly
* fix: Adjust transaction info, restructure EVMWalletChain to be an abstract, adjust external facing interfaces for polygon and ethereum, adjust configuration for ethereum and polygon in configure file
* fix: Testing issues
* fix: Add localization for nft tile and details page texts and add dashes for null responses
* fix: merge conflicts
* Minor fixes for building Monero.com
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
2024-01-30 18:01:48 +00:00
|
|
|
if (content.isEmpty) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
return json.decode(content) as Map<String, dynamic>;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _load() async {
|
|
|
|
try {
|
|
|
|
final content = await _read();
|
|
|
|
final txs = content['transactions'] as Map<String, dynamic>? ?? {};
|
|
|
|
|
|
|
|
for (var entry in txs.entries) {
|
|
|
|
final val = entry.value;
|
|
|
|
|
|
|
|
if (val is Map<String, dynamic>) {
|
|
|
|
final tx = getTransactionInfo(val);
|
|
|
|
_update(tx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
log(e.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void _update(EVMChainTransactionInfo transaction) => transactions[transaction.id] = transaction;
|
|
|
|
}
|