From 0d9475fedcd6a2e447489de4411d5e2f3064525c Mon Sep 17 00:00:00 2001 From: Alex Stelea Date: Mon, 6 Feb 2023 12:10:21 +0100 Subject: [PATCH] fix: decode usePersona wallet response --- lib/IO/decode-wallet-response.ts | 2 +- lib/IO/request-items/use-persona.ts | 3 ++- lib/__tests__/decode-wallet-response.spec.ts | 2 +- lib/__tests__/wallet-sdk.spec.ts | 18 ++++++++++++++++-- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/IO/decode-wallet-response.ts b/lib/IO/decode-wallet-response.ts index bb0000c..1aecbe9 100644 --- a/lib/IO/decode-wallet-response.ts +++ b/lib/IO/decode-wallet-response.ts @@ -10,7 +10,7 @@ export const decodeWalletResponse = ( 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 } } diff --git a/lib/IO/request-items/use-persona.ts b/lib/IO/request-items/use-persona.ts index 64e44dc..3f90c01 100644 --- a/lib/IO/request-items/use-persona.ts +++ b/lib/IO/request-items/use-persona.ts @@ -1,6 +1,7 @@ import { AuthUsePersonaRequestItem, AuthUsePersonaRequestResponseItem, + Persona, } from '../schemas' export type UsePersona = { @@ -11,7 +12,7 @@ export type UsePersona = { method: { input: { identityAddress: string } output: { - auth: { identityAddress: string } + persona: Persona } } } diff --git a/lib/__tests__/decode-wallet-response.spec.ts b/lib/__tests__/decode-wallet-response.spec.ts index 83977e0..16678ca 100644 --- a/lib/__tests__/decode-wallet-response.spec.ts +++ b/lib/__tests__/decode-wallet-response.spec.ts @@ -9,7 +9,7 @@ describe('decodeWalletResponse', () => { discriminator: 'authorizedRequest', auth: { discriminator: 'usePersona', - identityAddress: 'addr_xxx', + persona: { identityAddress: 'addr_xxx' }, }, oneTimeAccounts: { accounts: [ diff --git a/lib/__tests__/wallet-sdk.spec.ts b/lib/__tests__/wallet-sdk.spec.ts index 8af0bc7..cbd33d3 100644 --- a/lib/__tests__/wallet-sdk.spec.ts +++ b/lib/__tests__/wallet-sdk.spec.ts @@ -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', @@ -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' )