Skip to content

Commit

Permalink
Added API dependencies on isConnected
Browse files Browse the repository at this point in the history
  • Loading branch information
quaintrelle7 committed Oct 11, 2024
1 parent b1c0b33 commit ab4d383
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
5 changes: 4 additions & 1 deletion next-app/components/Homepage/Homepage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {factoryContract} from "@/blockend/interact"
type Props = {}

function Homepage({}: Props) {
const { address, chainId} = useAccount()
const { address, chainId, chain} = useAccount()
// const { openConnectModal } = useConnectModal()
const [uploadClicked, setUploadClicked] = useState(false)
const inputFile = useRef(null)
Expand Down Expand Up @@ -151,6 +151,9 @@ function Homepage({}: Props) {
}

const saveToMongoDB = async() => {
console.log("chainId: ", chainId);
console.log("chain: ", chain);

const newInvoice = new UploadedInvoice({
email: email,
contractAddress: deployedContractAddress,
Expand Down
2 changes: 1 addition & 1 deletion next-app/components/Portfolio/ClientDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const ClientDashboard = (sellerAddress:any) => {
}

fetchInvoices()
}, [])
}, [chainId, address])


const handleSignAgreement =async(invoice) => {
Expand Down
10 changes: 7 additions & 3 deletions next-app/components/Portfolio/PortfolioTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@ function PortfolioTable() {
})
}

const {address} = useAccount();
const {address, isConnected} = useAccount();

const [invoices, setInvoices] = useState([]);



useEffect(() => {
const fetchInvoices = async () => {


const result = await factoryContract.methods.getInvestorInvoices(address).call();

let uniqueAddresses = Array.from(new Set(result));
Expand All @@ -67,8 +69,10 @@ useEffect(() => {
const invoices = await Promise.all(invoicePromises);
setInvoices(invoices);
}
fetchInvoices()
}, [address])
if(isConnected)
fetchInvoices()

}, [isConnected, address])


return (
Expand Down
7 changes: 4 additions & 3 deletions next-app/pages/factor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type Props = {}

export default function ({}: Props) {
const [uploadedInvoices, setUploadedInvoices] = useState([])
const { address, chainId } = useAccount()
const { address, chainId, isConnected } = useAccount()
const [approveForm, setApproveForm] = useState(false)
const [isSubmitting, setIsSubmitting] = useState(false)
const [invoice, setInvoice] = useState<UploadedInvoice>();
Expand All @@ -70,6 +70,7 @@ export default function ({}: Props) {
})

useEffect(() => {

const fetchInvoices = async () => {
const response = await fetch(`api/uploaded_invoices?active=true&approved=false&chainId=${chainId}`).then((res) =>
res.json()
Expand All @@ -78,7 +79,7 @@ export default function ({}: Props) {
}

fetchInvoices()
}, [])
}, [isConnected, chainId])

const updateDecline = async (invoice: UploadedInvoice) => {}

Expand Down Expand Up @@ -177,7 +178,7 @@ export default function ({}: Props) {
marginBottom="20px"
marginTop="2px"
name="totalInvoiceAmount"
placeholder="Amount in Eth"
placeholder="Amount in USDC"
value={formData.totalInvoiceAmount}
onChange={handleInputChange}
/>
Expand Down
5 changes: 3 additions & 2 deletions next-app/pages/invest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,19 @@ import {useAccount} from 'wagmi'
function invest() {

const [signedInvoices, setSignedInvoices] = useState([]);
const { chainId } = useAccount()
const { isConnected, chainId } = useAccount();

useEffect(() => {
const fetchInvoices = async () => {
const response = await fetch(`api/uploaded_invoices?signedBySeller=true&chainId=${chainId}&isCompleted=false`).then((res) =>
res.json()

)
setSignedInvoices(response)
console.log(response);
}
fetchInvoices()
}, [])
}, [isConnected,chainId])


return (
Expand Down

0 comments on commit ab4d383

Please sign in to comment.