Skip to content

Commit

Permalink
Fix backup reminder shortcuts (#1454)
Browse files Browse the repository at this point in the history
  • Loading branch information
BrodyHughes authored Apr 30, 2024
1 parent 2e2915e commit 6094a6e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 19 deletions.
16 changes: 15 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,23 @@ export const BackupReminder = () => {
const { showWalletBackupReminder, closeBackupReminder } = useWalletBackups();
const navigate = useRainbowNavigate();

useKeyboardShortcut({
condition: () => showWalletBackupReminder,
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 +102,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 +115,7 @@ export const BackupReminder = () => {
height="44px"
variant="tinted"
onClick={closeBackupReminder}
tabIndex={0}
>
<Text
align="center"
Expand Down
12 changes: 12 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,16 @@ export const ExplainerSheet = ({
testId,
onClickOutside,
}: ExplainerSheetProps) => {
useKeyboardShortcut({
condition: () => !!show,
handler: (e: KeyboardEvent) => {
if (e.key === shortcuts.global.CLOSE.key) {
e.preventDefault();
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
29 changes: 11 additions & 18 deletions src/entries/popup/pages/home/TokenDetails/About.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import clsx from 'clsx';
import { ReactNode, useReducer } from 'react';
import { ReactNode, useState } from 'react';

import { i18n } from '~/core/languages';
import { ParsedUserAsset } from '~/core/types/assets';
Expand Down Expand Up @@ -95,10 +95,7 @@ export const InfoRow = ({
);

function MarketCapInfoRow({ marketCap }: { marketCap: ReactNode }) {
const [isMarketCapExplainerOpen, toggleMarketCapExplainer] = useReducer(
(s) => !s,
false,
);
const [isOpen, setIsOpen] = useState(false);
return (
<>
<InfoRow
Expand All @@ -108,7 +105,7 @@ function MarketCapInfoRow({ marketCap }: { marketCap: ReactNode }) {
display="flex"
alignItems="center"
gap="4px"
onClick={toggleMarketCapExplainer}
onClick={() => setIsOpen(true)}
>
{i18n.t(`token_details.about.market_cap`)}
<Symbol
Expand All @@ -122,17 +119,17 @@ function MarketCapInfoRow({ marketCap }: { marketCap: ReactNode }) {
value={marketCap}
/>
<ExplainerSheet
show={isMarketCapExplainerOpen}
show={isOpen}
title={i18n.t('token_details.about.market_cap_explainer.title')}
description={[
i18n.t('token_details.about.market_cap_explainer.description'),
]}
onClickOutside={toggleMarketCapExplainer}
onClickOutside={() => setIsOpen(false)}
actionButton={{
label: i18n.t('token_details.about.market_cap_explainer.action'),
variant: 'tinted',
labelColor: 'blue',
action: toggleMarketCapExplainer,
action: () => setIsOpen(false),
}}
header={{ emoji: '📈' }}
/>
Expand All @@ -141,11 +138,7 @@ function MarketCapInfoRow({ marketCap }: { marketCap: ReactNode }) {
}

function FullyDilutedInfoRow({ fullyDiluted }: { fullyDiluted: ReactNode }) {
const [isFullyDilutedExplainerOpen, toggleFullyDilutedExplainer] = useReducer(
(s) => !s,
false,
);

const [isOpen, setIsOpen] = useState(false);
return (
<>
<InfoRow
Expand All @@ -155,7 +148,7 @@ function FullyDilutedInfoRow({ fullyDiluted }: { fullyDiluted: ReactNode }) {
display="flex"
alignItems="center"
gap="4px"
onClick={toggleFullyDilutedExplainer}
onClick={() => setIsOpen(true)}
>
{i18n.t(`token_details.about.fully_diluted`)}
<Symbol
Expand All @@ -169,17 +162,17 @@ function FullyDilutedInfoRow({ fullyDiluted }: { fullyDiluted: ReactNode }) {
value={fullyDiluted}
/>
<ExplainerSheet
show={isFullyDilutedExplainerOpen}
show={isOpen}
title={i18n.t('token_details.about.fully_diluted_explainer.title')}
description={[
i18n.t('token_details.about.fully_diluted_explainer.description'),
]}
onClickOutside={toggleFullyDilutedExplainer}
onClickOutside={() => setIsOpen(false)}
actionButton={{
label: i18n.t('token_details.about.fully_diluted_explainer.action'),
variant: 'tinted',
labelColor: 'blue',
action: toggleFullyDilutedExplainer,
action: () => setIsOpen(false),
}}
header={{ emoji: '📊' }}
/>
Expand Down

0 comments on commit 6094a6e

Please sign in to comment.