Skip to content

Commit 7dfc3dd

Browse files
feat(nami): disable password change for hw wallet (#1481)
feat(nami): disable password change for hw wallet
1 parent e628f2e commit 7dfc3dd

File tree

5 files changed

+55
-37
lines changed

5 files changed

+55
-37
lines changed

packages/nami/src/adapters/wallet.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ describe('useChangePassword', () => {
236236

237237
await expect(
238238
result.current('wrong-password', 'new-password'),
239-
).rejects.toEqual(ERROR.wrongPassword);
239+
).rejects.toEqual(new Error(ERROR.wrongPassword));
240240
expect(mockDeleteWallet).not.toHaveBeenCalled();
241241
});
242242
});

packages/nami/src/adapters/wallet.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ export const useChangePassword = ({
5656

5757
return useCallback(
5858
async (currentPassword: string, newPassword: string) => {
59-
try {
60-
if (
61-
!wallet?.metadata?.name ||
62-
!('encryptedSecrets' in wallet) ||
63-
!('accounts' in wallet)
64-
) {
65-
return;
66-
}
59+
if (
60+
!wallet?.metadata?.name ||
61+
!('encryptedSecrets' in wallet) ||
62+
!('accounts' in wallet)
63+
) {
64+
throw new Error(ERROR.passwordChangeNotPossible);
65+
}
6766

67+
try {
6868
const decryptedRootPrivateKeyBytes =
6969
await Wallet.KeyManagement.emip3decrypt(
7070
Buffer.from(wallet.encryptedSecrets.rootPrivateKeyBytes, 'hex'),
@@ -106,7 +106,7 @@ export const useChangePassword = ({
106106
}
107107
await activateWallet({ chainId, walletId, accountIndex });
108108
} catch {
109-
throw ERROR.wrongPassword;
109+
throw new Error(ERROR.wrongPassword);
110110
}
111111
},
112112
[

packages/nami/src/config/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const POPUP_WINDOW = {
3131
export const ERROR = {
3232
accessDenied: 'Access denied',
3333
wrongPassword: 'Wrong password',
34+
passwordChangeNotPossible: 'Cannot change password',
3435
txTooBig: 'Transaction too big',
3536
txNotPossible: 'Transaction not possible',
3637
storeNotEmpty: 'Storage key is already set',

packages/nami/src/ui/app/pages/settings.tsx

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/* eslint-disable react/no-multi-comp */
33
import React, { useCallback, useEffect, useRef, useState } from 'react';
44

5+
import { WalletType } from '@cardano-sdk/web-extension';
56
import {
67
ChevronLeftIcon,
78
ChevronRightIcon,
@@ -44,6 +45,7 @@ import type { UseAccount } from '../../../adapters/account';
4445
import type { OutsideHandlesContextValue } from '../../../features/outside-handles-provider';
4546
import type { ChangePasswordModalComponentRef } from '../components/changePasswordModal';
4647
import type { Wallet } from '@lace/cardano';
48+
import type { CommonOutsideHandlesContextValue } from 'features/common-outside-handles-provider';
4749

4850
type Props = Pick<
4951
OutsideHandlesContextValue,
@@ -60,17 +62,18 @@ type Props = Pick<
6062
| 'setTheme'
6163
| 'switchNetwork'
6264
| 'theme'
63-
> & {
64-
currency: CurrencyCode;
65-
setCurrency: (currency: CurrencyCode) => void;
66-
changePassword: (
67-
currentPassword: string,
68-
newPassword: string,
69-
) => Promise<void>;
70-
accountName: string;
71-
accountAvatar?: string;
72-
updateAccountMetadata: UseAccount['updateAccountMetadata'];
73-
};
65+
> &
66+
Pick<CommonOutsideHandlesContextValue, 'walletType'> & {
67+
currency: CurrencyCode;
68+
setCurrency: (currency: CurrencyCode) => void;
69+
changePassword: (
70+
currentPassword: string,
71+
newPassword: string,
72+
) => Promise<void>;
73+
accountName: string;
74+
accountAvatar?: string;
75+
updateAccountMetadata: UseAccount['updateAccountMetadata'];
76+
};
7477

7578
const Settings = ({
7679
currency,
@@ -92,6 +95,7 @@ const Settings = ({
9295
getCustomSubmitApiForNetwork,
9396
defaultSubmitApi,
9497
isValidURL,
98+
walletType,
9599
}: Readonly<Props>) => {
96100
const history = useHistory();
97101
const location = useLocation();
@@ -136,6 +140,7 @@ const Settings = ({
136140
accountAvatar={accountAvatar}
137141
accountName={accountName}
138142
updateAccountMetadata={updateAccountMetadata}
143+
walletType={walletType}
139144
/>
140145
</Route>
141146
<Route path="/settings/whitelisted" exact>
@@ -275,6 +280,7 @@ const GeneralSettings = ({
275280
accountAvatar,
276281
changePassword,
277282
updateAccountMetadata,
283+
walletType,
278284
}: Readonly<
279285
Pick<
280286
Props,
@@ -286,6 +292,7 @@ const GeneralSettings = ({
286292
| 'setTheme'
287293
| 'theme'
288294
| 'updateAccountMetadata'
295+
| 'walletType'
289296
>
290297
>) => {
291298
const capture = useCaptureEvent();
@@ -395,20 +402,24 @@ const GeneralSettings = ({
395402
</Box>
396403
<Box height="15" />
397404
<Box height="5" />
398-
<Button
399-
colorScheme="orange"
400-
size="sm"
401-
onClick={() => {
402-
capture(Events.SettingsChangePasswordClick);
403-
changePasswordRef.current?.openModal();
404-
}}
405-
>
406-
Change Password
407-
</Button>
408-
<ChangePasswordModal
409-
ref={changePasswordRef}
410-
changePassword={changePassword}
411-
/>
405+
{walletType === WalletType.InMemory && (
406+
<>
407+
<Button
408+
colorScheme="orange"
409+
size="sm"
410+
onClick={() => {
411+
capture(Events.SettingsChangePasswordClick);
412+
changePasswordRef.current?.openModal();
413+
}}
414+
>
415+
Change Password
416+
</Button>
417+
<ChangePasswordModal
418+
ref={changePasswordRef}
419+
changePassword={changePassword}
420+
/>
421+
</>
422+
)}
412423
</>
413424
);
414425
};

packages/nami/src/ui/indexMain.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,13 @@ const App = () => {
6262
setDeletingWallet,
6363
} = useOutsideHandles();
6464

65-
const { inMemoryWallet, withSignTxConfirmation, cardanoCoin, openHWFlow } =
66-
useCommonOutsideHandles();
65+
const {
66+
inMemoryWallet,
67+
withSignTxConfirmation,
68+
cardanoCoin,
69+
openHWFlow,
70+
walletType,
71+
} = useCommonOutsideHandles();
6772

6873
const { currency, setCurrency } = useFiatCurrency(
6974
fiatCurrency,
@@ -188,6 +193,7 @@ const App = () => {
188193
getCustomSubmitApiForNetwork={getCustomSubmitApiForNetwork}
189194
defaultSubmitApi={defaultSubmitApi}
190195
isValidURL={isValidURL}
196+
walletType={walletType}
191197
/>
192198
</Route>
193199
<Route path="/send">

0 commit comments

Comments
 (0)