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

feat: multiple accounts support in ledger #10109

Merged
merged 99 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 98 commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
1ff5849
feat: add library @metamask/eth-ledger-bridge-keyring, and the patch …
dawnseeker8 Apr 8, 2024
15434b2
Merge branch 'main' into feat/ledger-multiple-accounts-support
dawnseeker8 Apr 10, 2024
c997d0c
feat: make a backup of the change to switch to another branch.
dawnseeker8 Apr 11, 2024
a83521d
Merge branch 'main' into feat/ledger-multiple-accounts-support
dawnseeker8 Apr 12, 2024
9be9588
Merge branch 'main' into feat/ledger-multiple-accounts-support
dawnseeker8 Apr 17, 2024
9e9e90b
fix: Downgrade the library
dawnseeker8 Apr 18, 2024
9ddf32c
Merge branch 'main' into feat/ledger-multiple-accounts-support
dawnseeker8 Apr 18, 2024
990e0b0
Merge branch 'main' into feat/ledger-multiple-accounts-support
dawnseeker8 Apr 22, 2024
d376691
fix: Rebase from main
dawnseeker8 Apr 22, 2024
5eb781c
feat: add `package.tgz` to project so that project can build without …
dawnseeker8 Apr 22, 2024
ee7efd4
feat: revert the ledger.ts code in hardwareWallet folder.
dawnseeker8 Apr 22, 2024
56f9229
feat: workable version with add multiple accounts and forget devices.…
dawnseeker8 Apr 23, 2024
f22b625
feat: workable version with add multiple accounts and forget devices.…
dawnseeker8 Apr 23, 2024
fe9a06a
feat: Fix the unit tests in LedgerConnect
dawnseeker8 Apr 24, 2024
0cd5536
feat: Fix the lint error and redundant imports
dawnseeker8 Apr 24, 2024
bd47961
feat: Try to fix the hash unmatch issue in @metamask/eth-ledger-keyring
dawnseeker8 Apr 25, 2024
52b8967
feat: Fix the build issue after the package.tgz file change.
dawnseeker8 Apr 25, 2024
d5be2ce
feat: Try to fix the `yarn setup` integrity check failed because chec…
dawnseeker8 Apr 25, 2024
aa4f2ed
feat: make a backup before carry out the rebase.
dawnseeker8 Apr 29, 2024
6f7721c
Merge branch 'main' into feat/ledger-multiple-accounts-support
dawnseeker8 Apr 29, 2024
dc848aa
feat: forget to push `yarn.lock`
dawnseeker8 Apr 29, 2024
aa461e2
feat: Fix the build issue after rebase.
dawnseeker8 Apr 29, 2024
078cc28
feat: add `remove hardware wallet` from AccountActions.tsx
dawnseeker8 Apr 30, 2024
ebfae11
feat: add `loading` mask when remove hardware account devices.
dawnseeker8 May 7, 2024
5cf3c9d
Merge branch 'main' into feat/ledger-multiple-accounts-support
dawnseeker8 May 9, 2024
82e0a5d
feat: Rebase from main to upgrade to keyringController 13. Fix all bl…
dawnseeker8 May 10, 2024
a0c2b16
fix: Backup new metric change.
dawnseeker8 Jun 4, 2024
e9528dc
Merge branch 'main' into feat/ledger-multiple-accounts-support-rebase
dawnseeker8 Jun 7, 2024
f9941c0
fix: Rebase from main to upgrade to keyring-controller 16.
dawnseeker8 Jun 7, 2024
192fdb4
feat: Add unit tests to cover all functions in ledger core.
dawnseeker8 Jun 11, 2024
dcbda06
Merge branch 'main' into feat/ledger-multiple-accounts-support-rebase
dawnseeker8 Jun 17, 2024
5dd2f51
feat: Fix the broken unit tests after rebase.
dawnseeker8 Jun 17, 2024
35cf1ec
feat: change ho use @metamask/[email protected] version.
dawnseeker8 Jun 25, 2024
7a82dee
Merge branch 'main' into feat/ledger-multiple-accounts-support-rebase
dawnseeker8 Jun 25, 2024
07cc7c2
feat: fix some lint issue after rebase from main
dawnseeker8 Jun 25, 2024
0158f84
feat: fix some lint issue after rebase from main
dawnseeker8 Jun 25, 2024
50fd23d
feat: fix all unit tests after rebase
dawnseeker8 Jun 26, 2024
a3a6566
feat: fix all lint and tsc in broken pipeline
dawnseeker8 Jun 26, 2024
c5b5c7d
feat: Fix ide complain about the navigationProp not contains pop method.
dawnseeker8 Jun 26, 2024
7d9d345
Merge branch 'main' into feat/ledger-multiple-accounts-support-rebase
dawnseeker8 Jun 26, 2024
d62e322
feat: Remove the redundant file `LedgerAccountInfo/index.tsx`,
dawnseeker8 Jun 26, 2024
f17359e
feat: Revert the format of file.
dawnseeker8 Jun 26, 2024
5ca0447
feat: revert to main version.
dawnseeker8 Jun 26, 2024
8d129da
feat: update yarn.lock
dawnseeker8 Jun 26, 2024
646cec4
feat: update yarn.lock
dawnseeker8 Jun 26, 2024
449fab3
feat: Remove TODO in the file.
dawnseeker8 Jun 26, 2024
1999fe8
feat: Backup the application to test ios later.
dawnseeker8 Jun 27, 2024
354db11
feat: Backup the application to test ios later and remove the TODO co…
dawnseeker8 Jun 27, 2024
c0a85a9
feat: Fix a deviceDiscontinued issue in ios.
dawnseeker8 Jun 27, 2024
53e3b5f
Merge branch 'main' into feat/ledger-multiple-accounts-support-rebase
dawnseeker8 Jun 27, 2024
ca5293d
feat: Fix the build issue after rebase.
dawnseeker8 Jun 27, 2024
a710a74
Merge branch 'main' into feat/ledger-multiple-accounts-support-rebase
dawnseeker8 Jun 28, 2024
443b452
Merge branch 'main' into feat/ledger-multiple-accounts-support-rebase
dawnseeker8 Jun 30, 2024
915edbe
feat: Improve code coverage for `LedgerSelectAccount` components.
dawnseeker8 Jul 1, 2024
aced129
feat: Fix the lint error in test
dawnseeker8 Jul 1, 2024
98b0175
feat: Fix the lint error in test
dawnseeker8 Jul 1, 2024
073260c
feat: code the branch code in `ledger` core
dawnseeker8 Jul 1, 2024
0ebdd4f
Merge branch 'main' into feat/ledger-multiple-accounts-support-rebase
dawnseeker8 Jul 1, 2024
feca7e0
feat: add unit tests for AccountActions components
dawnseeker8 Jul 2, 2024
59687e4
feat: Fix the lint issue in unit tests.
dawnseeker8 Jul 2, 2024
ef50cb9
Merge branch 'main' into feat/ledger-multiple-accounts-support-rebase
dawnseeker8 Jul 2, 2024
152f8b9
Merge branch 'main' into feat/ledger-multiple-accounts-support-rebase
dawnseeker8 Jul 2, 2024
4b12a26
Merge branch 'main' into feat/ledger-multiple-accounts-support-rebase
dawnseeker8 Jul 3, 2024
e3e46f9
Merge branch 'main' into feat/ledger-multiple-accounts-support-rebase
dawnseeker8 Jul 5, 2024
bdb32b0
Apply suggestions from code review
dawnseeker8 Jul 8, 2024
11109b9
Merge branch 'main' into feat/ledger-multiple-accounts-support-rebase
dawnseeker8 Jul 8, 2024
2c6bcee
feat: Rebase from main to resolve the conflict.
dawnseeker8 Jul 8, 2024
17c21ad
feat: fix lint error.
dawnseeker8 Jul 8, 2024
9982b72
feat: fix deduplicate in yarn.lock
dawnseeker8 Jul 8, 2024
4c545e1
feat: Remove the patch to Keyring-controller 16 and move unlockLedger…
dawnseeker8 Jul 8, 2024
2276ce7
feat: improve code coverage to Ledger.ts to 100%, remove the whitespa…
dawnseeker8 Jul 8, 2024
ac0d26d
feat: Change error log title to correct devices.
dawnseeker8 Jul 9, 2024
bf96365
feat: Fix the data migration issue from ledger accounts from V7.24.4
dawnseeker8 Jul 9, 2024
8163e84
Apply suggestions from code review
dawnseeker8 Jul 10, 2024
938c08b
feat: commit some change after code review,, Following change has ber…
dawnseeker8 Jul 10, 2024
0d1d9cc
Merge remote-tracking branch 'origin/feat/ledger-multiple-accounts-su…
dawnseeker8 Jul 10, 2024
076b661
feat: change MetrixEvent for HARDWARE_WALLET_FORGOTTEN with deviceTyp…
dawnseeker8 Jul 10, 2024
eb3319e
feat: Refactor the `getLedgerAccountsByPage`to `getLedgerAccountsByOp…
dawnseeker8 Jul 10, 2024
474b1e7
feat: fix the format issue in the file.
dawnseeker8 Jul 10, 2024
06e6f6a
feat: refactor to put OperationTypes to enum in `types.ts` file.
dawnseeker8 Jul 10, 2024
f05e7dd
feat: Create HardwareDeviceTypes enum to MetaMetrics.types.ts, and re…
dawnseeker8 Jul 10, 2024
662fb09
feat: refactor `triggerRemoveHWAccount` method to smaller pieces, int…
dawnseeker8 Jul 10, 2024
eb5c91f
feat: remove console log.
dawnseeker8 Jul 12, 2024
65871e4
Apply suggestions from code review
dawnseeker8 Jul 12, 2024
7c77ce1
feat: refactor the code according to Gustova's code review comments
dawnseeker8 Jul 12, 2024
2251d21
feat: Remove cancel button onPress event and also remove correspondin…
dawnseeker8 Jul 12, 2024
611d5a4
feat: Revert the metric change for `HARDWARE_WALLET_FORGOTTEN` event.
dawnseeker8 Jul 12, 2024
efefb63
feat: Change to use `selectSelectedInternalAccount` to get the select…
dawnseeker8 Jul 12, 2024
c182fc1
feat: Alex allow to use Hardware_wallet_forgotten metric event.
dawnseeker8 Jul 12, 2024
c403ad3
feat: fix the lint issue
dawnseeker8 Jul 12, 2024
e3d26a6
Merge branch 'main' into feat/ledger-multiple-accounts-support-rebase
dawnseeker8 Jul 12, 2024
368de0f
feat: fix the yarn deduplicate
dawnseeker8 Jul 12, 2024
1571f72
Merge branch 'main' into feat/ledger-multiple-accounts-support-rebase
dawnseeker8 Jul 15, 2024
c355be4
feat: upgrade the eth-ledger-keyring-bridge library, remove the patch…
dawnseeker8 Jul 15, 2024
fe4d92e
feat: to make account selection screen bigger so that more items can …
dawnseeker8 Jul 15, 2024
4ed3572
feat: Fix the remove account not log metric in mixpanel issue.
dawnseeker8 Jul 15, 2024
c1a24b2
feat: Modify the AccountSelector component to make `onCheck` optional…
dawnseeker8 Jul 16, 2024
90d86ab
Merge branch 'main' into feat/ledger-multiple-accounts-support-rebase
dawnseeker8 Jul 16, 2024
df0bd74
feat: Change the structure of `LedgerSelectAccount` and `LedgerConnec…
dawnseeker8 Jul 16, 2024
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
10 changes: 6 additions & 4 deletions app/components/Nav/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ import ImportPrivateKey from '../../Views/ImportPrivateKey';
import ImportPrivateKeySuccess from '../../Views/ImportPrivateKeySuccess';
import ConnectQRHardware from '../../Views/ConnectQRHardware';
import SelectHardwareWallet from '../../Views/ConnectHardware/SelectHardware';
import LedgerAccountInfo from '../../Views/LedgerAccountInfo';
import LedgerConnect from '../../Views/LedgerConnect';
import { AUTHENTICATION_APP_TRIGGERED_AUTH_NO_CREDENTIALS } from '../../../constants/error';
import { UpdateNeeded } from '../../../components/UI/UpdateNeeded';
import { EnableAutomaticSecurityChecksModal } from '../../../components/UI/EnableAutomaticSecurityChecksModal';
Expand Down Expand Up @@ -111,6 +109,7 @@ import { MetaMetrics } from '../../../core/Analytics';
import trackErrorAsAnalytics from '../../../util/metrics/TrackError/trackErrorAsAnalytics';
import generateDeviceAnalyticsMetaData from '../../../util/metrics/DeviceAnalyticsMetaData/generateDeviceAnalyticsMetaData';
import generateUserSettingsAnalyticsMetaData from '../../../util/metrics/UserSettingsAnalyticsMetaData/generateUserProfileAnalyticsMetaData';
import LedgerSelectAccount from '../../Views/LedgerSelectAccount';
import OnboardingSuccess from '../../Views/OnboardingSuccess';
import DefaultSettings from '../../Views/OnboardingSuccess/DefaultSettings';
import BasicFunctionalityModal from '../../UI/BasicFunctionality/BasicFunctionalityModal/BasicFunctionalityModal';
Expand Down Expand Up @@ -473,6 +472,7 @@ const App = ({ userLoggedIn }) => {
}
}
}

initSDKConnect()
.then(() => {
queueOfHandleDeeplinkFunctions.current.forEach((func) => func());
Expand Down Expand Up @@ -742,7 +742,10 @@ const App = ({ userLoggedIn }) => {

const LedgerConnectFlow = () => (
<Stack.Navigator initialRouteName={Routes.HW.LEDGER_CONNECT}>
<Stack.Screen name={Routes.HW.LEDGER_CONNECT} component={LedgerConnect} />
<Stack.Screen
name={Routes.HW.LEDGER_CONNECT}
component={LedgerSelectAccount}
/>
</Stack.Navigator>
);

Expand All @@ -753,7 +756,6 @@ const App = ({ userLoggedIn }) => {
component={SelectHardwareWallet}
options={SelectHardwareWallet.navigationOptions}
/>
<Stack.Screen name="LedgerAccountInfo" component={LedgerAccountInfo} />
</Stack.Navigator>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ exports[`BlockingActionModal should render correctly 1`] = `
deviceHeight={null}
deviceWidth={null}
hasBackdrop={true}
hideModalContentWhileAnimating={false}
hideModalContentWhileAnimating={true}
isVisible={true}
onBackButtonPress={[Function]}
onBackdropPress={[Function]}
Expand Down
5 changes: 5 additions & 0 deletions app/components/UI/BlockingActionModal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default function BlockingActionModal({
children,
modalVisible,
isLoadingAction,
onAnimationCompleted,
}) {
const { colors } = useTheme();
const styles = createStyles(colors);
Expand All @@ -43,6 +44,8 @@ export default function BlockingActionModal({
backdropOpacity={1}
isVisible={modalVisible}
style={styles.modal}
onModalShow={onAnimationCompleted}
hideModalContentWhileAnimating
>
<View style={styles.modalView}>
<View style={baseStyles.flexGrow}>
Expand All @@ -69,4 +72,6 @@ BlockingActionModal.propTypes = {
* Content to display above the action buttons
*/
children: PropTypes.node,

onAnimationCompleted: PropTypes.func,
};
11 changes: 7 additions & 4 deletions app/components/UI/HardwareWallet/AccountSelector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface ISelectQRAccountsProps {
selectedAccounts: string[];
nextPage: () => void;
prevPage: () => void;
toggleAccount: (index: number) => void;
onCheck?: (index: number) => void;
onUnlock: (accountIndex: number[]) => void;
onForget: () => void;
title: string;
Expand All @@ -30,7 +30,7 @@ const AccountSelector = (props: ISelectQRAccountsProps) => {
accounts,
prevPage,
nextPage,
toggleAccount,
onCheck,
selectedAccounts,
onForget,
onUnlock,
Expand Down Expand Up @@ -69,9 +69,12 @@ const AccountSelector = (props: ISelectQRAccountsProps) => {
prev.has(index) ? prev.delete(index) : prev.add(index);
return new Set(prev);
});
toggleAccount(index);

if (onCheck) {
onCheck(index);
}
},
[toggleAccount],
[onCheck],
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const createStyle = (colors: any) =>
bottom: {
alignItems: 'center',
justifyContent: 'space-between',
paddingTop: 70,
paddingTop: 30,
dawnseeker8 marked this conversation as resolved.
Show resolved Hide resolved
paddingBottom: Device.isIphoneX() ? 20 : 10,
},
button: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,11 @@ import {
BluetoothPermissionErrors,
LedgerCommunicationErrors,
} from '../../../core/Ledger/ledgerErrors';
import { unlockLedgerDefaultAccount } from '../../../core/Ledger/Ledger';
import { strings } from '../../../../locales/i18n';
import { useMetrics } from '../../hooks/useMetrics';
import { MetaMetricsEvents } from '../../../core/Analytics';
import { fireEvent } from '@testing-library/react-native';

jest.mock('../../../core/Ledger/Ledger', () => ({
unlockLedgerDefaultAccount: jest.fn(),
}));
import { HardwareDeviceTypes } from '../../../constants/keyringTypes';

jest.mock('../../hooks/Ledger/useBluetooth', () => ({
__esModule: true,
Expand Down Expand Up @@ -340,7 +336,6 @@ describe('LedgerConfirmationModal', () => {

it('calls onConfirmation when ledger commands are being sent and confirmed have been received.', async () => {
const onConfirmation = jest.fn();
unlockLedgerDefaultAccount.mockReturnValue(Promise.resolve(true));
useLedgerBluetooth.mockReturnValue({
isSendingLedgerCommands: true,
isAppLaunchConfirmationNeeded: false,
Expand All @@ -359,11 +354,10 @@ describe('LedgerConfirmationModal', () => {
// eslint-disable-next-line @typescript-eslint/no-empty-function
await act(async () => {});

expect(unlockLedgerDefaultAccount).toHaveBeenCalled();
expect(onConfirmation).toHaveBeenCalled();
});

it('logs LEDGER_HARDWARE_WALLET_ERROR thrown by unlockLedgerDefaultAccount', async () => {
it('logs LEDGER_HARDWARE_WALLET_ERROR event when the ledger error occurs', async () => {
const onConfirmation = jest.fn();

const ledgerLogicToRun = jest.fn();
Expand Down Expand Up @@ -400,7 +394,7 @@ describe('LedgerConfirmationModal', () => {
1,
MetaMetricsEvents.LEDGER_HARDWARE_WALLET_ERROR,
{
device_type: 'Ledger',
device_type: HardwareDeviceTypes.LEDGER,
error: 'LEDGER_ETH_APP_NOT_INSTALLED',
},
);
Expand Down
13 changes: 6 additions & 7 deletions app/components/UI/LedgerModals/LedgerConfirmationModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import ConfirmationStep from './Steps/ConfirmationStep';
import ErrorStep from './Steps/ErrorStep';
import OpenETHAppStep from './Steps/OpenETHAppStep';
import SearchingForDeviceStep from './Steps/SearchingForDeviceStep';
import { unlockLedgerDefaultAccount } from '../../../core/Ledger/Ledger';
import { MetaMetricsEvents } from '../../../core/Analytics';
import { useMetrics } from '../../../components/hooks/useMetrics';
import {
BluetoothPermissionErrors,
LedgerCommunicationErrors,
} from '../../../core/Ledger/ledgerErrors';
import { HardwareDeviceTypes } from '../../../constants/keyringTypes';

const createStyles = (colors: Colors) =>
StyleSheet.create({
Expand Down Expand Up @@ -71,14 +71,13 @@ const LedgerConfirmationModal = ({
const connectLedger = () => {
try {
ledgerLogicToRun(async () => {
await unlockLedgerDefaultAccount(false);
await onConfirmation();
});
} catch (_e) {
// Handle a super edge case of the user starting a transaction with the device connected
// After arriving to confirmation the ETH app is not installed anymore this causes a crash.
trackEvent(MetaMetricsEvents.LEDGER_HARDWARE_WALLET_ERROR, {
device_type: 'Ledger',
device_type: HardwareDeviceTypes.LEDGER,
error: 'LEDGER_ETH_APP_NOT_INSTALLED',
});
}
Expand All @@ -90,7 +89,7 @@ const LedgerConfirmationModal = ({
onRejection();
} finally {
trackEvent(MetaMetricsEvents.LEDGER_HARDWARE_TRANSACTION_CANCELLED, {
device_type: 'Ledger',
device_type: HardwareDeviceTypes.LEDGER,
});
}
};
Expand Down Expand Up @@ -179,7 +178,7 @@ const LedgerConfirmationModal = ({
}
if (ledgerError !== LedgerCommunicationErrors.UserRefusedConfirmation) {
trackEvent(MetaMetricsEvents.LEDGER_HARDWARE_WALLET_ERROR, {
device_type: 'Ledger',
device_type: HardwareDeviceTypes.LEDGER,
error: `${ledgerError}`,
});
}
Expand Down Expand Up @@ -208,7 +207,7 @@ const LedgerConfirmationModal = ({
}
setPermissionErrorShown(true);
trackEvent(MetaMetricsEvents.LEDGER_HARDWARE_WALLET_ERROR, {
device_type: 'Ledger',
device_type: HardwareDeviceTypes.LEDGER,
error: 'LEDGER_BLUETOOTH_PERMISSION_ERR',
});
}
Expand All @@ -219,7 +218,7 @@ const LedgerConfirmationModal = ({
subtitle: strings('ledger.bluetooth_off_message'),
});
trackEvent(MetaMetricsEvents.LEDGER_HARDWARE_WALLET_ERROR, {
device_type: 'Ledger',
device_type: HardwareDeviceTypes.LEDGER,
error: 'LEDGER_BLUETOOTH_CONNECTION_ERR',
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
// Third party dependencies.
import { StyleSheet } from 'react-native';
import { fontStyles } from '../../../styles/common';
import { Colors } from '../../../util/theme/models';

/**
* Style sheet function for AccountActions component.
*
* @returns StyleSheet object.
*/
const styleSheet = () =>
const styleSheet = (colors: Colors) =>
StyleSheet.create({
actionsContainer: {
alignItems: 'flex-start',
justifyContent: 'center',
paddingVertical: 16,
},
text: {
color: colors.text.default,
fontSize: 14,
...fontStyles.normal,
},
});

export default styleSheet;
Loading
Loading