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

feat: add backup page #594

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open

feat: add backup page #594

wants to merge 1 commit into from

Conversation

gamalielhere
Copy link
Contributor

@gamalielhere gamalielhere commented Jan 8, 2025

Summary by CodeRabbit

  • New Features

    • Added a new backup detection flow for wallet restoration
    • Introduced a new route for selecting wallet backups
    • Enhanced routing logic for wallet creation and restoration processes
  • Bug Fixes

    • Updated navigation flow after password validation in wallet restoration
  • Chores

    • Refined UI routing and component configurations for onboarding experience

Copy link

coderabbitai bot commented Jan 8, 2025

Walkthrough

This pull request introduces changes to the wallet restoration and onboarding flow in the extension's user interface. The modifications include adding a new backup detection route and component, updating routing logic in the password typing component, and adjusting the main App.vue to handle the new route. The changes primarily focus on enhancing the user experience during wallet restoration by introducing a step to detect and select existing backups before wallet initialization.

Changes

File Change Summary
packages/extension/src/ui/onboard/App.vue Updated isShowBackButton and wrapClassObject functions to handle new route 'restore-wallet-backup-detected'
packages/extension/src/ui/onboard/create-wallet/routes.ts Added new route configurations with namespace prefixes for wallet creation routes
packages/extension/src/ui/onboard/restore-wallet/backup-detected.vue New component for selecting and using wallet backups
packages/extension/src/ui/onboard/restore-wallet/routes.ts Added new route for backup detection with path and component
packages/extension/src/ui/onboard/restore-wallet/type-password.vue Modified routing after password validation to navigate to backup detection route

Sequence Diagram

sequenceDiagram
    participant User
    participant TypePasswordComponent
    participant BackupDetectedComponent
    participant Router

    User->>TypePasswordComponent: Enter and validate password
    TypePasswordComponent->>Router: Navigate to backup detection route
    Router->>BackupDetectedComponent: Load backup selection view
    BackupDetectedComponent->>User: Display available backups
    User->>BackupDetectedComponent: Select or skip backup
Loading

Possibly related PRs

Suggested reviewers

  • kvhnuke
  • NickKelly1

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

github-actions bot commented Jan 8, 2025

💼 Build Files
chrome: enkrypt-chrome-d2e39c14.zip
firefox: enkrypt-firefox-d2e39c14.zip

💉 Virus total analysis
chrome: d2e39c14
firefox: d2e39c14

@gamalielhere gamalielhere changed the base branch from main to develop January 8, 2025 19:53
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Nitpick comments (1)
packages/extension/src/ui/onboard/restore-wallet/backup-detected.vue (1)

87-89: Avoid fixed height containers

Using a fixed height for the backup items container might cause issues with overflow when there are many backups.

   &__backup-items-container {
-    height: 150px;
+    max-height: 150px;
+    overflow-y: auto;
   }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 793d0f0 and d2e39c1.

📒 Files selected for processing (5)
  • packages/extension/src/ui/onboard/App.vue (2 hunks)
  • packages/extension/src/ui/onboard/create-wallet/routes.ts (1 hunks)
  • packages/extension/src/ui/onboard/restore-wallet/backup-detected.vue (1 hunks)
  • packages/extension/src/ui/onboard/restore-wallet/routes.ts (2 hunks)
  • packages/extension/src/ui/onboard/restore-wallet/type-password.vue (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: buildAll
  • GitHub Check: test
🔇 Additional comments (3)
packages/extension/src/ui/onboard/create-wallet/routes.ts (1)

Line range hint 1-8: LGTM!

The route configuration is well-structured and follows Vue Router conventions.

packages/extension/src/ui/onboard/restore-wallet/routes.ts (1)

41-45: Verify navigation flow for backup detection

The backup detection route is correctly added, but let's verify the navigation flow:

  1. Should this route be accessible directly?
  2. Should users be able to navigate back from this route?

Run this script to analyze the navigation flow:

✅ Verification successful

Backup detection route follows secure navigation pattern

The route is correctly implemented with proper navigation guards:

  • Only accessible through the password verification flow
  • Cannot be directly accessed, maintaining security
  • Follows the established wallet restoration pattern
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for route guards and navigation patterns
rg -A 3 "router\.(push|replace)" packages/extension/src/ui/onboard/

Length of output: 8072

packages/extension/src/ui/onboard/App.vue (1)

49-49: LGTM! Back button visibility logic is consistent.

The addition of restore-wallet-backup-detected to the list of routes where the back button should be hidden follows the existing pattern for terminal states in the workflow.

Comment on lines 46 to 50
isInitializing.value = false;
router.push({
name: routes.walletReady.name,
name: routes.backupDetected.name,
});
});
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add error handling for wallet initialization

The wallet initialization process lacks error handling. If initialization fails, the user might be stuck in a broken state.

Consider this implementation:

 const nextAction = () => {
   if (!isDisabled.value) {
     isInitializing.value = true;
-    onboardInitializeWallets(store.mnemonic, store.password).then(() => {
-      isInitializing.value = false;
-      router.push({
-        name: routes.backupDetected.name,
-      });
-    });
+    onboardInitializeWallets(store.mnemonic, store.password)
+      .then(() => {
+        isInitializing.value = false;
+        router.push({
+          name: routes.backupDetected.name,
+        });
+      })
+      .catch((error) => {
+        isInitializing.value = false;
+        // Handle initialization error (e.g., show error message)
+        console.error('Wallet initialization failed:', error);
+      });
   }
 };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
isInitializing.value = false;
router.push({
name: routes.walletReady.name,
name: routes.backupDetected.name,
});
});
const nextAction = () => {
if (!isDisabled.value) {
isInitializing.value = true;
onboardInitializeWallets(store.mnemonic, store.password)
.then(() => {
isInitializing.value = false;
router.push({
name: routes.backupDetected.name,
});
})
.catch((error) => {
isInitializing.value = false;
// Handle initialization error (e.g., show error message)
console.error('Wallet initialization failed:', error);
});
}
};

Comment on lines +8 to +19
<a
v-for="backup in backups"
:key="backup"
@click="selectBackup(backup)"
:class="[
{ selected: selectedBackup === backup },
'backup-detected__backup-item',
]"
>
{{ backup }}
</a>
</div>
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve accessibility for backup selection

The backup selection UI needs accessibility improvements:

  1. Missing proper ARIA attributes
  2. Using anchor tags (<a>) for clickable elements without href
  3. No keyboard navigation support
-      <a
+      <button
+        type="button"
+        role="option"
+        :aria-selected="selectedBackup === backup"
         v-for="backup in backups"
         :key="backup"
         @click="selectBackup(backup)"
         :class="[
           { selected: selectedBackup === backup },
           'backup-detected__backup-item',
         ]"
       >
         {{ backup }}
-      </a>
+      </button>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<a
v-for="backup in backups"
:key="backup"
@click="selectBackup(backup)"
:class="[
{ selected: selectedBackup === backup },
'backup-detected__backup-item',
]"
>
{{ backup }}
</a>
</div>
<button
type="button"
role="option"
:aria-selected="selectedBackup === backup"
v-for="backup in backups"
:key="backup"
@click="selectBackup(backup)"
:class="[
{ selected: selectedBackup === backup },
'backup-detected__backup-item',
]"
>
{{ backup }}
</button>
</div>

Comment on lines +45 to +52
const useBackup = () => {
// replace with actual functionality
window.close();
};

const skip = () => {
window.close();
};
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Implement proper navigation instead of window.close()

Using window.close() directly is not a recommended practice in a Vue application. This should be handled through proper navigation.

-const useBackup = () => {
-  // replace with actual functionality
-  window.close();
-};
-
-const skip = () => {
-  window.close();
-};
+const router = useRouter();
+const useBackup = async () => {
+  try {
+    // Add actual backup restoration logic
+    await restoreFromBackup(selectedBackup.value);
+    router.push({ name: routes.walletReady.name });
+  } catch (error) {
+    // Handle backup restoration error
+    console.error('Failed to restore backup:', error);
+  }
+};
+
+const skip = () => {
+  router.push({ name: routes.walletReady.name });
+};

Committable suggestion skipped: line range outside the PR's diff.


const selectedBackup = ref('');
const disabled = computed(() => !selectedBackup.value);
const backups = ['Backup 1', 'Backup 2', 'Backup 3'];
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Replace hardcoded backup list

The backups array is hardcoded with test values. This needs to be replaced with actual backup data.

-const backups = ['Backup 1', 'Backup 2', 'Backup 3'];
+// TODO: Implement actual backup retrieval
+const backups = ref<string[]>([]);
+onMounted(async () => {
+  // Add actual backup retrieval logic
+  backups.value = await getAvailableBackups();
+});

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +58 to +59
route.name == 'restore-wallet-wallet-ready' ||
route.name == 'restore-wallet-backup-detected',
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Confirmed: Backup detection should not have the 'ready' visual treatment

The backup detection screen is an interactive selection step where users choose from available backups, not a completion state. The 'ready' styling (no background/shadow) should be reserved for actual completion states like 'wallet-ready' which also show the "Pin the extension" instructions.

  • Remove 'restore-wallet-backup-detected' from the wrapClassObject conditions to maintain consistent visual patterns throughout the onboarding flow.
🔗 Analysis chain

Verify if backup detection should have the same visual treatment as completion states.

The onboard__wrap--ready class is typically used for completion states (it removes background and box-shadow). However, based on the PR description, the backup detection route is for selecting and using a backup, which seems like an intermediate step rather than a completion state.

This might lead to inconsistent user experience as users might perceive it as a final step when it's actually a selection step.

Consider keeping the standard visual treatment for the backup detection step to maintain consistent UX patterns throughout the onboarding flow.

-      route.name == 'restore-wallet-wallet-ready' ||
-      route.name == 'restore-wallet-backup-detected',
+      route.name == 'restore-wallet-wallet-ready',
🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# Find route definitions
rg -A 3 "restore-wallet-backup-detected|restore-wallet-wallet-ready" --type vue

# Find other usages of the ready class
rg "onboard__wrap--ready" --type vue

# Look for route configuration files
fd "router|routes" --type file --extension vue,js,ts

Length of output: 229


Script:

#!/bin/bash
# Find route definitions and usages
rg -l "restore-wallet-backup-detected|restore-wallet-wallet-ready" 

# Find class usage
rg "onboard__wrap--ready"

# Look for router configuration
fd -e js -e ts -e vue . | rg -i "router|routes"

Length of output: 1499


Script:

#!/bin/bash
# Check restore wallet routes
cat packages/extension/src/ui/onboard/restore-wallet/routes.ts

# Look for backup detection component
rg -A 5 "backup-detected" packages/extension/src/ui/onboard/restore-wallet/

# Check App.vue for context
cat packages/extension/src/ui/onboard/App.vue

Length of output: 8763

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant