Copy actions show success even when clipboard write fails
- Ngôn ngữ chính
- TypeScript
- Star
- 5
- Fork
- 28
- Merge trung bình
- 9 giờ 50 phút
- Pull request đã merge (30 ngày)
- 123
Mô tả
### 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.
Hướng dẫn đóng góp
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- typescript
- Lĩnh vực
- cli, frontend
- Loại issue
- Lỗi
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức độ hoạt động
- Sôi nổi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 75/100