Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database upgrade #742

Merged
merged 6 commits into from Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions Decred Wallet.xcodeproj/project.pbxproj
Expand Up @@ -1369,7 +1369,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.5.2;
MARKETING_VERSION = 1.5.3;
PRODUCT_BUNDLE_IDENTIFIER = com.decred.dcrios.testnet3;
PRODUCT_NAME = "$(TARGET_NAME) Testnet";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -1453,7 +1453,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.5.2;
MARKETING_VERSION = 1.5.3;
PRODUCT_BUNDLE_IDENTIFIER = com.decred.dcrios.testnet3;
PRODUCT_NAME = "$(TARGET_NAME) Testnet";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -1598,7 +1598,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.5.2;
MARKETING_VERSION = 1.5.3;
PRODUCT_BUNDLE_IDENTIFIER = com.decred.dcrios.mainnet;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -1625,7 +1625,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.5.2;
MARKETING_VERSION = 1.5.3;
PRODUCT_BUNDLE_IDENTIFIER = com.decred.dcrios.mainnet;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
51 changes: 49 additions & 2 deletions Decred Wallet/Features/App Launch/StartScreenViewController.swift
Expand Up @@ -29,6 +29,14 @@ class StartScreenViewController: UIViewController, CAAnimationDelegate {
var startTimerWhenViewAppears = true
var animationDurationSeconds: Double = 4.7

let ONE_GB_VALUE: UInt64 = 1073741824
var numberOfRam: Int {
return Int(ProcessInfo.processInfo.physicalMemory/(ONE_GB_VALUE))
}
let appDataDir = NSHomeDirectory() + "/Documents/dcrlibwallet"

var upgradedDB = false

override func viewDidLoad() {
super.viewDidLoad()

Expand Down Expand Up @@ -151,7 +159,8 @@ class StartScreenViewController: UIViewController, CAAnimationDelegate {
let wallet = try WalletLoader.shared.multiWallet.createNewWallet(LocalizedStrings.myWallet, privatePassphrase: pinOrPassword, privatePassphraseType: type.type)

Utils.renameDefaultAccountToLocalLanguage(wallet: wallet)

UserDefaults.standard.set(true, forKey: "V1.5.3_DB")
UserDefaults.standard.synchronize()
DispatchQueue.main.async {
completion?.dismissDialog()
NavigationMenuTabBarController.setupMenuAndLaunchApp(isNewWallet: true)
Expand All @@ -178,7 +187,7 @@ class StartScreenViewController: UIViewController, CAAnimationDelegate {
}

if WalletLoader.shared.oneOrMoreWalletsExist {
self.checkStartupSecurityAndStartApp()
self.checkDBfile()
} else if SingleToMultiWalletMigration.migrationNeeded {
SingleToMultiWalletMigration.migrateExistingWallet()
} else {
Expand Down Expand Up @@ -236,6 +245,44 @@ class StartScreenViewController: UIViewController, CAAnimationDelegate {
}
}

func clearAppDir() {
do {
let filemgr = FileManager.default
try filemgr.removeItem(atPath: appDataDir)
self.displayWalletSetupScreen()
self.imageViewContainer.isUserInteractionEnabled = false
} catch let error {
Utils.showBanner(in: self.view, type: .error, text: error.localizedDescription)
print("Error: \(error.localizedDescription)")
}
}

func checkDBfile() {
let isNewDB = UserDefaults.standard.bool(forKey: "V1.5.3_DB")
if numberOfRam < 4 && !isNewDB {
self.showRemoveWalletWarning { (ok) in
guard ok else {
self.checkStartupSecurityAndStartApp()
return
}
self.clearAppDir()
}
return
} else {
self.checkStartupSecurityAndStartApp()
}
}

func showRemoveWalletWarning(callback: @escaping (Bool) -> Void) {
let message = LocalizedStrings.dataFileErrorMsg
SimpleOkCancelDialog.show(sender: self,
title: LocalizedStrings.dataFileErrorTitle,
message: message,
cancelButtonText: LocalizedStrings.no,
okButtonText: LocalizedStrings.yes,
callback: callback)
}

func displayWalletSetupScreen() {
// update splash screen location
UIView.animate(withDuration: 0,
Expand Down
Expand Up @@ -122,6 +122,8 @@ class RestoreExistingWalletViewController: UIViewController {
let wallet = try WalletLoader.shared.multiWallet.restore(self.walletName, seedMnemonic: seed, privatePassphrase: pinOrPassword, privatePassphraseType: type.type)

Utils.renameDefaultAccountToLocalLanguage(wallet: wallet)
UserDefaults.standard.set(true, forKey: "V1.5.3_DB")
UserDefaults.standard.synchronize()

DispatchQueue.main.async {
completion?.dismissDialog()
Expand Down
4 changes: 4 additions & 0 deletions Decred Wallet/Utils/LocalizedStrings.swift
Expand Up @@ -20,6 +20,10 @@ struct LocalizedStrings {
static let myWallet = NSLocalizedString("myWallet", comment: "")
static let default_ = NSLocalizedString("default_", comment: "")
static let migratingWallet = NSLocalizedString("migratingWallet", comment: "")
static let dataFileErrorMsg = NSLocalizedString("dataFileErrorMsg", comment: "")
static let yes = NSLocalizedString("yes", comment: "")
static let no = NSLocalizedString("no", comment: "")
static let dataFileErrorTitle = NSLocalizedString("dataFileErrorTitle", comment: "")

/* Create New Wallet(Seed display view) */
static let settingUpYourWallet = NSLocalizedString("settingUpYourWallet", comment: "")
Expand Down
2 changes: 1 addition & 1 deletion Decred Wallet/Wallet Utils/WalletLoader.swift
Expand Up @@ -44,7 +44,7 @@ class WalletLoader: NSObject {

func initMultiWallet() -> NSError? {
var error: NSError?
self.multiWallet = DcrlibwalletNewMultiWallet(WalletLoader.appDataDir, "bdb", BuildConfig.NetType, &error)
self.multiWallet = DcrlibwalletNewMultiWallet(WalletLoader.appDataDir, "badgerdb", BuildConfig.NetType, &error)
return error
}
}
4 changes: 4 additions & 0 deletions Decred Wallet/en.lproj/Localizable.strings
Expand Up @@ -17,6 +17,10 @@
"myWallet" = "mywallet";
"default_" = "default";
"migratingWallet" = "Migrating wallet";
"dataFileErrorMsg" = "We have detected a problem with your data files from an older version. To fix it, you will need to re-enter your wallet seed phrase. Can you do this now?";
"yes" = "Yes";
"no" = "No";
"dataFileErrorTitle" = "Data file error";

/* Create New Wallet(Seed display view) */
"settingUpYourWallet" = "Setting Up Decred Wallet";
Expand Down
4 changes: 4 additions & 0 deletions Decred Wallet/es.lproj/Localizable.strings
Expand Up @@ -17,6 +17,10 @@
"myWallet" = "mywallet";
"default_" = "default";
"migratingWallet" = "Migrating wallet";
"dataFileErrorMsg" = "We have detected a problem with your data files from an older version. To fix it, you will need to re-enter your wallet seed phrase. Can you do this now?";
"yes" = "Yes";
"no" = "No";
"DataFileErrorTitle" = "Data file error";

/* Create New Wallet(Seed display view) */
"settingUpYourWallet" = "Configurando Cartera Decred";
Expand Down
5 changes: 4 additions & 1 deletion Decred Wallet/pl.lproj/Localizable.strings
Expand Up @@ -17,7 +17,10 @@
"myWallet" = "mójportfel";
"default_" = "default";
"migratingWallet" = "Migrating wallet";

"dataFileErrorMsg" = "We have detected a problem with your data files from an older version. To fix it, you will need to re-enter your wallet seed phrase. Can you do this now?";
"yes" = "Yes";
"no" = "No";
"DataFileErrorTitle" = "Data file error";
/* Create New Wallet(Seed display view) */
"settingUpYourWallet" = "Setting Up Decred Wallet";

Expand Down
4 changes: 4 additions & 0 deletions Decred Wallet/pt-BR.lproj/Localizable.strings
Expand Up @@ -17,6 +17,10 @@
"myWallet" = "mywallet";
"default_" = "default";
"migratingWallet" = "Migrating wallet";
"dataFileErrorMsg" = "We have detected a problem with your data files from an older version. To fix it, you will need to re-enter your wallet seed phrase. Can you do this now?";
"yes" = "Yes";
"no" = "No";
"DataFileErrorTitle" = "Data file error";

/* Create New Wallet(Seed display view) */
"settingUpYourWallet" = "Preparando Carteira Decred";
Expand Down
4 changes: 4 additions & 0 deletions Decred Wallet/ru-RU.lproj/Localizable.strings
Expand Up @@ -17,6 +17,10 @@
"myWallet" = "mywallet";
"default_" = "default";
"migratingWallet" = "Migrating wallet";
"dataFileErrorMsg" = "We have detected a problem with your data files from an older version. To fix it, you will need to re-enter your wallet seed phrase. Can you do this now?";
"yes" = "Yes";
"no" = "No";
"DataFileErrorTitle" = "Data file error";

/* Create New Wallet(Seed display view) */
"settingUpYourWallet" = "НАСТРОЙКА КОШЕЛЬКА DECRED";
Expand Down
4 changes: 4 additions & 0 deletions Decred Wallet/vi.lproj/Localizable.strings
Expand Up @@ -17,6 +17,10 @@
"myWallet" = "mywallet";
"default_" = "default";
"migratingWallet" = "Migrating wallet";
"dataFileErrorMsg" = "We have detected a problem with your data files from an older version. To fix it, you will need to re-enter your wallet seed phrase. Can you do this now?";
"yes" = "Yes";
"no" = "No";
"DataFileErrorTitle" = "Data file error";

/* Create New Wallet(Seed display view) */
"settingUpYourWallet" = "Thiết lập Ví Decred";
Expand Down
4 changes: 4 additions & 0 deletions Decred Wallet/zh-Hans.lproj/Localizable.strings
Expand Up @@ -17,6 +17,10 @@
"myWallet" = "我的钱包";
"default_" = "默认";
"migratingWallet" = "转移钱包";
"dataFileErrorMsg" = "We have detected a problem with your data files from an older version. To fix it, you will need to re-enter your wallet seed phrase. Can you do this now?";
"yes" = "Yes";
"no" = "No";
"DataFileErrorTitle" = "Data file error";

/* Create New Wallet(Seed display view) */
"settingUpYourWallet" = "设置Decred钱包";
Expand Down
2 changes: 1 addition & 1 deletion Podfile.lock
Expand Up @@ -17,4 +17,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 64169a56707a1ecbb7c4d47f0d73f353f9e24ba6

COCOAPODS: 1.9.1
COCOAPODS: 1.9.3