From 00cd76219c91c038814ccdaef543c12d8da4ed43 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 5 Nov 2022 11:03:05 +0100 Subject: [PATCH] Update usePools.js --- packages/react-app/src/hooks/usePools.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/react-app/src/hooks/usePools.js b/packages/react-app/src/hooks/usePools.js index 35481a7..bc3ae20 100644 --- a/packages/react-app/src/hooks/usePools.js +++ b/packages/react-app/src/hooks/usePools.js @@ -1,11 +1,27 @@ -import Web3 from "web3"; //one of the most popular packages when interacting with smart contracts +import Web3 from "web3"; //one of the most popular packages when interacting with smart contracts import { useEffect, useState } from "react"; import { useConfig } from "@usedapp/core"; import { ROUTER_ADDRESS } from "../config"; +export const loadPools = async (providerUrl) => { //fetch liquidity pool + const provider = new Web3.providers.HttpProvider(providerUrl); + +} export const usePools = () => { const { readOnlyChainId, readOnlyUrls } = useConfig(); + const [loading, setLoading] = useState(true); + const [pools, setPools] = useState({}); + + useEffect(() => { + loadPools(readOnlyUrls[readOnlyChainId]) + .then((pools) => { //callback function / asynchronous + setPools(pools); + setLoading(false); + }); + }, [readOnlyUrls, readOnlyChainId]); //dependency array + + return [loading, pools]; }