From 108bc7719324623b7b8e8e2575d7a98dc7646e86 Mon Sep 17 00:00:00 2001 From: Dawid Sowa Date: Tue, 11 Jun 2024 11:19:15 +0200 Subject: [PATCH] fix: prevent error when personaData has empty arrays --- .../wallet-data-to-connect-button.spec.ts | 32 +++++++++++++++++++ .../wallet-data-to-connect-button.ts | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 packages/dapp-toolkit/src/modules/wallet-request/data-request/transformations/wallet-data-to-connect-button.spec.ts diff --git a/packages/dapp-toolkit/src/modules/wallet-request/data-request/transformations/wallet-data-to-connect-button.spec.ts b/packages/dapp-toolkit/src/modules/wallet-request/data-request/transformations/wallet-data-to-connect-button.spec.ts new file mode 100644 index 00000000..d1b07fc3 --- /dev/null +++ b/packages/dapp-toolkit/src/modules/wallet-request/data-request/transformations/wallet-data-to-connect-button.spec.ts @@ -0,0 +1,32 @@ +import { describe, expect, it } from 'vitest' +import { transformWalletDataToConnectButton } from './wallet-data-to-connect-button' +describe('transformWalletDataToConnectButton', () => { + describe('when persona data contain empty arrays', () => { + it('should not fail', () => { + // Arrange + const walletData = { + personaData: [ + { + entry: 'emailAddresses', + fields: [], + }, + { + entry: 'phoneNumbers', + fields: [], + }, + ], + } as any + + // Act + const result = transformWalletDataToConnectButton(walletData) + + // Assert + expect(result).toEqual({ + accounts: [], + personaLabel: '', + connected: false, + personaData: [], + }) + }) + }) +}) diff --git a/packages/dapp-toolkit/src/modules/wallet-request/data-request/transformations/wallet-data-to-connect-button.ts b/packages/dapp-toolkit/src/modules/wallet-request/data-request/transformations/wallet-data-to-connect-button.ts index 63841fd3..17b91f85 100644 --- a/packages/dapp-toolkit/src/modules/wallet-request/data-request/transformations/wallet-data-to-connect-button.ts +++ b/packages/dapp-toolkit/src/modules/wallet-request/data-request/transformations/wallet-data-to-connect-button.ts @@ -38,7 +38,7 @@ export const transformWalletDataToConnectButton = (walletData: WalletData) => { ): item is { value: string field: string - } => !!item && !!item.value.trim(), + } => !!item && !!item.value?.trim(), ) return { accounts, personaLabel, connected, personaData }