diff --git a/src/data-request/helpers/can-data-request-be-resolved-by-rdt-state.ts b/src/data-request/helpers/can-data-request-be-resolved-by-rdt-state.ts index 2138f2f5..9c12d219 100644 --- a/src/data-request/helpers/can-data-request-be-resolved-by-rdt-state.ts +++ b/src/data-request/helpers/can-data-request-be-resolved-by-rdt-state.ts @@ -30,8 +30,10 @@ export const canDataRequestBeResolvedByRdtState = ( const { quantifier, quantity } = dataRequest.ongoingAccounts.numberOfAccounts rdtStateSatisfiesRequest = - state.sharedData?.ongoingAccounts?.quantifier === quantifier && - state.sharedData?.ongoingAccounts?.quantity === quantity + state.sharedData?.ongoingAccounts?.numberOfAccounts?.quantifier === + quantifier && + state.sharedData?.ongoingAccounts?.numberOfAccounts?.quantity === + quantity } if (dataRequest.ongoingPersonaData) { diff --git a/src/data-request/transformations/shared-data.ts b/src/data-request/transformations/shared-data.ts index 999a2273..982c7435 100644 --- a/src/data-request/transformations/shared-data.ts +++ b/src/data-request/transformations/shared-data.ts @@ -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) { @@ -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, } } @@ -44,4 +56,8 @@ export const transformSharedDataToDataRequestState = ( reset: true, } } + + if (sharedData.persona) { + draft.persona = { withProof: !!sharedData.persona.proof } + } }) diff --git a/src/state/types.ts b/src/state/types.ts index ca6ba70a..804006d7 100644 --- a/src/state/types.ts +++ b/src/state/types.ts @@ -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', @@ -67,7 +75,11 @@ export const WalletData = object({ export type SharedData = z.infer export const SharedData = object({ - ongoingAccounts: NumberOfValues.optional(), + persona: object({ proof: boolean() }).optional(), + ongoingAccounts: object({ + numberOfAccounts: NumberOfValues.optional(), + proof: boolean(), + }).optional(), ongoingPersonaData: PersonaDataRequestItem.optional(), })