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: onSuccess; handle infinite reload #183

Closed
wants to merge 14 commits into from
5 changes: 5 additions & 0 deletions packages/constants/src/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ export const ESCROW_STEPS: { [key: number]: EscrowStep } = {
step_details: [],
next: 'create invoice',
},
5: {
step_title: 'Invoice Created',
step_details: [],
next: 'invoice created',
},
};

export const INSTANT_STEPS: { [key: number]: EscrowStep } = {
Expand Down
3 changes: 2 additions & 1 deletion packages/dapp/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const queryClient = new QueryClient({
queries: {
// With SSR, we usually want to set some default staleTime
// above 0 to avoid refetching immediately on the client
staleTime: 15 * 60 * 1000, // 15 minutes
staleTime: 5000,
refetchInterval: 5000,
},
},
});
Expand Down
34 changes: 16 additions & 18 deletions packages/dapp/pages/create/escrow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ import {
useToast,
} from '@smart-invoice/ui';
import { useQueryClient } from '@tanstack/react-query';
import { useRouter } from 'next/router';
// import _ from 'lodash';
import React, { useState } from 'react';
import { useForm } from 'react-hook-form';
import { Hex, numberToHex } from 'viem';
import { Address, Hex } from 'viem';
import { useChainId } from 'wagmi';

import { useOverlay } from '../../contexts/OverlayContext';
Expand All @@ -29,11 +28,12 @@ export function CreateInvoiceEscrow() {
const chainId = useChainId();
const invoiceForm = useForm();
const toast = useToast();
const router = useRouter();
const queryClient = useQueryClient();
const { modals, setModals } = useOverlay();
const [currentStep, setCurrentStep] = useState<number>(1);
const [txHash, setTxHash] = useState<Address>();

const [invoiceId, setInvoiceId] = useState<Address>();
const { headingSize, columnWidth } = useMediaStyles();

const nextStepHandler = () => {
Expand All @@ -50,10 +50,10 @@ export function CreateInvoiceEscrow() {
queryClient.invalidateQueries({ queryKey: ['invoiceDetails'] });
queryClient.invalidateQueries({ queryKey: ['invoiceList'] });

// redirect
setTimeout(() => {
router.push(`/invoice/${numberToHex(chainId)}/${result}`);
}, 500);
setInvoiceId(result as Address);

// Send to Success step
nextStepHandler();
};

const { writeAsync, isLoading } = useInvoiceCreate({
Expand All @@ -63,19 +63,10 @@ export function CreateInvoiceEscrow() {
});

const handleSubmit = async () => {
await writeAsync?.();
const data = await writeAsync?.();
setTxHash(data?.hash);
};

// if (txHash) {
// eslint-disable-next-line no-constant-condition
if (false) {
return (
<Container overlay>
<RegisterSuccess />
</Container>
);
}

return (
<Container overlay>
<Stack
Expand Down Expand Up @@ -158,6 +149,13 @@ export function CreateInvoiceEscrow() {
type={INVOICE_TYPES.Escrow}
/>
)}

{currentStep === 5 && (
<RegisterSuccess
invoiceId={invoiceId as Address}
txHash={txHash as Address}
/>
)}
</Flex>
</Stack>
</Stack>
Expand Down
6 changes: 1 addition & 5 deletions packages/dapp/pages/create/instant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@ export function CreateInvoiceInstant() {
// if (txHash) {
// eslint-disable-next-line no-constant-condition
if (false) {
return (
<Container overlay>
<RegisterSuccess />
</Container>
);
return <Container overlay>{/* <RegisterSuccess /> */}</Container>;
}

const nextStepHandler = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { Hex, isAddress } from 'viem';
import { useChainId } from 'wagmi';

import { useOverlay } from '../../../../contexts/OverlayContext';
import { useEffect } from 'react';

function ViewInvoice() {
const chainId = useChainId();
Expand Down
Loading