Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tim/eng 2345 account switching mid ledger send ordinals flow #498

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
20 changes: 19 additions & 1 deletion src/app/screens/sendOrdinal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ 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`
display: flex;
Expand Down Expand Up @@ -102,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 @@ -166,7 +170,21 @@ function SendOrdinal() {
navigate(-1);
};

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

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

function validateFields(associatedAddress: string): boolean {
if (!activeAccountOwnsOrdinal) {
setError(t('ERRORS.ORDINAL_NOT_OWNED'));
return false;
}
if (!associatedAddress) {
setError(t('ERRORS.ADDRESS_REQUIRED'));
return false;
Expand Down
3 changes: 2 additions & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@
"INSUFFICIENT_BALANCE": "Insufficient balance",
"MEMO_LENGTH": "Memo exceeds allowed length",
"INSUFFICIENT_BALANCE_FEES": "Insufficient balance when including transaction fees",
"NFT_SEND_DETAIL": "This Nft is already sent and is in pending state"
"NFT_SEND_DETAIL": "This Nft is already sent and is in pending state",
"ORDINAL_NOT_OWNED": "This ordinal is not owned by your active account"
},
"SEND_NFT": "Send NFT",
"ASSOCIATED_BNS_DOMAIN": "Associated BNS Name",
Expand Down