Skip to content

Fix escrow viewer error state and PDF export handling #63

@techrebelgit

Description

@techrebelgit

Context

After merging PR #62 for the Escrow Viewer PDF export feature, a few follow-up cleanup issues remain on main.

This task is intentionally small and focused. The goal is to improve production quality without changing escrow behavior or adding new product scope.

The Escrow Viewer is a read-only transparency surface. It should preserve clarity, avoid unnecessary console noise, handle errors safely, and provide good feedback when exporting reports.


Problem

Current issues observed on main:

  1. src/components/escrow/EscrowDetails.tsx still disables @typescript-eslint/no-explicit-any and uses catch (err: any).
  2. src/components/escrow/escrow-content.tsx imports error from next/error, then uses it in the welcome-state condition. This appears to be an incorrect import and may prevent the welcome state from behaving as intended.
  3. src/components/escrow/title-card.tsx calls exportEscrowToPDF() directly without loading state, error handling, or user feedback.

Objective

Clean up the escrow viewer error state and PDF export UX after the PDF export merge.


Scope of Work

1. Remove unsafe any usage in EscrowDetails.tsx

  • Remove the file-level eslint disable:
/* eslint-disable @typescript-eslint/no-explicit-any */
  • Replace catch (err: any) with safe unknown error handling.
  • Prefer a small reusable helper if useful, for example:
const getErrorMessage = (error: unknown, fallback: string): string => {
  if (error instanceof Error) return error.message;
  if (typeof error === "string") return error;
  return fallback;
};
  • Use the helper in transaction fetching error handling.

2. Fix invalid error usage in escrow-content.tsx

  • Remove this import:
import error from "next/error";
  • Ensure WelcomeState only appears when there is no organized escrow data and loading is false.
  • If actual error state is needed in this component, pass it explicitly as a typed prop from EscrowDetails.tsx.
  • Do not depend on next/error for UI state.

3. Improve PDF export button handling

In src/components/escrow/title-card.tsx:

  • Add export loading state.
  • Prevent duplicate clicks while export is running.
  • Wrap exportEscrowToPDF(organized, currentNetwork) in try/catch.
  • Show user feedback with existing project UI patterns. The repo already has sonner, so toast.success / toast.error is acceptable if consistent with the app.
  • Disable the button when no organized escrow data is available or while exporting.

Suggested behavior:

  • Button label changes to Exporting... while generating.
  • On success: show a success toast.
  • On failure: show an error toast with a safe fallback message.

Non-Goals

  • Do not change escrow fetching logic beyond the error handling cleanup.
  • Do not change the PDF content structure.
  • Do not add new PDF dependencies.
  • Do not change escrow lifecycle logic.
  • Do not add wallet interaction.
  • Do not modify smart contract, API, or signing behavior.

Acceptance Criteria

  • EscrowDetails.tsx no longer disables @typescript-eslint/no-explicit-any.
  • No catch (err: any) remains in the touched files.
  • escrow-content.tsx no longer imports error from next/error.
  • Welcome state behavior is based on actual component state, not a Next.js import.
  • PDF export button has a loading state.
  • PDF export button prevents duplicate export clicks.
  • PDF export success and failure produce user-visible feedback.
  • No new dependencies are added.
  • TypeScript types remain explicit and safe.

Suggested Files

src/components/escrow/EscrowDetails.tsx
src/components/escrow/escrow-content.tsx
src/components/escrow/title-card.tsx

Optional:

src/utils/error.ts

Security / Product Notes

  • Viewer must remain read-only.
  • No wallet connection should be required.
  • No escrow state should be modified.
  • Avoid exposing unnecessary raw data in production logs.
  • Keep testnet/mainnet behavior unchanged.

Recommended Validation

  • Load the default viewer state and confirm the welcome state appears correctly.
  • Load a valid escrow and confirm the details render.
  • Export a PDF and confirm the button shows loading feedback.
  • Try clicking export repeatedly and confirm duplicate exports are prevented.
  • Temporarily simulate export failure and confirm the error feedback is shown.
  • Run lint/type checks according to normal repo workflow if available.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions