Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent error when personaData has empty arrays #215

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading