-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into bkirby/rampsSell
- Loading branch information
Showing
12 changed files
with
812 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
app/components/Views/Settings/NotificationsSettings/AccountsList.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import React from 'react'; | ||
import renderWithProvider, { DeepPartial } from '../../../../util/test/renderWithProvider'; | ||
import { AccountsList } from './AccountsList'; | ||
import { AvatarAccountType } from '../../../../component-library/components/Avatars/Avatar'; | ||
import { Account } from '../../../../components/hooks/useAccounts/useAccounts.types'; | ||
import { MOCK_ACCOUNTS_CONTROLLER_STATE } from '../../../../util/test/accountsControllerTestUtils'; | ||
import { Hex } from '@metamask/utils'; | ||
import { KeyringTypes } from '@metamask/keyring-controller'; | ||
import { toChecksumAddress } from 'ethereumjs-util'; | ||
import { RootState } from '../../../../reducers'; | ||
import { backgroundState } from '../../../../util/test/initial-root-state'; | ||
|
||
const MOCK_ACCOUNT_ADDRESSES = Object.values( | ||
MOCK_ACCOUNTS_CONTROLLER_STATE.internalAccounts.accounts, | ||
).map((account) => account.address); | ||
|
||
const MOCK_ACCOUNT_1: Account = { | ||
name: 'Account 1', | ||
address: toChecksumAddress(MOCK_ACCOUNT_ADDRESSES[0]) as Hex, | ||
type: KeyringTypes.hd, | ||
yOffset: 0, | ||
isSelected: false, | ||
assets: { | ||
fiatBalance: '\n0 ETH', | ||
}, | ||
balanceError: undefined, | ||
}; | ||
const MOCK_ACCOUNT_2: Account = { | ||
name: 'Account 2', | ||
address: toChecksumAddress(MOCK_ACCOUNT_ADDRESSES[1]) as Hex, | ||
type: KeyringTypes.hd, | ||
yOffset: 78, | ||
isSelected: true, | ||
assets: { | ||
fiatBalance: '\n< 0.00001 ETH', | ||
}, | ||
balanceError: undefined, | ||
}; | ||
|
||
const MOCK_ACCOUNTS = [MOCK_ACCOUNT_1, MOCK_ACCOUNT_2]; | ||
|
||
const mockInitialState: DeepPartial<RootState> = { | ||
engine: { | ||
backgroundState: { | ||
...backgroundState, | ||
NotificationServicesController: { | ||
metamaskNotificationsList: [], | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
describe('AccountsList', () => { | ||
it('matches snapshot', () => { | ||
|
||
const { toJSON } = renderWithProvider( | ||
<AccountsList | ||
accounts={MOCK_ACCOUNTS} | ||
accountAvatarType={AvatarAccountType.JazzIcon} | ||
accountSettingsData={{}} | ||
updateAndfetchAccountSettings={jest.fn()} | ||
isUpdatingMetamaskNotificationsAccount={[]} | ||
/>, | ||
{ | ||
state: mockInitialState, | ||
}, | ||
); | ||
expect(toJSON()).toMatchSnapshot(); | ||
}); | ||
|
||
it('triggers updateAndfetchAccountSettings on mount', () => { | ||
const updateAndfetchAccountSettings = jest.fn(); | ||
renderWithProvider( | ||
<AccountsList | ||
accounts={MOCK_ACCOUNTS} | ||
accountAvatarType={AvatarAccountType.JazzIcon} | ||
accountSettingsData={{}} | ||
updateAndfetchAccountSettings={updateAndfetchAccountSettings} | ||
isUpdatingMetamaskNotificationsAccount={[]} | ||
/>, | ||
{ | ||
state: mockInitialState, | ||
}, | ||
); | ||
|
||
expect(updateAndfetchAccountSettings).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
53 changes: 53 additions & 0 deletions
53
app/components/Views/Settings/NotificationsSettings/AccountsList.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React, { useEffect } from 'react'; | ||
import { FlatList, View } from 'react-native'; | ||
import NotificationOptionToggle from './NotificationOptionToggle'; | ||
import { Account } from '../../../../components/hooks/useAccounts/useAccounts.types'; | ||
import { NotificationsToggleTypes } from './NotificationsSettings.constants'; | ||
import { NotificationsAccountsState } from '../../../../core/redux/slices/notifications'; | ||
import { AvatarAccountType } from '../../../../component-library/components/Avatars/Avatar'; | ||
|
||
export const AccountsList = ({ | ||
accounts, | ||
accountAvatarType, | ||
accountSettingsData, | ||
updateAndfetchAccountSettings, | ||
isUpdatingMetamaskNotificationsAccount, | ||
}: { | ||
accounts: Account[]; | ||
accountAvatarType: AvatarAccountType; | ||
accountSettingsData: NotificationsAccountsState; | ||
updateAndfetchAccountSettings: () => Promise<Record<string, boolean> | undefined>; | ||
isUpdatingMetamaskNotificationsAccount: string[]; | ||
}) => { | ||
|
||
useEffect(() => { | ||
const fetchInitialData = async () => { | ||
await updateAndfetchAccountSettings(); | ||
}; | ||
fetchInitialData(); | ||
}, [updateAndfetchAccountSettings]); | ||
|
||
return ( | ||
<View> | ||
<FlatList | ||
data={accounts} | ||
keyExtractor={(item) => `address-${item.address}`} | ||
renderItem={({ item }) => ( | ||
<NotificationOptionToggle | ||
type={NotificationsToggleTypes.ACCOUNT} | ||
icon={accountAvatarType} | ||
key={item.address} | ||
title={item.name} | ||
address={item.address} | ||
disabledSwitch={isUpdatingMetamaskNotificationsAccount.length > 0} | ||
isLoading={isUpdatingMetamaskNotificationsAccount.includes( | ||
item.address.toLowerCase(), | ||
)} | ||
isEnabled={accountSettingsData?.[item.address.toLowerCase()]} | ||
updateAndfetchAccountSettings={updateAndfetchAccountSettings} | ||
/> | ||
)} | ||
/> | ||
</View> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.