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

Fix backup reminder shortcuts #1454

Merged
merged 13 commits into from
Apr 30, 2024
15 changes: 14 additions & 1 deletion src/entries/popup/components/BackupReminder/BackupReminder.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';

import { i18n } from '~/core/languages';
import { shortcuts } from '~/core/references/shortcuts';
import {
Box,
Button,
Expand All @@ -13,6 +14,7 @@ import {
} from '~/design-system';
import { BottomSheet } from '~/design-system/components/BottomSheet/BottomSheet';

import { useKeyboardShortcut } from '../../hooks/useKeyboardShortcut';
import { useRainbowNavigate } from '../../hooks/useRainbowNavigate';
import { useWalletBackups } from '../../hooks/useWalletBackups';
import { ROUTES } from '../../urls';
Expand All @@ -23,13 +25,22 @@ export const BackupReminder = () => {
const { showWalletBackupReminder, closeBackupReminder } = useWalletBackups();
const navigate = useRainbowNavigate();

useKeyboardShortcut({
handler: (e: KeyboardEvent) => {
if (e.key === shortcuts.global.CLOSE.key) {
e.preventDefault();
closeBackupReminder();
}
},
});

return (
<BottomSheet
show={showWalletBackupReminder}
zIndex={zIndexes.APP_CONNECTION_WALLET_SWITCHER}
onClickOutside={closeBackupReminder}
>
<Box id="wallet-backup-reminder-sheet">
<Box id="wallet-backup-reminder-sheet" isExplainerSheet>
<Navbar
leftComponent={
<Navbar.CloseButton
Expand Down Expand Up @@ -90,6 +101,7 @@ export const BackupReminder = () => {
},
});
}}
tabIndex={0}
>
<Text align="center" color="label" size="16pt" weight="heavy">
{i18n.t('wallet_backup_reminder.button_label_action')}
Expand All @@ -102,6 +114,7 @@ export const BackupReminder = () => {
height="44px"
variant="tinted"
onClick={closeBackupReminder}
tabIndex={0}
>
<Text
align="center"
Expand Down
10 changes: 10 additions & 0 deletions src/entries/popup/components/ExplainerSheet/ExplainerSheet.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useCallback, useState } from 'react';

import { shortcuts } from '~/core/references/shortcuts';
import { goToNewTab } from '~/core/utils/tabs';
import {
Box,
Expand All @@ -18,6 +19,7 @@ import { TextLink } from '~/design-system/components/TextLink/TextLink';
import { TextStyles } from '~/design-system/styles/core.css';
import { ButtonVariant } from '~/design-system/styles/designTokens';

import { useKeyboardShortcut } from '../../hooks/useKeyboardShortcut';
import { zIndexes } from '../../utils/zIndexes';

export interface ExplainerSheetProps {
Expand Down Expand Up @@ -111,6 +113,14 @@ export const ExplainerSheet = ({
testId,
onClickOutside,
}: ExplainerSheetProps) => {
useKeyboardShortcut({
handler: (e: KeyboardEvent) => {
if (e.key === shortcuts.global.CLOSE.key) {
onClickOutside?.();
}
},
});

const goToLink = useCallback((link?: string) => {
link &&
goToNewTab({
Expand Down
3 changes: 3 additions & 0 deletions src/entries/popup/hooks/useHomeShortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { ROUTES } from '../urls';
import {
appConnectionMenuIsActive,
appConnectionSwitchWalletsPromptIsActive,
getExplainerSheet,
getInputIsFocused,
} from '../utils/activeElement';
import {
Expand Down Expand Up @@ -104,7 +105,9 @@ export function useHomeShortcuts() {
const activeAppWalletSwitcher =
appConnectionSwitchWalletsPromptIsActive();
const inputIsFocused = getInputIsFocused();
const isExplainerSheet = getExplainerSheet();
if (inputIsFocused) return;
if (isExplainerSheet) return;
switch (e.key) {
case shortcuts.home.BUY.key:
trackShortcut({
Expand Down