Skip to content

Commit

Permalink
feat: move pin extension notification to main screen (#902)
Browse files Browse the repository at this point in the history
* feat: move pin extension notification to main screen

* fix: start notification timeout only when modal is close

* fix: notification useEffect improvement
  • Loading branch information
greatertomi committed Mar 5, 2024
1 parent 87b66a6 commit 47906a0
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 12 deletions.
1 change: 1 addition & 0 deletions apps/browser-extension-wallet/src/types/local-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ export interface ILocalStorage {
multidelegationFirstVisitSincePortfolioPersistence?: boolean;
unconfirmedTransactions: UnconfirmedTransaction[];
stakingBrowserPreferences: StakingBrowserPreferences;
showPinExtension?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,10 @@ $main-gap: 49px;
@include content_grid($col-width-large, $grid-gap-large);
}
}

.pinExtension {
position: absolute;
top: 10px;
right: 80px;
z-index: 100;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { DrawerContent, DrawerUIContainer } from '../Drawer';
import { useNetworkError } from '@hooks/useNetworkError';
import { LeftSidePanel } from '../LeftSidePanel';
import styles from './Layout.module.scss';
import { PinExtension } from '@views/browser/features/wallet-setup/components/PinExtension';
import { useLocalStorage } from '@hooks';

interface LayoutProps {
children: React.ReactNode;
Expand All @@ -21,13 +23,17 @@ interface LayoutProps {

const toastThrottle = 500;
const isFlexible = process.env.USE_DESKTOP_LAYOUT === 'true';
const PIN_EXTENSION_TIMEOUT = 5000;

export const Layout = ({ children, drawerUIDefaultContent, isFullWidth }: LayoutProps): React.ReactElement => {
const { t } = useTranslation();
const [, setDrawerConfig] = useDrawer();
const { theme, setTheme } = useTheme();
const backgroundServices = useBackgroundServiceAPIContext();

const [showPinExtension, { updateLocalStorage: setShowPinExtension }] = useLocalStorage('showPinExtension', true);
const [showDappBetaModal] = useLocalStorage('showDappBetaModal', true);

useEffect(() => {
const openDrawer = async () => {
const backgroundStorage = await backgroundServices.getBackgroundStorage();
Expand All @@ -50,6 +56,16 @@ export const Layout = ({ children, drawerUIDefaultContent, isFullWidth }: Layout
return () => subscription.unsubscribe();
}, [backgroundServices, setTheme]);

useEffect(() => {
if (showDappBetaModal) return;
const timer = window.setTimeout(() => {
setShowPinExtension(false);
}, PIN_EXTENSION_TIMEOUT);

// eslint-disable-next-line consistent-return
return () => window.clearTimeout(timer);
}, [setShowPinExtension, showDappBetaModal]);

const debouncedToast = useMemo(() => debounce(toast.notify, toastThrottle), []);
const showNetworkError = useCallback(
() => debouncedToast({ text: t('general.errors.networkError') }),
Expand All @@ -64,6 +80,11 @@ export const Layout = ({ children, drawerUIDefaultContent, isFullWidth }: Layout
className={classnames(styles.layoutGridContainer, isFullWidth && styles.fullWidth, isFlexible && styles.flexible)}
>
<LeftSidePanel theme={theme.name} />
{showPinExtension && (
<div className={styles.pinExtension}>
<PinExtension />
</div>
)}
{children}
<DrawerUIContainer defaultContent={drawerUIDefaultContent} />
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
import { useExternalLinkOpener } from '@providers';
import { getValueFromLocalStorage, saveValueInLocalStorage } from '@src/utils/local-storage';
import { WarningModal } from '@src/views/browser-view/components';
import React, { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useLocalStorage } from '@hooks';

export const DappBetaModal = (): React.ReactElement => {
const { t } = useTranslation();
const [isModalVisible, setIsModalVisible] = useState(false);
const [showDappBetaModal, { updateLocalStorage: setShowDappBetaModal }] = useLocalStorage('showDappBetaModal', true);
const openExternalLink = useExternalLinkOpener();

useEffect(() => {
const showDappBetaModal = getValueFromLocalStorage('showDappBetaModal', true);
setIsModalVisible(showDappBetaModal);
}, []);
}, [showDappBetaModal]);

const onClose = () => {
saveValueInLocalStorage({ key: 'showDappBetaModal', value: false });
setShowDappBetaModal(false);
setIsModalVisible(false);
};

const onLearnMore = () => {
const showDappBetaModal = getValueFromLocalStorage('showDappBetaModal', true);
if (showDappBetaModal) openExternalLink(process.env.FAQ_URL);
onClose();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import React, { useState, useCallback, useEffect } from 'react';
import { Switch, Route, useHistory, useLocation } from 'react-router-dom';
import { Wallet } from '@lace/cardano';
import { WalletSetupLayout } from '@src/views/browser-view/components/Layout';
import { PinExtension } from './PinExtension';
import { ErrorDialog, HWErrorCode } from './ErrorDialog';
import { StartOverDialog } from '@views/browser/features/wallet-setup/components/StartOverDialog';
import { useTranslation } from 'react-i18next';
Expand Down Expand Up @@ -320,7 +319,7 @@ export const HardwareWalletFlow = ({
onStartOver={handleStartOver}
onClose={() => setIsStartOverDialogVisible(false)}
/>
<WalletSetupLayout prompt={location.pathname.endsWith('finish') ? <PinExtension /> : undefined}>
<WalletSetupLayout>
<Switch>
<Route path={route('analytics')}>{hardwareWalletStepRenderFunctions.analytics()}</Route>
<Route path={route('connect')}>{hardwareWalletStepRenderFunctions.connect()}</Route>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
gap: size_unit(2);
width: 300px;
padding: size_unit(2);
background: var(--color-white, var(--dark-mode-dark-grey-plus));
background: var(--primary-default, #7E5BF0);
box-shadow: var(--shadows-lighter-assets);
border-radius: 11px;

Expand All @@ -25,12 +25,12 @@

h5 {
@include text-bodySmall-bold;
color: var(--text-color-primary);
color: var(--text-color-white, #ffffff) !important;
}

p {
@include text-bodySmall-semi-bold;
color: var(--text-color-secondary);
color: var(--text-color-white, #ffffff);
display: flex;
align-items: center;
gap: 4px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
} from '@providers/AnalyticsProvider/analyticsTracker';
import { config } from '@src/config';

import { PinExtension } from './PinExtension';
import { Fallback } from './Fallback';

import { passwordTranslationMap } from '../constants';
Expand Down Expand Up @@ -449,7 +448,7 @@ export const WalletSetupWizard = ({
}, [shouldDisplayExperiment]);

return (
<WalletSetupLayout prompt={currentStep === WalletSetupSteps.Finish ? <PinExtension /> : undefined}>
<WalletSetupLayout>
{currentStep === WalletSetupSteps.Legal && (
<WalletSetupLegalStep
onBack={moveBack}
Expand Down

0 comments on commit 47906a0

Please sign in to comment.