0xMiden / 0xMiden/wallet

Copy actions show success even when clipboard write fails

Open Beginner friendly
#635 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
5
Forks
28
Avg merge
9h 50m
Merged PRs (30d)
123

Description

### Summary

The shared `useCopyToClipboard` hook marks copy actions as successful immediately after calling `navigator.clipboard.writeText(...)`, without waiting for the returned promise to resolve or handling rejections.

### Why this matters

Clipboard writes can reject in real wallet environments, for example when the extension popup loses document focus, when a mobile/webview environment does not support the async Clipboard API, or when the permission is denied. In those cases the UI can still show the success state even though nothing was copied.

This hook backs sensitive copy flows such as seed phrase / secret reveal screens as well as address copy actions, so a false success state can make users believe they have copied recovery material or an address when the clipboard still contains old content.

### Code path

`src/lib/ui/useCopyToClipboard.ts` currently calls:

```ts
navigator.clipboard.writeText(textarea.value);
setCopied(true);
```

Because `writeText()` returns a `Promise`, a rejection leaves the failure unhandled while `copied` has already been set to `true`.

### Expected behavior

The hook should only set `copied=true` after `writeText()` resolves, and should leave/reset the copied state on rejection.

Contributor guide

Open the contributing guide

Research direction

The issue is in src/lib/ui/useCopyToClipboard.ts. Start by examining the hook's current implementation, focusing on the writeText call and state update. The fix involves awaiting the promise and handling rejections. Check for any existing tests for this hook or write a simple one to verify the success state only updates on resolution. Look at how the hook is used in components to ensure the UI responds correctly to both success and failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
cli, frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
75/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.