diff --git a/package-lock.json b/package-lock.json index 894c754..286e2fc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,6 +17,8 @@ "@tanstack/react-table": "^8.9.3", "@wagmi/cli": "^1.3.0", "buffer": "^6.0.3", + "graphql": "^16.8.0", + "graphql-request": "^6.1.0", "process": "^0.11.10", "react": "^18.2.0", "react-dom": "^18.2.0", @@ -1679,6 +1681,14 @@ "cross-fetch": "^3.1.5" } }, + "node_modules/@graphql-typed-document-node/core": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/@graphql-typed-document-node/core/-/core-3.2.0.tgz", + "integrity": "sha512-mB9oAsNCm9aM3/SOv4YtBMqZbYj10R7dkq8byBqxGY/ncFwhf2oQzMV+LCRlWoDSEBJ3COiR1yeDvMtsoOsuFQ==", + "peerDependencies": { + "graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" + } + }, "node_modules/@heroicons/react": { "version": "2.0.18", "resolved": "https://registry.npmjs.org/@heroicons/react/-/react-2.0.18.tgz", @@ -5028,6 +5038,26 @@ "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==" }, + "node_modules/graphql": { + "version": "16.8.0", + "resolved": "https://registry.npmjs.org/graphql/-/graphql-16.8.0.tgz", + "integrity": "sha512-0oKGaR+y3qcS5mCu1vb7KG+a89vjn06C7Ihq/dDl3jA+A8B3TKomvi3CiEcVLJQGalbu8F52LxkOym7U5sSfbg==", + "engines": { + "node": "^12.22.0 || ^14.16.0 || ^16.0.0 || >=17.0.0" + } + }, + "node_modules/graphql-request": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/graphql-request/-/graphql-request-6.1.0.tgz", + "integrity": "sha512-p+XPfS4q7aIpKVcgmnZKhMNqhltk20hfXtkaIkTfjjmiKMJ5xrt5c743cL03y/K7y1rg3WrIC49xGiEQ4mxdNw==", + "dependencies": { + "@graphql-typed-document-node/core": "^3.2.0", + "cross-fetch": "^3.1.5" + }, + "peerDependencies": { + "graphql": "14 - 16" + } + }, "node_modules/has": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", @@ -8865,6 +8895,11 @@ "cross-fetch": "^3.1.5" } }, + "@graphql-typed-document-node/core": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/@graphql-typed-document-node/core/-/core-3.2.0.tgz", + "integrity": "sha512-mB9oAsNCm9aM3/SOv4YtBMqZbYj10R7dkq8byBqxGY/ncFwhf2oQzMV+LCRlWoDSEBJ3COiR1yeDvMtsoOsuFQ==" + }, "@heroicons/react": { "version": "2.0.18", "resolved": "https://registry.npmjs.org/@heroicons/react/-/react-2.0.18.tgz", @@ -11356,6 +11391,20 @@ "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==" }, + "graphql": { + "version": "16.8.0", + "resolved": "https://registry.npmjs.org/graphql/-/graphql-16.8.0.tgz", + "integrity": "sha512-0oKGaR+y3qcS5mCu1vb7KG+a89vjn06C7Ihq/dDl3jA+A8B3TKomvi3CiEcVLJQGalbu8F52LxkOym7U5sSfbg==" + }, + "graphql-request": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/graphql-request/-/graphql-request-6.1.0.tgz", + "integrity": "sha512-p+XPfS4q7aIpKVcgmnZKhMNqhltk20hfXtkaIkTfjjmiKMJ5xrt5c743cL03y/K7y1rg3WrIC49xGiEQ4mxdNw==", + "requires": { + "@graphql-typed-document-node/core": "^3.2.0", + "cross-fetch": "^3.1.5" + } + }, "has": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", diff --git a/package.json b/package.json index b19f972..3c9168f 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,8 @@ "@tanstack/react-table": "^8.9.3", "@wagmi/cli": "^1.3.0", "buffer": "^6.0.3", + "graphql": "^16.8.0", + "graphql-request": "^6.1.0", "process": "^0.11.10", "react": "^18.2.0", "react-dom": "^18.2.0", @@ -42,4 +44,4 @@ "typescript": "^4.9.5", "vite": "^4.1.4" } -} \ No newline at end of file +} diff --git a/src/components/EnablePlugin.tsx b/src/components/EnablePlugin.tsx index 5dd8f61..97952aa 100644 --- a/src/components/EnablePlugin.tsx +++ b/src/components/EnablePlugin.tsx @@ -12,6 +12,7 @@ import "../../styles/enablePlugin.css"; import { encodeFunctionData } from "viem"; import useGnosisBatch from "../queries/useGnosisBatch"; +import useGetUserGaugePositions from "../queries/useGetUserGaugePositions"; import { smartGardenManagerABI, @@ -19,20 +20,20 @@ import { harvesterPluginAddress, } from "../generated"; -// TODO: this gauge addr needs to be retrieve from subgraph. Probably auto-fill a select options? -// https://optimistic.etherscan.io/address/0xa1034Ed2C9eb616d6F7f318614316e64682e7923 -const GAUGE_USDC_DOLA_ADDRESS = "0xa1034Ed2C9eb616d6F7f318614316e64682e7923"; - export function EnablePlugin() { const { mutate: gnosisBatch } = useGnosisBatch(); + const { data: gaugePositions, isLoading, error } = useGetUserGaugePositions(); // defaulting: 86400(1 - day) const formPluginConfig = useFormStore({ - defaultValues: { gaugeAddr: GAUGE_USDC_DOLA_ADDRESS, cadence: 86400 }, + defaultValues: { gaugeAddr: "", cadence: 86400 }, }); const cadenceValue = formPluginConfig.useValue( formPluginConfig.names.cadence, ); + const gaugeAddrValue = formPluginConfig.useValue( + formPluginConfig.names.gaugeAddr, + ); formPluginConfig.useSubmit(() => { const values = formPluginConfig.getState().values; @@ -64,6 +65,13 @@ export function EnablePlugin() { parseInt(event.target.value), ); + // Use to modify the value of `vault` in the } + > + {gaugePositions?.map((gauge, index) => { + return ( + + ); + })} + { + gaugeResults.push({ + id: position.gauge.id, + pool_name: position.gauge.pool_name, + }); + }); + return gaugeResults; + } catch (error) { + console.error(error); + return null; + } +} + +export default function useGetUserGaugePositions() { + const { address } = useAccount(); + const { chain } = useNetwork(); + return useQuery(["userGaugePositions", address?.toLowerCase()], () => + getUserGaugePositions(address?.toLowerCase(), chain?.id), + ); +} diff --git a/src/queries/user_active_stakes.graphql b/src/queries/user_active_stakes.graphql index a6d7476..80eba72 100644 --- a/src/queries/user_active_stakes.graphql +++ b/src/queries/user_active_stakes.graphql @@ -17,4 +17,4 @@ query UserGaugePositions { pool_name } } -} +} \ No newline at end of file