-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat(4057): replace asset avatars with network avatars #13910
base: main
Are you sure you want to change the base?
Changes from all commits
d5508fa
f2ac4e4
5641532
3e47871
675ab11
01a4d95
f741507
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -27,51 +27,55 @@ const AvatarGroup = ({ | |||||
maxStackedAvatars = DEFAULT_AVATARGROUP_MAXSTACKEDAVATARS, | ||||||
includesBorder = true, | ||||||
spaceBetweenAvatars, | ||||||
renderOverflowCounter = true, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is introduced to optionally avoid rendering the overflow counter to match the Figma
|
||||||
style, | ||||||
}: AvatarGroupProps) => { | ||||||
const overflowCounter = avatarPropsList.length - maxStackedAvatars; | ||||||
const avatarNegativeSpacing = | ||||||
spaceBetweenAvatars || SPACEBETWEENAVATARS_BY_AVATARSIZE[size]; | ||||||
const shouldRenderOverflowCounter = overflowCounter > 0; | ||||||
|
||||||
const doesOverflowCountExist = overflowCounter > 0; | ||||||
const { styles } = useStyles(styleSheet, { | ||||||
size, | ||||||
style, | ||||||
}); | ||||||
|
||||||
const renderAvatarList = useCallback( | ||||||
() => | ||||||
avatarPropsList.slice(0, maxStackedAvatars).map((avatarProps, index) => { | ||||||
const marginLeft = index === 0 ? 0 : avatarNegativeSpacing; | ||||||
const renderAvatarList = useCallback(() => { | ||||||
const avatarsToRender = renderOverflowCounter | ||||||
? avatarPropsList.slice(0, maxStackedAvatars) | ||||||
: avatarPropsList.slice(-maxStackedAvatars); | ||||||
return avatarsToRender.map((avatarProps, index) => { | ||||||
const marginLeft = index === 0 ? 0 : avatarNegativeSpacing; | ||||||
|
||||||
return ( | ||||||
<View | ||||||
key={`avatar-${index}`} | ||||||
testID={`${AVATARGROUP_AVATAR_CONTAINER_TESTID}-${index}`} | ||||||
style={{ marginLeft }} | ||||||
> | ||||||
<Avatar | ||||||
{...avatarProps} | ||||||
size={size} | ||||||
includesBorder={includesBorder} | ||||||
testID={AVATARGROUP_AVATAR_TESTID} | ||||||
/> | ||||||
</View> | ||||||
); | ||||||
}), | ||||||
[ | ||||||
avatarPropsList, | ||||||
avatarNegativeSpacing, | ||||||
includesBorder, | ||||||
maxStackedAvatars, | ||||||
size, | ||||||
], | ||||||
); | ||||||
return ( | ||||||
<View | ||||||
key={`avatar-${index}`} | ||||||
testID={`${AVATARGROUP_AVATAR_CONTAINER_TESTID}-${index}`} | ||||||
style={{ marginLeft }} | ||||||
> | ||||||
<Avatar | ||||||
{...avatarProps} | ||||||
size={size} | ||||||
includesBorder={includesBorder} | ||||||
testID={AVATARGROUP_AVATAR_TESTID} | ||||||
style={styles.avatarGroup} | ||||||
/> | ||||||
</View> | ||||||
); | ||||||
}); | ||||||
}, [ | ||||||
avatarPropsList, | ||||||
avatarNegativeSpacing, | ||||||
includesBorder, | ||||||
maxStackedAvatars, | ||||||
renderOverflowCounter, | ||||||
size, | ||||||
styles.avatarGroup, | ||||||
]); | ||||||
|
||||||
return ( | ||||||
<View style={styles.base}> | ||||||
{renderAvatarList()} | ||||||
{shouldRenderOverflowCounter && ( | ||||||
{renderOverflowCounter && doesOverflowCountExist && ( | ||||||
<Text | ||||||
variant={TEXTVARIANT_BY_AVATARSIZE[size]} | ||||||
color={DEFAULT_AVATARGROUP_COUNTER_TEXTCOLOR} | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ import { | |
import { mockNetworkState } from '../../../util/test/network'; | ||
import { CHAIN_IDS } from '@metamask/transaction-controller'; | ||
import { AccountSelectorListProps } from './AccountSelectorList.types'; | ||
import { AVATARGROUP_AVATAR_CONTAINER_TESTID } from '../../../component-library/components/Avatars/AvatarGroup/AvatarGroup.constants'; | ||
|
||
// eslint-disable-next-line import/no-namespace | ||
import * as Utils from '../../hooks/useAccounts/utils'; | ||
|
@@ -159,12 +160,10 @@ describe('AccountSelectorList', () => { | |
`${AccountListBottomSheetSelectorsIDs.ACCOUNT_BALANCE_BY_ADDRESS_TEST_ID}-${PERSONAL_ACCOUNT}`, | ||
); | ||
|
||
expect(within(businessAccountItem).getByText(regex.eth(1))).toBeDefined(); | ||
expect( | ||
within(businessAccountItem).getByText(regex.usd(3200)), | ||
).toBeDefined(); | ||
|
||
expect(within(personalAccountItem).getByText(regex.eth(2))).toBeDefined(); | ||
expect( | ||
within(personalAccountItem).getByText(regex.usd(6400)), | ||
).toBeDefined(); | ||
|
@@ -199,7 +198,6 @@ describe('AccountSelectorList', () => { | |
`${AccountListBottomSheetSelectorsIDs.ACCOUNT_BALANCE_BY_ADDRESS_TEST_ID}-${BUSINESS_ACCOUNT}`, | ||
); | ||
|
||
expect(within(businessAccountItem).getByText(regex.eth(1))).toBeDefined(); | ||
expect( | ||
within(businessAccountItem).getByText(regex.usd(3200)), | ||
).toBeDefined(); | ||
|
@@ -267,33 +265,21 @@ describe('AccountSelectorList', () => { | |
`${AccountListBottomSheetSelectorsIDs.ACCOUNT_BALANCE_BY_ADDRESS_TEST_ID}-${BUSINESS_ACCOUNT}`, | ||
); | ||
|
||
expect(within(businessAccountItem).getByText(regex.eth(1))).toBeDefined(); | ||
expect( | ||
within(businessAccountItem).getByText(regex.usd(3200)), | ||
).toBeDefined(); | ||
|
||
expect(within(businessAccountItem).queryByText('••••••')).toBeNull(); | ||
}); | ||
}); | ||
it('Text is hidden when privacy mode is on', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test is removed because we are no longer showing the selected network token balance, instead it shows the network avatar icons. See the before and after screenshots |
||
const state = { | ||
...initialState, | ||
privacyMode: true, | ||
}; | ||
|
||
const { queryByTestId } = renderComponent(state); | ||
it('should render AvatarGroup', async () => { | ||
const { queryByTestId } = renderComponent(initialState); | ||
|
||
await waitFor(() => { | ||
const businessAccountItem = queryByTestId( | ||
`${AccountListBottomSheetSelectorsIDs.ACCOUNT_BALANCE_BY_ADDRESS_TEST_ID}-${BUSINESS_ACCOUNT}`, | ||
const avatarGroup = queryByTestId( | ||
`${AVATARGROUP_AVATAR_CONTAINER_TESTID}-0`, | ||
); | ||
|
||
expect(within(businessAccountItem).queryByText(regex.eth(1))).toBeNull(); | ||
expect( | ||
within(businessAccountItem).queryByText(regex.usd(3200)), | ||
).toBeNull(); | ||
|
||
expect(within(businessAccountItem).getByText('••••••')).toBeDefined(); | ||
expect(avatarGroup).toBeDefined(); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will these styles be applied to all
AvatarGroup
styles throughout the app?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Theres only one other instance of it being used which is network permission summary when interacting with dapps. I believe this change is fine for that scenario but I'll double check with Hester