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

Fixed inconsistent step count #1986

Merged
merged 1 commit into from
Aug 9, 2023
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: 10 additions & 2 deletions packages/gui/src/components/plot/add/PlotAddForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export default function PlotAddForm(props: Props) {
const [createNewPoolWallet] = useCreateNewPoolWalletMutation();
const addNFTref = useRef();
const { state } = useLocation();
const [showingPoolDetails, setShowingPoolDetails] = useState<boolean>(false);

const otherDefaults = {
plotCount: 1,
Expand Down Expand Up @@ -214,14 +215,21 @@ export default function PlotAddForm(props: Props) {
}
};

function adjustStepCount() {
if (showingPoolDetails) {
step++;
}
return step++;
}

return (
<Form methods={methods} onSubmit={handleSubmit}>
<Flex flexDirection="column" gap={3}>
<Back variant="h5" form>
<Trans>Add a Plot</Trans>
</Back>
<PlotAddNFT ref={addNFTref} step={step++} />
<PlotAddChoosePlotter step={step++} onChange={handlePlotterChanged} />
<PlotAddNFT ref={addNFTref} step={step++} setShowingPoolDetails={setShowingPoolDetails} />
<PlotAddChoosePlotter step={adjustStepCount()} onChange={handlePlotterChanged} />
<PlotAddChooseKeys step={step++} currencyCode={currencyCode} fingerprint={fingerprint} />
<PlotAddChooseSize step={step++} plotter={plotter} />
<PlotAddSelectFinalDirectory step={step++} plotter={plotter} />
Expand Down
10 changes: 9 additions & 1 deletion packages/gui/src/components/plot/add/PlotAddNFT.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,23 @@ import PlotNFTSelectPool from '../../plotNFT/select/PlotNFTSelectPool';

type Props = {
step: number;
setShowingPoolDetails?: (showing: boolean) => void;
};

const PlotAddNFT = forwardRef((props: Props, ref) => {
const { step } = props;
const { step, setShowingPoolDetails } = props;
const { nfts, external, loading } = usePlotNFTs();
const [showCreatePlotNFT, setShowCreatePlotNFT] = useState<boolean>(false);
const { setValue } = useFormContext();

const hasNFTs = !!nfts?.length || !!external?.length;

React.useEffect(() => {
if (!showCreatePlotNFT && setShowingPoolDetails) {
setShowingPoolDetails(false);
}
}, [showCreatePlotNFT, setShowingPoolDetails]);

function handleJoinPool() {
setShowCreatePlotNFT(true);
setValue('createNFT', true);
Expand All @@ -37,6 +44,7 @@ const PlotAddNFT = forwardRef((props: Props, ref) => {
onCancel={handleCancelPlotNFT}
ref={ref}
title={<Trans>Create a Plot NFT</Trans>}
setShowingPoolDetails={setShowingPoolDetails}
description={
<Trans>
Join a pool and get consistent XCH farming rewards. The average returns are the same, but it is much less
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ type Props = {
description?: ReactNode;
hideFee?: boolean;
feeDescription?: ReactNode;
setShowingPoolDetails?: (showing: boolean) => void;
};

export default function PlotNFTSelectBase(props: Props) {
const { step, onCancel, title, description, hideFee = false, feeDescription } = props;
const { step, onCancel, title, description, hideFee = false, feeDescription, setShowingPoolDetails } = props;
// const { nfts } = usePlotNFTs();
const { setValue } = useFormContext();
const self = useWatch<boolean>({
Expand Down Expand Up @@ -59,6 +60,12 @@ export default function PlotNFTSelectBase(props: Props) {

const showPoolInfo = !self && !!poolUrl;

React.useEffect(() => {
if (setShowingPoolDetails) {
setShowingPoolDetails(showPoolInfo);
}
}, [showPoolInfo, setShowingPoolDetails]);

return (
<>
<CardStep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type Props = {
poolUrl?: string;
};
feeDescription?: ReactNode;
setShowingPoolDetails?: (showing: boolean) => void;
};

const PlotNFTSelectPool = forwardRef((props: Props, ref) => {
Expand All @@ -79,6 +80,7 @@ const PlotNFTSelectPool = forwardRef((props: Props, ref) => {
submitTitle = <Trans>Create</Trans>,
hideFee = false,
feeDescription,
setShowingPoolDetails,
} = props;
const [loading, setLoading] = useState<boolean>(false);
const { balance, loading: walletLoading } = useStandardWallet();
Expand Down Expand Up @@ -161,6 +163,7 @@ const PlotNFTSelectPool = forwardRef((props: Props, ref) => {
description={description}
hideFee={hideFee}
feeDescription={feeDescription}
setShowingPoolDetails={setShowingPoolDetails}
/>
{exceededNFTLimit && (
<Alert severity="error">
Expand Down
Loading