Skip to content

Conversation

@PeterOche
Copy link

@PeterOche PeterOche commented Nov 7, 2025

PR Title
Feature: PDF Export for Escrow Audit Report

Summary
Adds a client-side “Export to PDF” feature to the Escrow Viewer. Users can generate a downloadable PDF audit report for any escrow (Testnet/Mainnet) with header, footer, and key configuration details.

What’s Included:

  1. Export Button
  2. Themed 
  3. Button
  4.  on escrow detail view using existing UI styles.
  5. Accessible label, FileDown icon, responsive-friendly.
  6. Client-Side PDF Generation
  7. New utility 
  8. src/utils/pdf/exportEscrowReport.ts
  9.  using jspdf.
  10. Header with Trustless Work logo and network tag.
  11. Footer with website and source URL.
  12. Timestamp of report generation.
  13. Sections:
  14. Title and Description
  15. Escrow Details: Escrow ID, Engagement ID, Amount, Balance, Platform Fee, Asset (trustline)
  16. Assigned Roles (human-friendly labels)
  17. Milestones (single and multi-release: titles, amounts, status, approved, signer/approver when present)
  18. Pagination-aware, increased spacing for readability.

UI/UX

Button matches current app theme.
Improved spacing/margins/line-height within the PDF for readability.
Falls back gracefully if the logo is not available.

How to Test
Create a Testnet escrow in the BackOffice (multi-release recommended).
Open the escrow in the Viewer.
Click “Export to PDF”.
Verify:
Header, footer, timestamp, network tag (Testnet/Mainnet).
Escrow ID, Engagement ID, Description, Platform Fee.
Roles (marker, approver, receiver, release signer, platform, dispute resolver).
Milestones (titles, amounts for multi-release, status/approved).
Layout and pagination look good for multiple milestones.

Screenshots:

image

Notes / Limitations:

Asset info currently shows the trustline address. The acceptance criteria mentions “Asset (code, issuer)”. The app does not yet expose code/issuer; a follow-up could resolve asset code/issuer from the trustline via a public API and include it in the PDF.

Future Enhancements

Add transaction history and lifecycle events (from Soroban Hooks).
Include signature hashes or verification QR codes.
Pagination/styling improvements for very long lists.
Offer JSON export alongside PDF.

Technical:
New dependency: jspdf.
exportEscrowReport is async and runs fully client-side.
Uses existing ROLE_MAPPING for readable role labels.
Button added in EscrowContent near the title section.

Acceptance Criteria Mapping
“Export to PDF” button visible on escrow detail view: Implemented.
PDF includes roles, milestones, metadata, and fees: Implemented.
Works for single- and multi-release escrows: Implemented.
Header, footer, date, and network tag: Implemented.
Fully client-side: Implemented.
Documentation and screenshots: Included in this PR.

closes #28

Summary by CodeRabbit

  • New Features

    • Export escrow reports to PDF from the escrow view via an "Export to PDF" button; includes title, description, details, roles, milestones and auto-named files with escrow ID and network.
    • Shows progress and disables the button while exporting, with user feedback on success/failure.
  • Chores

    • Added PDF generation dependency (jspdf) to support exports.

@vercel
Copy link
Contributor

vercel bot commented Nov 7, 2025

Someone is attempting to deploy a commit to the Trustless Work Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link

coderabbitai bot commented Nov 7, 2025

Walkthrough

Adds client-side PDF export: introduces jsPDF dependency, an "Export to PDF" button in the escrow detail UI with loading/toast handling, and a new utility at src/utils/pdf/exportEscrowReport.ts that builds and saves multi-page escrow audit PDFs (includes logo, metadata, roles, milestones, footer).

Changes

Cohort / File(s) Summary
Dependency Addition
package.json
Added jspdf dependency (^3.0.3) for client-side PDF generation
UI Button & State
src/components/escrow/escrow-content.tsx
Added export button, loading state, toast error handling, and uses network context (currentNetwork) to call PDF exporter
PDF Report Generation
src/utils/pdf/exportEscrowReport.ts
New module exporting NetworkTag and exportEscrowReport(organized, network); builds multi-page PDF with optional logo, header/footer, metadata, escrow details, roles, milestones, text wrapping and page breaks; saves file as trustlesswork-escrow-{id}-{network}.pdf

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant UI as Escrow Detail (Button)
    participant Export as exportEscrowReport
    participant jsPDF as jsPDF Library
    participant Browser as Browser Download

    User->>UI: Click "Export to PDF"
    UI->>UI: set exporting=true (show loader)
    UI->>Export: exportEscrowReport(organized, network)
    Export->>Export: load logo (optional)
    Export->>jsPDF: init doc, add header/meta/content
    Export->>jsPDF: paginate & wrap text
    Export->>jsPDF: finalize & save file
    jsPDF->>Browser: trigger download
    Browser->>User: Download PDF
    UI->>UI: set exporting=false (hide loader)
    Note right of Export: filename -> trustlesswork-escrow-{id}-{network}.pdf
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • New dependency + new UI + substantial new utility module with layout/pagination logic.
  • Review attention:
    • exportEscrowReport for text-wrapping, page-break correctness, and logo-loading fallback.
    • Filename construction and safe access to organized properties.
    • UI error handling and toast messages integration.

Possibly related issues

  • Trustless-Work/Product#157 — Implements client-side "Export to PDF" feature (adds jspdf, exporter util, and Export button); strongly aligned with this PR's changes.
  • #28: Add PDF Export Feature to Trustless Work Escrow Viewer — This PR implements the requested Export to PDF acceptance criteria (button, header/footer, network tag, client-side generation).

Possibly related PRs

  • escrow-viewer#18 — Related: introduces/uses network context (useNetwork / currentNetwork) which this PR consumes when generating the PDF.

Poem

🐰 I nibble bytes and format rows,

Titles, roles, and milestone glows,
jsPDF hops, the pages stack,
A trusted audit — saved and packed,
Down the burrow — PDF on track! 🎉

Pre-merge checks and finishing touches

❌ 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%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ 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 'Feature: PDF Export' clearly and concisely describes the main change: adding PDF export functionality to the escrow viewer.
Linked Issues check ✅ Passed The PR implementation fully satisfies all primary coding objectives: PDF export button added, client-side PDF generation using jspdf, includes all required escrow details (ID, Engagement ID, roles, milestones, fees, network tag), header/footer/timestamp, and supports both single and multi-release escrows.
Out of Scope Changes check ✅ Passed All changes are directly scoped to PDF export feature: jspdf dependency, export utility module, and UI button integration. No extraneous modifications detected.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7e3777b and 2fa85e2.

📒 Files selected for processing (2)
  • src/components/escrow/escrow-content.tsx (5 hunks)
  • src/utils/pdf/exportEscrowReport.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/utils/pdf/exportEscrowReport.ts (2)
src/mappers/escrow-mapper.ts (1)
  • OrganizedEscrowData (28-37)
src/lib/escrow-constants.ts (1)
  • ROLE_MAPPING (12-23)
src/components/escrow/escrow-content.tsx (1)
src/utils/pdf/exportEscrowReport.ts (1)
  • exportEscrowReport (91-272)
🔇 Additional comments (2)
src/components/escrow/escrow-content.tsx (1)

70-103: Solid exporting UX upgrade.
Async handler, guarded state, and toast feedback close the loop on export reliability and user visibility—nicely handled.

src/utils/pdf/exportEscrowReport.ts (1)

9-88: Timeout & cleanup look great.
Racing the image load with a timeout plus aggressive cleanup prevents logo hangs and keeps PDF generation resilient.


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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ab77cb2 and 7e3777b.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • package.json (1 hunks)
  • src/components/escrow/escrow-content.tsx (3 hunks)
  • src/utils/pdf/exportEscrowReport.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/components/escrow/escrow-content.tsx (1)
src/utils/pdf/exportEscrowReport.ts (1)
  • exportEscrowReport (36-206)
src/utils/pdf/exportEscrowReport.ts (2)
src/mappers/escrow-mapper.ts (1)
  • OrganizedEscrowData (28-37)
src/lib/escrow-constants.ts (1)
  • ROLE_MAPPING (12-23)
🔇 Additional comments (6)
src/components/escrow/escrow-content.tsx (1)

11-13: LGTM!

The imports are correctly organized and necessary for the PDF export feature.

src/utils/pdf/exportEscrowReport.ts (4)

43-50: LGTM!

The line helper correctly handles pagination by detecting when content exceeds the page height and creating a new page with a re-rendered header. The logic is sound.


52-68: LGTM!

The text wrapping and formatting logic correctly handles multi-line content with proper line advancement. The separation of concerns between text rendering and line advancement is intentional and provides flexibility.


76-94: LGTM!

The header rendering with optional logo, title, network tag, and divider line is well-implemented. The graceful fallback when the logo is unavailable ensures the report can always be generated.


135-143: LGTM!

The defensive programming throughout this code is excellent:

  • Using String(props.engagement_id || "-") for potentially missing properties
  • Type guards for optional milestone fields (typeof m.signer === "string")
  • Fallback values for missing data

This ensures the PDF generation is robust even with incomplete data.

Also applies to: 159-163, 179-197

package.json (1)

23-23: No issues found—jspdf version is current and secure.

Version 3.0.3 is the latest release and is not affected by any known security vulnerabilities. The caret constraint (^3.0.3) is appropriate and safe.

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.

Add PDF Export Feature to Trustless Work Escrow Viewer

1 participant