Skip to content

feat(dashproof-lab): prevent duplicate anchors with pre-flight check and clear rejection message#94

Merged
thephez merged 3 commits into
dashpay:mainfrom
thephez:dashproof/cleanup
Jun 11, 2026
Merged

feat(dashproof-lab): prevent duplicate anchors with pre-flight check and clear rejection message#94
thephez merged 3 commits into
dashpay:mainfrom
thephez:dashproof/cleanup

Conversation

@thephez

@thephez thephez commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

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)

  • After hashing a selected file locally, the form looks up the hash via findAnchorByHash. If a proof already exists, it shows an "Already anchored" notice instead of the submit CTA.
  • The notice surfaces the existing anchor's chain, timestamp, and owner, and links the chain ID into that chain's history (new onViewChainHistory prop, wired up in App.tsx).
  • The lookup is best-effort: a failed pre-flight query is logged but never blocks the local hash preview — the unique index remains the real guard.
  • Submit gating consolidated into a single getSubmitPayload() helper so canSubmit, the submit handler, and the new duplicate/checkingDuplicate states 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.create errors that look like a duplicate/unique-index violation are translated into a clear DUPLICATE_ANCHOR_MESSAGE rather 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, createAnchor not 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: createAnchor surfaces DUPLICATE_ANCHOR_MESSAGE on a unique-index violation.

All changes are scoped to example-apps/dashproof-lab/.

Summary by CodeRabbit

  • New Features
    • Duplicate anchor detection: the app checks if a file hash is already anchored before allowing submission.
    • View existing proof details (chain, timestamp, owner) and a link to open chain history when a duplicate is found.
  • Bug Fixes
    • Prevents submitting already-anchored files and shows a clear duplicate-error message.
  • Tests
    • Added coverage for duplicate-anchor scenarios and navigation-to-history behavior.

thephez and others added 2 commits June 9, 2026 17:01
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>
@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3a3e5d2e-30c3-4798-b22e-9ade601ab700

📥 Commits

Reviewing files that changed from the base of the PR and between b530eb9 and f95dcef.

📒 Files selected for processing (3)
  • example-apps/dashproof-lab/src/dash/createAnchor.ts
  • example-apps/dashproof-lab/src/dash/logger.ts
  • example-apps/dashproof-lab/src/session/SessionContext.tsx
✅ Files skipped from review due to trivial changes (1)
  • example-apps/dashproof-lab/src/dash/logger.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • example-apps/dashproof-lab/src/dash/createAnchor.ts

📝 Walkthrough

Walkthrough

This 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.

Changes

Duplicate Anchor Detection Feature

Layer / File(s) Summary
Duplicate anchor error handling in createAnchor
example-apps/dashproof-lab/src/dash/createAnchor.ts, example-apps/dashproof-lab/test/dash.test.ts
Exports DUPLICATE_ANCHOR_MESSAGE, detects duplicate/uniqueness SDK errors via errorMessage, and converts them to a consistent Error with that message while rethrowing other errors; test asserts the transformed message on duplicate failures.
AnchorForm duplicate detection logic and UI
example-apps/dashproof-lab/src/components/AnchorForm.tsx, example-apps/dashproof-lab/test/AnchorForm.test.tsx
Adds optional onViewChainHistory prop; introduces checkingDuplicate, existingAnchor, and anchoredCurrentFile state; after hashing calls findAnchorByHash to preflight-check duplicates; implements getSubmitPayload() to gate submission; shows "Checking for existing proof…" spinner and an "Already anchored" notice with chain/timestamp/owner and a history button that calls onViewChainHistory; tests mock findAnchorByHash and cover duplicate and non-duplicate flows plus submission behavior.
App callback wiring
example-apps/dashproof-lab/src/App.tsx
Passes openHistoryForChain into AnchorForm as onViewChainHistory, enabling navigation to the history tab from the duplicate notice.
Logger and SessionContext logging signature
example-apps/dashproof-lab/src/dash/logger.ts, example-apps/dashproof-lab/src/session/SessionContext.tsx
Expands exported Logger type to accept optional details payload and updates SessionProvider's log to include details in console output when provided.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 A nibble, a hash, a careful peek,
Before we anchor, we quietly seek.
If proof exists, we show its light—
Tap history, and there’s yesterday’s sight. ✨

🚥 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 clearly and specifically summarizes the main change: adding duplicate anchor prevention through pre-flight checks and improved error messaging.
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 unit tests (beta)
  • Create PR with unit tests

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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

example-apps/dashproof-lab/src/dash/createAnchor.ts

ESLint 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.ts

ESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.

example-apps/dashproof-lab/src/session/SessionContext.tsx

ESLint 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.

❤️ Share

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

thephez

This comment was marked as duplicate.

thephez

This comment was marked as duplicate.

@thephez

thephez commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.

@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

🤖 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

📥 Commits

Reviewing files that changed from the base of the PR and between 484d2f2 and b530eb9.

📒 Files selected for processing (5)
  • example-apps/dashproof-lab/src/App.tsx
  • example-apps/dashproof-lab/src/components/AnchorForm.tsx
  • example-apps/dashproof-lab/src/dash/createAnchor.ts
  • example-apps/dashproof-lab/test/AnchorForm.test.tsx
  • example-apps/dashproof-lab/test/dash.test.ts

Comment thread example-apps/dashproof-lab/src/dash/createAnchor.ts
@thephez thephez merged commit 683c5ca into dashpay:main Jun 11, 2026
3 checks passed
@thephez thephez deleted the dashproof/cleanup branch June 11, 2026 19:51
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