Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: include challenge in reset dApp request #146

Merged
merged 2 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
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
Loading