From ab9c6a0f57bfbec5e3845bb5e52b7feabc57f2a5 Mon Sep 17 00:00:00 2001
From: Tanner Silva <t@tannersilva.com>
Date: Mon, 21 Sep 2020 23:06:29 -0500
Subject: [PATCH] built basic NSUserDefaults key translation into
 migrate_ios_v1() function. bundle id changed for ios build.

---
 cw_monero/pubspec.lock                  | 85 ++++++++-----------------
 ios/Flutter/.last_build_id              |  2 +-
 ios/Podfile.lock                        |  2 +-
 ios/Runner.xcodeproj/project.pbxproj    |  6 +-
 ios/Runner/Info.plist                   |  4 +-
 lib/src/domain/common/fs_migration.dart | 44 +++++++++++++
 6 files changed, 76 insertions(+), 67 deletions(-)

diff --git a/cw_monero/pubspec.lock b/cw_monero/pubspec.lock
index 0aa42cd07..648dce288 100644
--- a/cw_monero/pubspec.lock
+++ b/cw_monero/pubspec.lock
@@ -1,27 +1,13 @@
 # Generated by pub
 # See https://dart.dev/tools/pub/glossary#lockfile
 packages:
-  archive:
-    dependency: transitive
-    description:
-      name: archive
-      url: "https://pub.dartlang.org"
-    source: hosted
-    version: "2.0.13"
-  args:
-    dependency: transitive
-    description:
-      name: args
-      url: "https://pub.dartlang.org"
-    source: hosted
-    version: "1.6.0"
   async:
     dependency: transitive
     description:
       name: async
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "2.4.1"
+    version: "2.4.2"
   boolean_selector:
     dependency: transitive
     description:
@@ -29,6 +15,13 @@ packages:
       url: "https://pub.dartlang.org"
     source: hosted
     version: "2.0.0"
+  characters:
+    dependency: transitive
+    description:
+      name: characters
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "1.0.0"
   charcode:
     dependency: transitive
     description:
@@ -36,27 +29,27 @@ packages:
       url: "https://pub.dartlang.org"
     source: hosted
     version: "1.1.3"
+  clock:
+    dependency: transitive
+    description:
+      name: clock
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "1.0.1"
   collection:
     dependency: transitive
     description:
       name: collection
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "1.14.12"
-  convert:
+    version: "1.14.13"
+  fake_async:
     dependency: transitive
     description:
-      name: convert
+      name: fake_async
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "2.1.1"
-  crypto:
-    dependency: transitive
-    description:
-      name: crypto
-      url: "https://pub.dartlang.org"
-    source: hosted
-    version: "2.1.4"
+    version: "1.1.0"
   ffi:
     dependency: "direct main"
     description:
@@ -74,20 +67,13 @@ packages:
     description: flutter
     source: sdk
     version: "0.0.0"
-  image:
-    dependency: transitive
-    description:
-      name: image
-      url: "https://pub.dartlang.org"
-    source: hosted
-    version: "2.1.12"
   matcher:
     dependency: transitive
     description:
       name: matcher
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "0.12.6"
+    version: "0.12.8"
   meta:
     dependency: transitive
     description:
@@ -101,7 +87,7 @@ packages:
       name: path
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "1.6.4"
+    version: "1.7.0"
   path_provider:
     dependency: "direct main"
     description:
@@ -109,13 +95,6 @@ packages:
       url: "https://pub.dartlang.org"
     source: hosted
     version: "1.4.0"
-  petitparser:
-    dependency: transitive
-    description:
-      name: petitparser
-      url: "https://pub.dartlang.org"
-    source: hosted
-    version: "2.4.0"
   platform:
     dependency: transitive
     description:
@@ -123,13 +102,6 @@ packages:
       url: "https://pub.dartlang.org"
     source: hosted
     version: "2.2.1"
-  quiver:
-    dependency: transitive
-    description:
-      name: quiver
-      url: "https://pub.dartlang.org"
-    source: hosted
-    version: "2.1.3"
   sky_engine:
     dependency: transitive
     description: flutter
@@ -148,7 +120,7 @@ packages:
       name: stack_trace
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "1.9.3"
+    version: "1.9.5"
   stream_channel:
     dependency: transitive
     description:
@@ -176,14 +148,14 @@ packages:
       name: test_api
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "0.2.15"
+    version: "0.2.17"
   typed_data:
     dependency: transitive
     description:
       name: typed_data
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "1.1.6"
+    version: "1.2.0"
   vector_math:
     dependency: transitive
     description:
@@ -191,13 +163,6 @@ packages:
       url: "https://pub.dartlang.org"
     source: hosted
     version: "2.0.8"
-  xml:
-    dependency: transitive
-    description:
-      name: xml
-      url: "https://pub.dartlang.org"
-    source: hosted
-    version: "3.6.1"
 sdks:
-  dart: ">=2.6.0 <3.0.0"
+  dart: ">=2.9.0-14.0.dev <3.0.0"
   flutter: ">=0.1.4 <2.0.0"
diff --git a/ios/Flutter/.last_build_id b/ios/Flutter/.last_build_id
index 8e3e3da7e..7f8f760fa 100644
--- a/ios/Flutter/.last_build_id
+++ b/ios/Flutter/.last_build_id
@@ -1 +1 @@
-a2dce69f54a78f5b00e19850e4b2d402
\ No newline at end of file
+f88b397cc50258e916c86427fe071d09
\ No newline at end of file
diff --git a/ios/Podfile.lock b/ios/Podfile.lock
index 451d74c1f..1e69ce2ed 100644
--- a/ios/Podfile.lock
+++ b/ios/Podfile.lock
@@ -159,4 +159,4 @@ SPEC CHECKSUMS:
 
 PODFILE CHECKSUM: c34e2287a9ccaa606aeceab922830efb9a6ff69a
 
-COCOAPODS: 1.9.3
+COCOAPODS: 1.8.4
diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj
index 822dd4355..00af58a69 100644
--- a/ios/Runner.xcodeproj/project.pbxproj
+++ b/ios/Runner.xcodeproj/project.pbxproj
@@ -418,7 +418,7 @@
 					"$(PROJECT_DIR)/Flutter",
 				);
 				MARKETING_VERSION = 3.2.0;
-				PRODUCT_BUNDLE_IDENTIFIER = com.cakewallet.cakewallet;
+				PRODUCT_BUNDLE_IDENTIFIER = com.fotolockr.cakewallet;
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
 				SWIFT_VERSION = 5.0;
@@ -552,7 +552,7 @@
 					"$(PROJECT_DIR)/Flutter",
 				);
 				MARKETING_VERSION = 3.2.0;
-				PRODUCT_BUNDLE_IDENTIFIER = com.cakewallet.cakewallet;
+				PRODUCT_BUNDLE_IDENTIFIER = com.fotolockr.cakewallet;
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
 				SWIFT_OPTIMIZATION_LEVEL = "-Onone";
@@ -583,7 +583,7 @@
 					"$(PROJECT_DIR)/Flutter",
 				);
 				MARKETING_VERSION = 3.2.0;
-				PRODUCT_BUNDLE_IDENTIFIER = com.cakewallet.cakewallet;
+				PRODUCT_BUNDLE_IDENTIFIER = com.fotolockr.cakewallet;
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
 				SWIFT_VERSION = 5.0;
diff --git a/ios/Runner/Info.plist b/ios/Runner/Info.plist
index 8f3d469bd..6cb43a34f 100644
--- a/ios/Runner/Info.plist
+++ b/ios/Runner/Info.plist
@@ -2,8 +2,6 @@
 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
 <plist version="1.0">
 <dict>
-	<key>NSFaceIDUsageDescription</key>
-	<string>Enable Face ID for fast and secure access to wallets and private keys</string>
 	<key>CFBundleDevelopmentRegion</key>
 	<string>$(DEVELOPMENT_LANGUAGE)</string>
 	<key>CFBundleExecutable</key>
@@ -26,6 +24,8 @@
 	<true/>
 	<key>NSCameraUsageDescription</key>
 	<string>Used for scan QR code</string>
+	<key>NSFaceIDUsageDescription</key>
+	<string>Enable Face ID for fast and secure access to wallets and private keys</string>
 	<key>UILaunchStoryboardName</key>
 	<string>LaunchScreen</string>
 	<key>UIMainStoryboardFile</key>
diff --git a/lib/src/domain/common/fs_migration.dart b/lib/src/domain/common/fs_migration.dart
index db17cd134..6df65c111 100644
--- a/lib/src/domain/common/fs_migration.dart
+++ b/lib/src/domain/common/fs_migration.dart
@@ -5,6 +5,8 @@ import 'package:cake_wallet/src/domain/common/crypto_currency.dart';
 import 'package:cake_wallet/src/domain/common/wallet_info.dart';
 import 'package:cake_wallet/src/domain/common/wallet_type.dart';
 import 'package:cake_wallet/src/domain/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';
@@ -20,6 +22,48 @@ Future<void> migrate_android_v1() async {
 
 Future<void> migrate_ios_v1() async {
   final appDocDir = await getApplicationDocumentsDirectory();
+  //get the new shared preferences instance
+  SharedPreferences prefs = await SharedPreferences.getInstance();
+
+  //translate the node uri
+  String nodeURI = prefs.getString('node_uri');
+  await prefs.setString('current_node_id', nodeURI);
+
+  //should we provide default btc node key?
+  int activeCurrency = prefs.getInt('currency');
+  await prefs.setInt('current_fiat_currency', activeCurrency);
+
+  //translate fee priority
+  int activeFeeTier = prefs.getInt('saved_fee_priority');
+  await prefs.setInt('current_fee_priority', activeFeeTier);
+
+  //translate current balance mode
+  int currentBalanceMode = prefs.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');
+  await prefs.setBool('save_recipient_address', shouldSave);
+
+  //translate biometric
+  bool biometricOn = prefs.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');
+  bool isDark = false;
+  if (currentTheme == 1) {
+    isDark = true;
+  }
+  await prefs.setBool('dark_theme', isDark);
+
+  //assign the pin lenght
+  int pinLength = prefs.getInt('pin-length');
+  await prefs.setInt('pin-length', pinLength);
+
+  //default value for display list key?
+  String walletName = prefs.getString('current_wallet_name');
+  await prefs.setString('current_wallet_name', walletName);
 }
 
 Future<void> migrate_hives({Directory appDocDir}) async {