diff --git a/README.md b/README.md index 15e1f2482..7797cffe6 100644 --- a/README.md +++ b/README.md @@ -19,3 +19,15 @@ 2. Check `Developer mode` 3. Click on `Load unpacked extension` 4. Select the `build` folder. + +### Developing with local dependencies + +Use esm build, and reference your filesystem in package.json + +For example, if your xverse-core and xverse-web-extension are in same directory, +make or pull your local changes to xverse-core, then: + +``` +cd ../xverse-core && npm i && npm run build:esm && \ +cd $OLDPWD && npm i --legacy-peer-deps @secretkeylabs/xverse-core@../xverse-core && npm start +``` diff --git a/package.json b/package.json index cbcee14d5..45ce1ba65 100644 --- a/package.json +++ b/package.json @@ -10,11 +10,11 @@ "@stacks/connect": "^6.10.2", "@stacks/encryption": "4.3.5", "@stacks/stacks-blockchain-api-types": "^6.1.1", + "@stacks/transactions": "^4.3.8", "@tanstack/query-sync-storage-persister": "^4.29.1", "@tanstack/react-query": "^4.29.3", "@tanstack/react-query-devtools": "^4.29.3", "@tanstack/react-query-persist-client": "^4.29.3", - "@stacks/transactions": "^4.3.8", "@testing-library/jest-dom": "^5.16.5", "@testing-library/react": "^13.4.0", "@testing-library/user-event": "^13.5.0", diff --git a/src/app/hooks/useResetUserFlow.ts b/src/app/hooks/useResetUserFlow.ts new file mode 100644 index 000000000..ede719bb3 --- /dev/null +++ b/src/app/hooks/useResetUserFlow.ts @@ -0,0 +1,74 @@ +import { useMemo } from 'react'; +import { useNavigate } from 'react-router-dom'; + +const resetUserFlowChannel = 'resetUserFlow'; + +/* + * Extend UserFlowConfigKey here + * + * resetTo: should be a valid route + * + */ +const userFlowConfig: Record = { + '/send-btc': { resetTo: '/send-btc' }, + '/confirm-btc-tx': { resetTo: '/send-btc' }, + '/send-brc20': { resetTo: '/send-brc20' }, + '/confirm-inscription-request': { resetTo: '/send-brc20' }, + '/ordinal-detail': { resetTo: '/nft-dashboard' }, + '/send-ordinal': { resetTo: '/nft-dashboard' }, + '/confirm-ordinal-tx': { resetTo: '/nft-dashboard' }, + '/nft-detail': { resetTo: '/nft-dashboard' }, + '/send-nft': { resetTo: '/nft-dashboard' }, + '/confirm-nft-tx': { resetTo: '/nft-dashboard' }, +}; +type UserFlowConfigKey = keyof typeof userFlowConfig; + +/* + * Usage: + * + * To subscribe: + * const { subscribeToResetUserFlow } = useResetUserFlow(); + * useEffect(() => subscribeToResetUserFlow('/nft-detail'), []); + * + * To broadcast (once on first render): + * const { broadcastResetUserFlow, closeChannel } = useResetUserFlow(); + * useEffect(() => broadcastResetUserFlow(), []); + * + * Both subscribe and broadcast methods return the cleanup callback, + * but you can also use closeChannel, which only returns a close callback: + * const { closeChannel } = useResetUserFlow(); + * useEffect(() => closeChannel, []); + * + */ +export const useResetUserFlow = () => { + const navigate = useNavigate(); + + const resetUserFlow = (path: UserFlowConfigKey) => { + // TODO: infer UserFlowConfigKey from location? + if (!userFlowConfig[path]) { + return; + } + navigate(userFlowConfig[path]?.resetTo); + }; + + const broadcastChannel = useMemo(() => new BroadcastChannel(resetUserFlowChannel), []); + const closeChannel = () => broadcastChannel.close(); + + const broadcastResetUserFlow = () => { + broadcastChannel.postMessage('reset'); + return closeChannel; + }; + + const subscribeToResetUserFlow = (path: UserFlowConfigKey) => { + broadcastChannel.onmessage = (message) => { + if (message.data !== 'reset') { + return; + } + resetUserFlow(path); + }; + return closeChannel; + }; + return { subscribeToResetUserFlow, broadcastResetUserFlow, closeChannel }; +}; + +export default useResetUserFlow; diff --git a/src/app/screens/accountList/index.tsx b/src/app/screens/accountList/index.tsx index 0244cc13c..9cb05ef3d 100644 --- a/src/app/screens/accountList/index.tsx +++ b/src/app/screens/accountList/index.tsx @@ -6,12 +6,13 @@ import styled from 'styled-components'; import Plus from '@assets/img/dashboard/plus.svg'; import ConnectLedger from '@assets/img/dashboard/connect_ledger.svg'; import { useDispatch } from 'react-redux'; -import { selectAccount, setShouldResetUserFlow } from '@stores/wallet/actions/actionCreators'; +import { selectAccount } from '@stores/wallet/actions/actionCreators'; import Seperator from '@components/seperator'; import { Account } from '@secretkeylabs/xverse-core/types'; import useWalletSelector from '@hooks/useWalletSelector'; import useWalletReducer from '@hooks/useWalletReducer'; -import React, { useMemo } from 'react'; +import React, { useEffect, useMemo } from 'react'; +import { useResetUserFlow } from '@hooks/useResetUserFlow'; const Container = styled.div` display: flex; @@ -89,6 +90,10 @@ function AccountList(): JSX.Element { return accountsList; }, [accountsList, ledgerAccountsList, network]); + const { broadcastResetUserFlow, closeChannel } = useResetUserFlow(); + // destructor + useEffect(() => closeChannel, []); + const handleAccountSelect = (account: Account) => { dispatch( selectAccount( @@ -106,7 +111,7 @@ function AccountList(): JSX.Element { account.accountName ) ); - dispatch(setShouldResetUserFlow(true)); + broadcastResetUserFlow(); navigate('/'); }; diff --git a/src/app/screens/confirmBtcTransaction/index.tsx b/src/app/screens/confirmBtcTransaction/index.tsx index ae9f84f51..c34694b00 100644 --- a/src/app/screens/confirmBtcTransaction/index.tsx +++ b/src/app/screens/confirmBtcTransaction/index.tsx @@ -17,8 +17,7 @@ import useBtcClient from '@hooks/useBtcClient'; import { isLedgerAccount } from '@utils/helper'; import BigNumber from 'bignumber.js'; import { LedgerTransactionType } from '@screens/ledger/confirmLedgerTransaction'; -import { useDispatch } from 'react-redux'; -import { setShouldResetUserFlow } from '@stores/wallet/actions/actionCreators'; +import { useResetUserFlow } from '@hooks/useResetUserFlow'; const BottomBarContainer = styled.h1((props) => ({ marginTop: props.theme.spacing(5), @@ -27,7 +26,7 @@ const BottomBarContainer = styled.h1((props) => ({ function ConfirmBtcTransaction() { const navigate = useNavigate(); const { t } = useTranslation('translation', { keyPrefix: 'CONFIRM_TRANSACTION' }); - const { ordinalsAddress, btcAddress, selectedAccount, shouldResetUserFlow } = useWalletSelector(); + const { ordinalsAddress, btcAddress, selectedAccount } = useWalletSelector(); const btcClient = useBtcClient(); const [recipientAddress, setRecipientAddress] = useState(''); const [signedTx, setSignedTx] = useState(''); @@ -41,7 +40,6 @@ function ConfirmBtcTransaction() { fee, amount, signedTxHex, recipient, isRestoreFundFlow, unspentUtxos, isBrc20TokenFlow, feePerVByte, } = location.state; - const dispatch = useDispatch(); const { isLoading, @@ -62,17 +60,8 @@ function ConfirmBtcTransaction() { }); }; - useEffect(() => { - if (shouldResetUserFlow) { - navigate('/send-btc', { - state: { - amount, - recipientAddress, - }, - }); - dispatch(setShouldResetUserFlow(false)); - } - }, [shouldResetUserFlow]); + const { subscribeToResetUserFlow } = useResetUserFlow(); + useEffect(() => subscribeToResetUserFlow('/confirm-btc-tx'), []); const onContinueButtonClick = () => { mutate({ signedTx }); diff --git a/src/app/screens/confirmInscriptionRequest/index.tsx b/src/app/screens/confirmInscriptionRequest/index.tsx index cb9c42676..73683e1c5 100644 --- a/src/app/screens/confirmInscriptionRequest/index.tsx +++ b/src/app/screens/confirmInscriptionRequest/index.tsx @@ -28,6 +28,7 @@ import OrdinalsIcon from '@assets/img/nftDashboard/white_ordinals_icon.svg'; import SettingIcon from '@assets/img/dashboard/faders_horizontal.svg'; import { isLedgerAccount } from '@utils/helper'; import { LedgerTransactionType } from '@screens/ledger/confirmLedgerTransaction'; +import { useResetUserFlow } from '@hooks/useResetUserFlow'; const OuterContainer = styled.div` display: flex; @@ -137,7 +138,7 @@ function ConfirmInscriptionRequest() { feePerVByte, } = location.state; const { - btcAddress, network, selectedAccount, seedPhrase, btcFiatRate, + btcAddress, network, selectedAccount, seedPhrase, btcFiatRate } = useWalletSelector(); const btcClient = useBtcClient(); const [signedTx, setSignedTx] = useState(''); @@ -152,6 +153,9 @@ function ConfirmInscriptionRequest() { const content = useMemo(() => textContent && JSON.parse(textContent), [textContent]); + const { subscribeToResetUserFlow } = useResetUserFlow(); + useEffect(() => subscribeToResetUserFlow('/confirm-inscription-request'), []); + useEffect(() => { axios .get(brcContent, { diff --git a/src/app/screens/confirmNftTransaction/index.tsx b/src/app/screens/confirmNftTransaction/index.tsx index 16fa6f825..12a5c13f9 100644 --- a/src/app/screens/confirmNftTransaction/index.tsx +++ b/src/app/screens/confirmNftTransaction/index.tsx @@ -5,7 +5,6 @@ import { useEffect } from 'react'; import { useLocation, useNavigate, useParams } from 'react-router-dom'; import { StacksTransaction } from '@secretkeylabs/xverse-core/types'; import { broadcastSignedTransaction } from '@secretkeylabs/xverse-core/transactions'; -import ArrowLeft from '@assets/img/dashboard/arrow_left.svg'; import BottomBar from '@components/tabBar'; import AssetIcon from '@assets/img/transactions/Assets.svg'; import ConfirmStxTransationComponent from '@components/confirmStxTransactionComponent'; @@ -20,8 +19,7 @@ import useWalletSelector from '@hooks/useWalletSelector'; import useStxWalletData from '@hooks/queries/useStxWalletData'; import { isLedgerAccount } from '@utils/helper'; import { LedgerTransactionType } from '@screens/ledger/confirmLedgerTransaction'; -import { setShouldResetUserFlow } from '@stores/wallet/actions/actionCreators'; -import { useDispatch } from 'react-redux'; +import { useResetUserFlow } from '@hooks/useResetUserFlow'; const ScrollContainer = styled.div` display: flex; @@ -98,10 +96,9 @@ const ReviewTransactionText = styled.h1((props) => ({ function ConfirmNftTransaction() { const { t } = useTranslation('translation', { keyPrefix: 'CONFIRM_TRANSACTION' }); const isGalleryOpen: boolean = document.documentElement.clientWidth > 360; - const { selectedAccount, shouldResetUserFlow } = useWalletSelector(); + const { selectedAccount } = useWalletSelector(); const navigate = useNavigate(); const location = useLocation(); - const dispatch = useDispatch(); const { id } = useParams(); const { nftData } = useNftDataSelector(); const nftIdDetails = id!.split('::'); @@ -164,12 +161,8 @@ function ConfirmNftTransaction() { mutate({ signedTx: txs[0] }); }; - useEffect(() => { - if (shouldResetUserFlow) { - navigate('/nft-dashboard'); - dispatch(setShouldResetUserFlow(false)); - } - }, [shouldResetUserFlow]); + const { subscribeToResetUserFlow } = useResetUserFlow(); + useEffect(() => subscribeToResetUserFlow('/confirm-nft-tx'), []); const handleOnCancelClick = () => { navigate(-1); diff --git a/src/app/screens/confirmOrdinalTransaction/index.tsx b/src/app/screens/confirmOrdinalTransaction/index.tsx index 3ba66fe4f..c8040d5b0 100644 --- a/src/app/screens/confirmOrdinalTransaction/index.tsx +++ b/src/app/screens/confirmOrdinalTransaction/index.tsx @@ -3,7 +3,6 @@ import styled from 'styled-components'; import { useMutation } from '@tanstack/react-query'; import { useEffect, useState } from 'react'; import { useLocation, useNavigate } from 'react-router-dom'; -import ArrowLeft from '@assets/img/dashboard/arrow_left.svg'; import BottomBar from '@components/tabBar'; import useNftDataSelector from '@hooks/stores/useNftDataSelector'; import AccountHeaderComponent from '@components/accountHeader'; @@ -16,8 +15,7 @@ import useBtcClient from '@hooks/useBtcClient'; import { isLedgerAccount } from '@utils/helper'; import useWalletSelector from '@hooks/useWalletSelector'; import { LedgerTransactionType } from '@screens/ledger/confirmLedgerTransaction'; -import { useDispatch } from 'react-redux'; -import { setShouldResetUserFlow } from '@stores/wallet/actions/actionCreators'; +import { useResetUserFlow } from '@hooks/useResetUserFlow'; const ScrollContainer = styled.div` display: flex; @@ -91,12 +89,11 @@ const NftContainer = styled.div((props) => ({ function ConfirmOrdinalTransaction() { const { t } = useTranslation('translation', { keyPrefix: 'CONFIRM_TRANSACTION' }); const isGalleryOpen: boolean = document.documentElement.clientWidth > 360; - const { selectedAccount, shouldResetUserFlow } = useWalletSelector(); + const { selectedAccount } = useWalletSelector(); const navigate = useNavigate(); const btcClient = useBtcClient(); const [recipientAddress, setRecipientAddress] = useState(''); const location = useLocation(); - const dispatch = useDispatch(); const { fee, feePerVByte, signedTxHex, ordinalUtxo, } = location.state; @@ -157,12 +154,8 @@ function ConfirmOrdinalTransaction() { navigate(-1); }; - useEffect(() => { - if (shouldResetUserFlow) { - navigate('/nft-dashboard'); - dispatch(setShouldResetUserFlow(false)); - } - }, [shouldResetUserFlow]); + const { subscribeToResetUserFlow } = useResetUserFlow(); + useEffect(() => subscribeToResetUserFlow('/confirm-ordinal-tx'), []); return ( <> diff --git a/src/app/screens/nftDetail/index.tsx b/src/app/screens/nftDetail/index.tsx index d450caa4e..95e269db1 100644 --- a/src/app/screens/nftDetail/index.tsx +++ b/src/app/screens/nftDetail/index.tsx @@ -24,6 +24,7 @@ import { NftDetailResponse } from '@secretkeylabs/xverse-core/types'; import { MoonLoader } from 'react-spinners'; import AccountHeaderComponent from '@components/accountHeader'; import SmallActionButton from '@components/smallActionButton'; +import { useResetUserFlow } from '@hooks/useResetUserFlow'; import NftAttribute from './nftAttribute'; import DescriptionTile from './descriptionTile'; @@ -272,6 +273,9 @@ function NftDetailScreen() { const [showShareNftOptions, setShowNftOptions] = useState(false); const isGalleryOpen: boolean = document.documentElement.clientWidth > 360; + const { subscribeToResetUserFlow } = useResetUserFlow(); + useEffect(() => subscribeToResetUserFlow('/nft-detail'), []); + useEffect(() => { const data = nftData.find((nftItem) => Number(nftItem?.token_id) === Number(nftIdDetails[2].slice(1))); if (!data) { diff --git a/src/app/screens/ordinalDetail/index.tsx b/src/app/screens/ordinalDetail/index.tsx index 3f32148ab..eb4788034 100644 --- a/src/app/screens/ordinalDetail/index.tsx +++ b/src/app/screens/ordinalDetail/index.tsx @@ -23,6 +23,7 @@ import { useEffect, useMemo, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useNavigate } from 'react-router-dom'; import styled, { useTheme } from 'styled-components'; +import { useResetUserFlow } from '@hooks/useResetUserFlow'; import OrdinalAttributeComponent from './ordinalAttributeComponent'; const Container = styled.div` @@ -286,6 +287,9 @@ function OrdinalDetailScreen() { [selectedOrdinal], ); + const { subscribeToResetUserFlow } = useResetUserFlow(); + useEffect(() => subscribeToResetUserFlow('/ordinal-detail'), []); + useEffect(() => { if (selectedOrdinal) { if ( diff --git a/src/app/screens/sendBrc20/index.tsx b/src/app/screens/sendBrc20/index.tsx index 03c105f0f..cdec7f623 100644 --- a/src/app/screens/sendBrc20/index.tsx +++ b/src/app/screens/sendBrc20/index.tsx @@ -1,6 +1,6 @@ import styled from 'styled-components'; import BigNumber from 'bignumber.js'; -import { useState } from 'react'; +import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useLocation, useNavigate } from 'react-router-dom'; import { @@ -10,6 +10,7 @@ import { ErrorCodes, } from '@secretkeylabs/xverse-core'; import { Recipient } from '@secretkeylabs/xverse-core/transactions/btc'; +import { useResetUserFlow } from '@hooks/useResetUserFlow'; import useWalletSelector from '@hooks/useWalletSelector'; import TopRow from '@components/topRow'; import BottomBar from '@components/tabBar'; @@ -53,7 +54,7 @@ function SendBrc20Screen() { const { t } = useTranslation('translation'); const navigate = useNavigate(); const { - btcAddress, ordinalsAddress, selectedAccount, seedPhrase, network, btcFiatRate, brcCoinsList, + btcAddress, ordinalsAddress, selectedAccount, seedPhrase, network, btcFiatRate, brcCoinsList } = useWalletSelector(); const [amountError, setAmountError] = useState(''); const [amountToSend, setAmountToSend] = useState(''); @@ -65,6 +66,9 @@ function SendBrc20Screen() { const coinName = location.search ? location.search.split('coinName=')[1] : undefined; const fungibleToken = location.state?.fungibleToken || brcCoinsList?.find((coin) => coin.name === coinName); + const { subscribeToResetUserFlow } = useResetUserFlow(); + useEffect(() => subscribeToResetUserFlow('/send-brc20'), []); + const handleBackButtonClick = () => { if (showForm) { setAmountError(''); diff --git a/src/app/screens/sendBtc/index.tsx b/src/app/screens/sendBtc/index.tsx index 67079de47..578a5cd20 100644 --- a/src/app/screens/sendBtc/index.tsx +++ b/src/app/screens/sendBtc/index.tsx @@ -2,7 +2,7 @@ import BigNumber from 'bignumber.js'; import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useMutation } from '@tanstack/react-query'; -import { useDispatch, useSelector } from 'react-redux'; +import { useSelector } from 'react-redux'; import { useLocation, useNavigate } from 'react-router-dom'; import SendForm from '@components/sendForm'; import TopRow from '@components/topRow'; @@ -15,7 +15,7 @@ import { BITCOIN_DUST_AMOUNT_SATS } from '@utils/constants'; import { Recipient, SignedBtcTx } from '@secretkeylabs/xverse-core/transactions/btc'; import { ErrorCodes, ResponseError } from '@secretkeylabs/xverse-core'; import { isInOptions } from '@utils/helper'; -import { setShouldResetUserFlow } from '@stores/wallet/actions/actionCreators'; +import { useResetUserFlow } from '@hooks/useResetUserFlow'; function SendBtcScreen() { const location = useLocation(); @@ -37,10 +37,8 @@ function SendBtcScreen() { selectedAccount, seedPhrase, btcFiatRate, - shouldResetUserFlow, } = useSelector((state: StoreState) => state.walletState); const { t } = useTranslation('translation', { keyPrefix: 'SEND' }); - const dispatch = useDispatch(); const navigate = useNavigate(); const { @@ -81,13 +79,8 @@ function SendBtcScreen() { } }, [data]); - useEffect(() => { - if (shouldResetUserFlow) { - setAmount(''); - setRecipientAddress(''); - dispatch(setShouldResetUserFlow(false)); - } - }, [shouldResetUserFlow]); + const { subscribeToResetUserFlow } = useResetUserFlow(); + useEffect(() => subscribeToResetUserFlow('/send-btc'), []); useEffect(() => { if (recipientAddress && amount && txError) { diff --git a/src/app/screens/sendNft/index.tsx b/src/app/screens/sendNft/index.tsx index 8d50cb992..a40235d79 100644 --- a/src/app/screens/sendNft/index.tsx +++ b/src/app/screens/sendNft/index.tsx @@ -20,8 +20,7 @@ import useNftDataSelector from '@hooks/stores/useNftDataSelector'; import { NftData } from '@secretkeylabs/xverse-core/types/api/stacks/assets'; import AccountHeaderComponent from '@components/accountHeader'; import useNetworkSelector from '@hooks/useNetwork'; -import { setShouldResetUserFlow } from '@stores/wallet/actions/actionCreators'; -import { useDispatch } from 'react-redux'; +import { useResetUserFlow } from '@hooks/useResetUserFlow'; const ScrollContainer = styled.div` display: flex; @@ -102,7 +101,6 @@ function SendNft() { const navigate = useNavigate(); const { id } = useParams(); const location = useLocation(); - const dispatch = useDispatch(); let address: string | undefined; if (location.state) { @@ -126,7 +124,6 @@ function SendNft() { stxPublicKey, network, feeMultipliers, - shouldResetUserFlow, } = useWalletSelector(); const [error, setError] = useState(''); const [recipientAddress, setRecipientAddress] = useState(''); @@ -176,12 +173,8 @@ function SendNft() { } }, [data]); - useEffect(() => { - if (shouldResetUserFlow) { - navigate('/nft-dashboard'); - dispatch(setShouldResetUserFlow(false)); - } - }, [shouldResetUserFlow]); + const { subscribeToResetUserFlow } = useResetUserFlow(); + useEffect(() => subscribeToResetUserFlow('/send-nft'), []); const handleBackButtonClick = () => { navigate(-1); diff --git a/src/app/screens/sendOrdinal/index.tsx b/src/app/screens/sendOrdinal/index.tsx index 3f0108297..917967eeb 100644 --- a/src/app/screens/sendOrdinal/index.tsx +++ b/src/app/screens/sendOrdinal/index.tsx @@ -21,9 +21,8 @@ import useNftDataSelector from '@hooks/stores/useNftDataSelector'; import useBtcClient from '@hooks/useBtcClient'; import useTextOrdinalContent from '@hooks/useTextOrdinalContent'; import { isLedgerAccount } from '@utils/helper'; -import { setShouldResetUserFlow } from '@stores/wallet/actions/actionCreators'; -import { useDispatch } from 'react-redux'; import { isOrdinalOwnedByAccount } from '@secretkeylabs/xverse-core/api'; +import { useResetUserFlow } from '@hooks/useResetUserFlow'; const ScrollContainer = styled.div` display: flex; @@ -105,9 +104,8 @@ function SendOrdinal() { const { selectedOrdinal } = useNftDataSelector(); const btcClient = useBtcClient(); const location = useLocation(); - const dispatch = useDispatch(); const { - network, ordinalsAddress, btcAddress, selectedAccount, seedPhrase, btcFiatRate, shouldResetUserFlow + network, ordinalsAddress, btcAddress, selectedAccount, seedPhrase, btcFiatRate } = useWalletSelector(); const [ordinalUtxo, setOrdinalUtxo] = useState(undefined); const [error, setError] = useState(''); @@ -170,12 +168,9 @@ function SendOrdinal() { navigate(-1); }; - useEffect(() => { - if (shouldResetUserFlow) { - navigate('/nft-dashboard'); - dispatch(setShouldResetUserFlow(false)); - } - }, [shouldResetUserFlow]); + const { subscribeToResetUserFlow } = useResetUserFlow(); + useEffect(() => subscribeToResetUserFlow('/send-ordinal'), []); + const activeAccountOwnsOrdinal = selectedOrdinal && selectedAccount && isOrdinalOwnedByAccount(selectedOrdinal, selectedAccount); diff --git a/src/app/stores/index.ts b/src/app/stores/index.ts index ded78d637..d93264ccf 100644 --- a/src/app/stores/index.ts +++ b/src/app/stores/index.ts @@ -42,7 +42,6 @@ const storeMiddleware = [ actions.SetWalletSeedPhraseKey, actions.UnlockWalletKey, actions.SelectAccountKey, - actions.SetShouldResetUserFlowKey ], }), ]; diff --git a/src/app/stores/wallet/actions/actionCreators.ts b/src/app/stores/wallet/actions/actionCreators.ts index 951ffa868..a866b7d22 100644 --- a/src/app/stores/wallet/actions/actionCreators.ts +++ b/src/app/stores/wallet/actions/actionCreators.ts @@ -248,12 +248,3 @@ export function setWalletLockPeriodAction( walletLockPeriod, }; } - -export function setShouldResetUserFlow( - shouldResetUserFlow: boolean -): actions.SetShouldResetUserFlow { - return { - type: actions.SetShouldResetUserFlowKey, - shouldResetUserFlow - }; -} diff --git a/src/app/stores/wallet/actions/types.ts b/src/app/stores/wallet/actions/types.ts index cde4a668c..8e522bcaa 100644 --- a/src/app/stores/wallet/actions/types.ts +++ b/src/app/stores/wallet/actions/types.ts @@ -44,7 +44,6 @@ export const AddLedgerAccountKey = 'AddLedgerAccountKey'; export const SetBrcCoinsListKey = 'SetBrcCoinsList'; export const SetWalletLockPeriodKey = 'SetWalletLockPeriod'; -export const SetShouldResetUserFlowKey = 'SetShouldResetUserFlow'; export enum WalletSessionPeriods { LOW = 1, @@ -86,7 +85,6 @@ export interface WalletState { accountName: string | undefined; btcApiUrl: string; walletLockPeriod: WalletSessionPeriods; - shouldResetUserFlow: boolean; } export interface SetWallet { @@ -247,8 +245,3 @@ export type WalletActions = | SetBrcCoinsData | SetWalletLockPeriod | DisableWalletExistsGuard; - -export type ShouldResetUserFlow = { - type: typeof ShouldResetUserFlowKey; - shouldResetUserFlow: boolean; -} diff --git a/src/app/stores/wallet/reducer.ts b/src/app/stores/wallet/reducer.ts index 0cb454017..d1add3d62 100644 --- a/src/app/stores/wallet/reducer.ts +++ b/src/app/stores/wallet/reducer.ts @@ -28,7 +28,6 @@ import { WalletActions, WalletSessionPeriods, WalletState, - SetShouldResetUserFlowKey, } from './actions/types'; const initialWalletState: WalletState = { @@ -65,7 +64,6 @@ const initialWalletState: WalletState = { accountType: 'software', accountName: undefined, walletLockPeriod: WalletSessionPeriods.STANDARD, - shouldResetUserFlow: false, }; const walletReducer = ( @@ -211,11 +209,6 @@ const walletReducer = ( ...state, walletLockPeriod: action.walletLockPeriod, }; - case SetShouldResetUserFlowKey: - return { - ...state, - shouldResetUserFlow: action.shouldResetUserFlow - } default: return state; } diff --git a/src/app/utils/helper.ts b/src/app/utils/helper.ts index f8da72108..cfa93438f 100644 --- a/src/app/utils/helper.ts +++ b/src/app/utils/helper.ts @@ -121,8 +121,9 @@ export function checkNftExists( ): boolean { const principal: string[] = nft?.fully_qualified_token_id?.split('::'); const transaction = pendingTransactions.find( - (tx) => tx.contractCall?.contract_id === principal[0] - && tx.contractCall.function_args[0].repr.substring(1) === nft.token_id.toString(), + (tx) => + tx.contractCall?.contract_id === principal[0] && + tx.contractCall.function_args[0].repr.substring(1) === nft.token_id.toString(), ); if (transaction) return true; return false; @@ -156,10 +157,13 @@ export async function isValidBtcApi(url: string, network: NetworkType) { throw new Error('Invalid URL'); } -export const getNetworkType = (stxNetwork) => (stxNetwork.chainId === ChainID.Mainnet ? 'Mainnet' : 'Testnet'); +export const getNetworkType = (stxNetwork) => + stxNetwork.chainId === ChainID.Mainnet ? 'Mainnet' : 'Testnet'; -export const isHardwareAccount = (account: Account | null): boolean => !!account?.accountType && account?.accountType !== 'software'; +export const isHardwareAccount = (account: Account | null): boolean => + !!account?.accountType && account?.accountType !== 'software'; -export const isLedgerAccount = (account: Account | null): boolean => account?.accountType === 'ledger'; +export const isLedgerAccount = (account: Account | null): boolean => + account?.accountType === 'ledger'; -export const isInOptions = (): boolean => !!location?.pathname?.match(/options.html$/); +export const isInOptions = (): boolean => !!window.location?.pathname?.match(/options.html$/);