Skip to content

Commit

Permalink
Merge pull request #215 from radixdlt/fix-persona-data
Browse files Browse the repository at this point in the history
fix: prevent error when personaData has empty arrays
  • Loading branch information
dawidsowardx authored Jun 11, 2024
2 parents d9e1e88 + 51515da commit 87d1f97
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 87d1f97

Please sign in to comment.