Skip to content

Commit

Permalink
code: specify expiration option in simple dapp
Browse files Browse the repository at this point in the history
  • Loading branch information
xstelea committed Nov 7, 2024
1 parent d2890c0 commit 49c0bfe
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion examples/simple-dapp/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ content.innerHTML = `
</div>
<hr/>
<textarea id="subintentManifest">YIELD_TO_PARENT;</textarea>
<div class="mt-25">
<label>
<input checked type="radio" name="option" value="secondsAfterSignature"> afterDelay
</label>
<label>
<input type="radio" name="option" value="atTime"> atTime
</label>
</div>
<input id="subintentExpirationValue" type="text" value="3600"/>
<button id="subintent">Send Pre Authorization</button>
<hr/>
Expand All @@ -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')!
Expand All @@ -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) => {
Expand All @@ -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)
Expand Down

0 comments on commit 49c0bfe

Please sign in to comment.