Skip to content

Commit

Permalink
(Wallet) Fix Wallet restore action when triggered from unlock screen …
Browse files Browse the repository at this point in the history
…(uplift to 1.73.x) (#26778)

Uplift of #26773 (squashed) to release
  • Loading branch information
brave-builds authored Nov 28, 2024
1 parent da6750a commit 5a0ccd0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public Fragment createFragment(int position) {
}
case PASSWORD_CREATION -> {
final boolean isOnboarding = true;

final boolean overridePreviousWallet = false;
if (position == 0) {
return new OnboardingInitWalletFragment(
mRestartSetupAction, mRestartRestoreAction);
Expand All @@ -138,7 +138,7 @@ public Fragment createFragment(int position) {
} else if (position == 4) {
return new OnboardingFingerprintUnlockFragment();
} else if (position == 5) {
return new OnboardingCreatingWalletFragment();
return OnboardingCreatingWalletFragment.newInstance(overridePreviousWallet);
} else if (position == 6) {
return OnboardingRecoveryPhraseFragment.newInstance(isOnboarding);
} else if (position == 7) {
Expand All @@ -158,6 +158,7 @@ public Fragment createFragment(int position) {
}
}
case ONBOARDING_RESTORE -> {
final boolean overridePreviousWallet = false;
if (position == 0) {
return new OnboardingInitWalletFragment(
mRestartSetupAction, mRestartRestoreAction);
Expand All @@ -172,7 +173,7 @@ public Fragment createFragment(int position) {
} else if (position == 5) {
return new OnboardingFingerprintUnlockFragment();
} else if (position == 6) {
return new OnboardingCreatingWalletFragment();
return OnboardingCreatingWalletFragment.newInstance(overridePreviousWallet);
} else if (position == 7) {
return new OnboardingConfirmationFragment();
} else {
Expand All @@ -187,17 +188,20 @@ public Fragment createFragment(int position) {
return new UnlockWalletFragment();
}
case RESTORE -> {
final boolean overridePreviousWallet = true;
if (position == 0) {
return new UnlockWalletFragment();
} else if (position == 1) {
return OnboardingRestoreWalletFragment.newInstance();
} else if (position == 2) {
return new OnboardingSecurePasswordFragment();
return OnboardingNetworkSelectionFragment.newInstance();
} else if (position == 3) {
return new OnboardingFingerprintUnlockFragment();
return new OnboardingSecurePasswordFragment();
} else if (position == 4) {
return new OnboardingCreatingWalletFragment();
return new OnboardingFingerprintUnlockFragment();
} else if (position == 5) {
return OnboardingCreatingWalletFragment.newInstance(overridePreviousWallet);
} else if (position == 6) {
return new OnboardingConfirmationFragment();
} else {
throw new IllegalStateException(
Expand Down Expand Up @@ -241,7 +245,7 @@ public int getItemCount() {
} else if (mWalletAction == WalletAction.UNLOCK) {
return 1;
} else if (mWalletAction == WalletAction.RESTORE) {
return 6;
return 7;
} else if (mWalletAction == WalletAction.BACKUP) {
return 5;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public void afterTextChanged(Editable text) {

mUnlockWalletRestoreButton.setOnClickListener(
v -> {
mUnlockWalletRestoreButton.setEnabled(false);
onNextPage.gotoRestorePage(false);
mUnlockWalletPassword.setText(null);
});
Expand All @@ -143,6 +144,7 @@ public void afterTextChanged(Editable text) {
@Override
public void onResume() {
super.onResume();
mUnlockWalletRestoreButton.setEnabled(true);
if (mOnNextPage != null) {
mOnNextPage.showCloseButton(false);
mOnNextPage.showBackButton(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,27 @@
public class OnboardingCreatingWalletFragment extends BaseOnboardingWalletFragment {

private static final int NEXT_PAGE_DELAY_MS = 700;
private static final String OVERRIDE_PREVIOUS_WALLET_ARG = "overridePreviousWallet";

private boolean mAddTransitionDelay = true;
private boolean mOverridePreviousWallet;

@NonNull
public static OnboardingCreatingWalletFragment newInstance(
final boolean overridePreviousWallet) {
OnboardingCreatingWalletFragment fragment = new OnboardingCreatingWalletFragment();
Bundle args = new Bundle();
args.putBoolean(OVERRIDE_PREVIOUS_WALLET_ARG, overridePreviousWallet);
fragment.setArguments(args);
return fragment;
}

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mOverridePreviousWallet =
requireArguments().getBoolean(OVERRIDE_PREVIOUS_WALLET_ARG, false);
}

@Override
public View onCreateView(
Expand All @@ -55,10 +74,12 @@ public void onResume() {

KeyringModel keyringModel = getKeyringModel();
if (keyringModel != null) {
// Check if a wallet is already present and skip if that's the case.
// Check if a wallet is already present and skip only
// when not restoring a wallet over an existing one from
// unlock screen button.
keyringModel.isWalletCreated(
isCreated -> {
if (isCreated) {
if (isCreated && !mOverridePreviousWallet) {
goToNextPage();
return;
}
Expand Down

0 comments on commit 5a0ccd0

Please sign in to comment.