Skip to content

Commit f1f129a

Browse files
committed
react-native: AvatarAccount use explicit size->px mapping to avoid Number(size) NaN after size tokens change
1 parent fca8c01 commit f1f129a

3 files changed

Lines changed: 25 additions & 8 deletions

File tree

packages/design-system-react-native/src/components/AvatarAccount/AvatarAccount.constants.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { AvatarAccountSize } from '../../types';
2+
13
// Sample account addresses
24
export const SAMPLE_AVATARACCOUNT_ADDRESSES = [
35
'0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8',
@@ -13,3 +15,13 @@ export const SAMPLE_AVATARACCOUNT_ADDRESSES = [
1315
'0xEC5CE72f2e18B0017C88F7B12d3308119C5Cf129',
1416
'0xeC56Da21c90Af6b50E4Ba5ec252bD97e735290fc',
1517
];
18+
19+
// Map AvatarAccount size token to numeric pixel dimension
20+
export const MAP_AVATARACCOUNT_SIZE_SIZENUMBER: Record<AvatarAccountSize, number> =
21+
{
22+
[AvatarAccountSize.Xs]: 16,
23+
[AvatarAccountSize.Sm]: 24,
24+
[AvatarAccountSize.Md]: 32,
25+
[AvatarAccountSize.Lg]: 40,
26+
[AvatarAccountSize.Xl]: 48,
27+
};

packages/design-system-react-native/src/components/AvatarAccount/AvatarAccount.test.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import React from 'react';
44
import { AvatarAccountSize, AvatarAccountVariant } from '../../types';
55

66
import { AvatarAccount } from './AvatarAccount';
7-
import { SAMPLE_AVATARACCOUNT_ADDRESSES } from './AvatarAccount.constants';
7+
import {
8+
SAMPLE_AVATARACCOUNT_ADDRESSES,
9+
MAP_AVATARACCOUNT_SIZE_SIZENUMBER,
10+
} from './AvatarAccount.constants';
811

912
jest.mock('react-native-svg', () => {
1013
// eslint-disable-next-line @typescript-eslint/no-require-imports
@@ -69,10 +72,10 @@ describe('AvatarAccount', () => {
6972
const avatarAccount = getByTestId('avatar-account');
7073
expect(avatarAccount).toBeDefined();
7174
expect(avatarAccount.props.style[0].width).toStrictEqual(
72-
Number(AvatarAccountSize.Md),
75+
MAP_AVATARACCOUNT_SIZE_SIZENUMBER[AvatarAccountSize.Md],
7376
);
7477
expect(avatarAccount.props.style[0].height).toStrictEqual(
75-
Number(AvatarAccountSize.Md),
78+
MAP_AVATARACCOUNT_SIZE_SIZENUMBER[AvatarAccountSize.Md],
7679
);
7780
});
7881

@@ -92,10 +95,10 @@ describe('AvatarAccount', () => {
9295
const avatarAccount = getByTestId('avatar-account');
9396
expect(avatarAccount).toBeDefined();
9497
expect(avatarAccount.props.style[0].width).toStrictEqual(
95-
Number(AvatarAccountSize.Xl),
98+
MAP_AVATARACCOUNT_SIZE_SIZENUMBER[AvatarAccountSize.Xl],
9699
);
97100
expect(avatarAccount.props.style[0].height).toStrictEqual(
98-
Number(AvatarAccountSize.Xl),
101+
MAP_AVATARACCOUNT_SIZE_SIZENUMBER[AvatarAccountSize.Xl],
99102
);
100103
});
101104

packages/design-system-react-native/src/components/AvatarAccount/AvatarAccount.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Jazzicon } from '../temp-components/Jazzicon';
1111
import { Maskicon } from '../temp-components/Maskicon';
1212

1313
import type { AvatarAccountProps } from './AvatarAccount.types';
14+
import { MAP_AVATARACCOUNT_SIZE_SIZENUMBER } from './AvatarAccount.constants';
1415

1516
export const AvatarAccount = ({
1617
address,
@@ -22,22 +23,23 @@ export const AvatarAccount = ({
2223
...props
2324
}: AvatarAccountProps) => {
2425
let AvatarArtComponent;
26+
const pixelSize = MAP_AVATARACCOUNT_SIZE_SIZENUMBER[size];
2527

2628
switch (variant) {
2729
case AvatarAccountVariant.Blockies:
2830
AvatarArtComponent = (
29-
<Blockies address={address} size={Number(size)} {...blockiesProps} />
31+
<Blockies address={address} size={pixelSize} {...blockiesProps} />
3032
);
3133
break;
3234
case AvatarAccountVariant.Maskicon:
3335
AvatarArtComponent = (
34-
<Maskicon address={address} size={Number(size)} {...maskiconProps} />
36+
<Maskicon address={address} size={pixelSize} {...maskiconProps} />
3537
);
3638
break;
3739
case AvatarAccountVariant.Jazzicon:
3840
default:
3941
AvatarArtComponent = (
40-
<Jazzicon address={address} size={Number(size)} {...jazziconProps} />
42+
<Jazzicon address={address} size={pixelSize} {...jazziconProps} />
4143
);
4244
break;
4345
}

0 commit comments

Comments
 (0)