Skip to content

feat: populate orders and transactions via get-escrows-by-signer (#316) - #335

Open
Benjtalkshow wants to merge 10 commits into
Kaizenode:mainfrom
Benjtalkshow:feature/populate-orders-and-transactions-316
Open

feat: populate orders and transactions via get-escrows-by-signer (#316)#335
Benjtalkshow wants to merge 10 commits into
Kaizenode:mainfrom
Benjtalkshow:feature/populate-orders-and-transactions-316

Conversation

@Benjtalkshow

@Benjtalkshow Benjtalkshow commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Closes #316

This work is for issue #316. It populates /transactions and /p2p/orders with live escrow data from GET /helper/get-escrows-by-signer.

What this adds

Wallet connection. A user can connect an existing external Stellar wallet using the Stellar Wallets Kit (Freighter, xBull, Albedo, Lobstr, Rabet, or Hana). The kit returns the wallet address, which is the signer the escrow endpoint needs. This flow only connects a wallet. It does not create one.

Client method and server route. A getEscrowsBySigner method on the Trustless Work client, plus a GET /api/escrows route that calls it so the api key stays on the server and never reaches the browser.

Data layer. Escrow types, a helper that derives status from flags and balance, adapters that map an escrow into the transaction and order shapes, and a useEscrows hook with page based pagination.

Transactions page. Lists the connected wallet's escrow history, with a no wallet prompt, loading, error, empty states, and pagination.

Orders page. A "Mis escrows" status panel above the marketplace list shows each escrow with a badge for pending, funded, disputed, or released, plus a status filter and pagination. The panel is additive, so the marketplace browse and the trade chat flow keep working.

Verified against the live API

Tested with a connected testnet wallet against real single release and multi release records:

  • Status, direction, amount, and dates render correctly.
  • The route returns 200 and proxies the real endpoint with the server key.
  • Typecheck, lint, and production build all pass.

Notes on the live API shape

Testing showed the live response differs from the docs, and the code handles it:

  • On multi release records, flags, amount, and receiver live per milestone and the top level values are null. Single release records keep them top level. Both shapes are supported.
  • Timestamps arrive as Firestore objects and are converted to ISO.
  • The endpoint rejects the role filter with a 400, so direction and status are filtered on the client instead of the server.

For review

  • The api key var is TW_API_KEY, matching app/api/.env.example. The root README mentions TRUSTLESS_WORK_API_KEY, which is inconsistent and worth aligning.
  • On the orders page, whether the marketplace list and a user's escrows should relate more directly is a product decision. I kept both and made the escrow panel additive.
  • This branch mounts the wallet provider in app/layout.tsx. Issue [FEAT]: Add the app navigation shell to connect all screens #323 also plans to edit the layout, so please review the merge order.

Proof

image image

Add Stellar wallet connection using the Stellar Wallets Kit. A user can
connect an existing external wallet such as Freighter, xBull, Albedo,
Lobstr, Rabet, or Hana. The kit opens a modal, the user picks a wallet,
and it returns the wallet address. That address is the signer the escrow
endpoints need. This flow only connects a wallet. It does not create one.

Add the data layer for the two lists. This covers the indexer types from
the Trustless Work docs, a helper that derives the status from flags and
balance, adapters that map an escrow into the order and transaction
shapes, a mock client, and a useEscrows hook with page based pagination.

Place the connect button on the orders page and the transactions page.

The pages still use mock data. The real call to get-escrows-by-signer is
not wired yet. The whole feature sits behind one function so the swap
stays small once the API client is ready.
…feature/populate-orders-and-transactions-316

# Conflicts:
#	p2p-safe-swap/app/p2p/orders/page.tsx
…node#316)

Add the getEscrowsBySigner method to the Trustless Work client, following
the existing request helper and x-api-key auth. Add a GET /api/escrows
server route that validates the signer and filter params, then calls the
client so the api key stays on the server and never reaches the browser.

Point the escrow fetch seam at the new route in place of the mock data.
The hook and adapters stay the same because the function signature did
not change.
Replace the mock transaction array with live escrows from the connected
wallet. The page reads the signer from the wallet context, calls the
useEscrows hook with the single-release filter, and maps each escrow into
a transaction row.

Add the states the page needs to work: a prompt when no wallet is
connected, a loading state, an error state, and page based navigation
using the hook pagination.
Add an escrow status panel above the marketplace order list. It reads the
signer from the wallet context, loads the escrows for that signer, and
shows each one with a status badge for pending, funded, disputed, or
released. It includes loading, error, empty, and page based navigation.

The panel is additive. The marketplace browse and the trade chat flow
keep working. How the marketplace list and a user's escrows should relate
is a product decision left for the maintainer.

Add a reusable EscrowStatusBadge and export both from the escrows module.
Add a status tab bar to the orders escrow panel, wired to the endpoint
status param, so the user can filter by pending, funded, disputed, or
released. The status names sent to the api are our assumed values and
should be confirmed against the live api.

Wire the transactions direction tabs to the endpoint role param. Entradas
maps to the receiver and Salidas maps to the service provider, which is
the payer into escrow in this model.
…#316)

Update the escrow types, status helper, and adapters to match the shape
the live API actually returns. On multi release records the flags, amount,
and receiver live per milestone, and timestamps arrive as Firestore
objects, so the code now reads from milestones and converts timestamps to
ISO. Status derivation aggregates flags across milestones.

Stop sending the role query param because the live API rejects it with a
400. Transaction direction is filtered on the client instead, and the
orders status panel filters on the client too.

Trim comments across the wallet and escrow modules and remove the unused
mock fixture. Verified with the connected wallet against real single
release and multi release records. Typecheck, lint, and production build
all pass.
…ture/populate-orders-and-transactions-316

# Conflicts:
#	p2p-safe-swap/app/p2p/orders/page.tsx
@Benjtalkshow
Benjtalkshow marked this pull request as ready for review July 26, 2026 09:22
@danielcdz
danielcdz self-requested a review July 27, 2026 14:22
@diegoTech14

Copy link
Copy Markdown
Contributor

Hi @Benjtalkshow could you resolve conflicts please?

…ture/populate-orders-and-transactions-316

# Conflicts:
#	p2p-safe-swap/lib/trustless-work.ts
@Benjtalkshow

Copy link
Copy Markdown
Contributor Author

Hi @Benjtalkshow could you resolve conflicts please?

@diegoTech14
Done

@diegoTech14

Copy link
Copy Markdown
Contributor

still conflicts sir @Benjtalkshow

…feature/populate-orders-and-transactions-316

# Conflicts:
#	p2p-safe-swap/app/layout.tsx
@Benjtalkshow

Copy link
Copy Markdown
Contributor Author

still conflicts sir @Benjtalkshow

@diegoTech14
I have resolved it

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.

Populate /transactions and /p2p/orders via GET /helper/get-escrows-by-signer

2 participants