Skip to content

Commit

Permalink
Merge branch 'release/subintent' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
dawidsowardx committed Nov 13, 2024
2 parents 38208e7 + 0fc6024 commit 0f38cd0
Show file tree
Hide file tree
Showing 17 changed files with 514 additions and 199 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ yarn-error.log*

.envrc

examples/cdn/radix-dapp-toolkit.bundle.umd.cjs
examples/cdn/radix-dapp-toolkit.bundle.umd.js

# Editor directories and files
.vscode/*
Expand Down
4 changes: 2 additions & 2 deletions examples/cdn/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<header><radix-connect-button /></header>
<div id="app"></div>

<script src="./radix-dapp-toolkit.bundle.umd.cjs"></script>
<script src="./radix-dapp-toolkit.bundle.umd.js"></script>
<script>
const rdt = window.RDT.RadixDappToolkit({
dAppDefinitionAddress:
Expand All @@ -25,7 +25,7 @@
applicationVersion: '1.0.0',
logger: window.RDT.Logger(1),
})
console.log(rdt);
console.log(rdt)
</script>
</body>
</html>
53 changes: 53 additions & 0 deletions examples/simple-dapp/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
OneTimeDataRequestBuilder,
LocalStorageModule,
generateRolaChallenge,
SubintentRequestBuilder,
} from '@radixdlt/radix-dapp-toolkit'

const dAppDefinitionAddress = import.meta.env.VITE_DAPP_DEFINITION_ADDRESS
Expand All @@ -34,6 +35,22 @@ content.innerHTML = `
<div class="mt-25">
<button id="proof-of-ownership-request">Send proof of ownership request</button>
</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/>
<pre id="sessions"></pre>
<pre id="requests"></pre>
Expand All @@ -48,6 +65,13 @@ const sendTxButton = document.getElementById('sendTx')!
const sessions = document.getElementById('sessions')!
const removeCb = document.getElementById('removeCb')!
const addCb = document.getElementById('addCb')!
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 @@ -58,6 +82,20 @@ const proofOfOwnershipRequest = document.getElementById(
'proof-of-ownership-request',
)!

let subintentExpiration: 'afterDelay' | 'atTime' = 'afterDelay'

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 'afterDelay' | 'atTime'
}
})
})

const logger = Logger()

logger.attachTransport((logObj) => {
Expand All @@ -75,6 +113,21 @@ removeCb.onclick = () => {
document.querySelector('radix-connect-button')?.remove()
}

subintentButton.onclick = async () => {
console.log(subintentManifest.value)
console.log(subintentExpirationValue.value)
const result = await dAppToolkit.walletApi.sendPreAuthorizationRequest(
SubintentRequestBuilder()
.manifest(subintentManifest.value)
.setExpiration(
subintentExpiration,
parseInt(subintentExpirationValue.value as string),
),
)

console.log(result)
}

addCb.onclick = () => {
const connectButton = document.createElement('radix-connect-button')
const header = document.querySelector('header')!
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const RequestItemType = {
dataRequest: 'dataRequest',
sendTransaction: 'sendTransaction',
proofRequest: 'proofRequest',
preAuthorizationRequest: 'preAuthorizationRequest',
} as const

export type RequestItemType = typeof RequestItemType
Expand Down
12 changes: 11 additions & 1 deletion packages/connect-button/src/components/card/request-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,17 @@ export class RadixRequestCard extends LitElement {
content: this.getRequestContentTemplate(
'Open Your Radix Wallet App to complete the request',
),
}
},
preAuthorizationRequest: {
pending: 'Preauthorization Request Pending',
fail: 'Preauthorization Request Rejected',
cancelled: 'Preauthorization Request Rejected',
success: 'Preauthorization Request',
ignored: '',
content: this.getRequestContentTemplate(
'Open Your Radix Wallet App to complete the request',
),
},
}

return html`<radix-card
Expand Down
Loading

0 comments on commit 0f38cd0

Please sign in to comment.