Skip to content

Commit

Permalink
fix: improve error type returned from validateWalletResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
dawidsowardx committed Sep 24, 2024
1 parent 6d3ef6c commit ad29c8f
Showing 1 changed file with 7 additions and 4 deletions.
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<any>,
(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

0 comments on commit ad29c8f

Please sign in to comment.