Skip to content

Commit

Permalink
fix: prevent error when personaData has empty arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
dawidsowardx committed Jun 11, 2024
1 parent d9e1e88 commit 51515da
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

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: [],
})
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export const transformWalletDataToConnectButton = (walletData: WalletData) => {
const accounts = walletData.accounts ?? []
const personaLabel = walletData?.persona?.label ?? ''
const connected = !!walletData?.persona
const personaData = walletData.personaData
.map((item) => {
const personaData = walletData?.personaData
?.map((item) => {
if (item.entry === 'fullName') {
const { variant, givenNames, familyName, nickname } = item.fields
const value =
Expand Down Expand Up @@ -34,11 +34,11 @@ export const transformWalletDataToConnectButton = (walletData: WalletData) => {
})
.filter(
(
item
item,
): item is {
value: string
field: string
} => !!item && !!item.value.trim()
} => !!item && !!item.value?.trim(),
)

return { accounts, personaLabel, connected, personaData }
Expand Down

0 comments on commit 51515da

Please sign in to comment.