mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-22 03:29:36 +00:00
CW-673: Save Haven seeds to show it to the user after Haven removal (#1518)
* haven: backup seeds * haven backup fixes * ci fix * reorder build script * disable haven * properly call cw_haven code * [skip ci] update PR * Update evm_chain_transaction_history.dart remove print --------- Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
This commit is contained in:
parent
329a1fd6de
commit
e2a1d865af
7 changed files with 87 additions and 14 deletions
|
@ -19,3 +19,4 @@ const DERIVATION_INFO_TYPE_ID = 17;
|
|||
const TRON_TOKEN_TYPE_ID = 18;
|
||||
const HARDWARE_WALLET_TYPE_TYPE_ID = 19;
|
||||
const MWEB_UTXO_TYPE_ID = 20;
|
||||
const HAVEN_SEED_STORE_TYPE_ID = 21;
|
|
@ -84,7 +84,6 @@ abstract class EVMChainTransactionHistoryBase
|
|||
_update(tx);
|
||||
}
|
||||
}
|
||||
print('doneee');
|
||||
} catch (e) {
|
||||
log(e.toString());
|
||||
}
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:io' show Directory, File, Platform;
|
||||
import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
||||
import 'package:cake_wallet/core/key_service.dart';
|
||||
import 'package:cake_wallet/core/secure_storage.dart';
|
||||
import 'package:cake_wallet/entities/exchange_api_mode.dart';
|
||||
import 'package:cake_wallet/entities/fiat_api_mode.dart';
|
||||
import 'package:cake_wallet/entities/haven_seed_store.dart';
|
||||
import 'package:cake_wallet/haven/haven.dart';
|
||||
import 'package:cw_core/cake_hive.dart';
|
||||
import 'package:cw_core/pathForWallet.dart';
|
||||
import 'package:cake_wallet/entities/secret_store_key.dart';
|
||||
import 'package:cw_core/root_dir.dart';
|
||||
|
@ -52,7 +56,8 @@ Future<void> defaultSettingsMigration(
|
|||
required Box<Node> powNodes,
|
||||
required Box<WalletInfo> walletInfoSource,
|
||||
required Box<Trade> tradeSource,
|
||||
required Box<Contact> contactSource}) async {
|
||||
required Box<Contact> contactSource,
|
||||
required Box<HavenSeedStore> havenSeedStore}) async {
|
||||
if (Platform.isIOS) {
|
||||
await ios_migrate_v1(walletInfoSource, tradeSource, contactSource);
|
||||
}
|
||||
|
@ -290,14 +295,16 @@ Future<void> defaultSettingsMigration(
|
|||
);
|
||||
break;
|
||||
case 45:
|
||||
await updateWalletTypeNodesWithNewNode(
|
||||
await _backupHavenSeeds(havenSeedStore);
|
||||
|
||||
updateWalletTypeNodesWithNewNode(
|
||||
newNodeUri: 'matic.nownodes.io',
|
||||
sharedPreferences: sharedPreferences,
|
||||
nodes: nodes,
|
||||
type: WalletType.polygon,
|
||||
useSSL: true,
|
||||
);
|
||||
await updateWalletTypeNodesWithNewNode(
|
||||
updateWalletTypeNodesWithNewNode(
|
||||
newNodeUri: 'eth.nownodes.io',
|
||||
sharedPreferences: sharedPreferences,
|
||||
nodes: nodes,
|
||||
|
@ -318,6 +325,13 @@ Future<void> defaultSettingsMigration(
|
|||
await sharedPreferences.setInt(PreferencesKey.currentDefaultSettingsMigrationVersion, version);
|
||||
}
|
||||
|
||||
Future<void> _backupHavenSeeds(Box<HavenSeedStore> havenSeedStore) async {
|
||||
final future = haven?.backupHavenSeeds(havenSeedStore);
|
||||
if (future != null) {
|
||||
await future;
|
||||
}
|
||||
return;
|
||||
}
|
||||
/// generic function for changing any wallet default node
|
||||
/// instead of making a new function for each change
|
||||
Future<void> _changeDefaultNode({
|
||||
|
|
19
lib/entities/haven_seed_store.dart
Normal file
19
lib/entities/haven_seed_store.dart
Normal file
|
@ -0,0 +1,19 @@
|
|||
import 'package:cw_core/hive_type_ids.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
|
||||
part 'haven_seed_store.g.dart';
|
||||
|
||||
@HiveType(typeId: HavenSeedStore.typeId)
|
||||
class HavenSeedStore extends HiveObject {
|
||||
HavenSeedStore({required this.id, this.seed});
|
||||
|
||||
static const typeId = HAVEN_SEED_STORE_TYPE_ID;
|
||||
static const boxName = 'HavenSeedStore';
|
||||
static const boxKey = 'havenSeedStoreKey';
|
||||
|
||||
@HiveField(0, defaultValue: '')
|
||||
String id;
|
||||
|
||||
@HiveField(2)
|
||||
String? seed;
|
||||
}
|
|
@ -307,6 +307,23 @@ class CWHaven extends Haven {
|
|||
return havenTransactionInfo.accountIndex;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> backupHavenSeeds(Box<HavenSeedStore> havenSeedStore) async {
|
||||
final walletInfoSource = await CakeHive.openBox<WalletInfo>(WalletInfo.boxName);
|
||||
final wallets = walletInfoSource.values
|
||||
.where((element) => element.type == WalletType.haven);
|
||||
for (var w in wallets) {
|
||||
final walletService = HavenWalletService(walletInfoSource);
|
||||
final flutterSecureStorage = secureStorageShared;
|
||||
final keyService = KeyService(flutterSecureStorage);
|
||||
final password = await keyService.getWalletPassword(walletName: w.name);
|
||||
final wallet = await walletService.openWallet(w.name, password);
|
||||
await havenSeedStore.add(HavenSeedStore(id: wallet.id, seed: wallet.seed));
|
||||
wallet.close();
|
||||
}
|
||||
await havenSeedStore.flush();
|
||||
}
|
||||
|
||||
@override
|
||||
WalletService createHavenWalletService(Box<WalletInfo> walletInfoSource) {
|
||||
return HavenWalletService(walletInfoSource);
|
||||
|
|
|
@ -9,6 +9,7 @@ import 'package:cake_wallet/entities/contact.dart';
|
|||
import 'package:cake_wallet/entities/default_settings_migration.dart';
|
||||
import 'package:cake_wallet/entities/get_encryption_key.dart';
|
||||
import 'package:cake_wallet/core/secure_storage.dart';
|
||||
import 'package:cake_wallet/entities/haven_seed_store.dart';
|
||||
import 'package:cake_wallet/entities/language_service.dart';
|
||||
import 'package:cake_wallet/entities/template.dart';
|
||||
import 'package:cake_wallet/entities/transaction_description.dart';
|
||||
|
@ -164,6 +165,10 @@ Future<void> initializeAppConfigs() async {
|
|||
CakeHive.registerAdapter(AnonpayInvoiceInfoAdapter());
|
||||
}
|
||||
|
||||
if (!CakeHive.isAdapterRegistered(HavenSeedStore.typeId)) {
|
||||
CakeHive.registerAdapter(HavenSeedStoreAdapter());
|
||||
}
|
||||
|
||||
if (!CakeHive.isAdapterRegistered(MwebUtxo.typeId)) {
|
||||
CakeHive.registerAdapter(MwebUtxoAdapter());
|
||||
}
|
||||
|
@ -188,6 +193,12 @@ Future<void> initializeAppConfigs() async {
|
|||
final anonpayInvoiceInfo = await CakeHive.openBox<AnonpayInvoiceInfo>(AnonpayInvoiceInfo.boxName);
|
||||
final unspentCoinsInfoSource = await CakeHive.openBox<UnspentCoinsInfo>(UnspentCoinsInfo.boxName);
|
||||
|
||||
final havenSeedStoreBoxKey =
|
||||
await getEncryptionKey(secureStorage: secureStorage, forKey: HavenSeedStore.boxKey);
|
||||
final havenSeedStore = await CakeHive.openBox<HavenSeedStore>(
|
||||
HavenSeedStore.boxName,
|
||||
encryptionKey: havenSeedStoreBoxKey);
|
||||
|
||||
await initialSetup(
|
||||
sharedPreferences: await SharedPreferences.getInstance(),
|
||||
nodes: nodes,
|
||||
|
@ -203,6 +214,7 @@ Future<void> initializeAppConfigs() async {
|
|||
transactionDescriptions: transactionDescriptions,
|
||||
secureStorage: secureStorage,
|
||||
anonpayInvoiceInfo: anonpayInvoiceInfo,
|
||||
havenSeedStore: havenSeedStore,
|
||||
initialMigrationVersion: 45,
|
||||
);
|
||||
}
|
||||
|
@ -222,7 +234,8 @@ Future<void> initialSetup(
|
|||
required SecureStorage secureStorage,
|
||||
required Box<AnonpayInvoiceInfo> anonpayInvoiceInfo,
|
||||
required Box<UnspentCoinsInfo> unspentCoinsInfoSource,
|
||||
int initialMigrationVersion = 15}) async {
|
||||
required Box<HavenSeedStore> havenSeedStore,
|
||||
int initialMigrationVersion = 15, }) async {
|
||||
LanguageService.loadLocaleList();
|
||||
await defaultSettingsMigration(
|
||||
secureStorage: secureStorage,
|
||||
|
@ -232,7 +245,8 @@ Future<void> initialSetup(
|
|||
contactSource: contactSource,
|
||||
tradeSource: tradesSource,
|
||||
nodes: nodes,
|
||||
powNodes: powNodes);
|
||||
powNodes: powNodes,
|
||||
havenSeedStore: havenSeedStore);
|
||||
await setup(
|
||||
walletInfoSource: walletInfoSource,
|
||||
nodeSource: nodes,
|
||||
|
|
|
@ -656,7 +656,14 @@ import 'package:cw_core/output_info.dart';
|
|||
import 'package:cake_wallet/view_model/send/output.dart';
|
||||
import 'package:cw_core/wallet_service.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:cw_core/crypto_currency.dart';""";
|
||||
import 'package:cw_core/crypto_currency.dart';
|
||||
import 'package:cake_wallet/core/key_service.dart';
|
||||
import 'package:cake_wallet/core/secure_storage.dart';
|
||||
import 'package:cake_wallet/entities/haven_seed_store.dart';
|
||||
import 'package:cw_core/cake_hive.dart';
|
||||
import 'package:cw_core/wallet_info.dart';
|
||||
import 'package:cw_core/wallet_type.dart';
|
||||
""";
|
||||
const havenCWHeaders = """
|
||||
import 'package:cw_core/get_height_by_date.dart';
|
||||
import 'package:cw_core/monero_amount_format.dart';
|
||||
|
@ -679,6 +686,7 @@ import 'package:cw_haven/mnemonics/french.dart';
|
|||
import 'package:cw_haven/mnemonics/italian.dart';
|
||||
import 'package:cw_haven/haven_transaction_creation_credentials.dart';
|
||||
import 'package:cw_haven/api/balance_list.dart';
|
||||
import 'package:cw_haven/haven_wallet_service.dart';
|
||||
""";
|
||||
const havenCwPart = "part 'cw_haven.dart';";
|
||||
const havenContent = """
|
||||
|
@ -779,6 +787,7 @@ abstract class Haven {
|
|||
void onStartup();
|
||||
int getTransactionInfoAccountId(TransactionInfo tx);
|
||||
WalletService createHavenWalletService(Box<WalletInfo> walletInfoSource);
|
||||
Future<void> backupHavenSeeds(Box<HavenSeedStore> havenSeedStore);
|
||||
CryptoCurrency assetOfTransaction(TransactionInfo tx);
|
||||
List<AssetRate> getAssetRate();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue