mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-19 05:58:50 +02:00
* 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>
212 lines
7.5 KiB
Dart
212 lines
7.5 KiB
Dart
import 'package:cake_wallet/base/base.dart';
|
|
import 'package:cake_wallet/bitcoin_cash/bitcoin_cash.dart';
|
|
import 'package:cake_wallet/decred/decred.dart';
|
|
import 'package:cake_wallet/dogecoin/dogecoin.dart';
|
|
import 'package:cake_wallet/entities/priority_for_wallet_type.dart';
|
|
import 'package:cake_wallet/core/wallet_change_listener_view_model.dart';
|
|
import 'package:cake_wallet/ethereum/ethereum.dart';
|
|
import 'package:cake_wallet/monero/monero.dart';
|
|
import 'package:cake_wallet/polygon/polygon.dart';
|
|
import 'package:cake_wallet/store/app_store.dart';
|
|
import 'package:cake_wallet/view_model/dashboard/balance_view_model.dart';
|
|
import 'package:cw_core/crypto_currency.dart';
|
|
import 'package:cw_core/transaction_priority.dart';
|
|
import 'package:mobx/mobx.dart';
|
|
import 'package:cake_wallet/entities/fiat_currency.dart';
|
|
import 'package:cw_core/wallet_type.dart';
|
|
import 'package:cake_wallet/store/settings_store.dart';
|
|
import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
|
import 'package:collection/collection.dart';
|
|
|
|
part 'fees_view_model.g.dart';
|
|
|
|
class FeesViewModel = FeesViewModelBase with _$FeesViewModel;
|
|
|
|
abstract class FeesViewModelBase extends WalletChangeListenerViewModel with Store {
|
|
FeesViewModelBase(
|
|
AppStore appStore,
|
|
this.balanceViewModel,
|
|
) : _settingsStore = appStore.settingsStore,
|
|
super(appStore: appStore) {
|
|
if (wallet.type == WalletType.bitcoin &&
|
|
_settingsStore.priority[wallet.type] == bitcoinTransactionPriorityCustom) {
|
|
setTransactionPriority(bitcoinTransactionPriorityMedium);
|
|
}
|
|
final priority = _settingsStore.priority[wallet.type];
|
|
final priorities = priorityForWalletType(wallet.type);
|
|
if (!priorityForWalletType(wallet.type).contains(priority) && priorities.isNotEmpty) {
|
|
_settingsStore.priority[wallet.type] = priorities.first;
|
|
}
|
|
}
|
|
|
|
@computed
|
|
WalletType get walletType => wallet.type;
|
|
CryptoCurrency get currency => wallet.currency;
|
|
FiatCurrency get fiat => _settingsStore.fiatCurrency;
|
|
bool get isFiatDisabled => balanceViewModel.isFiatDisabled;
|
|
|
|
final BalanceViewModel balanceViewModel;
|
|
|
|
TransactionPriority get transactionPriority {
|
|
final priority = _settingsStore.priority[wallet.type];
|
|
|
|
if (priority == null) {
|
|
throw Exception('Unexpected type ${wallet.type}');
|
|
}
|
|
|
|
return priority;
|
|
}
|
|
|
|
int? getCustomPriorityIndex(List<TransactionPriority> priorities) {
|
|
if (wallet.type == WalletType.bitcoin) {
|
|
final customItem = priorities
|
|
.firstWhereOrNull((element) => element == bitcoin!.getBitcoinTransactionPriorityCustom());
|
|
|
|
return customItem != null ? priorities.indexOf(customItem) : null;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
int? get maxCustomFeeRate {
|
|
if (wallet.type == WalletType.bitcoin) {
|
|
return bitcoin!.getMaxCustomFeeRate(wallet);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
bool get isLowFee {
|
|
switch (wallet.type) {
|
|
case WalletType.monero:
|
|
case WalletType.wownero:
|
|
case WalletType.haven:
|
|
case WalletType.zano:
|
|
return transactionPriority == monero!.getMoneroTransactionPrioritySlow();
|
|
case WalletType.bitcoin:
|
|
return transactionPriority == bitcoin!.getBitcoinTransactionPrioritySlow();
|
|
case WalletType.litecoin:
|
|
return transactionPriority == bitcoin!.getLitecoinTransactionPrioritySlow();
|
|
case WalletType.ethereum:
|
|
return transactionPriority == ethereum!.getEthereumTransactionPrioritySlow();
|
|
case WalletType.bitcoinCash:
|
|
return transactionPriority == bitcoinCash!.getBitcoinCashTransactionPrioritySlow();
|
|
case WalletType.polygon:
|
|
return transactionPriority == polygon!.getPolygonTransactionPrioritySlow();
|
|
case WalletType.base:
|
|
return transactionPriority == base!.getBaseTransactionPrioritySlow();
|
|
case WalletType.decred:
|
|
return transactionPriority == decred!.getDecredTransactionPrioritySlow();
|
|
case WalletType.dogecoin:
|
|
return transactionPriority == dogecoin!.getDogeCoinTransactionPrioritySlow();
|
|
case WalletType.none:
|
|
case WalletType.nano:
|
|
case WalletType.banano:
|
|
case WalletType.solana:
|
|
case WalletType.tron:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
@computed
|
|
int get customBitcoinFeeRate => _settingsStore.customBitcoinFeeRate;
|
|
|
|
void set customBitcoinFeeRate(int value) => _settingsStore.customBitcoinFeeRate = value;
|
|
|
|
@computed
|
|
bool get hasFees => wallet.type != WalletType.nano && wallet.type != WalletType.banano;
|
|
|
|
@computed
|
|
bool get hasFeesPriority =>
|
|
wallet.type != WalletType.nano &&
|
|
wallet.type != WalletType.banano &&
|
|
wallet.type != WalletType.solana &&
|
|
wallet.type != WalletType.tron;
|
|
|
|
@computed
|
|
bool get isElectrumWallet =>
|
|
wallet.type == WalletType.bitcoin ||
|
|
wallet.type == WalletType.litecoin ||
|
|
wallet.type == WalletType.bitcoinCash ||
|
|
wallet.type == WalletType.dogecoin;
|
|
|
|
String? get walletCurrencyName => wallet.currency.fullName?.toLowerCase() ?? wallet.currency.name;
|
|
|
|
@computed
|
|
FiatCurrency get fiatCurrency => _settingsStore.fiatCurrency;
|
|
|
|
final SettingsStore _settingsStore;
|
|
|
|
@action
|
|
void setTransactionPriority(TransactionPriority priority) =>
|
|
_settingsStore.priority[wallet.type] = priority;
|
|
|
|
bool showAlertForCustomFeeRate() {
|
|
if (wallet.type != WalletType.bitcoin || isLowFee) {
|
|
return false;
|
|
}
|
|
|
|
if (transactionPriority != bitcoinTransactionPriorityCustom) {
|
|
return false;
|
|
}
|
|
|
|
final mediumRate = bitcoin!.getFeeRate(wallet, bitcoinTransactionPriorityMedium);
|
|
return customBitcoinFeeRate < mediumRate;
|
|
}
|
|
|
|
String displayFeeRate(dynamic priority, int? customValue) {
|
|
final _priority = priority as TransactionPriority;
|
|
|
|
if (wallet.type == WalletType.bitcoin) {
|
|
final rate = bitcoin!.getFeeRate(wallet, _priority);
|
|
return bitcoin!.bitcoinTransactionPriorityWithLabel(_priority, rate, customRate: customValue);
|
|
}
|
|
|
|
if (isElectrumWallet) {
|
|
final rate = bitcoin!.getFeeRate(wallet, _priority);
|
|
return bitcoin!.bitcoinTransactionPriorityWithLabel(_priority, rate);
|
|
}
|
|
|
|
return priority.toString();
|
|
}
|
|
|
|
TransactionPriority get bitcoinTransactionPriorityCustom =>
|
|
bitcoin!.getBitcoinTransactionPriorityCustom();
|
|
|
|
TransactionPriority get bitcoinTransactionPriorityMedium =>
|
|
bitcoin!.getBitcoinTransactionPriorityMedium();
|
|
|
|
@action
|
|
void setDefaultTransactionPriority() {
|
|
switch (wallet.type) {
|
|
case WalletType.monero:
|
|
case WalletType.haven:
|
|
case WalletType.wownero:
|
|
case WalletType.zano:
|
|
_settingsStore.priority[wallet.type] = monero!.getMoneroTransactionPriorityAutomatic();
|
|
break;
|
|
case WalletType.bitcoin:
|
|
_settingsStore.priority[wallet.type] = bitcoin!.getBitcoinTransactionPriorityMedium();
|
|
break;
|
|
case WalletType.litecoin:
|
|
_settingsStore.priority[wallet.type] = bitcoin!.getLitecoinTransactionPriorityMedium();
|
|
break;
|
|
case WalletType.ethereum:
|
|
_settingsStore.priority[wallet.type] = ethereum!.getDefaultTransactionPriority();
|
|
break;
|
|
case WalletType.bitcoinCash:
|
|
_settingsStore.priority[wallet.type] = bitcoinCash!.getDefaultTransactionPriority();
|
|
break;
|
|
case WalletType.dogecoin:
|
|
_settingsStore.priority[wallet.type] = dogecoin!.getDefaultTransactionPriority();
|
|
break;
|
|
case WalletType.polygon:
|
|
_settingsStore.priority[wallet.type] = polygon!.getDefaultTransactionPriority();
|
|
break;
|
|
case WalletType.base:
|
|
_settingsStore.priority[wallet.type] = base!.getDefaultTransactionPriority();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|