mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-12-04 12:34:14 +01:00
Add Base Wallet (#2558)
* chore: Create Base package template * chore: Update configuration scripts and dependencies to include 'base' coin support * chore: Update pubspec.yaml, adjust SDK constraints, and add new dependencies * feat: Add support for base wallet type and cryptocurrency in related configurations * feat: Implement BaseWallet and DefaultBaseTokens classes for managing base cryptocurrency transactions * feat: Add BaseTransactionHistory and BaseTransactionInfo classes for handling base cryptocurrency transaction data * feat: Implement BaseClient, BaseWalletService, and BaseMnemonicIsIncorrectException * feat: Setup base proxy for main package and adjust token class name * feat: Setup initial base node configuration * feat: Integrate support for base wallet type across various functions and services * feat: Add base support to exchange and outputs * feat: Add base wallet type integration to wallet creation and node management * feat: Add base support to transaction details and transaction list item * feat: Implement BaseURI class and add base support across wallet creation and keys view models * feat: Add support for BaseScan preference in settings store * feat: Integrate Base support into various workflows and documentation * feat: Addingbase config to windows and secret key support * feat: Add base support to settings and address handling * chore: Move walletTypeToCurrency to another file and adjust across codebase * feat: Add 'basescan_history' string localization * feat: Remove Cryptocurrency.base, it doesn't have a base currency * feat: Set eth as native currency * feat: Enhance Base support across various sending, exchange, transaction details, fees, dashboard and balance * feat: Integrate Base wallet support in advanced privacy settings and home settings view models * feat: Add Base wallet support with icon and integration across providers, default settings migration, preferences, wallet connect, settings and token utilities * feat: Update currency handling to use baseEth for Base wallet integration across various components * fix: Update default token symbol to ETH in Base wallet transaction model * refactor: Change default currency references from BASE to ETH across client, transaction info, and wallet components * feat: Introduce normalizedIconPath for CryptoCurrency to standardize icon retrieval across wallet components * fix: Include baseEth as a native token in EVMChainClient for currency handling * chore: Update base_icon.png * feat: Add more nodes to base_node_list.yml * refactor: Update wallet icon retrieval to use normalizedIconPath * chore: Remove unused cases and cleanup impl. * feat: Add base proxy generation to configure * refactor: Update base proxy and generation code in configure.dart * feat: Add missing wallet and mono images * fix: Wrong image path for pr and add missing base qr image * feat: Enhance EVMTransactionErrorFeesHandler to parse new insufficient funds error format and calculate transaction fees in ETH and USD * feat: Add gas price safety buffer for Base chain transactions to improve fee estimation accuracy, also fixes send all not calculating correctly * Update model_generator.sh [skip ci] * Update assets/base_node_list.yml [skip ci] * Update cw_base/lib/default_base_erc20_tokens.dart [skip ci] * Review fixes * fixes --------- Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
This commit is contained in:
co-authored by
OmarHatem
parent
025fc9154c
commit
2a74317aff
@@ -0,0 +1,238 @@
|
||||
part of 'base.dart';
|
||||
|
||||
class CWBase extends Base {
|
||||
@override
|
||||
List<String> getBaseWordList(String language) => EVMChainMnemonics.englishWordlist;
|
||||
|
||||
WalletService createBaseWalletService(Box<WalletInfo> walletInfoSource, bool isDirect) =>
|
||||
BaseWalletService(walletInfoSource, isDirect, client: BaseClient());
|
||||
|
||||
@override
|
||||
WalletCredentials createBaseNewWalletCredentials({
|
||||
required String name,
|
||||
String? mnemonic,
|
||||
WalletInfo? walletInfo,
|
||||
String? password,
|
||||
String? passphrase,
|
||||
}) =>
|
||||
EVMChainNewWalletCredentials(
|
||||
name: name,
|
||||
walletInfo: walletInfo,
|
||||
password: password,
|
||||
mnemonic: mnemonic,
|
||||
passphrase: passphrase,
|
||||
);
|
||||
|
||||
@override
|
||||
WalletCredentials createBaseRestoreWalletFromSeedCredentials({
|
||||
required String name,
|
||||
required String mnemonic,
|
||||
required String password,
|
||||
String? passphrase,
|
||||
}) =>
|
||||
EVMChainRestoreWalletFromSeedCredentials(
|
||||
name: name,
|
||||
password: password,
|
||||
mnemonic: mnemonic,
|
||||
passphrase: passphrase,
|
||||
);
|
||||
|
||||
@override
|
||||
WalletCredentials createBaseRestoreWalletFromPrivateKey({
|
||||
required String name,
|
||||
required String privateKey,
|
||||
required String password,
|
||||
}) =>
|
||||
EVMChainRestoreWalletFromPrivateKey(name: name, password: password, privateKey: privateKey);
|
||||
|
||||
@override
|
||||
WalletCredentials createBaseHardwareWalletCredentials({
|
||||
required String name,
|
||||
required HardwareAccountData hwAccountData,
|
||||
WalletInfo? walletInfo,
|
||||
}) =>
|
||||
EVMChainRestoreWalletFromHardware(
|
||||
name: name,
|
||||
hwAccountData: hwAccountData,
|
||||
walletInfo: walletInfo,
|
||||
);
|
||||
|
||||
@override
|
||||
String getAddress(WalletBase wallet) => (wallet as BaseWallet).walletAddresses.address;
|
||||
|
||||
@override
|
||||
String getPrivateKey(WalletBase wallet) {
|
||||
final privateKeyHolder = (wallet as BaseWallet).evmChainPrivateKey;
|
||||
if (privateKeyHolder is EthPrivateKey) return bytesToHex(privateKeyHolder.privateKey);
|
||||
return "";
|
||||
}
|
||||
|
||||
@override
|
||||
String getPublicKey(WalletBase wallet) {
|
||||
final privateKeyInUnitInt = (wallet as BaseWallet).evmChainPrivateKey;
|
||||
return privateKeyInUnitInt.address.hex;
|
||||
}
|
||||
|
||||
@override
|
||||
TransactionPriority getDefaultTransactionPriority() => EVMChainTransactionPriority.medium;
|
||||
|
||||
@override
|
||||
TransactionPriority getBaseTransactionPrioritySlow() => EVMChainTransactionPriority.slow;
|
||||
|
||||
@override
|
||||
List<TransactionPriority> getTransactionPriorities() => EVMChainTransactionPriority.all;
|
||||
|
||||
@override
|
||||
TransactionPriority deserializeBaseTransactionPriority(int raw) =>
|
||||
EVMChainTransactionPriority.deserialize(raw: raw);
|
||||
|
||||
Object createBaseTransactionCredentials(
|
||||
List<Output> outputs, {
|
||||
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,
|
||||
);
|
||||
|
||||
Object createBaseTransactionCredentialsRaw(
|
||||
List<OutputInfo> outputs, {
|
||||
TransactionPriority? priority,
|
||||
required CryptoCurrency currency,
|
||||
required int feeRate,
|
||||
}) =>
|
||||
EVMChainTransactionCredentials(
|
||||
outputs,
|
||||
priority: priority as EVMChainTransactionPriority?,
|
||||
currency: currency,
|
||||
feeRate: feeRate,
|
||||
);
|
||||
|
||||
@override
|
||||
int formatterBaseParseAmount(String amount) => EVMChainFormatter.parseEVMChainAmount(amount);
|
||||
|
||||
@override
|
||||
double formatterBaseAmountToDouble({
|
||||
TransactionInfo? transaction,
|
||||
BigInt? amount,
|
||||
int exponent = 18,
|
||||
}) {
|
||||
assert(transaction != null || amount != null);
|
||||
|
||||
if (transaction != null) {
|
||||
transaction as EVMChainTransactionInfo;
|
||||
return transaction.ethAmount / BigInt.from(10).pow(transaction.exponent);
|
||||
} else {
|
||||
return (amount!) / BigInt.from(10).pow(exponent);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
List<Erc20Token> getERC20Currencies(WalletBase wallet) => (wallet as BaseWallet).erc20Currencies;
|
||||
|
||||
@override
|
||||
Future<void> addErc20Token(WalletBase wallet, CryptoCurrency token) =>
|
||||
(wallet as BaseWallet).addErc20Token(token as Erc20Token);
|
||||
|
||||
@override
|
||||
Future<void> deleteErc20Token(WalletBase wallet, CryptoCurrency token) =>
|
||||
(wallet as BaseWallet).deleteErc20Token(token as Erc20Token);
|
||||
|
||||
@override
|
||||
Future<void> removeTokenTransactionsInHistory(WalletBase wallet, CryptoCurrency token) =>
|
||||
(wallet as BaseWallet).removeTokenTransactionsInHistory(token as Erc20Token);
|
||||
|
||||
@override
|
||||
Future<Erc20Token?> getErc20Token(WalletBase wallet, String contractAddress) =>
|
||||
(wallet as BaseWallet).getErc20Token(contractAddress, 'base');
|
||||
|
||||
@override
|
||||
CryptoCurrency assetOfTransaction(WalletBase wallet, TransactionInfo transaction) {
|
||||
transaction as EVMChainTransactionInfo;
|
||||
if (transaction.tokenSymbol == CryptoCurrency.baseEth.title ||
|
||||
transaction.tokenSymbol == "BASE") {
|
||||
return CryptoCurrency.baseEth;
|
||||
}
|
||||
|
||||
wallet as BaseWallet;
|
||||
|
||||
return wallet.erc20Currencies.firstWhere(
|
||||
(element) =>
|
||||
transaction.contractAddress?.toLowerCase() == element.contractAddress?.toLowerCase(),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void updateBaseScanUsageState(WalletBase wallet, bool isEnabled) =>
|
||||
(wallet as BaseWallet).updateScanProviderUsageState(isEnabled);
|
||||
|
||||
@override
|
||||
Web3Client? getWeb3Client(WalletBase wallet) => (wallet as BaseWallet).getWeb3Client();
|
||||
|
||||
@override
|
||||
String getTokenAddress(CryptoCurrency asset) => (asset as Erc20Token).contractAddress;
|
||||
|
||||
@override
|
||||
Future<PendingTransaction> createTokenApproval(
|
||||
WalletBase wallet,
|
||||
BigInt amount,
|
||||
String spender,
|
||||
CryptoCurrency token,
|
||||
TransactionPriority priority,
|
||||
) =>
|
||||
(wallet as EVMChainWallet).createApprovalTransaction(
|
||||
amount,
|
||||
spender,
|
||||
token,
|
||||
priority as EVMChainTransactionPriority,
|
||||
"BASE",
|
||||
);
|
||||
|
||||
@override
|
||||
void setHardwareWalletService(WalletBase wallet, HardwareWalletService service) {
|
||||
if (service is EVMChainLedgerService) {
|
||||
((wallet as EVMChainWallet).evmChainPrivateKey as EvmLedgerCredentials).setLedgerConnection(
|
||||
service.ledgerConnection, wallet.walletInfo.derivationInfo?.derivationPath);
|
||||
} else if (service is EVMChainBitboxService) {
|
||||
((wallet as EVMChainWallet).evmChainPrivateKey as EvmBitboxCredentials)
|
||||
.setBitbox(service.manager, wallet.walletInfo.derivationInfo?.derivationPath);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
HardwareWalletService getLedgerHardwareWalletService(ledger.LedgerConnection connection) =>
|
||||
EVMChainLedgerService(connection);
|
||||
|
||||
@override
|
||||
HardwareWalletService getBitboxHardwareWalletService(bitbox.BitboxManager manager) =>
|
||||
EVMChainBitboxService(manager, chainId: 8453);
|
||||
|
||||
@override
|
||||
List<String> getDefaultTokenContractAddresses() =>
|
||||
DefaultBaseErc20Tokens().initialBaseErc20Tokens.map((e) => e.contractAddress).toList();
|
||||
|
||||
@override
|
||||
bool isTokenAlreadyAdded(WalletBase wallet, String contractAddress) {
|
||||
final baseWallet = wallet as BaseWallet;
|
||||
return baseWallet.erc20Currencies.any(
|
||||
(element) => element.contractAddress.toLowerCase() == contractAddress.toLowerCase(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user