Skip to content

Commit

Permalink
Merge pull request #259 from radixdlt/RDT-219
Browse files Browse the repository at this point in the history
feat: bump valibot version
  • Loading branch information
dawidsowardx authored Sep 24, 2024
2 parents ab6e22a + ad29c8f commit ea39977
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 135 deletions.
18 changes: 13 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/dapp-toolkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"rxjs": "^7.8.1",
"tslog": ">=4.8.0",
"uuid": "^10.0.0",
"valibot": "0.30.0"
"valibot": "0.42.1"
},
"devDependencies": {
"@radixdlt/connect-button": "*",
Expand Down
11 changes: 7 additions & 4 deletions packages/dapp-toolkit/src/helpers/validate-wallet-response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ import {
WalletInteractionSuccessResponse,
} from '../schemas'
import { SdkError } from '../error'
import { ValiError, parse } from 'valibot'
import { parse } from 'valibot'

export const validateWalletResponse = (
walletResponse: unknown,
): ResultAsync<WalletInteractionSuccessResponse, SdkError> => {
): ResultAsync<
WalletInteractionSuccessResponse,
SdkError | { discriminator: 'failure'; interactionId: string; error: string }
> => {
const fn = Result.fromThrowable(
(_) => parse(WalletInteractionResponse, _),
(error) => error as ValiError,
(error) => error,
)

const result = fn(walletResponse)
Expand All @@ -20,7 +23,7 @@ export const validateWalletResponse = (
} else if (result.isOk()) {
return result.value.discriminator === 'success'
? okAsync(result.value)
: errAsync(result.value as any)
: errAsync(result.value)
}

return errAsync(SdkError('walletResponseValidation', ''))
Expand Down
16 changes: 8 additions & 8 deletions packages/dapp-toolkit/src/modules/state/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,31 @@ import {
object,
variant,
string,
Output,
InferOutput,
} from 'valibot'

export const proofType = {
persona: 'persona',
account: 'account',
} as const

export type SignedChallengePersona = Output<typeof SignedChallengePersona>
export type SignedChallengePersona = InferOutput<typeof SignedChallengePersona>
export const SignedChallengePersona = object({
challenge: string(),
proof: Proof,
address: string(),
type: literal(proofType.persona),
})

export type SignedChallengeAccount = Output<typeof SignedChallengeAccount>
export type SignedChallengeAccount = InferOutput<typeof SignedChallengeAccount>
export const SignedChallengeAccount = object({
challenge: string(),
proof: Proof,
address: string(),
type: literal(proofType.account),
})

export type SignedChallenge = Output<typeof SignedChallenge>
export type SignedChallenge = InferOutput<typeof SignedChallenge>
export const SignedChallenge = variant('type', [
SignedChallengePersona,
SignedChallengeAccount,
Expand All @@ -59,22 +59,22 @@ export const WalletDataPersonaDataPhoneNumbersAddresses = object({
fields: array(string()),
})

export type WalletDataPersonaData = Output<typeof WalletDataPersonaData>
export type WalletDataPersonaData = InferOutput<typeof WalletDataPersonaData>
export const WalletDataPersonaData = variant('entry', [
WalletDataPersonaDataFullName,
WalletDataPersonaDataEmailAddresses,
WalletDataPersonaDataPhoneNumbersAddresses,
])

export type WalletData = Output<typeof WalletData>
export type WalletData = InferOutput<typeof WalletData>
export const WalletData = object({
accounts: array(Account),
personaData: array(WalletDataPersonaData),
persona: optional(Persona),
proofs: array(SignedChallenge),
})

export type SharedData = Output<typeof SharedData>
export type SharedData = InferOutput<typeof SharedData>
export const SharedData = object({
persona: optional(object({ proof: boolean() })),
ongoingAccounts: optional(
Expand All @@ -86,7 +86,7 @@ export const SharedData = object({
ongoingPersonaData: optional(PersonaDataRequestItem),
})

export type RdtState = Output<typeof RdtState>
export type RdtState = InferOutput<typeof RdtState>
export const RdtState = object({
loggedInTimestamp: string(),
walletData: WalletData,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { produce } from 'immer'
import { boolean, object, Output, optional } from 'valibot'
import { boolean, object, InferOutput, optional } from 'valibot'
import { NumberOfValues } from '../../../../schemas'

export type AccountsRequestBuilder = {
Expand All @@ -13,7 +13,7 @@ export type OneTimeAccountsRequestBuilder = {
exactly: (n: number) => OneTimeAccountsRequestBuilder
withProof: (value?: boolean) => OneTimeAccountsRequestBuilder
}
export type AccountsDataRequest = Output<typeof AccountsDataRequestSchema>
export type AccountsDataRequest = InferOutput<typeof AccountsDataRequestSchema>

export const AccountsDataRequestSchema = object({
numberOfAccounts: NumberOfValues,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { produce } from 'immer'
import { boolean, object, Output, partial } from 'valibot'
import { boolean, object, InferOutput, partial } from 'valibot'
import { NumberOfValues } from '../../../../schemas'

export type PersonaDataRequestBuilder = {
Expand All @@ -13,7 +13,7 @@ export type OneTimePersonaDataRequestBuilder = {
emailAddresses: (value?: boolean) => PersonaDataRequestBuilder
phoneNumbers: (value?: boolean) => PersonaDataRequestBuilder
}
export type PersonaDataRequest = Output<typeof PersonaDataRequestSchema>
export type PersonaDataRequest = InferOutput<typeof PersonaDataRequestSchema>

export const PersonaDataRequestSchema = partial(
object({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { produce } from 'immer'
import { boolean, object, Output, optional } from 'valibot'
import { boolean, object, InferOutput, optional } from 'valibot'

export type PersonaRequestBuilder = {
withProof: (value?: boolean) => PersonaRequestBuilder
}
export type PersonaRequest = Output<typeof schema>
export type PersonaRequest = InferOutput<typeof schema>

const schema = object({
withProof: optional(boolean()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { NumberOfValues } from '../../../../schemas'
import { produce } from 'immer'
import type { Result } from 'neverthrow'
import { ok } from 'neverthrow'
import { boolean, object, string, Output, optional } from 'valibot'
import { boolean, object, string, InferOutput, optional } from 'valibot'

export type TransformRdtDataRequestToWalletRequestInput = Output<
export type TransformRdtDataRequestToWalletRequestInput = InferOutput<
typeof TransformRdtDataRequestToWalletRequestInput
>
export const TransformRdtDataRequestToWalletRequestInput = object({
Expand Down
Loading

0 comments on commit ea39977

Please sign in to comment.