| 1 | import "package:cw_core/receive_page_option.dart"; |
| 2 | import 'package:mobx/mobx.dart'; |
| 3 | import 'package:cw_core/balance.dart'; |
| 4 | import 'package:cw_core/transaction_info.dart'; |
| 5 | import 'package:cw_core/transaction_history.dart'; |
| 6 | import 'package:cw_core/transaction_priority.dart'; |
| 7 | import 'package:cw_core/wallet_addresses.dart'; |
| 8 | import 'package:flutter/foundation.dart'; |
| 9 | import 'package:cw_core/wallet_info.dart'; |
| 10 | import 'package:cw_core/pending_transaction.dart'; |
| 11 | import 'package:cw_core/currency_for_wallet_type.dart'; |
| 12 | import 'package:cw_core/crypto_currency.dart'; |
| 13 | import 'package:cw_core/sync_status.dart'; |
| 14 | import 'package:cw_core/node.dart'; |
| 15 | import 'package:cw_core/wallet_type.dart'; |
| 16 | import 'package:cw_core/pathForWallet.dart'; |
| 17 | |
| 18 | abstract class WalletBase<BalanceType extends Balance, HistoryType extends TransactionHistoryBase, |
| 19 | TransactionType extends TransactionInfo> { |
| 20 | WalletBase(this.walletInfo, this.derivationInfo); |
| 21 | |
| 22 | static String idFor(String name, WalletType type) => |
| 23 | walletTypeToString(type).toLowerCase() + '_' + name; |
| 24 | |
| 25 | WalletInfo walletInfo; |
| 26 | DerivationInfo derivationInfo; |
| 27 | |
| 28 | WalletType get type => walletInfo.type; |
| 29 | |
| 30 | int? get chainId => null; |
| 31 | |
| 32 | CryptoCurrency get currency => walletTypeToCryptoCurrency( |
| 33 | type, |
| 34 | chainId: chainId, |
| 35 | isTestnet: isTestnet, |
| 36 | ); |
| 37 | |
| 38 | String get id => walletInfo.id; |
| 39 | |
| 40 | String get name => walletInfo.name; |
| 41 | |
| 42 | //String get address; |
| 43 | |
| 44 | //set address(String address); |
| 45 | |
| 46 | ObservableMap<CryptoCurrency, BalanceType> get balance; |
| 47 | |
| 48 | SyncStatus get syncStatus; |
| 49 | |
| 50 | set syncStatus(SyncStatus status); |
| 51 | |
| 52 | String? get seed; |
| 53 | |
| 54 | String? get privateKey => null; |
| 55 | |
| 56 | String? get hexSeed => null; |
| 57 | |
| 58 | String? get passphrase => null; |
| 59 | |
| 60 | Object get keys; |
| 61 | |
| 62 | WalletAddresses get walletAddresses; |
| 63 | |
| 64 | late HistoryType transactionHistory; |
| 65 | |
| 66 | set isEnabledAutoGenerateSubaddress(bool value) {} |
| 67 | |
| 68 | bool get isEnabledAutoGenerateSubaddress => false; |
| 69 | |
| 70 | bool get isHardwareWallet => walletInfo.isHardwareWallet; |
| 71 | |
| 72 | bool get isSoftwareWallet => walletInfo.hardwareWalletType == null; |
| 73 | |
| 74 | HardwareWalletType? get hardwareWalletType => walletInfo.hardwareWalletType; |
| 75 | |
| 76 | bool get hasRescan => false; |
| 77 | |
| 78 | Future<void> connectToNode({required Node node}); |
| 79 | |
| 80 | // there is a default definition here because only coins with a pow node (nano based) need to override this |
| 81 | Future<void> connectToPowNode({required Node node}) async {} |
| 82 | |
| 83 | // startBackgroundSync is used to start sync in the background, without doing any |
| 84 | // extra things in the background. |
| 85 | // startSync is used as a fallback. |
| 86 | Future<void> startBackgroundSync() => startSync(); |
| 87 | Future<void> stopBackgroundSync(String password) => stopSync(); |
| 88 | |
| 89 | Future<void> startSync(); |
| 90 | |
| 91 | Future<void> stopSync() async {} |
| 92 | |
| 93 | Future<PendingTransaction> createTransaction(Object credentials); |
| 94 | |
| 95 | int calculateEstimatedFee(TransactionPriority priority, int? amount); |
| 96 | |
| 97 | Future<void> updateEstimatedFeesParams(TransactionPriority? priority) async {} |
| 98 | |
| 99 | // void fetchTransactionsAsync( |
| 100 | // void Function(TransactionType transaction) onTransactionLoaded, |
| 101 | // {void Function() onFinished}); |
| 102 | |
| 103 | Future<Map<String, TransactionType>> fetchTransactions(); |
| 104 | |
| 105 | Future<void> save(); |
| 106 | |
| 107 | Future<void> rescan({required int height}); |
| 108 | |
| 109 | Future<void> close({bool shouldCleanup = false}); |
| 110 | |
| 111 | Future<void> changePassword(String password); |
| 112 | |
| 113 | String get password; |
| 114 | |
| 115 | Future<void>? updateBalance(); |
| 116 | Future<void> updateTransactionsHistory() async {} |
| 117 | |
| 118 | void setExceptionHandler(void Function(FlutterErrorDetails) onError) => null; |
| 119 | |
| 120 | Future<void> renameWalletFiles(String newWalletName) => |
| 121 | copyWalletFilesTo(fromName: walletInfo.name, toName: newWalletName, type: type); |
| 122 | |
| 123 | Future<String> signMessage(String message, {String? address = null}); |
| 124 | |
| 125 | Future<bool> verifyMessage(String message, String signature, {String? address = null}); |
| 126 | |
| 127 | bool isTestnet = false; |
| 128 | |
| 129 | bool canSend() => true; |
| 130 | |
| 131 | /// Check if the wallet's socket connection is healthy. |
| 132 | /// Returns true if the connection is alive, false otherwise. |
| 133 | /// Default implementation returns true (no-op for wallets without socket connections). |
| 134 | Future<bool> checkSocketHealth() async => true; |
| 135 | |
| 136 | /// This is used to check if the current node is healthy by making a lightweight RPC call |
| 137 | /// Each wallet implementation should override this to make a single, efficient call |
| 138 | /// Returns true if the node is healthy, false otherwise |
| 139 | Future<bool> checkNodeHealth(); |
| 140 | |
| 141 | bool get hasPayjoinSupport => false; |
| 142 | bool get hasLightningSupport => false; |
| 143 | bool get hasSilentPaymentsScanning => false; |
| 144 | |
| 145 | // hardware wallet - bitbox, ledger, trezor. |
| 146 | // we also have airgap wallets but those can't sign messages |
| 147 | bool get canSignMessages => walletInfo.hardwareWalletType == null || walletInfo.isHardwareWallet; |
| 148 | |
| 149 | bool receiveOptionAvailable(ReceivePageOption option) => true; |
| 150 | } |