From 49c0bfec487c350af4ea8e974aa4d31ae584f364 Mon Sep 17 00:00:00 2001 From: Alex Stelea Date: Thu, 7 Nov 2024 10:19:37 +0000 Subject: [PATCH] code: specify expiration option in simple dapp --- examples/simple-dapp/src/main.ts | 38 +++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/examples/simple-dapp/src/main.ts b/examples/simple-dapp/src/main.ts index 56e41af1..231c6929 100644 --- a/examples/simple-dapp/src/main.ts +++ b/examples/simple-dapp/src/main.ts @@ -37,6 +37,18 @@ content.innerHTML = `
+ +
+ + +
+ + +
@@ -57,6 +69,9 @@ const subintentButton = document.getElementById('subintent')! const subintentManifest = document.getElementById( 'subintentManifest', )! as HTMLTextAreaElement +const subintentExpirationValue = document.getElementById( + 'subintentExpirationValue', +)! as HTMLInputElement const requests = document.getElementById('requests')! const logs = document.getElementById('logs')! const state = document.getElementById('state')! @@ -67,6 +82,23 @@ const proofOfOwnershipRequest = document.getElementById( 'proof-of-ownership-request', )! +let subintentExpiration: 'secondsAfterSignature' | 'atTime' = + 'secondsAfterSignature' + +document.querySelectorAll('input[name="option"]').forEach((radio) => { + radio.addEventListener('change', () => { + const selectedOption = document.querySelector( + 'input[name="option"]:checked', + ) as HTMLInputElement + if (selectedOption) { + console.log(`Selected value: ${selectedOption.value}`) + subintentExpiration = selectedOption.value as + | 'secondsAfterSignature' + | 'atTime' + } + }) +}) + const logger = Logger() logger.attachTransport((logObj) => { @@ -86,10 +118,14 @@ removeCb.onclick = () => { subintentButton.onclick = async () => { console.log(subintentManifest.value) + console.log(subintentExpirationValue.value) const result = await dAppToolkit.walletApi.sendPreAuthorizationRequest( SubintentRequestBuilder() .manifest(subintentManifest.value) - .setExpiration('secondsAfterSignature', 3600), + .setExpiration( + subintentExpiration, + subintentExpirationValue.value as unknown as number, + ), ) console.log(result)