From 39bb06c8334e00cf104267316659c6109856abb6 Mon Sep 17 00:00:00 2001 From: pokkst Date: Fri, 4 Nov 2022 23:25:59 -0500 Subject: [PATCH] Handle wallet creation differently in preparation for seed offset support --- .../fragment/onboarding/OnboardingFragment.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/net/mynero/wallet/fragment/onboarding/OnboardingFragment.java b/app/src/main/java/net/mynero/wallet/fragment/onboarding/OnboardingFragment.java index 72fbd5a..382e63d 100644 --- a/app/src/main/java/net/mynero/wallet/fragment/onboarding/OnboardingFragment.java +++ b/app/src/main/java/net/mynero/wallet/fragment/onboarding/OnboardingFragment.java @@ -28,8 +28,10 @@ import net.mynero.wallet.model.Wallet; import net.mynero.wallet.model.WalletManager; import net.mynero.wallet.service.PrefService; import net.mynero.wallet.util.Constants; +import net.mynero.wallet.util.RestoreHeight; import java.io.File; +import java.util.Calendar; public class OnboardingFragment extends Fragment { @@ -172,7 +174,8 @@ public class OnboardingFragment extends Fragment { File walletFile = new File(mainActivity.getApplicationInfo().dataDir, Constants.WALLET_NAME); Wallet wallet = null; if (walletSeed.isEmpty()) { - wallet = WalletManager.getInstance().createWallet(walletFile, walletPassword, Constants.MNEMONIC_LANGUAGE, restoreHeight); + Wallet tmpWallet = createTempWallet(mainActivity.getApplicationInfo().dataDir); //we do this to get seed, then recover wallet so we can use seed offset + wallet = WalletManager.getInstance().recoveryWallet(walletFile, walletPassword, tmpWallet.getSeed(""), "", getNewRestoreHeight()); } else { if (!checkMnemonic(walletSeed)) { Toast.makeText(mainActivity, getString(R.string.invalid_mnemonic_code), Toast.LENGTH_SHORT).show(); @@ -217,6 +220,17 @@ public class OnboardingFragment extends Fragment { } } + private long getNewRestoreHeight() { + Calendar restoreDate = Calendar.getInstance(); + restoreDate.add(Calendar.DAY_OF_MONTH, 0); + return RestoreHeight.getInstance().getHeight(restoreDate.getTime()); + } + + private Wallet createTempWallet(String dir) { + File tmpWalletFile = new File(dir, Constants.WALLET_NAME + "_tmp"); + return WalletManager.getInstance().createWallet(tmpWalletFile, "", Constants.MNEMONIC_LANGUAGE, 0); + } + private boolean checkMnemonic(String seed) { return (seed.split("\\s").length == 25); }