Copy actions show success even when clipboard write fails
- 主要语言
- TypeScript
- 星标
- 5
- 派生
- 28
- 平均合并
- 9 小时 50 分钟
- 30 天内合并 PR
- 123
描述
### 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.
贡献指南
调研方向
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.
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript
- 领域
- cli, frontend
- Issue 类型
- 缺陷
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 活跃
- 描述清晰度
- 描述清楚
- 新手友好度
- 75/100