Skip to content

chore: add helpers for clipboard copy and paste#441

Merged
im-adithya merged 1 commit into
masterfrom
chore/clipboard-helpers
Jun 17, 2026
Merged

chore: add helpers for clipboard copy and paste#441
im-adithya merged 1 commit into
masterfrom
chore/clipboard-helpers

Conversation

@im-adithya

@im-adithya im-adithya commented Jun 17, 2026

Copy link
Copy Markdown
Member

Fixes the problem mentioned in #440 (comment), also DRYs up the clipboard code by moving it to utils

Summary by CodeRabbit

  • Refactor
    • Standardized copy and paste behavior across all app sections. Users now experience consistent success and error notifications when copying invoices, transaction details, wallet connection secrets, and payment addresses, resulting in a more unified and predictable user experience throughout the application.

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Two shared async clipboard utility functions (copyToClipboard and readClipboardText) are added to lib/utils.ts, centralizing clipboard I/O and toast notifications. Eight components previously using expo-clipboard and react-native-toast-message directly are updated to call these helpers instead.

Changes

Clipboard Utility Centralization

Layer / File(s) Summary
Shared clipboard helpers
lib/utils.ts
Adds copyToClipboard(text, successMessage?) and readClipboardText() as exported async functions, importing expo-clipboard, react-native-toast-message, and errorToast; handles success toasts, empty-clipboard errors, and read failures.
Migrate copy call sites
components/CreateInvoice.tsx, pages/Transaction.tsx, pages/receive/Receive.tsx, pages/settings/wallets/EditWallet.tsx
Removes direct expo-clipboard and react-native-toast-message imports; rewrites each copy/onPress handler as an async function awaiting copyToClipboard. EditWallet additionally passes a custom success message string.
Migrate paste call sites
pages/receive/Withdraw.tsx, pages/send/Address.tsx, pages/send/Send.tsx, pages/settings/wallets/SetupWallet.tsx
Removes expo-clipboard imports and local try/catch blocks; replaces inline Clipboard.getStringAsync() calls with readClipboardText(), acting on the result only when a non-empty string is returned.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • getAlby/go#440: Also modifies TransactionDetailRow clipboard copy behavior in pages/Transaction.tsx, making all rows copyable; the two PRs touch the same handler with overlapping intent.

Poem

🐇 Hop, hop, no more copy-paste mess,
One helper to write, one helper to read,
No scattered toasts left to address,
lib/utils.ts plants the clipboard seed.
The warren is tidy, the code is clean—
The cleverest clipboard you've ever seen! ✂️

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: introducing helper functions for clipboard copy and paste operations to reduce code duplication across multiple files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/clipboard-helpers

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pages/settings/wallets/EditWallet.tsx (1)

190-193: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Use the edited wallet id for exported secret lookup.

The export flow uses walletId for capability checks but switches to selectedWalletId for nostrWalletConnectUrl. If they diverge, the wrong wallet secret can be copied.

Suggested fix
-                      const nwcUrl =
-                        useAppStore.getState().wallets[
-                          useAppStore.getState().selectedWalletId
-                        ].nostrWalletConnectUrl;
+                      const nwcUrl =
+                        useAppStore.getState().wallets[walletId]
+                          ?.nostrWalletConnectUrl;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pages/settings/wallets/EditWallet.tsx` around lines 190 - 193, The
nostrWalletConnectUrl lookup is using selectedWalletId instead of walletId,
which creates a mismatch when the export flow uses walletId for capability
checks. Replace selectedWalletId with walletId in the wallet lookup for
nostrWalletConnectUrl so that the same wallet identifier is used consistently
throughout the export flow and the correct wallet's secret is copied.
🧹 Nitpick comments (1)
pages/receive/Withdraw.tsx (1)

61-63: ⚡ Quick win

Await loadWithdrawal in paste for consistent async flow.

This avoids a floating promise and keeps behavior aligned with other paste handlers that await downstream loaders.

Suggested fix
   async function paste() {
     const clipboardText = await readClipboardText();
     if (clipboardText) {
-      loadWithdrawal(clipboardText);
+      await loadWithdrawal(clipboardText);
     }
   }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pages/receive/Withdraw.tsx` around lines 61 - 63, The loadWithdrawal function
call in the paste handler is not being awaited, which creates a floating promise
and breaks the consistent async flow pattern. Add the await keyword before the
loadWithdrawal(clipboardText) call to ensure the promise is properly handled and
the async operation completes before moving forward, keeping the behavior
aligned with other paste handlers.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/utils.ts`:
- Around line 45-56: The copyToClipboard function lacks error handling for Web
platform failures. Add a try-catch block around the await
Clipboard.setStringAsync(text) call to handle potential rejections on Web due to
permission denial or clipboard unavailability. In the catch block, call
errorToast with an appropriate error message to provide user feedback when the
clipboard operation fails on Web platforms.

---

Outside diff comments:
In `@pages/settings/wallets/EditWallet.tsx`:
- Around line 190-193: The nostrWalletConnectUrl lookup is using
selectedWalletId instead of walletId, which creates a mismatch when the export
flow uses walletId for capability checks. Replace selectedWalletId with walletId
in the wallet lookup for nostrWalletConnectUrl so that the same wallet
identifier is used consistently throughout the export flow and the correct
wallet's secret is copied.

---

Nitpick comments:
In `@pages/receive/Withdraw.tsx`:
- Around line 61-63: The loadWithdrawal function call in the paste handler is
not being awaited, which creates a floating promise and breaks the consistent
async flow pattern. Add the await keyword before the
loadWithdrawal(clipboardText) call to ensure the promise is properly handled and
the async operation completes before moving forward, keeping the behavior
aligned with other paste handlers.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1e5e4896-eeab-4da6-87fe-3a27a2c0b96a

📥 Commits

Reviewing files that changed from the base of the PR and between 613dc04 and a10011c.

📒 Files selected for processing (9)
  • components/CreateInvoice.tsx
  • lib/utils.ts
  • pages/Transaction.tsx
  • pages/receive/Receive.tsx
  • pages/receive/Withdraw.tsx
  • pages/send/Address.tsx
  • pages/send/Send.tsx
  • pages/settings/wallets/EditWallet.tsx
  • pages/settings/wallets/SetupWallet.tsx

Comment thread lib/utils.ts
@im-adithya im-adithya merged commit cb26512 into master Jun 17, 2026
2 of 3 checks passed
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