Skip to content

Commit

Permalink
feat: navigate the user back to nft dashboard upon account switch
Browse files Browse the repository at this point in the history
  • Loading branch information
teebszet committed Jul 4, 2023
1 parent b58d323 commit 7646d4d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/app/screens/confirmNftTransaction/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ 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';

const ScrollContainer = styled.div`
display: flex;
Expand Down Expand Up @@ -96,9 +98,10 @@ const ReviewTransactionText = styled.h1((props) => ({
function ConfirmNftTransaction() {
const { t } = useTranslation('translation', { keyPrefix: 'CONFIRM_TRANSACTION' });
const isGalleryOpen: boolean = document.documentElement.clientWidth > 360;
const { selectedAccount } = useWalletSelector();
const { selectedAccount, shouldResetUserFlow } = useWalletSelector();
const navigate = useNavigate();
const location = useLocation();
const dispatch = useDispatch();
const { id } = useParams();
const { nftData } = useNftDataSelector();
const nftIdDetails = id!.split('::');
Expand Down Expand Up @@ -161,6 +164,13 @@ function ConfirmNftTransaction() {
mutate({ signedTx: txs[0] });
};

useEffect(() => {
if (shouldResetUserFlow) {
navigate('/nft-dashboard');
dispatch(setShouldResetUserFlow(false));
}
}, [shouldResetUserFlow]);

const handleOnCancelClick = () => {
navigate(-1);
};
Expand Down
12 changes: 11 additions & 1 deletion src/app/screens/confirmOrdinalTransaction/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ 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';

const ScrollContainer = styled.div`
display: flex;
Expand Down Expand Up @@ -89,11 +91,12 @@ const NFtContainer = styled.div((props) => ({
function ConfirmOrdinalTransaction() {
const { t } = useTranslation('translation', { keyPrefix: 'CONFIRM_TRANSACTION' });
const isGalleryOpen: boolean = document.documentElement.clientWidth > 360;
const { selectedAccount } = useWalletSelector();
const { selectedAccount, shouldResetUserFlow } = useWalletSelector();
const navigate = useNavigate();
const btcClient = useBtcClient();
const [recipientAddress, setRecipientAddress] = useState('');
const location = useLocation();
const dispatch = useDispatch();
const {
fee, feePerVByte, signedTxHex, ordinalUtxo,
} = location.state;
Expand Down Expand Up @@ -154,6 +157,13 @@ function ConfirmOrdinalTransaction() {
navigate(-1);
};

useEffect(() => {
if (shouldResetUserFlow) {
navigate('/nft-dashboard');
dispatch(setShouldResetUserFlow(false));
}
}, [shouldResetUserFlow]);

return (
<>
{isGalleryOpen && (
Expand Down
11 changes: 11 additions & 0 deletions src/app/screens/sendNft/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ 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';

const ScrollContainer = styled.div`
display: flex;
Expand Down Expand Up @@ -100,6 +102,7 @@ function SendNft() {
const navigate = useNavigate();
const { id } = useParams();
const location = useLocation();
const dispatch = useDispatch();
let address: string | undefined;

if (location.state) {
Expand All @@ -123,6 +126,7 @@ function SendNft() {
stxPublicKey,
network,
feeMultipliers,
shouldResetUserFlow,
} = useWalletSelector();
const [error, setError] = useState('');
const [recipientAddress, setRecipientAddress] = useState('');
Expand Down Expand Up @@ -172,6 +176,13 @@ function SendNft() {
}
}, [data]);

useEffect(() => {
if (shouldResetUserFlow) {
navigate('/nft-dashboard');
dispatch(setShouldResetUserFlow(false));
}
}, [shouldResetUserFlow]);

const handleBackButtonClick = () => {
navigate(-1);
};
Expand Down
12 changes: 11 additions & 1 deletion src/app/screens/sendOrdinal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +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';

const ScrollContainer = styled.div`
Expand Down Expand Up @@ -103,8 +105,9 @@ function SendOrdinal() {
const { selectedOrdinal } = useNftDataSelector();
const btcClient = useBtcClient();
const location = useLocation();
const dispatch = useDispatch();
const {
network, ordinalsAddress, btcAddress, selectedAccount, seedPhrase, btcFiatRate,
network, ordinalsAddress, btcAddress, selectedAccount, seedPhrase, btcFiatRate, shouldResetUserFlow
} = useWalletSelector();
const [ordinalUtxo, setOrdinalUtxo] = useState<UTXO | undefined>(undefined);
const [error, setError] = useState('');
Expand Down Expand Up @@ -167,6 +170,13 @@ function SendOrdinal() {
navigate(-1);
};

useEffect(() => {
if (shouldResetUserFlow) {
navigate('/nft-dashboard');
dispatch(setShouldResetUserFlow(false));
}
}, [shouldResetUserFlow]);

const activeAccountOwnsOrdinal =
selectedOrdinal && selectedAccount && isOrdinalOwnedByAccount(selectedOrdinal, selectedAccount);

Expand Down

0 comments on commit 7646d4d

Please sign in to comment.