feat(dashproof-lab): prevent duplicate anchors with pre-flight check and clear rejection message#94
Conversation
The Create proof form now runs findAnchorByHash right after computing the local SHA-256, mirroring VerifyPanel's lookup. If the file already has a proof on Platform it shows an "Already anchored" notice with the existing chain (linking into its history), timestamp, and owner, and removes the submit CTA so users don't attempt a write the unique hash index would reject. A failed pre-flight lookup is logged but doesn't block the local hash preview. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Disable the AnchorForm submit button after a successful anchor so the same file's hash isn't sent twice into the unique index. Translate the contract's duplicate-hash rejection into a plain-language message instead of surfacing the raw SDK error. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR adds duplicate-anchor detection to dashproof-lab: the anchor form queries whether a file hash is already anchored after hashing, displays existing proof details and a history button if found, blocks duplicate submissions, and normalizes backend duplicate errors into a consistent user-facing message. ChangesDuplicate Anchor Detection Feature
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
example-apps/dashproof-lab/src/dash/createAnchor.tsESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox. example-apps/dashproof-lab/src/dash/logger.tsESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox. example-apps/dashproof-lab/src/session/SessionContext.tsxESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox. 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. Comment |
|
@coderabbitai full review |
✅ Action performedFull review finished. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@example-apps/dashproof-lab/src/dash/createAnchor.ts`:
- Around line 88-95: The catch in createAnchor (around sdk.documents.create)
rethrows errors without logging at "error" level; update the createAnchor helper
to accept the plumbed Logger (e.g., SessionContext.log or a Logger param from
src/dash/logger.ts), and in the catch before rethrow call log("error",
<descriptive message>, { err }) or log.error with the error details; preserve
the duplicate path that throws DUPLICATE_ANCHOR_MESSAGE when
isDuplicateAnchorError(err) is true, but ensure non-duplicate errors are logged
at error level (including the original err) immediately before rethrowing from
the catch.
🪄 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: 071a1ca1-fc22-46fc-b0d0-afaf12707845
📒 Files selected for processing (5)
example-apps/dashproof-lab/src/App.tsxexample-apps/dashproof-lab/src/components/AnchorForm.tsxexample-apps/dashproof-lab/src/dash/createAnchor.tsexample-apps/dashproof-lab/test/AnchorForm.test.tsxexample-apps/dashproof-lab/test/dash.test.ts
Summary
DashProof's data contract already rejects duplicate SHA-256 hashes via a unique index, but the app exposed that only as a raw SDK error after the user had filled out and submitted the form. This PR adds two layers of duplicate handling so the dead end is caught early and explained clearly.
Changes
Pre-flight duplicate detection (
AnchorForm.tsx)findAnchorByHash. If a proof already exists, it shows an "Already anchored" notice instead of the submit CTA.onViewChainHistoryprop, wired up inApp.tsx).getSubmitPayload()helper socanSubmit, the submit handler, and the new duplicate/checkingDuplicatestates can't drift apart. Submission is blocked while the check is in flight, when a duplicate is found, or after the current file has been anchored.Hardened rejection path (
createAnchor.ts)sdk.documents.createerrors that look like a duplicate/unique-index violation are translated into a clearDUPLICATE_ANCHOR_MESSAGErather than a raw SDK error string. This covers the race where a duplicate slips past the pre-flight check.Tests
AnchorForm.test.tsx: warns and blocks submit (CTA removed,createAnchornot called) when the file is already anchored, including the chain-history link; confirms submit stays enabled with no warning for a fresh file; verifies the form can't be re-submitted after a successful anchor.dash.test.ts:createAnchorsurfacesDUPLICATE_ANCHOR_MESSAGEon a unique-index violation.All changes are scoped to
example-apps/dashproof-lab/.Summary by CodeRabbit