2023-12-02 02:26:43 +00:00
|
|
|
import 'package:cake_wallet/reactions/wallet_connect.dart';
|
2023-04-14 04:39:08 +00:00
|
|
|
import 'package:cake_wallet/store/app_store.dart';
|
2023-05-24 21:00:54 +00:00
|
|
|
import 'package:cw_core/transaction_direction.dart';
|
|
|
|
import 'package:cw_core/transaction_info.dart';
|
2021-12-24 12:37:24 +00:00
|
|
|
import 'package:cw_core/wallet_type.dart';
|
2020-07-06 20:09:03 +00:00
|
|
|
import 'package:mobx/mobx.dart';
|
|
|
|
import 'package:cake_wallet/generated/i18n.dart';
|
2021-12-24 12:37:24 +00:00
|
|
|
import 'package:cw_core/wallet_base.dart';
|
2020-07-06 20:09:03 +00:00
|
|
|
import 'package:cake_wallet/src/screens/transaction_details/standart_list_item.dart';
|
2021-12-30 17:20:00 +00:00
|
|
|
import 'package:cake_wallet/monero/monero.dart';
|
2022-03-30 15:57:04 +00:00
|
|
|
import 'package:cake_wallet/haven/haven.dart';
|
2023-03-15 15:30:06 +00:00
|
|
|
import 'package:cw_monero/api/wallet.dart' as monero_wallet;
|
2023-12-09 01:37:39 +00:00
|
|
|
import 'package:polyseed/polyseed.dart';
|
2020-07-06 20:09:03 +00:00
|
|
|
|
|
|
|
part 'wallet_keys_view_model.g.dart';
|
|
|
|
|
|
|
|
class WalletKeysViewModel = WalletKeysViewModelBase with _$WalletKeysViewModel;
|
|
|
|
|
|
|
|
abstract class WalletKeysViewModelBase with Store {
|
2023-04-14 04:39:08 +00:00
|
|
|
WalletKeysViewModelBase(this._appStore)
|
|
|
|
: title = _appStore.wallet!.type == WalletType.bitcoin ||
|
2023-08-04 17:01:49 +00:00
|
|
|
_appStore.wallet!.type == WalletType.litecoin ||
|
2023-10-12 22:50:16 +00:00
|
|
|
_appStore.wallet!.type == WalletType.bitcoinCash ||
|
2023-12-02 02:26:43 +00:00
|
|
|
_appStore.wallet!.type == WalletType.ethereum ||
|
|
|
|
_appStore.wallet!.type == WalletType.polygon
|
2022-06-23 13:36:50 +00:00
|
|
|
? S.current.wallet_seed
|
|
|
|
: S.current.wallet_keys,
|
2023-04-14 04:39:08 +00:00
|
|
|
_restoreHeight = _appStore.wallet!.walletInfo.restoreHeight,
|
2023-05-24 21:00:54 +00:00
|
|
|
_restoreHeightByTransactions = 0,
|
2022-06-23 13:36:50 +00:00
|
|
|
items = ObservableList<StandartListItem>() {
|
2023-04-14 04:39:08 +00:00
|
|
|
_populateItems();
|
|
|
|
|
|
|
|
reaction((_) => _appStore.wallet, (WalletBase? _wallet) {
|
|
|
|
_populateItems();
|
|
|
|
});
|
2023-05-24 21:00:54 +00:00
|
|
|
|
|
|
|
if (_appStore.wallet!.type == WalletType.monero || _appStore.wallet!.type == WalletType.haven) {
|
|
|
|
final accountTransactions = _getWalletTransactions(_appStore.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(
|
|
|
|
_appStore.wallet!.type, incomingAccountTransactions.first.date);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-04-14 04:39:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
final ObservableList<StandartListItem> items;
|
|
|
|
|
|
|
|
final String title;
|
|
|
|
|
|
|
|
final AppStore _appStore;
|
|
|
|
|
|
|
|
final int _restoreHeight;
|
|
|
|
|
2023-05-24 21:00:54 +00:00
|
|
|
int _restoreHeightByTransactions;
|
|
|
|
|
2023-04-14 04:39:08 +00:00
|
|
|
void _populateItems() {
|
|
|
|
items.clear();
|
|
|
|
|
|
|
|
if (_appStore.wallet!.type == WalletType.monero) {
|
|
|
|
final keys = monero!.getKeys(_appStore.wallet!);
|
|
|
|
|
2021-12-30 17:20:00 +00:00
|
|
|
items.addAll([
|
2022-10-12 17:09:57 +00:00
|
|
|
if (keys['publicSpendKey'] != null)
|
|
|
|
StandartListItem(title: S.current.spend_key_public, value: keys['publicSpendKey']!),
|
|
|
|
if (keys['privateSpendKey'] != null)
|
|
|
|
StandartListItem(title: S.current.spend_key_private, value: keys['privateSpendKey']!),
|
|
|
|
if (keys['publicViewKey'] != null)
|
|
|
|
StandartListItem(title: S.current.view_key_public, value: keys['publicViewKey']!),
|
|
|
|
if (keys['privateViewKey'] != null)
|
|
|
|
StandartListItem(title: S.current.view_key_private, value: keys['privateViewKey']!),
|
2023-08-23 12:33:20 +00:00
|
|
|
StandartListItem(title: S.current.wallet_seed, value: _appStore.wallet!.seed!),
|
2022-03-30 15:57:04 +00:00
|
|
|
]);
|
2023-12-09 01:37:39 +00:00
|
|
|
|
|
|
|
if (_appStore.wallet?.seed != null && Polyseed.isValidSeed(_appStore.wallet!.seed!)) {
|
|
|
|
final lang = PolyseedLang.getByPhrase(_appStore.wallet!.seed!);
|
|
|
|
final legacyLang = _getLegacySeedLang(lang);
|
|
|
|
final legacySeed =
|
|
|
|
Polyseed.decode(_appStore.wallet!.seed!, lang, PolyseedCoin.POLYSEED_MONERO)
|
|
|
|
.toLegacySeed(legacyLang);
|
|
|
|
items.add(StandartListItem(title: S.current.wallet_seed_legacy, value: legacySeed));
|
|
|
|
}
|
2022-03-30 15:57:04 +00:00
|
|
|
}
|
|
|
|
|
2023-04-14 04:39:08 +00:00
|
|
|
if (_appStore.wallet!.type == WalletType.haven) {
|
|
|
|
final keys = haven!.getKeys(_appStore.wallet!);
|
|
|
|
|
2022-03-30 15:57:04 +00:00
|
|
|
items.addAll([
|
2022-10-12 17:09:57 +00:00
|
|
|
if (keys['publicSpendKey'] != null)
|
|
|
|
StandartListItem(title: S.current.spend_key_public, value: keys['publicSpendKey']!),
|
|
|
|
if (keys['privateSpendKey'] != null)
|
|
|
|
StandartListItem(title: S.current.spend_key_private, value: keys['privateSpendKey']!),
|
|
|
|
if (keys['publicViewKey'] != null)
|
|
|
|
StandartListItem(title: S.current.view_key_public, value: keys['publicViewKey']!),
|
|
|
|
if (keys['privateViewKey'] != null)
|
|
|
|
StandartListItem(title: S.current.view_key_private, value: keys['privateViewKey']!),
|
2023-08-23 12:33:20 +00:00
|
|
|
StandartListItem(title: S.current.wallet_seed, value: _appStore.wallet!.seed!),
|
2021-12-30 17:20:00 +00:00
|
|
|
]);
|
2020-07-06 20:09:03 +00:00
|
|
|
}
|
|
|
|
|
2023-04-14 04:39:08 +00:00
|
|
|
if (_appStore.wallet!.type == WalletType.bitcoin ||
|
2023-10-12 22:50:16 +00:00
|
|
|
_appStore.wallet!.type == WalletType.litecoin ||
|
|
|
|
_appStore.wallet!.type == WalletType.bitcoinCash) {
|
2020-07-06 20:09:03 +00:00
|
|
|
items.addAll([
|
2023-08-23 12:33:20 +00:00
|
|
|
StandartListItem(title: S.current.wallet_seed, value: _appStore.wallet!.seed!),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
CW-555-Add-Solana-Wallet (#1272)
* chore: Create cw_solana package and clean up files
* feat: Add Solana Wallet - Create, Restore form seed, restore from Key, Restore from QR, Send, Receive, transaction history, spl tokens
* fix: Make transactions file specific to solana only for solana transactions
* chore: Revert inject app details script
* fix: Fix issue with node and switch current node to main beta instead of testnet
* fix: Fix merge conflicts and adjust migration version
* fix: Fetch spl token error
Signed-off-by: Blazebrain <davidadegoke16@gmail.com>
* fix: Diplay and activate spl tokens bug
* fix: Review and fixes
* fix: reverted formatting for cryptocurrency class
* fix: Review comments, split sending flow into signing and sending separately, fix issues
* fix: Revert throwing unimplenented error
* chore: Fix comment
* chore: Fix comment
* fix: Errors in flow
* Update provider_types.dart [skip ci]
* fix: Issues with solana wallet
* Update solana_wallet.dart [skip ci]
* fix: Review comments
* fix: Date time config
* fix: Revert bash script for app details
* fix: Error with balance, displaying fees, fixing sent or received identifier bug, displaying token symbol with token transaction item in transactions list
* fix: Issues with address validation when sending spl tokens and walletconnect initial setup
* fix: Issues with sending, fetching transactions history, almost wrapping up walletconnect
* fix: Adjust imports that would affect monerocom building successfully
* fix: Refine transaction direction and continue work on walletconnect
* feat: Display SPL token transfers in the transaction history and finally settle the transaction direction
* fix: Delay in transactions history dispaly, show native token transactions first, then process spl token transactions
* feat: Switch node and revert solana chain id to previous id
* fix: Remove print statement
* fix: Remove await for transactions, fetch all transaction histories instantly and adjust solana send success message
* chore: Code refactoring and streamlined wallet type check for solana send success message
* fix: Make timeout error for node silent and add spl token images
---------
Signed-off-by: Blazebrain <davidadegoke16@gmail.com>
Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
2024-02-23 13:39:19 +00:00
|
|
|
if (isEVMCompatibleChain(_appStore.wallet!.type) ||
|
|
|
|
_appStore.wallet!.type == WalletType.solana) {
|
2023-08-23 12:33:20 +00:00
|
|
|
items.addAll([
|
|
|
|
if (_appStore.wallet!.privateKey != null)
|
|
|
|
StandartListItem(title: S.current.private_key, value: _appStore.wallet!.privateKey!),
|
|
|
|
if (_appStore.wallet!.seed != null)
|
|
|
|
StandartListItem(title: S.current.wallet_seed, value: _appStore.wallet!.seed!),
|
2020-07-06 20:09:03 +00:00
|
|
|
]);
|
|
|
|
}
|
2023-10-05 01:09:07 +00:00
|
|
|
|
2023-11-24 23:35:00 +00:00
|
|
|
bool nanoBased =
|
|
|
|
_appStore.wallet!.type == WalletType.nano || _appStore.wallet!.type == WalletType.banano;
|
2023-10-05 01:09:07 +00:00
|
|
|
|
2023-11-24 23:35:00 +00:00
|
|
|
if (nanoBased) {
|
|
|
|
// we always have the hex version of the seed and private key:
|
2023-10-05 01:09:07 +00:00
|
|
|
items.addAll([
|
2023-11-24 23:35:00 +00:00
|
|
|
if (_appStore.wallet!.seed != null)
|
|
|
|
StandartListItem(title: S.current.wallet_seed, value: _appStore.wallet!.seed!),
|
|
|
|
if (_appStore.wallet!.hexSeed != null)
|
|
|
|
StandartListItem(title: S.current.seed_hex_form, value: _appStore.wallet!.hexSeed!),
|
2023-10-05 01:09:07 +00:00
|
|
|
if (_appStore.wallet!.privateKey != null)
|
2023-11-24 23:35:00 +00:00
|
|
|
StandartListItem(title: S.current.private_key, value: _appStore.wallet!.privateKey!),
|
2023-10-05 01:09:07 +00:00
|
|
|
]);
|
|
|
|
}
|
2020-07-06 20:09:03 +00:00
|
|
|
}
|
|
|
|
|
2023-05-24 21:00:54 +00:00
|
|
|
Future<int?> _currentHeight() async {
|
2023-04-14 04:39:08 +00:00
|
|
|
if (_appStore.wallet!.type == WalletType.haven) {
|
2023-03-15 15:30:06 +00:00
|
|
|
return await haven!.getCurrentHeight();
|
|
|
|
}
|
2023-04-14 04:39:08 +00:00
|
|
|
if (_appStore.wallet!.type == WalletType.monero) {
|
2023-03-15 15:30:06 +00:00
|
|
|
return monero_wallet.getCurrentHeight();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-04-21 18:36:47 +00:00
|
|
|
String get _scheme {
|
2023-04-14 04:39:08 +00:00
|
|
|
switch (_appStore.wallet!.type) {
|
2023-03-15 15:30:06 +00:00
|
|
|
case WalletType.monero:
|
2023-04-21 18:36:47 +00:00
|
|
|
return 'monero-wallet';
|
2023-03-15 15:30:06 +00:00
|
|
|
case WalletType.bitcoin:
|
2023-04-21 18:36:47 +00:00
|
|
|
return 'bitcoin-wallet';
|
2023-03-15 15:30:06 +00:00
|
|
|
case WalletType.litecoin:
|
2023-04-21 18:36:47 +00:00
|
|
|
return 'litecoin-wallet';
|
2023-03-15 15:30:06 +00:00
|
|
|
case WalletType.haven:
|
2023-04-21 18:36:47 +00:00
|
|
|
return 'haven-wallet';
|
2023-08-04 17:01:49 +00:00
|
|
|
case WalletType.ethereum:
|
|
|
|
return 'ethereum-wallet';
|
2023-10-12 22:50:16 +00:00
|
|
|
case WalletType.bitcoinCash:
|
2023-10-13 11:49:00 +00:00
|
|
|
return 'bitcoincash-wallet';
|
2023-10-05 01:09:07 +00:00
|
|
|
case WalletType.nano:
|
|
|
|
return 'nano-wallet';
|
|
|
|
case WalletType.banano:
|
|
|
|
return 'banano-wallet';
|
2023-12-02 02:26:43 +00:00
|
|
|
case WalletType.polygon:
|
|
|
|
return 'polygon-wallet';
|
CW-555-Add-Solana-Wallet (#1272)
* chore: Create cw_solana package and clean up files
* feat: Add Solana Wallet - Create, Restore form seed, restore from Key, Restore from QR, Send, Receive, transaction history, spl tokens
* fix: Make transactions file specific to solana only for solana transactions
* chore: Revert inject app details script
* fix: Fix issue with node and switch current node to main beta instead of testnet
* fix: Fix merge conflicts and adjust migration version
* fix: Fetch spl token error
Signed-off-by: Blazebrain <davidadegoke16@gmail.com>
* fix: Diplay and activate spl tokens bug
* fix: Review and fixes
* fix: reverted formatting for cryptocurrency class
* fix: Review comments, split sending flow into signing and sending separately, fix issues
* fix: Revert throwing unimplenented error
* chore: Fix comment
* chore: Fix comment
* fix: Errors in flow
* Update provider_types.dart [skip ci]
* fix: Issues with solana wallet
* Update solana_wallet.dart [skip ci]
* fix: Review comments
* fix: Date time config
* fix: Revert bash script for app details
* fix: Error with balance, displaying fees, fixing sent or received identifier bug, displaying token symbol with token transaction item in transactions list
* fix: Issues with address validation when sending spl tokens and walletconnect initial setup
* fix: Issues with sending, fetching transactions history, almost wrapping up walletconnect
* fix: Adjust imports that would affect monerocom building successfully
* fix: Refine transaction direction and continue work on walletconnect
* feat: Display SPL token transfers in the transaction history and finally settle the transaction direction
* fix: Delay in transactions history dispaly, show native token transactions first, then process spl token transactions
* feat: Switch node and revert solana chain id to previous id
* fix: Remove print statement
* fix: Remove await for transactions, fetch all transaction histories instantly and adjust solana send success message
* chore: Code refactoring and streamlined wallet type check for solana send success message
* fix: Make timeout error for node silent and add spl token images
---------
Signed-off-by: Blazebrain <davidadegoke16@gmail.com>
Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
2024-02-23 13:39:19 +00:00
|
|
|
case WalletType.solana:
|
|
|
|
return 'solana-wallet';
|
2023-03-15 15:30:06 +00:00
|
|
|
default:
|
2023-04-14 04:39:08 +00:00
|
|
|
throw Exception('Unexpected wallet type: ${_appStore.wallet!.toString()}');
|
2023-03-15 15:30:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<String?> get restoreHeight async {
|
2023-05-24 21:00:54 +00:00
|
|
|
if (_restoreHeightByTransactions != 0)
|
|
|
|
return getRoundedRestoreHeight(_restoreHeightByTransactions);
|
|
|
|
if (_restoreHeight != 0) return _restoreHeight.toString();
|
|
|
|
|
|
|
|
final currentHeight = await _currentHeight();
|
|
|
|
if (currentHeight == null) return null;
|
|
|
|
|
|
|
|
return getRoundedRestoreHeight(currentHeight);
|
2023-03-15 15:30:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Future<Map<String, String>> get _queryParams async {
|
|
|
|
final restoreHeightResult = await restoreHeight;
|
|
|
|
return {
|
2023-08-23 12:33:20 +00:00
|
|
|
if (_appStore.wallet!.seed != null) 'seed': _appStore.wallet!.seed!,
|
2023-11-24 23:35:00 +00:00
|
|
|
if (_appStore.wallet!.seed == null && _appStore.wallet!.hexSeed != null)
|
|
|
|
'hexSeed': _appStore.wallet!.hexSeed!,
|
|
|
|
if (_appStore.wallet!.seed == null && _appStore.wallet!.privateKey != null)
|
|
|
|
'private_key': _appStore.wallet!.privateKey!,
|
2023-03-15 15:30:06 +00:00
|
|
|
if (restoreHeightResult != null) ...{'height': restoreHeightResult}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-05-24 21:00:54 +00:00
|
|
|
Future<Uri> get url async => Uri(
|
|
|
|
scheme: _scheme,
|
|
|
|
queryParameters: await _queryParams,
|
|
|
|
);
|
|
|
|
|
|
|
|
List<TransactionInfo> _getWalletTransactions(WalletBase wallet) {
|
|
|
|
if (wallet.type == WalletType.monero) {
|
|
|
|
return monero!.getTransactionHistory(wallet).transactions.values.toList();
|
|
|
|
} else if (wallet.type == WalletType.haven) {
|
|
|
|
return haven!.getTransactionHistory(wallet).transactions.values.toList();
|
|
|
|
}
|
|
|
|
return [];
|
2023-03-15 15:30:06 +00:00
|
|
|
}
|
2023-05-24 21:00:54 +00:00
|
|
|
|
|
|
|
int _getRestoreHeightByTransactions(WalletType type, DateTime date) {
|
|
|
|
if (type == WalletType.monero) {
|
2023-11-02 15:52:47 +00:00
|
|
|
return monero!.getHeightByDate(date: date);
|
2023-05-24 21:00:54 +00:00
|
|
|
} else if (type == WalletType.haven) {
|
|
|
|
return haven!.getHeightByDate(date: date);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
String getRoundedRestoreHeight(int height) => ((height / 1000).floor() * 1000).toString();
|
2023-12-09 01:37:39 +00:00
|
|
|
|
|
|
|
LegacySeedLang _getLegacySeedLang(PolyseedLang lang) {
|
|
|
|
switch (lang.nameEnglish) {
|
|
|
|
case "Spanish":
|
|
|
|
return LegacySeedLang.getByEnglishName("Spanish");
|
|
|
|
case "French":
|
|
|
|
return LegacySeedLang.getByEnglishName("French");
|
|
|
|
case "Italian":
|
|
|
|
return LegacySeedLang.getByEnglishName("Italian");
|
|
|
|
case "Japanese":
|
|
|
|
return LegacySeedLang.getByEnglishName("Japanese");
|
|
|
|
case "Portuguese":
|
|
|
|
return LegacySeedLang.getByEnglishName("Portuguese");
|
|
|
|
case "Chinese (Simplified)":
|
|
|
|
return LegacySeedLang.getByEnglishName("Chinese (simplified)");
|
|
|
|
default:
|
|
|
|
return LegacySeedLang.getByEnglishName("English");
|
|
|
|
}
|
|
|
|
}
|
2020-07-06 20:09:03 +00:00
|
|
|
}
|