-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
failed interactions were never resolved in connect button
- Loading branch information
1 parent
38b990e
commit 4254878
Showing
7 changed files
with
50 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 11 additions & 19 deletions
30
packages/dapp-toolkit/src/helpers/validate-wallet-response.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,22 @@ | ||
import { Result, ResultAsync, errAsync, okAsync } from 'neverthrow' | ||
import { | ||
WalletInteractionResponse, | ||
WalletInteractionSuccessResponse, | ||
} from '../schemas' | ||
import { Result } from 'neverthrow' | ||
import { WalletInteractionResponse } from '../schemas' | ||
import { SdkError } from '../error' | ||
import { parse } from 'valibot' | ||
|
||
export const validateWalletResponse = ( | ||
walletResponse: unknown, | ||
): ResultAsync< | ||
WalletInteractionSuccessResponse, | ||
SdkError | { discriminator: 'failure'; interactionId: string; error: string } | ||
> => { | ||
): Result<WalletInteractionResponse, SdkError> => { | ||
const fn = Result.fromThrowable( | ||
(_) => parse(WalletInteractionResponse, _), | ||
(error) => error, | ||
) | ||
|
||
const result = fn(walletResponse) | ||
if (result.isErr()) { | ||
return errAsync(SdkError('walletResponseValidation', '', 'Invalid input')) | ||
} else if (result.isOk()) { | ||
return result.value.discriminator === 'success' | ||
? okAsync(result.value) | ||
: errAsync(result.value) | ||
} | ||
|
||
return errAsync(SdkError('walletResponseValidation', '')) | ||
return fn(walletResponse).mapErr((response) => | ||
SdkError( | ||
'walletResponseValidation', | ||
(walletResponse as any)?.interactionId, | ||
'Invalid input', | ||
response, | ||
), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters