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: private key onboarding string #1142

Closed
wants to merge 4 commits into from
Closed

Conversation

saulmc
Copy link
Member

@saulmc saulmc commented Oct 30, 2024

Fix to accurately state that we do not store private keys.

Summary by CodeRabbit

  • New Features

    • Incremented iOS build number to 16 and Android version code to 223, indicating new app versions.
    • Enhanced message handling in the chat component with improved frame detection logic.
  • Bug Fixes

    • Simplified subtitle in the onboarding process for clarity regarding private key storage.
  • Documentation

    • Updated English translations to reflect changes in the onboarding subtitle.

@saulmc saulmc requested a review from a team as a code owner October 30, 2024 22:39
Copy link
Contributor

coderabbitai bot commented Oct 30, 2024

Walkthrough

The pull request includes updates to the app.json configuration file to increment the iOS build number from "15" to "16" and the Android version code from 222 to 223. Additionally, it modifies the Message.tsx component to implement a new utility function isFrameMessage, enhancing the logic for identifying frame messages. The PrivateKeyConnect.tsx component is simplified by changing the subtitle to a static translation. Lastly, the frames.ts utility file updates the isFrameMessage function's signature and improves error handling in the handleTxAction function.

Changes

File Change Summary
app.json Updated iOS build number from "15" to "16" and Android version code from 222 to 223.
components/Chat/Message/Message.tsx Introduced isFrameMessage utility function to enhance frame message logic; minor code formatting.
components/Onboarding/PrivateKeyConnect.tsx Simplified subtitle prop in OnboardingComponent to a static translation, removing platform-specific logic.
i18n/translations/en.ts Modified privateKeyConnect subtitle to "Your private key is not stored," removing local storage reference.
utils/frames.ts Updated isFrameMessage function signature and logic; improved error handling in handleTxAction.

Possibly related PRs

Suggested reviewers

  • thierryskoda
  • nmalzieu

Poem

🐰 In the garden of code, changes bloom bright,
Version numbers rise, reaching new height.
Frames now dance with a clearer embrace,
As subtitles simplify, finding their place.
Hop along, dear devs, let’s celebrate,
With each little change, we innovate! 🌼


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 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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
Contributor

@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: 1

🧹 Outside diff range and nitpick comments (4)
components/Onboarding/PrivateKeyConnect.tsx (3)

Line range hint 44-54: Remove commented-out private key storage code.

The commented code for private key storage contradicts the PR's objective of clarifying that private keys are not stored. To maintain code clarity and prevent potential confusion or accidental reactivation, this commented section should be removed.

        }
        setSigner(signer);
-        // Let's save
-        // const pkPath = `PK-${uuidv4()}`;
-        // try {
-        //   await savePrivateKey(pkPath, seedPhraseSigner.privateKey);
-        //   setPkPath(pkPath);
-        //   setSigner(seedPhraseSigner);
-        // } catch (e: any) {
-        //   // No biometrics?
-        //   Alert.alert("An error occured", e.toString());
-        //   setLoading(false);
-        // }

Line range hint 91-94: Enhance input validation and error handling.

The current validation could be improved to provide better user feedback and maintain consistency.

       primaryButtonText={translate("privateKeyConnect.connectButton")}
       primaryButtonAction={() => {
-        if (!privateKey || privateKey.trim().length === 0) return;
-        loginWithPrivateKey(privateKey.trim());
+        const trimmedKey = privateKey.trim();
+        if (!trimmedKey) {
+          Alert.alert(translate("privateKeyConnect.emptyKeyError"));
+          return;
+        }
+        loginWithPrivateKey(trimmedKey);
       }}

Line range hint 91-130: Consider UX improvements for private key input.

A few suggestions to enhance the user experience:

  1. Add visual feedback during the loading state
  2. Consider using a single-line input with paste support, as private keys shouldn't contain line breaks
       primaryButtonAction={() => {
         if (!privateKey || privateKey.trim().length === 0) return;
         loginWithPrivateKey(privateKey.trim());
       }}
       backButtonText={translate("privateKeyConnect.backButton")}
       backButtonAction={() => {
         setConnectionMethod(undefined);
       }}
       showTerms
+      isLoading={loading}
     >
       <View style={styles.entryContainer}>
         <TextInput
-          multiline
+          multiline={false}
           textAlignVertical="top"
           style={styles.textInput}
           placeholder={translate("privateKeyConnect.privateKeyPlaceholder")}
utils/frames.ts (1)

274-285: LGTM! Good refactoring of isFrameMessage.

The function has been improved by:

  • Separating concerns with distinct parameters
  • Adding clear content sanitization
  • Implementing early returns

Consider these improvements for more robust URL handling:

 export const isFrameMessage = (
   messageIsText: boolean,
   messageContent: string,
   framesStore: {
     [frameUrl: string]: FrameWithType;
   }
 ): boolean => {
   if (!messageIsText) return false;
+  if (!messageContent) return false;
   const content = messageContent.toLowerCase().trim();
   const sanitizedContent = content.endsWith("/")
     ? content.slice(0, -1)
     : content;
+  // Remove leading slash if present
+  const normalizedContent = sanitizedContent.startsWith("/")
+    ? sanitizedContent.slice(1)
+    : sanitizedContent;
-  return !!framesStore[sanitizedContent];
+  return !!framesStore[normalizedContent];
 };
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 04d44d7 and 19232e9.

📒 Files selected for processing (5)
  • app.json (1 hunks)
  • components/Chat/Message/Message.tsx (2 hunks)
  • components/Onboarding/PrivateKeyConnect.tsx (1 hunks)
  • i18n/translations/en.ts (1 hunks)
  • utils/frames.ts (1 hunks)
🔇 Additional comments (6)
app.json (1)

5-5: LGTM! Version increments follow proper practices.

The version increments are consistent across platforms and follow proper versioning practices.

Let's verify if these version bumps align with the changes in the PR:

Also applies to: 8-8

✅ Verification successful

Version bumps are justified by significant UI/UX changes around private key handling

The version increments are warranted as the changes involve significant updates to the private key onboarding flow:

  • Updates to user-facing messages in translations
  • Changes to private key validation and error handling in EnableTransactions.tsx
  • Modifications to the private key handling logic in multiple components
  • Security-related messaging updates clarifying that private keys are not stored

These changes affect core functionality and user experience, justifying the version bumps across both platforms.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for substantial changes that would warrant version bumps

# Look for changes in source files
echo "Checking for substantial changes in source files..."
rg -l --type-add 'src:*.{ts,tsx,js,jsx}' -t src 'private.*key' 

# Look for changes in translation files
echo "Checking for changes in translation files..."
fd -e json -e ts translations/

Length of output: 432


Script:

#!/bin/bash
# Let's examine the actual changes in the identified files

# Check changes in files containing private key references
echo "Changes in EnableTransactions.tsx:"
rg -B 2 -A 2 'private.*key' screens/EnableTransactions.tsx

echo -e "\nChanges in api.ts:"
rg -B 2 -A 2 'private.*key' utils/xmtpRN/api.ts

echo -e "\nChanges in SendMoneyButton.tsx:"
rg -B 2 -A 2 'private.*key' components/Chat/Transaction/SendMoneyButton.tsx

echo -e "\nChanges in translations:"
rg -B 1 -A 1 'private.*key' i18n/translations/en.ts

Length of output: 1940

components/Onboarding/PrivateKeyConnect.tsx (1)

87-87: LGTM! Clear communication about private key handling.

The simplified subtitle effectively communicates that private keys are not stored, which aligns with the PR's objective to improve user understanding of private key handling.

utils/frames.ts (2)

274-285: Improved error handling in handleTxAction.

The error handling has been enhanced with:

  • Early validation of required parameters
  • Clear error messages for unsupported testnets
  • Proper chain ID validation
  • Transaction receipt verification

274-285: Verify PR objective alignment.

The PR description mentions fixing "private key onboarding string", but the changes in this file focus on frame message handling improvements. Please clarify if there are additional changes pending or if the PR description needs to be updated.

i18n/translations/en.ts (1)

66-66: LGTM! Clear and accurate security messaging.

The updated message "Your private key is not stored" provides a more direct and transparent communication about the application's private key handling policy. This change aligns well with the PR objective to accurately convey that the application does not store private keys.

Let's verify that all storage-related code has been removed:

✅ Verification successful

Verified: Private key storage code has been properly removed

The code inspection confirms that:

  • The PrivateKeyConnect component no longer contains any storage-related functionality
  • Previous storage-related code is commented out and appears to be in the process of removal
  • The component only temporarily holds the private key in component state (useState) for form handling
  • No localStorage, sessionStorage, or other persistent storage mechanisms are being used
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining references to private key storage
# Test: Search for mentions of private key storage. Expect: No results indicating storage.
rg -i "private.?key.*stor(e|age|ed)" --type ts --type tsx

Length of output: 87


Script:

#!/bin/bash
# Search for private key storage references with correct file extensions
rg -i "private.?key.*stor(e|age|ed)" -t ts -t typescript -t js -t jsx

# Search for any storage-related code in PrivateKeyConnect component
rg -i "PrivateKeyConnect.*storage" -t ts -t typescript -t js -t jsx

# Find and examine PrivateKeyConnect component implementation
fd -e ts -e tsx -e js -e jsx | xargs rg "PrivateKeyConnect"

Length of output: 634


Script:

#!/bin/bash
# Examine the PrivateKeyConnect component implementation
cat components/Onboarding/PrivateKeyConnect.tsx

# Look for any storage-related code with simpler pattern
rg -i "storage" components/Onboarding/PrivateKeyConnect.tsx

# Check for any localStorage or sessionStorage usage
rg -i "localStorage|sessionStorage" components/Onboarding/PrivateKeyConnect.tsx

Length of output: 4641

components/Chat/Message/Message.tsx (1)

Line range hint 1-500: Implementation looks solid!

The code demonstrates good practices with:

  • Efficient performance optimizations (memoization, caching)
  • Proper error handling
  • Clear separation of concerns
  • Comprehensive feature implementation

Comment on lines +171 to +176
useShallow((s) =>
isFrameMessage(
isContentType("text", message.contentType),
message.content,
s.frames
)
)
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider memoizing the content type check.

The isContentType check could be memoized outside the useFramesStore selector to avoid unnecessary re-computations, as it only depends on message.contentType.

Consider refactoring to:

+ const isTextContent = useMemo(
+   () => isContentType("text", message.contentType),
+   [message.contentType]
+ );
  const isFrame = useFramesStore(
    useShallow((s) =>
-     isFrameMessage(
-       isContentType("text", message.contentType),
-       message.content,
-       s.frames
-     )
+     isFrameMessage(isTextContent, message.content, s.frames)
    )
  );

Committable suggestion was skipped due to low confidence.

Copy link
Contributor

Performance Comparison Report

  • Current: 0a0b3a6 - 2024-10-31 01:15:05Z
  • Baseline: release/2.0.8 (04d44d7) - 2024-10-31 01:14:27Z

Significant Changes To Duration

There are no entries

Meaningless Changes To Duration

Show entries
Name Type Duration Count
Avatar Image 10 runs render 0.9 ms → 1.2 ms (+0.3 ms, +33.3%) 🔴 1 → 1
Avatar Image 50 runs render 1.1 ms → 1.1 ms 1 → 1
Empty Avatar 10 runs render 1.0 ms → 0.9 ms (-0.1 ms, -10.0%) 1 → 1
Empty Avatar 50 runs render 0.7 ms → 0.8 ms (+0.1 ms, +18.2%) 🔴 1 → 1
Show details
Name Type Duration Count
Avatar Image 10 runs render Baseline
Mean: 0.9 ms
Stdev: 0.3 ms (35.1%)
Runs: 1 1 1 1 1 1 1 1 1 0
Warmup runs: 2

Current
Mean: 1.2 ms
Stdev: 0.4 ms (35.1%)
Runs: 1 1 1 1 1 2 1 2 1 1
Warmup runs: 2
Baseline
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1
Render issues:

Current
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1
Render issues:
Avatar Image 50 runs render Baseline
Mean: 1.1 ms
Stdev: 0.2 ms (22.6%)
Runs: 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Warmup runs: 1

Current
Mean: 1.1 ms
Stdev: 0.2 ms (22.6%)
Runs: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 2 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Warmup runs: 2
Baseline
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Render issues:

Current
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Render issues:
Empty Avatar 10 runs render Baseline
Mean: 1.0 ms
Stdev: 0.5 ms (47.1%)
Runs: 1 2 1 1 1 1 1 1 0 1
Warmup runs: 72

Current
Mean: 0.9 ms
Stdev: 0.3 ms (35.1%)
Runs: 1 1 1 1 1 0 1 1 1 1
Warmup runs: 8
Baseline
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1
Render issues:

Current
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1
Render issues:
Empty Avatar 50 runs render Baseline
Mean: 0.7 ms
Stdev: 0.5 ms (72.5%)
Runs: 0 1 1 0 1 1 1 1 1 1 1 1 0 1 0 0 1 0 1 0 1 1 1 0 1 0 0 0 1 0 0 1 1 1 1 1 1 0 1 1 1 0 1 1 1 0 1 0 1 1
Warmup runs: 1

Current
Mean: 0.8 ms
Stdev: 0.5 ms (59.6%)
Runs: 1 1 1 0 1 1 1 1 1 1 2 1 1 1 1 1 0 1 1 1 0 1 1 1 1 1 1 0 0 0 1 0 1 1 1 1 1 0 1 1 1 1 1 0 0 1 1 1 0 0
Warmup runs: 1
Baseline
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Render issues:

Current
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Render issues:

Render Count Changes

There are no entries

Render Issues

There are no entries

Added Scenarios

There are no entries

Removed Scenarios

There are no entries

Generated by 🚫 dangerJS against 1efc8b0

Copy link
Contributor

@nmalzieu nmalzieu left a comment

Choose a reason for hiding this comment

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

Hey @saulmc I don't think your branch was based off 2.0.8 as the PrivateKeyConnect component has been removed by @thierryskoda !
There are now two components, OnboardingPrivateKeyScreen and NewAccountPrivateKeyScreen where the wording is used

@alexrisch alexrisch added the 2.0.8 Release 2.0.8 label Oct 31, 2024
ios: "your iPhone's Secure Enclave",
android: "the Android Keystore system",
},
"Enter the private key for the address you are connecting.\n\nYour private key is not stored.",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just added this fix into my PR

Copy link
Collaborator

@thierryskoda thierryskoda left a comment

Choose a reason for hiding this comment

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

@saulmc Added the text fix into my PR.

Was the other stuff intended? Because it's brining back some deleted files.

And the changes on Message.tsx and frames.ts? I think it's related to what you were doing @alexrisch right?

@saulmc
Copy link
Member Author

saulmc commented Oct 31, 2024

Thanks @thierryskoda closing this!

I don't know what's going on with the extra commits being added to the PR. Thought I screwed something up bc I hadn't made those changes locally. Fixed merge conflicts, pushed update, and they were back again. I noticed an action ran when I pushed -- wonder if that's possibly related...

@saulmc saulmc closed this Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.0.8 Release 2.0.8
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants