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 @@