mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-20 06:08:34 +02:00
* feat: initialize cw_arbitrum package with essential files - Implement ArbitrumClient for transaction handling - Add ArbitrumWallet and related classes for wallet management - Establish transaction history and info classes for Arbitrum transactions - Add ArbitrumWalletService for wallet operations and management * feat: Add arbitrum related secrets to workflow * feat: Add nodes for arbitrum * feat: Add Arbitrum support to cryptocurrency handling * refactor: Update Arbitrum currency references from 'ARB' to 'ETH' * feat: Add Arbitrum support to wallet type and transaction handling * feat: Add Arbitrum URL schemes to Android and iOS configurations * feat: Add Arbitrum SVG icons and a WebP image * feat: Setup Arbitrum proxy * fix: Add localization * feat: Integrate Arbitrum support across various configurations and files - Updated cakewallet.bat to include Arbitrum in app configuration. - Added Arbitrum node list to pubspec_base.yaml. - Modified Android, iOS, Linux, and macOS app configuration scripts to support Arbitrum. - Introduced Arbitrum output path and generation logic in configure.dart. - Enhanced wallet type and pubspec generation to include Arbitrum. - Added Arbitrum-related secrets in secret_key.dart. * feat: Enhance Arbitrum integration with new URI class and updates across various components - Introduced ArbitrumURI class for handling Arbitrum payment URIs. - Updated seed validator, wallet creation service, and other components to support Arbitrum. - Added Arbitrum node handling in default settings migration and node list management. - Enhanced preferences and settings store to include Arbitrum-specific configurations. - Updated QR utility and token utilities to accommodate Arbitrum functionalities. * feat: Add Arbitrum support to various buy providers - Updated DFXBuyProvider, KryptonimBuyProvider, OnRamperBuyProvider, and RobinhoodBuyProvider to include Arbitrum wallet type and blockchain references. - Enhanced integration for Arbitrum across multiple components to ensure consistent support. * feat: Implement Arbitrum support in wallet selection and settings - Added Arbitrum wallet type handling in common test flows and wallet services. - Integrated Arbitrum icons in desktop wallet selection and menu widgets. - Updated privacy settings to include ArbiScan options. - Enhanced key service to support Arbitrum private and public key retrieval. * feat: Expand Arbitrum support across various view models and components - Integrated Arbitrum wallet type handling in advanced privacy settings, transaction details, and wallet management. - Added Arbitrum-specific methods for transaction and wallet creation, restoration, and fee management. - Updated dashboard and home settings to accommodate Arbitrum functionalities, including token management and transaction display. - Enhanced exchange and send view models to support Arbitrum transactions and currency handling. - Included Arbitrum in wallet address list and privacy settings for improved user experience. * refactor: Simplify token initialization in Arbitrum wallet service - Removed the migration flag from the addInitialTokens method in ArbitrumWalletService. - Updated addInitialTokens method in ArbitrumWallet to handle existing tokens more efficiently. - Enhanced initial token retrieval logic in DefaultArbitrumErc20Tokens to prioritize iconPath assignment. - Improved token update logic in BaseWallet for consistency across wallet services. * chore: Update Dart SDK constraints in pubspec.yaml * fix: Update file paths for arbitrum assets * fix: Correct box name formatting in Arbitrum wallet initialization * Update .github/workflows/pr_test_build_android.yml [skip ci * Update .github/workflows/pr_test_build_android.yml * fix: Add missing evm params * fix: Remove duplicate method declaration * refactor: simplify isSwapsXyzSendingEVMTokenSwap check * fix: Update arbitrum configs with sql storage update * feat: Add estimated fee retrieval for Arbitrum and revamp priority fee handling for EVMChainWallet * refactor: Update transaction priority handling and estimated fee calculations across EVMChain chains, also remove priority fee levels for Arbitrum --------- Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
340 lines
12 KiB
Dart
340 lines
12 KiB
Dart
import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
|
import 'package:cake_wallet/generated/i18n.dart';
|
|
import 'package:cake_wallet/monero/monero.dart';
|
|
import 'package:cake_wallet/src/screens/transaction_details/standart_list_item.dart';
|
|
import 'package:cake_wallet/store/app_store.dart';
|
|
import 'package:cake_wallet/wownero/wownero.dart';
|
|
import 'package:cake_wallet/zano/zano.dart';
|
|
import 'package:cw_core/transaction_direction.dart';
|
|
import 'package:cw_core/transaction_info.dart';
|
|
import 'package:cw_core/wallet_base.dart';
|
|
import 'package:cw_core/wallet_type.dart';
|
|
import 'package:cw_monero/monero_wallet.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:mobx/mobx.dart';
|
|
import 'package:cake_wallet/decred/decred.dart';
|
|
import 'package:polyseed/polyseed.dart';
|
|
|
|
part 'wallet_keys_view_model.g.dart';
|
|
|
|
class WalletKeysViewModel = WalletKeysViewModelBase with _$WalletKeysViewModel;
|
|
|
|
abstract class WalletKeysViewModelBase with Store {
|
|
WalletKeysViewModelBase(this._appStore)
|
|
: title = '${walletTypeToString(_appStore.wallet!.type)} ${S.current.wallet_keys}',
|
|
_wallet = _appStore.wallet!,
|
|
_walletName = _appStore.wallet!.type.name,
|
|
_restoreHeight = _appStore.wallet!.walletInfo.restoreHeight,
|
|
_restoreHeightByTransactions = 0,
|
|
items = ObservableList<StandartListItem>() {
|
|
_populateKeysItems();
|
|
|
|
reaction((_) => _appStore.wallet, (WalletBase? _wallet) {
|
|
_populateKeysItems();
|
|
});
|
|
|
|
if (_wallet.type == WalletType.monero ||
|
|
_wallet.type == WalletType.haven ||
|
|
_wallet.type == WalletType.wownero) {
|
|
final accountTransactions = _getWalletTransactions(_wallet);
|
|
if (accountTransactions.isNotEmpty) {
|
|
final incomingAccountTransactions =
|
|
accountTransactions.where((tx) => tx.direction == TransactionDirection.incoming);
|
|
if (incomingAccountTransactions.isNotEmpty) {
|
|
incomingAccountTransactions.toList().sort((a, b) => a.date.compareTo(b.date));
|
|
_restoreHeightByTransactions =
|
|
_getRestoreHeightByTransactions(_wallet.type, incomingAccountTransactions.first.date);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
bool get isBitcoin => _wallet.type == WalletType.bitcoin;
|
|
|
|
final ObservableList<StandartListItem> items;
|
|
|
|
final String title;
|
|
final WalletBase _wallet;
|
|
final String _walletName;
|
|
final AppStore _appStore;
|
|
final int _restoreHeight;
|
|
|
|
int _restoreHeightByTransactions;
|
|
|
|
AppStore get appStore => _appStore;
|
|
|
|
String get seed => _wallet.seed != null ? _wallet.seed! : '';
|
|
|
|
bool get isLegacySeedOnly =>
|
|
[WalletType.monero, WalletType.wownero].contains(_wallet.type) &&
|
|
_wallet.seed != null &&
|
|
!(Polyseed.isValidSeed(_wallet.seed!) || _wallet.seed!.split(' ').length == 12);
|
|
|
|
String get legacySeed {
|
|
if ((_wallet.type == WalletType.monero || _wallet.type == WalletType.wownero) &&
|
|
_wallet.seed != null &&
|
|
(Polyseed.isValidSeed(_wallet.seed!) || _wallet.seed!.split(' ').length == 12)) {
|
|
final langName = PolyseedLang.getByPhrase(_wallet.seed!).nameEnglish;
|
|
|
|
if (_wallet.type == WalletType.monero) {
|
|
return (_wallet as MoneroWalletBase).seedLegacy(langName);
|
|
} else if (_wallet.type == WalletType.wownero) {
|
|
return wownero!.getLegacySeed(_wallet, langName);
|
|
}
|
|
}
|
|
return '';
|
|
}
|
|
|
|
String get legacyRestoreHeight {
|
|
if (_wallet.type == WalletType.monero) {
|
|
return monero!.getRestoreHeight(_wallet)?.toString() ?? '';
|
|
}
|
|
if (_wallet.type == WalletType.wownero) {
|
|
return wownero!.getRestoreHeight(_wallet)?.toString() ?? '';
|
|
}
|
|
return '';
|
|
}
|
|
|
|
@observable
|
|
bool obscurePassphrase = true;
|
|
|
|
String get passphrase {
|
|
return _wallet.passphrase ?? '';
|
|
}
|
|
|
|
/// The Regex split the words based on any whitespace character.
|
|
///
|
|
/// Either standard ASCII space (U+0020) or the full-width space character (U+3000) used by the Japanese.
|
|
List<String> get seedSplit => seed.isNotEmpty ? seed.split(RegExp(r'\s+')) : [];
|
|
|
|
List<String> get legacySeedSplit => legacySeed.isNotEmpty ? legacySeed.split(RegExp(r'\s+')) : [];
|
|
|
|
void _populateKeysItems() {
|
|
items.clear();
|
|
|
|
Map<String, String>? keys;
|
|
|
|
switch (_wallet.type) {
|
|
case WalletType.monero:
|
|
keys = monero!.getKeys(_wallet);
|
|
break;
|
|
case WalletType.wownero:
|
|
keys = wownero!.getKeys(_wallet);
|
|
break;
|
|
case WalletType.zano:
|
|
keys = zano!.getKeys(_wallet);
|
|
break;
|
|
case WalletType.ethereum:
|
|
case WalletType.polygon:
|
|
case WalletType.base:
|
|
case WalletType.arbitrum:
|
|
case WalletType.solana:
|
|
case WalletType.tron:
|
|
items.addAll([
|
|
if (_wallet.privateKey != null)
|
|
StandartListItem(
|
|
key: ValueKey('${_walletName}_wallet_private_key_item_key'),
|
|
title: S.current.private_key,
|
|
value: _wallet.privateKey!,
|
|
),
|
|
]);
|
|
break;
|
|
case WalletType.nano:
|
|
case WalletType.banano:
|
|
// we always have the hex version of the seed and private key:
|
|
items.addAll([
|
|
if (_wallet.hexSeed != null)
|
|
StandartListItem(
|
|
key: ValueKey('${_walletName}_wallet_hex_seed_key'),
|
|
title: S.current.seed_hex_form,
|
|
value: _wallet.hexSeed!,
|
|
),
|
|
if (_wallet.privateKey != null)
|
|
StandartListItem(
|
|
key: ValueKey('${_walletName}_wallet_private_key_item_key'),
|
|
title: S.current.private_key,
|
|
value: _wallet.privateKey!,
|
|
),
|
|
]);
|
|
break;
|
|
case WalletType.decred:
|
|
final pubkey = decred!.pubkey(_appStore.wallet!);
|
|
items.addAll([
|
|
StandartListItem(title: S.current.view_key_public, value: pubkey),
|
|
]);
|
|
break;
|
|
case WalletType.bitcoin:
|
|
case WalletType.litecoin:
|
|
case WalletType.bitcoinCash:
|
|
case WalletType.dogecoin:
|
|
if (_wallet.type == WalletType.bitcoin) {
|
|
keys = bitcoin!.getSilentPaymentKeys(_appStore.wallet!);
|
|
}
|
|
|
|
final electrumKeys = bitcoin!.getWalletKeys(_appStore.wallet!);
|
|
|
|
items.addAll([
|
|
if ((electrumKeys['wif'] ?? '').isNotEmpty)
|
|
StandartListItem(title: "WIF", value: electrumKeys['wif']!),
|
|
if ((electrumKeys['privateKey'] ?? '').isNotEmpty)
|
|
StandartListItem(title: S.current.private_key, value: electrumKeys['privateKey']!),
|
|
if (electrumKeys['publicKey'] != null)
|
|
StandartListItem(title: S.current.public_key, value: electrumKeys['publicKey']!),
|
|
if (electrumKeys['xpub'] != null)
|
|
StandartListItem(title: "xPub", value: electrumKeys['xpub']!),
|
|
]);
|
|
break;
|
|
case WalletType.none:
|
|
case WalletType.haven:
|
|
break;
|
|
}
|
|
|
|
if (keys != null) {
|
|
items.addAll([
|
|
if (keys['primaryAddress'] != null)
|
|
StandartListItem(
|
|
key: ValueKey('${_walletName}_wallet_primary_address_item_key'),
|
|
title: S.current.primary_address,
|
|
value: keys['primaryAddress']!),
|
|
if (keys['publicSpendKey'] != null)
|
|
StandartListItem(
|
|
key: ValueKey('${_walletName}_wallet_public_spend_key_item_key'),
|
|
title: S.current.spend_key_public,
|
|
value: keys['publicSpendKey']!,
|
|
),
|
|
if (keys['privateSpendKey'] != null)
|
|
StandartListItem(
|
|
key: ValueKey('${_walletName}_wallet_private_spend_key_item_key'),
|
|
title: S.current.spend_key_private,
|
|
value: keys['privateSpendKey']!,
|
|
),
|
|
if (keys['publicViewKey'] != null)
|
|
StandartListItem(
|
|
key: ValueKey('${_walletName}_wallet_public_view_key_item_key'),
|
|
title: S.current.view_key_public,
|
|
value: keys['publicViewKey']!,
|
|
),
|
|
if (keys['privateViewKey'] != null)
|
|
StandartListItem(
|
|
key: ValueKey('${_walletName}_wallet_private_view_key_item_key'),
|
|
title: S.current.view_key_private,
|
|
value: keys['privateViewKey']!,
|
|
),
|
|
]);
|
|
}
|
|
}
|
|
|
|
Future<int?> _currentHeight() async {
|
|
if (_wallet.type == WalletType.monero) {
|
|
return await monero!.getCurrentHeight();
|
|
}
|
|
if (_wallet.type == WalletType.wownero) {
|
|
return await wownero!.getCurrentHeight();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
String get _scheme {
|
|
switch (_wallet.type) {
|
|
case WalletType.monero:
|
|
return 'monero-wallet';
|
|
case WalletType.bitcoin:
|
|
return 'bitcoin-wallet';
|
|
case WalletType.litecoin:
|
|
return 'litecoin-wallet';
|
|
case WalletType.haven:
|
|
return 'haven-wallet';
|
|
case WalletType.ethereum:
|
|
return 'ethereum-wallet';
|
|
case WalletType.bitcoinCash:
|
|
return 'bitcoincash-wallet';
|
|
case WalletType.nano:
|
|
return 'nano-wallet';
|
|
case WalletType.banano:
|
|
return 'banano-wallet';
|
|
case WalletType.polygon:
|
|
return 'polygon-wallet';
|
|
case WalletType.base:
|
|
return 'base-wallet';
|
|
case WalletType.arbitrum:
|
|
return 'arbitrum-wallet';
|
|
case WalletType.solana:
|
|
return 'solana-wallet';
|
|
case WalletType.tron:
|
|
return 'tron-wallet';
|
|
case WalletType.wownero:
|
|
return 'wownero-wallet';
|
|
case WalletType.zano:
|
|
return 'zano-wallet';
|
|
case WalletType.decred:
|
|
return 'decred-wallet';
|
|
case WalletType.dogecoin:
|
|
return 'dogecoin-wallet';
|
|
default:
|
|
throw Exception('Unexpected wallet type: ${_wallet.type.toString()}');
|
|
}
|
|
}
|
|
|
|
Future<String?> get restoreHeight async {
|
|
if (_wallet.type == WalletType.monero) {
|
|
return monero!.getRestoreHeight(_wallet)?.toString();
|
|
}
|
|
if (_wallet.type == WalletType.wownero) {
|
|
return wownero!.getRestoreHeight(_wallet)?.toString();
|
|
}
|
|
if (_restoreHeightByTransactions != 0)
|
|
return getRoundedRestoreHeight(_restoreHeightByTransactions);
|
|
if (_restoreHeight != 0) return _restoreHeight.toString();
|
|
|
|
final currentHeight = await _currentHeight();
|
|
if (currentHeight == null) return null;
|
|
|
|
return getRoundedRestoreHeight(currentHeight);
|
|
}
|
|
|
|
Future<Map<String, String>> get _queryParams async {
|
|
final restoreHeightResult = await restoreHeight;
|
|
return {
|
|
if (_wallet.seed != null) 'seed': _wallet.seed!,
|
|
if (_wallet.seed == null && _wallet.hexSeed != null) 'hexSeed': _wallet.hexSeed!,
|
|
if (_wallet.seed == null && _wallet.privateKey != null) 'private_key': _wallet.privateKey!,
|
|
if (restoreHeightResult != null) ...{'height': restoreHeightResult},
|
|
if (_wallet.passphrase != null) 'passphrase': _wallet.passphrase!
|
|
};
|
|
}
|
|
|
|
Future<Map<String, String>> get _queryParamsForLegacy async {
|
|
final restoreHeightResult = await restoreHeight;
|
|
return {
|
|
if (legacySeed.isNotEmpty) 'seed': legacySeed,
|
|
if (restoreHeightResult != null) ...{'height': restoreHeightResult},
|
|
if ((_wallet.passphrase ?? '') != '') 'passphrase': _wallet.passphrase!
|
|
};
|
|
}
|
|
|
|
Future<Uri> getUrl(bool isLegacySeed) async => Uri(
|
|
scheme: _scheme,
|
|
queryParameters: isLegacySeed ? await _queryParamsForLegacy : await _queryParams,
|
|
);
|
|
|
|
List<TransactionInfo> _getWalletTransactions(WalletBase wallet) {
|
|
if (wallet.type == WalletType.monero) {
|
|
return monero!.getTransactionHistory(wallet).transactions.values.toList();
|
|
} else if (wallet.type == WalletType.wownero) {
|
|
return wownero!.getTransactionHistory(wallet).transactions.values.toList();
|
|
}
|
|
return [];
|
|
}
|
|
|
|
int _getRestoreHeightByTransactions(WalletType type, DateTime date) {
|
|
if (type == WalletType.monero) {
|
|
return monero!.getHeightByDate(date: date);
|
|
} else if (type == WalletType.wownero) {
|
|
return wownero!.getHeightByDate(date: date);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
String getRoundedRestoreHeight(int height) => ((height / 1000).floor() * 1000).toString();
|
|
}
|