Skip to content

Commit

Permalink
Merge pull request #189 from SmartInvoiceXYZ/fix-infinite-reload
Browse files Browse the repository at this point in the history
Fix infinite reload
  • Loading branch information
wtfsayo authored Apr 1, 2024
2 parents 11fe28d + 455aa4a commit 85352fd
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 194 deletions.
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
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
Loading

0 comments on commit 85352fd

Please sign in to comment.