Skip to content

Commit

Permalink
fix: include challenge in reset dApp request
Browse files Browse the repository at this point in the history
  • Loading branch information
xstelea committed Sep 27, 2023
1 parent 23a68fc commit d8fec0c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
24 changes: 20 additions & 4 deletions src/data-request/transformations/shared-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,21 @@ export const transformWalletRequestToSharedData = (
): SharedData => {
if (walletDataRequest.discriminator === 'authorizedRequest')
return produce({}, (draft: SharedData) => {
draft.persona = { proof: false }

draft.ongoingAccounts = {
proof: false,
numberOfAccounts: undefined,
}

if (walletDataRequest.auth.discriminator === 'loginWithChallenge')
draft.persona.proof = !!walletDataRequest.auth.challenge

if (walletDataRequest.ongoingAccounts) {
draft.ongoingAccounts =
walletDataRequest.ongoingAccounts.numberOfAccounts
draft.ongoingAccounts = {
proof: !!walletDataRequest.ongoingAccounts.challenge,
numberOfAccounts: walletDataRequest.ongoingAccounts.numberOfAccounts,
}
}

if (walletDataRequest.ongoingPersonaData) {
Expand All @@ -28,8 +40,8 @@ export const transformSharedDataToDataRequestState = (
produce({}, (draft: DataRequestState) => {
if (sharedData.ongoingAccounts) {
draft.accounts = {
numberOfAccounts: sharedData.ongoingAccounts,
withProof: false,
numberOfAccounts: sharedData.ongoingAccounts.numberOfAccounts!,
withProof: sharedData.ongoingAccounts.proof,
reset: true,
}
}
Expand All @@ -44,4 +56,8 @@ export const transformSharedDataToDataRequestState = (
reset: true,
}
}

if (sharedData.persona) {
draft.persona = { withProof: !!sharedData.persona.proof }
}
})
16 changes: 14 additions & 2 deletions src/state/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ import {
PersonaDataRequestItem,
Proof,
} from '@radixdlt/wallet-sdk'
import { array, discriminatedUnion, literal, object, string, z } from 'zod'
import {
array,
boolean,
discriminatedUnion,
literal,
object,
string,
z,
} from 'zod'

export const proofType = {
persona: 'persona',
Expand Down Expand Up @@ -67,7 +75,11 @@ export const WalletData = object({

export type SharedData = z.infer<typeof SharedData>
export const SharedData = object({
ongoingAccounts: NumberOfValues.optional(),
persona: object({ proof: boolean() }).optional(),
ongoingAccounts: object({
numberOfAccounts: NumberOfValues.optional(),
proof: boolean(),
}).optional(),
ongoingPersonaData: PersonaDataRequestItem.optional(),
})

Expand Down

0 comments on commit d8fec0c

Please sign in to comment.