Skip to content

Commit

Permalink
[Issue 3062] [fix] Extension - Unable to back screen in case open Gen…
Browse files Browse the repository at this point in the history
…eral settings to Marketing campaign #4
  • Loading branch information
Thiendekaco committed May 16, 2024
1 parent 41aa0e5 commit 4223897
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 37 deletions.
2 changes: 1 addition & 1 deletion packages/extension-koni-ui/src/Popup/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ function DefaultRoute ({ children }: { children: React.ReactNode }): React.React

if (infoSession - latestSession.timeCalculate > latestSession.timeBackup && sessionLatest.remind &&
!needUnlock &&
![createPasswordUrl, welcomeUrl, loginUrl, accountNewSeedPhrase, createDoneUrl].includes(location.pathname)) {
location.pathname.includes('home')) {
activeModal(REMIND_BACKUP_SEED_PHRASE_MODAL);
}
}, [activeModal, location.pathname, needUnlock, sessionLatest.remind]);
Expand Down
23 changes: 7 additions & 16 deletions packages/extension-koni-ui/src/Popup/Transaction/variants/Earn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import { AccountSelector, AlertBox, AmountInput, EarningPoolSelector, EarningVal
import { EarningProcessItem } from '@subwallet/extension-koni-ui/components/Earning';
import { getInputValuesFromString } from '@subwallet/extension-koni-ui/components/Field/AmountInput';
import { EarningInstructionModal } from '@subwallet/extension-koni-ui/components/Modal/Earning';
import { BN_ZERO, EARNING_INSTRUCTION_MODAL, LATEST_SESSION, SELECT_ACCOUNT_MODAL, STAKE_ALERT_DATA } from '@subwallet/extension-koni-ui/constants';
import { BN_ZERO, EARNING_INSTRUCTION_MODAL, STAKE_ALERT_DATA } from '@subwallet/extension-koni-ui/constants';
import { useChainConnection, useFetchChainState, useGetBalance, useGetNativeTokenSlug, useInitValidateTransaction, useNotification, usePreCheckAction, useRestoreTransaction, useSelector, useTransactionContext, useWatchTransaction, useYieldPositionDetail } from '@subwallet/extension-koni-ui/hooks';
import { insufficientMessages } from '@subwallet/extension-koni-ui/hooks/transaction/useHandleSubmitTransaction';
import { fetchPoolTarget, getOptimalYieldPath, submitJoinYieldPool, validateYieldProcess } from '@subwallet/extension-koni-ui/messaging';
import { DEFAULT_YIELD_PROCESS, EarningActionType, earningReducer } from '@subwallet/extension-koni-ui/reducer';
import { store } from '@subwallet/extension-koni-ui/stores';
import { EarnParams, FormCallbacks, FormFieldData, SessionStorage, ThemeProps } from '@subwallet/extension-koni-ui/types';
import { EarnParams, FormCallbacks, FormFieldData, ThemeProps } from '@subwallet/extension-koni-ui/types';
import { convertFieldToObject, isAccountAll, parseNominations, reformatAddress, simpleCheckForm } from '@subwallet/extension-koni-ui/utils';
import { ActivityIndicator, Button, ButtonProps, Form, Icon, ModalContext, Number } from '@subwallet/react-ui';
import BigN from 'bignumber.js';
Expand All @@ -26,7 +26,6 @@ import { CheckCircle, PlusCircle } from 'phosphor-react';
import React, { useCallback, useContext, useEffect, useMemo, useReducer, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import styled from 'styled-components';
import { useLocalStorage } from 'usehooks-ts';

import { isEthereumAddress } from '@polkadot/util-crypto';

Expand All @@ -43,19 +42,11 @@ const instructionModalId = EARNING_INSTRUCTION_MODAL;

// Not enough balance to xcm;
export const insufficientXCMMessages = ['You can only enter a maximum'];
const DEFAULT_SESSION_VALUE: SessionStorage = {
remind: false,
timeCalculate: Date.now(),
timeBackup: 300000,
finishStep: true
};
const AccountSelectorModalId = SELECT_ACCOUNT_MODAL;

const Component = () => {
const { t } = useTranslation();
const notify = useNotification();
const { activeModal, checkActive } = useContext(ModalContext);
const [sessionLatest] = useLocalStorage<SessionStorage>(LATEST_SESSION, DEFAULT_SESSION_VALUE);
const { activeModal } = useContext(ModalContext);

const { closeAlert, defaultData, goBack, onDone,
openAlert, persistData,
Expand Down Expand Up @@ -847,11 +838,11 @@ const Component = () => {
}, [chainState?.active, forceFetchValidator, slug, chainValue, fromValue]);

useEffect(() => {
if (!compound && !screenLoading && !sessionLatest.finishStep && !checkActive(AccountSelectorModalId)) {
if (!compound && !screenLoading) {
isClickInfoButtonRef.current = false;
activeModal(instructionModalId);
}
}, [activeModal, checkActive, compound, screenLoading, sessionLatest.finishStep]);
}, [activeModal, compound, screenLoading]);

const subHeaderButtons: ButtonProps[] = useMemo(() => {
return [
Expand All @@ -864,11 +855,11 @@ const Component = () => {
}

isClickInfoButtonRef.current = true;
!sessionLatest.finishStep && checkActive(AccountSelectorModalId) && activeModal(instructionModalId);
activeModal(instructionModalId);
}
}
];
}, [activeModal, checkActive, screenLoading, sessionLatest.finishStep, submitLoading]);
}, [activeModal, screenLoading, submitLoading]);

useEffect(() => {
setSubHeaderRightButtons(subHeaderButtons);
Expand Down
21 changes: 5 additions & 16 deletions packages/extension-koni-ui/src/Popup/Transaction/variants/Swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import { AccountSelector, AddressInput, AlertBox, HiddenInput, MetaInfo, PageWra
import { SwapFromField, SwapToField } from '@subwallet/extension-koni-ui/components/Field/Swap';
import { AddMoreBalanceModal, ChooseFeeTokenModal, SlippageModal, SwapIdleWarningModal, SwapQuotesSelectorModal, SwapTermsOfServiceModal } from '@subwallet/extension-koni-ui/components/Modal/Swap';
import { QuoteResetTime, SwapRoute } from '@subwallet/extension-koni-ui/components/Swap';
import { BN_TEN, BN_ZERO, CONFIRM_SWAP_TERM, DEFAULT_SWAP_PARAMS, LATEST_SESSION, SELECT_ACCOUNT_MODAL, SWAP_ALL_QUOTES_MODAL, SWAP_CHOOSE_FEE_TOKEN_MODAL, SWAP_IDLE_WARNING_MODAL, SWAP_MORE_BALANCE_MODAL, SWAP_SLIPPAGE_MODAL, SWAP_TERMS_OF_SERVICE_MODAL } from '@subwallet/extension-koni-ui/constants';
import { BN_TEN, BN_ZERO, CONFIRM_SWAP_TERM, DEFAULT_SWAP_PARAMS, SWAP_ALL_QUOTES_MODAL, SWAP_CHOOSE_FEE_TOKEN_MODAL, SWAP_IDLE_WARNING_MODAL, SWAP_MORE_BALANCE_MODAL, SWAP_SLIPPAGE_MODAL, SWAP_TERMS_OF_SERVICE_MODAL } from '@subwallet/extension-koni-ui/constants';
import { DataContext } from '@subwallet/extension-koni-ui/contexts/DataContext';
import { useChainConnection, useGetChainPrefixBySlug, useNotification, useSelector, useSetCurrentPage, useTransactionContext, useWatchTransaction } from '@subwallet/extension-koni-ui/hooks';
import { getLatestSwapQuote, handleSwapRequest, handleSwapStep, validateSwapProcess } from '@subwallet/extension-koni-ui/messaging/transaction/swap';
import { FreeBalance, FreeBalanceToEarn, TransactionContent, TransactionFooter } from '@subwallet/extension-koni-ui/Popup/Transaction/parts';
import { DEFAULT_SWAP_PROCESS, SwapActionType, swapReducer } from '@subwallet/extension-koni-ui/reducer';
import { RootState } from '@subwallet/extension-koni-ui/stores';
import { Theme } from '@subwallet/extension-koni-ui/themes';
import { FormCallbacks, FormFieldData, SessionStorage, SwapParams, ThemeProps } from '@subwallet/extension-koni-ui/types';
import { FormCallbacks, FormFieldData, SwapParams, ThemeProps } from '@subwallet/extension-koni-ui/types';
import { TokenSelectorItemType } from '@subwallet/extension-koni-ui/types/field';
import { convertFieldToObject, findAccountByAddress, isAccountAll, reformatAddress } from '@subwallet/extension-koni-ui/utils';
import { ActivityIndicator, BackgroundIcon, Button, Form, Icon, Logo, ModalContext, Number, Tooltip } from '@subwallet/react-ui';
Expand Down Expand Up @@ -72,21 +72,13 @@ function getTokenSelectorItem (tokenSlugs: string[], assetRegistryMap: Record<st

const numberMetadata = { maxNumberFormat: 8 };

const DEFAULT_SESSION_VALUE: SessionStorage = {
remind: false,
timeCalculate: Date.now(),
timeBackup: 300000,
finishStep: true
};
const AccountSelectorModalId = SELECT_ACCOUNT_MODAL;

const Component = () => {
useSetCurrentPage('/transaction/swap');
const { t } = useTranslation();
const notify = useNotification();
const { closeAlert, defaultData, onDone, openAlert, persistData, setBackProps, setCustomScreenTitle } = useTransactionContext<SwapParams>();

const { activeModal, checkActive, inactiveAll, inactiveModal } = useContext(ModalContext);
const { activeModal, inactiveAll, inactiveModal } = useContext(ModalContext);

const { accounts, currentAccount, isAllAccount } = useSelector((state) => state.accountState);
const assetRegistryMap = useSelector((state) => state.assetRegistry.assetRegistry);
Expand All @@ -109,7 +101,6 @@ const Component = () => {
const [isFormInvalid, setIsFormInvalid] = useState<boolean>(false);
const [currentOptimalSwapPath, setOptimalSwapPath] = useState<OptimalSwapPath | undefined>(undefined);

const [sessionLatest] = useLocalStorage<SessionStorage>(LATEST_SESSION, DEFAULT_SESSION_VALUE);
const [confirmedTerm, setConfirmedTerm] = useLocalStorage(CONFIRM_SWAP_TERM, '');
const [showQuoteArea, setShowQuoteArea] = useState<boolean>(false);
const optimalQuoteRef = useRef<SwapQuote | undefined>(undefined);
Expand Down Expand Up @@ -1085,12 +1076,10 @@ const Component = () => {
}, [currentQuoteRequest, hasInternalConfirmations, quoteAliveUntil, requestUserInteractToContinue]);

useEffect(() => {
if (!confirmedTerm && sessionLatest.finishStep && !checkActive(AccountSelectorModalId)) {
if (!confirmedTerm) {
activeModal(SWAP_TERMS_OF_SERVICE_MODAL);
} else if (confirmedTerm) {
inactiveModal(SWAP_TERMS_OF_SERVICE_MODAL);
}
}, [sessionLatest.finishStep, activeModal, confirmedTerm, checkActive, inactiveModal]);
}, [activeModal, confirmedTerm]);

useEffect(() => {
if (requestUserInteractToContinue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,14 @@ const RemindBackupSeedPhraseModal = styled(Component)<Props>(({ theme: { token }
lineHeight: token.lineHeightHeading6
},

'.__modal-user-guide': {
marginLeft: token.marginXXS
},

'.ant-sw-modal-footer': {
borderTop: 'none',
display: 'flex',
gap: token.sizeSM
},

'.__modal-user-guide': {
marginLeft: token.marginXXS
}
};
});
Expand Down

0 comments on commit 4223897

Please sign in to comment.