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

fix: onboarding gate in ledger mode #4871

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/app/routes/onboarding-gate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Navigate } from 'react-router-dom';
import { RouteUrls } from '@shared/route-urls';

import { useDefaultWalletSecretKey } from '@app/store/in-memory-key/in-memory-key.selectors';
import { useHasLedgerKeys } from '@app/store/ledger/ledger.selectors';
import { useCurrentKeyDetails } from '@app/store/software-keys/software-key.selectors';

function hasAlreadyMadeWalletAndPlaintextKeyInMemory(encryptedKey?: string, inMemoryKey?: string) {
Expand All @@ -20,10 +21,15 @@ interface OnboardingGateProps {
export function OnboardingGate({ children }: OnboardingGateProps) {
const keyDetails = useCurrentKeyDetails();
const currentInMemoryKey = useDefaultWalletSecretKey();
const isLedger = useHasLedgerKeys();

if (
keyDetails?.type === 'software' &&
hasAlreadyMadeWalletAndPlaintextKeyInMemory(keyDetails.encryptedSecretKey, currentInMemoryKey)
(keyDetails?.type === 'software' &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works but it's very tricky to read with somewhat of a ternary and function call inside of an if.

I'd go for a small refactor to make it easier to understand

const isLedger = useHasLedgerKeys();
const hasKeyInMemory = hasAlreadyMadeWalletAndPlaintextKeyInMemory(
        keyDetails.encryptedSecretKey,
        currentInMemoryKey
      );
const canGoHome = (keyDetails?.type === 'software' && hasKeyInMemory) || isLedger;

  if (canGoHome){
...

For now lets leave it as is, working well but in future I think small refactors like that are worth it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

completely agree here, just was in a hurry a bit

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah thats fine, and understandable! nice job getting it fixed so quickly 👍

hasAlreadyMadeWalletAndPlaintextKeyInMemory(
keyDetails.encryptedSecretKey,
currentInMemoryKey
)) ||
isLedger
) {
return <Navigate to={RouteUrls.Home} />;
}
Expand Down
Loading