-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: error interactions regression (#293)
* fix: error interactions regression failed interactions were never resolved in connect button * refactor: optionally provide interactionIdFactory for WalletRequestSdk module * test: fix failing unit tests
- Loading branch information
1 parent
38b990e
commit 719c02d
Showing
11 changed files
with
174 additions
and
66 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
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
35 changes: 35 additions & 0 deletions
35
...oolkit/src/modules/wallet-request/transport/testing-transport/transport.testing-module.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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { okAsync, ResultAsync } from 'neverthrow' | ||
import { TransportProvider } from '../../../../_types' | ||
import { WalletInteractionResponse } from '../../../../schemas' | ||
|
||
export const TestingTransportModule = ({ | ||
requestResolverModule, | ||
}: { | ||
requestResolverModule: { | ||
addWalletResponses: ( | ||
responses: WalletInteractionResponse[], | ||
) => ResultAsync<unknown, unknown> | ||
} | ||
}): TransportProvider & { | ||
setNextWalletResponse: (response: WalletInteractionResponse) => void | ||
} => { | ||
let _isSupported = true | ||
let id = 'TestingTransportModule' | ||
let _sendResponse: WalletInteractionResponse | ||
|
||
return { | ||
id, | ||
isSupported: () => _isSupported, | ||
destroy: () => {}, | ||
disconnect: () => {}, | ||
send: () => { | ||
requestResolverModule.addWalletResponses([_sendResponse]) | ||
return okAsync(_sendResponse) | ||
}, | ||
|
||
// Test helpers | ||
setNextWalletResponse: (response: WalletInteractionResponse) => { | ||
_sendResponse = 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
Oops, something went wrong.