Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Commit

Permalink
fix: decode usePersona wallet response
Browse files Browse the repository at this point in the history
  • Loading branch information
xstelea committed Feb 6, 2023
1 parent 09add37 commit 0d9475f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/IO/decode-wallet-response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const decodeWalletResponse = <R>(
case RequestTypeSchema.auth.value: {
const { discriminator: authDiscriminator, ...auth } = value
if (authDiscriminator === 'usePersona') {
return { ...acc, persona: auth }
return { ...acc, persona: auth.persona }
} else {
return { ...acc, login: auth }
}
Expand Down
3 changes: 2 additions & 1 deletion lib/IO/request-items/use-persona.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
AuthUsePersonaRequestItem,
AuthUsePersonaRequestResponseItem,
Persona,
} from '../schemas'

export type UsePersona = {
Expand All @@ -11,7 +12,7 @@ export type UsePersona = {
method: {
input: { identityAddress: string }
output: {
auth: { identityAddress: string }
persona: Persona
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/__tests__/decode-wallet-response.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('decodeWalletResponse', () => {
discriminator: 'authorizedRequest',
auth: {
discriminator: 'usePersona',
identityAddress: 'addr_xxx',
persona: { identityAddress: 'addr_xxx' },
},
oneTimeAccounts: {
accounts: [
Expand Down
18 changes: 16 additions & 2 deletions lib/__tests__/wallet-sdk.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,26 @@ describe('sdk flow', () => {
)
)

sdk
.request(
{
usePersona: {
identityAddress:
'account_tdx_b_1qlu8fdyj77jpmu2mqe4rgh3738jcva4nfd2y2vp675zqgdg72y',
},
},
{
eventCallback: callbackSpy,
}
)
.map((result) => result.persona)

// mock a wallet response
delay(300).then(() => {
sendIncomingMessage({
discriminator: 'authorizedRequest',
auth: {
discriminator: 'loginWithoutChallenge',
discriminator: 'usePersona',
persona: {
identityAddress:
'account_tdx_b_1qlu8fdyj77jpmu2mqe4rgh3738jcva4nfd2y2vp675zqgdg72y',
Expand All @@ -274,7 +288,7 @@ describe('sdk flow', () => {
const result = await request

if (result.isErr()) throw new Error('should not get a error response')
expect((result.value as any).login.persona.identityAddress).toEqual(
expect((result.value as any).persona.identityAddress).toEqual(
'account_tdx_b_1qlu8fdyj77jpmu2mqe4rgh3738jcva4nfd2y2vp675zqgdg72y'
)

Expand Down

0 comments on commit 0d9475f

Please sign in to comment.