Skip to content

Commit

Permalink
Ensure remind backup show only onetime every open popup
Browse files Browse the repository at this point in the history
  • Loading branch information
saltict committed May 30, 2024
1 parent 67f2dde commit 9b3098a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
25 changes: 15 additions & 10 deletions packages/extension-koni-ui/src/Popup/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useAccountBalance, useGetBannerByScreen, useGetChainSlugsByAccountType,
import { RootState } from '@subwallet/extension-koni-ui/stores';
import { RemindBackUpSeedPhraseParamState, SessionStorage, ThemeProps } from '@subwallet/extension-koni-ui/types';
import { ModalContext } from '@subwallet/react-ui';
import React, { useCallback, useContext, useEffect, useMemo } from 'react';
import React, {useCallback, useContext, useEffect, useMemo, useRef} from 'react';

Check failure on line 14 in packages/extension-koni-ui/src/Popup/Home/index.tsx

View workflow job for this annotation

GitHub Actions / Build Development Preview

A space is required after '{'

Check failure on line 14 in packages/extension-koni-ui/src/Popup/Home/index.tsx

View workflow job for this annotation

GitHub Actions / Build Development Preview

A space is required before '}'
import { useSelector } from 'react-redux';
import { Outlet } from 'react-router';
import { useLocation } from 'react-router-dom';
Expand All @@ -36,6 +36,7 @@ function Component ({ className = '' }: Props): React.ReactElement<Props> {
const isZkModeSyncing = useSelector((state: RootState) => state.mantaPay.isSyncing);
const handleMantaPaySync = useHandleMantaPaySync();
const banners = useGetBannerByScreen('home');
const remindBackUpShowed = useRef<boolean>(false);

const firstBanner = useMemo((): CampaignBanner | undefined => banners[0], [banners]);

Expand Down Expand Up @@ -69,15 +70,19 @@ function Component ({ className = '' }: Props): React.ReactElement<Props> {
}, [activeModal, firstBanner, location]);

useEffect(() => {
const infoSession = Date.now();

const isFromIgnorePage = location.state as RemindBackUpSeedPhraseParamState;

if (infoSession - sessionLatest.timeCalculate > sessionLatest.timeBackup &&
sessionLatest.remind &&
(isFromIgnorePage?.from !== historyPageIgnoreRemind)) {
inactiveModal(HOME_CAMPAIGN_BANNER_MODAL);
activeModal(REMIND_BACKUP_SEED_PHRASE_MODAL);
// Run remind backup seed phrase one time
if (!remindBackUpShowed.current) {
const infoSession = Date.now();

const isFromIgnorePage = location.state as RemindBackUpSeedPhraseParamState;

if (infoSession - sessionLatest.timeCalculate > sessionLatest.timeBackup &&
sessionLatest.remind &&
(isFromIgnorePage?.from !== historyPageIgnoreRemind)) {
inactiveModal(HOME_CAMPAIGN_BANNER_MODAL);
activeModal(REMIND_BACKUP_SEED_PHRASE_MODAL);
remindBackUpShowed.current = true;
}
}
}, [activeModal, inactiveModal, location, sessionLatest]);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// Copyright 2019-2022 @polkadot/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0

import { LATEST_SESSION } from '@subwallet/extension-koni-ui/constants/localStorage';

export function handleRemindBackupTime () {
// Handle
const keyLatestSession = 'general.latest-session';
const timeBackup = 1209600000;
const DEFAULT_LATEST_SESSION = { remind: false, timeCalculate: Date.now(), timeBackup, isFinished: false };

window.onbeforeunload = () => {
const latestSessionRaw = localStorage.getItem(keyLatestSession);
const latestSessionRaw = localStorage.getItem(LATEST_SESSION);

const latestSession = latestSessionRaw
? JSON.parse(latestSessionRaw) as {
Expand All @@ -17,6 +18,6 @@ export function handleRemindBackupTime () {
}
: DEFAULT_LATEST_SESSION;

localStorage.setItem(keyLatestSession, JSON.stringify({ ...latestSession, remind: true }));
localStorage.setItem(LATEST_SESSION, JSON.stringify({ ...latestSession, remind: true }));
};
}

0 comments on commit 9b3098a

Please sign in to comment.