From 1b770df7b7ac23cc225b0928d7e0bb2b72f8fafe Mon Sep 17 00:00:00 2001 From: FaithOnuh Date: Mon, 30 Mar 2026 13:06:07 +0000 Subject: [PATCH] feat(ui): trade expiry countdown and auto-release (Issue #123) - frontend/tradeExpiry.js: reusable countdown timer + showReleaseButton helper; dispatches trade:auto_released custom event on success - contract.ts: add executeAutoRelease() calling claim_time_release - trades/[id]/+page.svelte: - live countdown timer (HH:MM:SS) with aria-live for accessibility - Release Funds button appears only when isExpired && status === Funded - calls executeAutoRelease, shows tx hash on success, error on failure - cleans up interval on component destroy Closes #123 --- client/src/lib/contract.ts | 18 +++ client/src/routes/trades/[id]/+page.svelte | 105 +++++++++++++- frontend/tradeExpiry.js | 153 +++++++++++++++++++++ 3 files changed, 273 insertions(+), 3 deletions(-) create mode 100644 frontend/tradeExpiry.js diff --git a/client/src/lib/contract.ts b/client/src/lib/contract.ts index bd6155e9..e0ebd0eb 100644 --- a/client/src/lib/contract.ts +++ b/client/src/lib/contract.ts @@ -95,6 +95,24 @@ export class StellarEscrowClient { // Similar pattern for get_trade_detail // Implement based on backend TradeDetail } + + /** + * Call claim_time_release on the contract once the trade's expiry has passed. + * Anyone can call this — the contract enforces the time-lock check. + */ + async executeAutoRelease(tradeId: number, callerKeypair: string): Promise { + const account = await this.server.getAccount(callerKeypair); + const tx = new TransactionBuilder(account, { fee: BASE_FEE }) + .addInvocation( + this.contract.call('claim_time_release', xdr.ScVal.scvU64(tradeId)) + ) + .setTimeout(30) + .setNetworkPassphrase('Test SDF Network ; September 2015') + .build(); + + const txHash = await this.rpcServer.sendTransaction(tx); + return txHash; + } } export const escrowClient = new StellarEscrowClient('testnet', 'YOUR_CONTRACT_ID'); diff --git a/client/src/routes/trades/[id]/+page.svelte b/client/src/routes/trades/[id]/+page.svelte index f932e63e..3aece0e8 100644 --- a/client/src/routes/trades/[id]/+page.svelte +++ b/client/src/routes/trades/[id]/+page.svelte @@ -1,6 +1,6 @@