mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-20 06:08:34 +02:00
Migration for iOS.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import 'dart:io' show Platform;
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
@@ -8,11 +9,22 @@ import 'package:cake_wallet/entities/balance_display_mode.dart';
|
||||
import 'package:cake_wallet/entities/fiat_currency.dart';
|
||||
import 'package:cake_wallet/entities/node_list.dart';
|
||||
import 'package:cake_wallet/entities/transaction_priority.dart';
|
||||
import 'package:cake_wallet/entities/contact.dart';
|
||||
import 'package:cake_wallet/entities/fs_migration.dart';
|
||||
import 'package:cake_wallet/entities/wallet_info.dart';
|
||||
import 'package:cake_wallet/exchange/trade.dart';
|
||||
|
||||
Future defaultSettingsMigration(
|
||||
{@required int version,
|
||||
@required SharedPreferences sharedPreferences,
|
||||
@required Box<Node> nodes}) async {
|
||||
@required Box<Node> nodes,
|
||||
@required Box<WalletInfo> walletInfoSource,
|
||||
@required Box<Trade> tradeSource,
|
||||
@required Box<Contact> contactSource}) async {
|
||||
if (Platform.isIOS) {
|
||||
await ios_migrate_v1(walletInfoSource, tradeSource, contactSource);
|
||||
}
|
||||
|
||||
final currentVersion =
|
||||
sharedPreferences.getInt('current_default_settings_migration_version') ??
|
||||
0;
|
||||
@@ -60,6 +72,7 @@ Future defaultSettingsMigration(
|
||||
await changeBitcoinCurrentElectrumServerToDefault(
|
||||
sharedPreferences: sharedPreferences, nodes: nodes);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -3,44 +3,7 @@ import 'package:cake_wallet/entities/enumerable_item.dart';
|
||||
class FiatCurrency extends EnumerableItem<String> with Serializable<String> {
|
||||
const FiatCurrency({String symbol}) : super(title: symbol, raw: symbol);
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) => other is FiatCurrency && other.raw == raw;
|
||||
|
||||
static const all = [
|
||||
FiatCurrency.aud,
|
||||
FiatCurrency.bgn,
|
||||
FiatCurrency.brl,
|
||||
FiatCurrency.cad,
|
||||
FiatCurrency.chf,
|
||||
FiatCurrency.cny,
|
||||
FiatCurrency.czk,
|
||||
FiatCurrency.eur,
|
||||
FiatCurrency.dkk,
|
||||
FiatCurrency.gbp,
|
||||
FiatCurrency.hkd,
|
||||
FiatCurrency.hrk,
|
||||
FiatCurrency.huf,
|
||||
FiatCurrency.idr,
|
||||
FiatCurrency.ils,
|
||||
FiatCurrency.inr,
|
||||
FiatCurrency.isk,
|
||||
FiatCurrency.jpy,
|
||||
FiatCurrency.krw,
|
||||
FiatCurrency.mxn,
|
||||
FiatCurrency.myr,
|
||||
FiatCurrency.nok,
|
||||
FiatCurrency.nzd,
|
||||
FiatCurrency.php,
|
||||
FiatCurrency.pln,
|
||||
FiatCurrency.ron,
|
||||
FiatCurrency.rub,
|
||||
FiatCurrency.sek,
|
||||
FiatCurrency.sgd,
|
||||
FiatCurrency.thb,
|
||||
FiatCurrency.usd,
|
||||
FiatCurrency.zar,
|
||||
FiatCurrency.vef
|
||||
];
|
||||
static List<FiatCurrency> get all => _all.values.toList();
|
||||
|
||||
static const aud = FiatCurrency(symbol: 'AUD');
|
||||
static const bgn = FiatCurrency(symbol: 'BGN');
|
||||
@@ -76,6 +39,47 @@ class FiatCurrency extends EnumerableItem<String> with Serializable<String> {
|
||||
static const zar = FiatCurrency(symbol: 'ZAR');
|
||||
static const vef = FiatCurrency(symbol: 'VEF');
|
||||
|
||||
static final _all = {
|
||||
FiatCurrency.aud.raw: FiatCurrency.aud,
|
||||
FiatCurrency.bgn.raw: FiatCurrency.bgn,
|
||||
FiatCurrency.brl.raw: FiatCurrency.brl,
|
||||
FiatCurrency.cad.raw: FiatCurrency.cad,
|
||||
FiatCurrency.chf.raw: FiatCurrency.chf,
|
||||
FiatCurrency.cny.raw: FiatCurrency.cny,
|
||||
FiatCurrency.czk.raw: FiatCurrency.czk,
|
||||
FiatCurrency.eur.raw: FiatCurrency.eur,
|
||||
FiatCurrency.dkk.raw: FiatCurrency.dkk,
|
||||
FiatCurrency.gbp.raw: FiatCurrency.gbp,
|
||||
FiatCurrency.hkd.raw: FiatCurrency.hkd,
|
||||
FiatCurrency.hrk.raw: FiatCurrency.hrk,
|
||||
FiatCurrency.huf.raw: FiatCurrency.huf,
|
||||
FiatCurrency.idr.raw: FiatCurrency.idr,
|
||||
FiatCurrency.ils.raw: FiatCurrency.ils,
|
||||
FiatCurrency.inr.raw: FiatCurrency.inr,
|
||||
FiatCurrency.isk.raw: FiatCurrency.isk,
|
||||
FiatCurrency.jpy.raw: FiatCurrency.jpy,
|
||||
FiatCurrency.krw.raw: FiatCurrency.krw,
|
||||
FiatCurrency.mxn.raw: FiatCurrency.mxn,
|
||||
FiatCurrency.myr.raw: FiatCurrency.myr,
|
||||
FiatCurrency.nok.raw: FiatCurrency.nok,
|
||||
FiatCurrency.nzd.raw: FiatCurrency.nzd,
|
||||
FiatCurrency.php.raw: FiatCurrency.php,
|
||||
FiatCurrency.pln.raw: FiatCurrency.pln,
|
||||
FiatCurrency.ron.raw: FiatCurrency.ron,
|
||||
FiatCurrency.rub.raw: FiatCurrency.rub,
|
||||
FiatCurrency.sek.raw: FiatCurrency.sek,
|
||||
FiatCurrency.sgd.raw: FiatCurrency.sgd,
|
||||
FiatCurrency.thb.raw: FiatCurrency.thb,
|
||||
FiatCurrency.usd.raw: FiatCurrency.usd,
|
||||
FiatCurrency.zar.raw: FiatCurrency.zar,
|
||||
FiatCurrency.vef.raw: FiatCurrency.vef
|
||||
};
|
||||
|
||||
static FiatCurrency deserialize({String raw}) => _all[raw];
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) => other is FiatCurrency && other.raw == raw;
|
||||
|
||||
@override
|
||||
int get hashCode => raw.hashCode ^ title.hashCode;
|
||||
}
|
||||
|
||||
+294
-55
@@ -1,56 +1,94 @@
|
||||
import 'dart:io';
|
||||
import 'dart:convert';
|
||||
import 'package:cake_wallet/core/key_service.dart';
|
||||
import 'package:cake_wallet/di.dart';
|
||||
import 'package:cake_wallet/entities/contact.dart';
|
||||
import 'package:cake_wallet/entities/crypto_currency.dart';
|
||||
import 'package:cake_wallet/entities/encrypt.dart';
|
||||
import 'package:cake_wallet/entities/fiat_currency.dart';
|
||||
import 'package:cake_wallet/entities/ios_legacy_helper.dart'
|
||||
as ios_legacy_helper;
|
||||
import 'package:cake_wallet/entities/secret_store_key.dart';
|
||||
import 'package:cake_wallet/entities/wallet_info.dart';
|
||||
import 'package:cake_wallet/entities/wallet_type.dart';
|
||||
import 'package:cake_wallet/exchange/exchange_provider_description.dart';
|
||||
import 'package:cake_wallet/exchange/trade.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:cake_wallet/.secrets.g.dart' as secrets;
|
||||
|
||||
const reservedNames = ["flutter_assets", "wallets", "db"];
|
||||
|
||||
Future<void> migrate_android_v1() async {
|
||||
final appDocDir = await getApplicationDocumentsDirectory();
|
||||
|
||||
await migrate_hives(appDocDir: appDocDir);
|
||||
await migrate_wallets(appDocDir: appDocDir);
|
||||
await android_migrate_hives(appDocDir: appDocDir);
|
||||
await android_migrate_wallets(appDocDir: appDocDir);
|
||||
}
|
||||
|
||||
Future<void> migrate_ios_v1() async {
|
||||
final appDocDir = await getApplicationDocumentsDirectory();
|
||||
Future<void> ios_migrate_v1(Box<WalletInfo> walletInfoSource, Box<Trade> tradeSource, Box<Contact> contactSource) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
|
||||
if (prefs.getBool('ios_migration_v1_completed') ?? false) {
|
||||
return;
|
||||
}
|
||||
|
||||
await ios_migrate_user_defaults();
|
||||
await ios_migrate_pin();
|
||||
await ios_migrate_wallet_passwords();
|
||||
await ios_migrate_wallet_info(walletInfoSource);
|
||||
await ios_migrate_trades_list(tradeSource);
|
||||
await ios_migrate_address_book(contactSource);
|
||||
|
||||
await prefs.setBool('ios_migration_v1_completed', true);
|
||||
}
|
||||
|
||||
Future<void> ios_migrate_user_defaults() async {
|
||||
//get the new shared preferences instance
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
|
||||
if (prefs.getBool('ios_migration_user_defaults_completed') ?? false) {
|
||||
return;
|
||||
}
|
||||
|
||||
//translate the node uri
|
||||
String nodeURI = prefs.getString('node_uri');
|
||||
await prefs.setString('current_node_id', nodeURI);
|
||||
final nodeURI = await ios_legacy_helper.getString('node_uri');
|
||||
// await prefs.setString('current_node_id', nodeURI);
|
||||
await prefs.setInt('current_node_id', 0);
|
||||
|
||||
//should we provide default btc node key?
|
||||
int activeCurrency = prefs.getInt('currency');
|
||||
await prefs.setInt('current_fiat_currency', activeCurrency);
|
||||
final activeCurrency = await ios_legacy_helper.getInt('currency');
|
||||
final convertedCurrency = convertFiatLegacy(activeCurrency);
|
||||
|
||||
if (convertedCurrency != null) {
|
||||
await prefs.setString(
|
||||
'current_fiat_currency', convertedCurrency.serialize());
|
||||
}
|
||||
|
||||
//translate fee priority
|
||||
int activeFeeTier = prefs.getInt('saved_fee_priority');
|
||||
final activeFeeTier = await ios_legacy_helper.getInt('saved_fee_priority');
|
||||
await prefs.setInt('current_fee_priority', activeFeeTier);
|
||||
|
||||
//translate current balance mode
|
||||
int currentBalanceMode = prefs.getInt('display_balance_mode');
|
||||
final currentBalanceMode =
|
||||
await ios_legacy_helper.getInt('display_balance_mode');
|
||||
await prefs.setInt('current_balance_display_mode', currentBalanceMode);
|
||||
|
||||
//translate should save recipient address
|
||||
bool shouldSave = prefs.getBool('should_save_recipient_address');
|
||||
final shouldSave =
|
||||
await ios_legacy_helper.getBool('should_save_recipient_address');
|
||||
await prefs.setBool('save_recipient_address', shouldSave);
|
||||
|
||||
//translate biometric
|
||||
bool biometricOn = prefs.getBool('biometric_authentication_on');
|
||||
final biometricOn =
|
||||
await ios_legacy_helper.getBool('biometric_authentication_on');
|
||||
await prefs.setBool('allow_biometrical_authentication', biometricOn);
|
||||
|
||||
//read the current theme as integer, write it back as a bool
|
||||
int currentTheme = prefs.getInt('current-theme');
|
||||
final currentTheme = prefs.getInt('current-theme');
|
||||
bool isDark = false;
|
||||
if (currentTheme == 1) {
|
||||
isDark = true;
|
||||
@@ -58,15 +96,108 @@ Future<void> migrate_ios_v1() async {
|
||||
await prefs.setBool('dark_theme', isDark);
|
||||
|
||||
//assign the pin lenght
|
||||
int pinLength = prefs.getInt('pin-length');
|
||||
final pinLength = await ios_legacy_helper.getInt('pin-length');
|
||||
await prefs.setInt('pin-length', pinLength);
|
||||
|
||||
//default value for display list key?
|
||||
String walletName = prefs.getString('current_wallet_name');
|
||||
final walletName = await ios_legacy_helper.getString('current_wallet_name');
|
||||
await prefs.setString('current_wallet_name', walletName);
|
||||
|
||||
await prefs.setInt('current_wallet_type', serializeToInt(WalletType.monero));
|
||||
|
||||
await prefs.setBool('ios_migration_user_defaults_completed', true);
|
||||
}
|
||||
|
||||
Future<void> migrate_hives({Directory appDocDir}) async {
|
||||
Future<void> ios_migrate_pin() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
|
||||
if (prefs.getBool('ios_migration_pin_completed') ?? false) {
|
||||
return;
|
||||
}
|
||||
|
||||
final flutterSecureStorage = FlutterSecureStorage();
|
||||
final pinPassword = await flutterSecureStorage.read(
|
||||
key: 'pin_password', iOptions: IOSOptions(syncFlag: "syna"));
|
||||
final key = generateStoreKeyFor(key: SecretStoreKey.pinCodePassword);
|
||||
final encodedPassword = encodedPinCode(pin: pinPassword);
|
||||
await flutterSecureStorage.write(key: key, value: encodedPassword);
|
||||
await prefs.setBool('ios_migration_pin_completed', true);
|
||||
}
|
||||
|
||||
Future<void> ios_migrate_wallet_passwords() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
|
||||
if (prefs.getBool('ios_migration_wallet_passwords_completed') ?? false) {
|
||||
return;
|
||||
}
|
||||
|
||||
final appDocDir = await getApplicationDocumentsDirectory();
|
||||
final flutterSecureStorage = FlutterSecureStorage();
|
||||
final keyService = KeyService(flutterSecureStorage);
|
||||
final walletsDir = Directory('${appDocDir.path}/wallets');
|
||||
final moneroWalletsDir = Directory('${walletsDir.path}/monero');
|
||||
|
||||
moneroWalletsDir.listSync().forEach((item) async {
|
||||
try {
|
||||
if (item is Directory) {
|
||||
final name = item.path.split('/').last;
|
||||
final oldKey = 'wallet_monero_' + name + '_password';
|
||||
final password = await flutterSecureStorage.read(
|
||||
key: oldKey, iOptions: IOSOptions(syncFlag: "syna"));
|
||||
await keyService.saveWalletPassword(
|
||||
walletName: name, password: password);
|
||||
}
|
||||
} catch (e) {
|
||||
print(e.toString());
|
||||
}
|
||||
});
|
||||
|
||||
await prefs.setBool('ios_migration_wallet_passwords_completed', true);
|
||||
}
|
||||
|
||||
FiatCurrency convertFiatLegacy(int raw) {
|
||||
final _map = {
|
||||
0: 'aud',
|
||||
1: 'bgn',
|
||||
2: 'brl',
|
||||
3: 'cad',
|
||||
4: 'chf',
|
||||
5: 'cny',
|
||||
6: 'czk',
|
||||
7: 'eur',
|
||||
8: 'dkk',
|
||||
9: 'gbp',
|
||||
10: 'hkd',
|
||||
11: 'hrk',
|
||||
12: 'huf',
|
||||
13: 'idr',
|
||||
14: 'ils',
|
||||
15: 'inr',
|
||||
16: 'isk',
|
||||
17: 'jpy',
|
||||
18: 'krw',
|
||||
19: 'mxn',
|
||||
20: 'myr',
|
||||
21: 'nok',
|
||||
22: 'nzd',
|
||||
23: 'php',
|
||||
24: 'pln',
|
||||
25: 'ron',
|
||||
26: 'rub',
|
||||
27: 'sek',
|
||||
28: 'sgd',
|
||||
29: 'thb',
|
||||
30: 'try',
|
||||
31: 'usd',
|
||||
32: 'zar',
|
||||
33: 'vef'
|
||||
};
|
||||
final fiatAsString = _map[raw];
|
||||
|
||||
return FiatCurrency.deserialize(raw: fiatAsString.toUpperCase());
|
||||
}
|
||||
|
||||
Future<void> android_migrate_hives({Directory appDocDir}) async {
|
||||
final dbDir = Directory('${appDocDir.path}/db');
|
||||
final files = List<File>();
|
||||
|
||||
@@ -89,7 +220,7 @@ Future<void> migrate_hives({Directory appDocDir}) async {
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> migrate_wallets({Directory appDocDir}) async {
|
||||
Future<void> android_migrate_wallets({Directory appDocDir}) async {
|
||||
final walletsDir = Directory('${appDocDir.path}/wallets');
|
||||
final moneroWalletsDir = Directory('${walletsDir.path}/monero');
|
||||
final dirs = List<Directory>();
|
||||
@@ -123,54 +254,162 @@ Future<void> migrate_wallets({Directory appDocDir}) async {
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> migrate_ios_wallet_info(
|
||||
{@required Directory appDocDir,
|
||||
@required Box<WalletInfo> walletsInfo}) async {
|
||||
// final walletsDir = Directory('${appDocDir.path}/wallets');
|
||||
// final moneroWalletsDir = Directory('${walletsDir.path}/monero');
|
||||
Future<void> ios_migrate_wallet_info(Box<WalletInfo> walletsInfoSource) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
|
||||
// moneroWalletsDir.listSync().forEach((item) async {
|
||||
// try {
|
||||
// if (item is Directory) {
|
||||
// final name = item.path.split('/').last;
|
||||
// final configFile = File('${item.path}/$name.json');
|
||||
// final config =
|
||||
// json.decode(configFile.readAsStringSync()) as Map<String, dynamic>;
|
||||
// final isRecovery = config["isRecovery"] as bool ?? false;
|
||||
// final id =
|
||||
// walletTypeToString(WalletType.monero).toLowerCase() + '_' + name;
|
||||
// final walletInfo =
|
||||
// WalletInfo(id: id, name: name, isRecovery: isRecovery);
|
||||
if (prefs.getBool('ios_migration_wallet_info_completed') ?? false) {
|
||||
return;
|
||||
}
|
||||
|
||||
// await walletsInfo.add(walletInfo);
|
||||
// }
|
||||
// } catch (e) {
|
||||
// print(e.toString());
|
||||
// }
|
||||
// });
|
||||
try {
|
||||
final appDocDir = await getApplicationDocumentsDirectory();
|
||||
final walletsDir = Directory('${appDocDir.path}/wallets');
|
||||
final moneroWalletsDir = Directory('${walletsDir.path}/monero');
|
||||
final infoRecords = moneroWalletsDir
|
||||
.listSync()
|
||||
.map((item) {
|
||||
try {
|
||||
if (item is Directory) {
|
||||
final name = item.path.split('/').last;
|
||||
final configFile = File('${item.path}/$name.json');
|
||||
|
||||
if (!configFile.existsSync()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final config = json.decode(configFile.readAsStringSync())
|
||||
as Map<String, dynamic>;
|
||||
final isRecovery = config['isRecovery'] as bool ?? false;
|
||||
final dateAsDouble = config['date'] as double;
|
||||
final timestamp = dateAsDouble.toInt() * 1000;
|
||||
final date = DateTime.fromMillisecondsSinceEpoch(timestamp);
|
||||
final id = walletTypeToString(WalletType.monero).toLowerCase() +
|
||||
'_' +
|
||||
name;
|
||||
final exist = walletsInfoSource.values
|
||||
.firstWhere((el) => el.id == id, orElse: () => null) !=
|
||||
null;
|
||||
|
||||
if (exist) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final walletInfo = WalletInfo.external(
|
||||
id: id,
|
||||
type: WalletType.monero,
|
||||
name: name,
|
||||
isRecovery: isRecovery,
|
||||
restoreHeight: 0,
|
||||
date: date,
|
||||
dirPath: item.path,
|
||||
path: '${item.path}/$name');
|
||||
|
||||
return walletInfo;
|
||||
}
|
||||
} catch (e) {
|
||||
print(e.toString());
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.where((el) => el != null)
|
||||
.toList();
|
||||
print(infoRecords);
|
||||
await walletsInfoSource.addAll(infoRecords);
|
||||
await prefs.setBool('ios_migration_wallet_info_completed', true);
|
||||
} catch (e) {
|
||||
print(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> migrate_ios_trades_list(
|
||||
{@required Directory appDocDir, @required Box<Trade> trades}) async {
|
||||
final adderessBookJSON = File('${appDocDir.path}/trades_list.json');
|
||||
final List<dynamic> trades =
|
||||
json.decode(adderessBookJSON.readAsStringSync()) as List<dynamic>;
|
||||
Future<void> ios_migrate_trades_list(Box<Trade> tradeSource) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
|
||||
if (prefs.getBool('ios_migration_trade_list_completed') ?? false) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
final appDocDir = await getApplicationDocumentsDirectory();
|
||||
final url = '${appDocDir.path}/trades_list.json';
|
||||
final file = File(url);
|
||||
|
||||
if (!file.existsSync()) {
|
||||
await prefs.setBool('ios_migration_trade_list_completed', true);
|
||||
return;
|
||||
}
|
||||
|
||||
final content = file.readAsBytesSync();
|
||||
final flutterSecureStorage = FlutterSecureStorage();
|
||||
final masterPassword = await flutterSecureStorage.read(
|
||||
key: 'master_password', iOptions: IOSOptions(syncFlag: "syna"));
|
||||
final key = masterPassword.replaceAll('-', '');
|
||||
final decoded = await ios_legacy_helper.decrypt(content,
|
||||
key: key, salt: secrets.keychainSalt);
|
||||
final decodedJson = json.decode(decoded) as List<dynamic>;
|
||||
final trades = decodedJson.map((dynamic el) {
|
||||
final elAsMap = el as Map<String, dynamic>;
|
||||
final providerAsString = elAsMap['provider'] as String;
|
||||
final fromAsString = elAsMap['from'] as String;
|
||||
final toAsString = elAsMap['to'] as String;
|
||||
final dateAsDouble = elAsMap['date'] as double;
|
||||
final tradeId = elAsMap['tradeID'] as String;
|
||||
final to = CryptoCurrency.fromString(toAsString);
|
||||
final from = CryptoCurrency.fromString(fromAsString);
|
||||
final timestamp = dateAsDouble.toInt() * 1000;
|
||||
final date = DateTime.fromMillisecondsSinceEpoch(timestamp);
|
||||
ExchangeProviderDescription provider;
|
||||
|
||||
switch (providerAsString.toLowerCase()) {
|
||||
case 'changenow':
|
||||
provider = ExchangeProviderDescription.changeNow;
|
||||
break;
|
||||
case 'xmr.to':
|
||||
provider = ExchangeProviderDescription.xmrto;
|
||||
break;
|
||||
case 'morph':
|
||||
provider = ExchangeProviderDescription.morphToken;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return Trade(
|
||||
id: tradeId, provider: provider, from: from, to: to, createdAt: date);
|
||||
});
|
||||
await tradeSource.addAll(trades);
|
||||
await prefs.setBool('ios_migration_trade_list_completed', true);
|
||||
} catch (e) {
|
||||
print(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> migrate_ios_address_book(
|
||||
{@required Directory appDocDir, @required Box<Contact> contacts}) async {
|
||||
final adderessBookJSON = File('${appDocDir.path}/address_book.json');
|
||||
Future<void> ios_migrate_address_book(Box<Contact> contactSource) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
|
||||
if (prefs.getBool('ios_migration_address_book_completed') ?? false) {
|
||||
return;
|
||||
}
|
||||
|
||||
final appDocDir = await getApplicationDocumentsDirectory();
|
||||
final addressBookJSON = File('${appDocDir.path}/address_book.json');
|
||||
|
||||
if (!addressBookJSON.existsSync()) {
|
||||
await prefs.setBool('ios_migration_address_book_completed', true);
|
||||
return;
|
||||
}
|
||||
|
||||
final List<dynamic> addresses =
|
||||
json.decode(adderessBookJSON.readAsStringSync()) as List<dynamic>;
|
||||
|
||||
addresses.forEach((dynamic item) async {
|
||||
json.decode(addressBookJSON.readAsStringSync()) as List<dynamic>;
|
||||
final contacts = addresses.map((dynamic item) {
|
||||
final _item = item as Map<String, dynamic>;
|
||||
final type = _item["type"] as String;
|
||||
final address = _item["address"] as String;
|
||||
final name = _item["name"] as String;
|
||||
final contact = Contact(
|
||||
address: address, name: name, type: CryptoCurrency.fromString(type));
|
||||
|
||||
await contacts.add(contact);
|
||||
return Contact(
|
||||
address: address, name: name, type: CryptoCurrency.fromString(type));
|
||||
});
|
||||
|
||||
await contactSource.addAll(contacts);
|
||||
await prefs.setBool('ios_migration_address_book_completed', true);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,25 @@
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
const platform =
|
||||
const MethodChannel('com.cakewallet.cakewallet/legacy_wallet_migration');
|
||||
|
||||
Future<String> readTradeList(
|
||||
Future<String> decrypt(Uint8List bytes,
|
||||
{@required String key, @required String salt}) async =>
|
||||
await platform.invokeMethod('read_trade_list', {'key': key, 'salt': salt});
|
||||
await platform
|
||||
.invokeMethod('decrypt', {'bytes': bytes, 'key': key, 'salt': salt});
|
||||
|
||||
Future<String> readEncryptedFile(String url,
|
||||
{@required String key, @required String salt}) async =>
|
||||
await platform.invokeMethod(
|
||||
'read_encrypted_file', {'url': url, 'key': key, 'salt': salt});
|
||||
Future<dynamic> readUserDefaults(String key, {@required String type}) async =>
|
||||
await platform
|
||||
.invokeMethod<dynamic>('read_user_defaults', {'key': key, 'type': type});
|
||||
|
||||
Future<String> getString(String key) async =>
|
||||
await readUserDefaults(key, type: 'string') as String;
|
||||
|
||||
Future<bool> getBool(String key) async =>
|
||||
await readUserDefaults(key, type: 'bool') as bool;
|
||||
|
||||
Future<int> getInt(String key) async =>
|
||||
await readUserDefaults(key, type: 'int') as int;
|
||||
|
||||
+17
-9
@@ -1,3 +1,4 @@
|
||||
import 'package:cake_wallet/entities/fs_migration.dart';
|
||||
import 'package:cake_wallet/entities/transaction_description.dart';
|
||||
import 'package:cake_wallet/entities/transaction_description.dart';
|
||||
import 'package:cake_wallet/reactions/bootstrap.dart';
|
||||
@@ -94,7 +95,7 @@ void main() async {
|
||||
final exchangeTemplates =
|
||||
await Hive.openBox<ExchangeTemplate>(ExchangeTemplate.boxName);
|
||||
|
||||
final sharedPreferences = await SharedPreferences.getInstance();
|
||||
// final sharedPreferences = await SharedPreferences.getInstance();
|
||||
// final walletService = WalletService();
|
||||
// final fiatConvertationService = FiatConvertationService();
|
||||
// final walletListService = WalletListService(
|
||||
@@ -138,7 +139,6 @@ void main() async {
|
||||
templates: templates,
|
||||
exchangeTemplates: exchangeTemplates,
|
||||
initialMigrationVersion: 4);
|
||||
|
||||
// setReactions(
|
||||
// settingsStore: settingsStore,
|
||||
// priceStore: priceStore,
|
||||
@@ -147,8 +147,8 @@ void main() async {
|
||||
// walletService: walletService,
|
||||
// // authenticationStore: authenticationStore,
|
||||
// loginStore: loginStore);
|
||||
|
||||
runApp(CakeWalletApp());
|
||||
final initialLanguage = await Language.localeDetection();
|
||||
runApp(CakeWalletApp(initialLanguage));
|
||||
}
|
||||
|
||||
Future<void> initialSetup(
|
||||
@@ -160,10 +160,13 @@ Future<void> initialSetup(
|
||||
// @required FiatConvertationService fiatConvertationService,
|
||||
@required Box<Template> templates,
|
||||
@required Box<ExchangeTemplate> exchangeTemplates,
|
||||
int initialMigrationVersion = 4}) async {
|
||||
int initialMigrationVersion = 5}) async {
|
||||
await defaultSettingsMigration(
|
||||
version: initialMigrationVersion,
|
||||
sharedPreferences: sharedPreferences,
|
||||
walletInfoSource: walletInfoSource,
|
||||
contactSource: contactSource,
|
||||
tradeSource: tradesSource,
|
||||
nodes: nodes);
|
||||
await setup(
|
||||
walletInfoSource: walletInfoSource,
|
||||
@@ -177,11 +180,13 @@ Future<void> initialSetup(
|
||||
}
|
||||
|
||||
class CakeWalletApp extends StatelessWidget {
|
||||
CakeWalletApp() {
|
||||
CakeWalletApp(this.initialLanguage) {
|
||||
SystemChrome.setPreferredOrientations(
|
||||
[DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
|
||||
}
|
||||
|
||||
final String initialLanguage;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
//final settingsStore = Provider.of<SettingsStore>(context);
|
||||
@@ -192,11 +197,14 @@ class CakeWalletApp extends StatelessWidget {
|
||||
settingsStore.isDarkTheme ? Themes.darkTheme : Themes.lightTheme),
|
||||
child: ChangeNotifierProvider<Language>(
|
||||
create: (_) => Language(settingsStore.languageCode),
|
||||
child: MaterialAppWithTheme()));
|
||||
child: MaterialAppWithTheme(initialLanguage)));
|
||||
}
|
||||
}
|
||||
|
||||
class MaterialAppWithTheme extends StatelessWidget {
|
||||
MaterialAppWithTheme(this.initialLanguage);
|
||||
final String initialLanguage;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// final sharedPreferences = Provider.of<SharedPreferences>(context);
|
||||
@@ -209,7 +217,7 @@ class MaterialAppWithTheme extends StatelessWidget {
|
||||
// final syncStore = Provider.of<SyncStore>(context);
|
||||
// final balanceStore = Provider.of<BalanceStore>(context);
|
||||
final theme = Provider.of<ThemeChanger>(context);
|
||||
// final currentLanguage = Provider.of<Language>(context);
|
||||
final currentLanguage = Provider.of<Language>(context);
|
||||
// final contacts = Provider.of<Box<Contact>>(context);
|
||||
// final nodes = Provider.of<Box<Node>>(context);
|
||||
// final trades = Provider.of<Box<Trade>>(context);
|
||||
@@ -253,7 +261,7 @@ class MaterialAppWithTheme extends StatelessWidget {
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: S.delegate.supportedLocales,
|
||||
// locale: Locale(currentLanguage.getCurrentLanguage()),
|
||||
locale: Locale(currentLanguage.getCurrentLanguage()),
|
||||
onGenerateRoute: (settings) => Router.generateRoute(settings),
|
||||
initialRoute: initialRoute,
|
||||
));
|
||||
|
||||
@@ -90,12 +90,9 @@ class MoneroWalletService extends WalletService<
|
||||
final path = await pathForWallet(name: name, type: WalletType.monero);
|
||||
final file = File(path);
|
||||
final stat = await file.stat();
|
||||
print(stat.changed);
|
||||
print(stat.modified);
|
||||
print(stat.accessed);
|
||||
monero_wallet_manager.openWallet(path: path, password: password);
|
||||
final walletInfo = walletInfoSource.values.firstWhere(
|
||||
(info) => info.id == WalletBase.idFor(name, WalletType.monero));
|
||||
(info) => info.id == WalletBase.idFor(name, WalletType.monero), orElse: () => null);
|
||||
final wallet = MoneroWallet(
|
||||
filename: monero_wallet.getFilename(), walletInfo: walletInfo);
|
||||
await wallet.init();
|
||||
|
||||
@@ -19,10 +19,10 @@ Future<void> bootstrap(GlobalKey<NavigatorState> navigatorKey) async {
|
||||
final fiatConversionStore = getIt.get<FiatConversionStore>();
|
||||
|
||||
if (authenticationStore.state == AuthenticationState.uninitialized) {
|
||||
authenticationStore.state = getIt
|
||||
.get<SharedPreferences>()
|
||||
.getString(PreferencesKey.currentWalletName) ==
|
||||
null
|
||||
final currentWalletName = getIt
|
||||
.get<SharedPreferences>()
|
||||
.getString(PreferencesKey.currentWalletName);
|
||||
authenticationStore.state = currentWalletName == null
|
||||
? AuthenticationState.denied
|
||||
: AuthenticationState.installed;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user