Skip to content

Commit

Permalink
fix(rdt): update rdt state after ongoing response
Browse files Browse the repository at this point in the history
  • Loading branch information
xstelea committed Oct 9, 2024
1 parent 2dd5155 commit 5380b44
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 12 deletions.
33 changes: 32 additions & 1 deletion examples/simple-dapp/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ content.innerHTML = `
<button id="removeCb">Remove Connect Button</button>
<button id="addCb">Add Connect Button</button>
<div class="mt-25"><button id="one-time-request">Send one time request</button></div>
<div class="mt-25">
<button id="one-time-request">Send one time request</button>
</div>
<div class="mt-25">
<button id="proof-of-ownership-request">Send proof of ownership request</button>
</div>
<pre id="sessions"></pre>
<pre id="requests"></pre>
Expand All @@ -49,6 +54,9 @@ const state = document.getElementById('state')!
const gatewayConfig = document.getElementById('gatewayConfig')!
const gatewayStatus = document.getElementById('gatewayStatus')!
const oneTimeRequest = document.getElementById('one-time-request')!
const proofOfOwnershipRequest = document.getElementById(
'proof-of-ownership-request',
)!

const logger = Logger()

Expand Down Expand Up @@ -128,6 +136,29 @@ oneTimeRequest.onclick = () => {
)
}

proofOfOwnershipRequest.onclick = async () => {
const connectedAccounts =
dAppToolkit.walletApi.getWalletData()?.accounts ?? []
const connectedPersona = dAppToolkit.walletApi.getWalletData()?.persona

if (connectedAccounts.length === 0 || !connectedPersona) {
alert('No connected account or persona')
return
}

const result = await dAppToolkit.walletApi
.sendOneTimeRequest(
OneTimeDataRequestBuilder.accounts().exactly(1),
OneTimeDataRequestBuilder.proofOfOwnership()
.accounts(connectedAccounts.map((account) => account.address))
.identity(connectedPersona.identityAddress),
)
.map(() => 'success')
.unwrapOr('error')

alert(result)
}

setInterval(() => {
requestsStore.getState().map((value: any) => {
requests.innerHTML = JSON.stringify({ requests: value ?? {} }, null, 2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,19 @@ const handleAuthorizedRequestResponse = ({
stateModule
.getState()
.andThen((state) =>
stateModule.setState({
loggedInTimestamp:
requestItem.type === 'loginRequest'
? Date.now().toString()
: state!.loggedInTimestamp,
walletData,
sharedData: transformWalletRequestToSharedData(
walletInteraction,
state!.sharedData,
),
}),
stateModule
.setState({
loggedInTimestamp:
requestItem.type === 'loginRequest'
? Date.now().toString()
: state!.loggedInTimestamp,
walletData,
sharedData: transformWalletRequestToSharedData(
walletInteraction,
state!.sharedData,
),
})
.andTee(() => stateModule.emitWalletData()),
)
.orElse(() =>
err(SdkError('FailedToUpdateRdtState', walletInteraction.interactionId)),
Expand Down

0 comments on commit 5380b44

Please sign in to comment.