Skip to content

Commit

Permalink
feat(extension): hide show recovery phrase when key material is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
renanvalentin committed Apr 17, 2024
1 parent e957c11 commit 80c8a22
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
Expand Up @@ -23,6 +23,7 @@ export const walletInfoSlice: SliceCreator<WalletInfoSlice & BlockchainProviderS
initialHdDiscoveryCompleted: false,
isInMemoryWallet: undefined,
isHardwareWallet: undefined,
hasKeyMaterial: undefined,
walletType: undefined,
stayOnAllDonePage: false,
setAddressesDiscoveryCompleted: (addressesDiscoveryCompleted) =>
Expand All @@ -36,7 +37,10 @@ export const walletInfoSlice: SliceCreator<WalletInfoSlice & BlockchainProviderS
cardanoWallet: wallet,
walletType: wallet?.source.wallet.type,
isInMemoryWallet: wallet?.source.wallet.type === WalletType.InMemory,
isHardwareWallet: [WalletType.Ledger, WalletType.Trezor].includes(wallet?.source.wallet.type)
isHardwareWallet: [WalletType.Ledger, WalletType.Trezor].includes(wallet?.source.wallet.type),
hasKeyMaterial:
wallet?.source.wallet.type === WalletType.InMemory &&
wallet?.source.wallet.encryptedSecrets.keyMaterial.length > 0
}),
setCurrentChain: (chain: Wallet.ChainName) => {
set({ currentChain: Wallet.Cardano.ChainIds[chain], environmentName: chain });
Expand Down
1 change: 1 addition & 0 deletions apps/browser-extension-wallet/src/stores/types.ts
Expand Up @@ -116,6 +116,7 @@ export interface WalletInfoSlice {
walletType: WalletType;
isInMemoryWallet: boolean;
isHardwareWallet: boolean;
hasKeyMaterial: boolean;
deletingWallet?: boolean;
stayOnAllDonePage?: boolean;
setDeletingWallet: (deletingWallet: boolean) => void;
Expand Down
1 change: 1 addition & 0 deletions apps/browser-extension-wallet/src/utils/mocks/store.tsx
Expand Up @@ -46,6 +46,7 @@ export const walletStoreMock = async (
walletType: WalletType.InMemory,
isInMemoryWallet: true,
isHardwareWallet: false,
hasKeyMaterial: true,
// TODO: mock [LW-5454]
cardanoWallet: undefined,
isWalletLocked: jest.fn(() => false),
Expand Down
Expand Up @@ -27,7 +27,7 @@ export const SettingsSecurity = ({
const [isShowPassphraseDrawerOpen, setIsShowPassphraseDrawerOpen] = useState(false);
const [hideShowPassphraseSetting, setHideShowPassphraseSetting] = useState(true);
const { t } = useTranslation();
const { isWalletLocked, isInMemoryWallet } = useWalletStore();
const { isWalletLocked, isInMemoryWallet, hasKeyMaterial } = useWalletStore();
const [settings] = useAppSettingsContext();
const { mnemonicVerificationFrequency } = settings;
const frequency = PHRASE_FREQUENCY_OPTIONS.find(({ value }) => value === mnemonicVerificationFrequency)?.label;
Expand All @@ -54,8 +54,8 @@ export const SettingsSecurity = ({
};

const isMnemonicAvailable = useCallback(async () => {
setHideShowPassphraseSetting(isWalletLocked() || !isInMemoryWallet);
}, [isInMemoryWallet, isWalletLocked]);
setHideShowPassphraseSetting(isWalletLocked() || !isInMemoryWallet || !hasKeyMaterial);
}, [isInMemoryWallet, isWalletLocked, hasKeyMaterial]);

const handleCloseShowPassphraseDrawer = () => {
setIsShowPassphraseDrawerOpen(false);
Expand Down

0 comments on commit 80c8a22

Please sign in to comment.