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

fix: fix routing issues with send flow #5146

Merged
merged 1 commit into from
Mar 29, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useMemo } from 'react';
import { useNavigate } from 'react-router-dom';
import { useLocation, useNavigate } from 'react-router-dom';

import { bytesToHex } from '@stacks/common';
import { StacksTransaction } from '@stacks/transactions';
Expand Down Expand Up @@ -32,6 +32,7 @@ interface ConfirmationRouteBtcArgs {

export function useSendFormNavigate() {
const navigate = useNavigate();
const location = useLocation();

return useMemo(
() => ({
Expand All @@ -43,7 +44,8 @@ export function useSendFormNavigate() {
utxos: UtxoResponseItem[],
values: BitcoinSendFormValues
) {
return navigate('choose-fee', {
return navigate(RouteUrls.SendBtcChooseFee, {
replace: true,
state: {
isSendingMax,
utxos,
Expand All @@ -69,7 +71,7 @@ export function useSendFormNavigate() {
});
},
toConfirmAndSignStxTransaction(tx: StacksTransaction, showFeeChangeWarning: boolean) {
return navigate('confirm', {
return navigate(RouteUrls.SendStxConfirmation, {
replace: true,
state: {
tx: bytesToHex(tx.serialize()),
Expand All @@ -82,8 +84,7 @@ export function useSendFormNavigate() {
name,
tx,
}: ConfirmationRouteStacksSip10Args) {
return navigate('confirm', {
replace: true,
return navigate(`${location.pathname}/confirm`, {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previously working relative paths now fail so I am using the location.pathname to prepend this route.

I think this may have stopped working as to move the Continue button to the footer, we had to change the form to use props.handleSubmit()

e.g. in BtcSendForm:

  return (
            <Form>
              <Card
                footer={
                  <Footer variant="card">
                    <Button
                      data-testid={SendCryptoAssetSelectors.PreviewSendTxBtn}
                      onClick={() => props.handleSubmit()}
                      type="submit"
                    >
                      Continue
                    </Button>
                    <AvailableBalance balance={formatMoney(btcBalance.balance)} />
                  </Footer>
                }
              >
                <CardContent dataTestId={SendCryptoAssetSelectors.SendForm}>
                  <AmountField
    

Before we had a lot of nested components doing this that drilled down a lot to a preview-button component

state: {
decimals,
token: name,
Expand All @@ -102,6 +103,6 @@ export function useSendFormNavigate() {
});
},
}),
[navigate]
[navigate, location]
);
}
Loading