From 489c5a37c4aa2a88bc691fb46c3fa9ec3207ba3b Mon Sep 17 00:00:00 2001 From: Ashutosh Kumar Date: Tue, 17 Dec 2024 02:44:16 +0530 Subject: [PATCH] Send Notification to a URL on proposal created (#877) --- env.example | 21 +++++++++++++++++ src/services/config/constants.ts | 3 ++- .../baseDAO/hooks/useLambdaAddPropose.ts | 4 ++++ .../baseDAO/hooks/useLambdaExecutePropose.ts | 2 ++ .../baseDAO/hooks/useLambdaRemovePropose.ts | 2 ++ .../baseDAO/hooks/useProposeConfigChange.ts | 8 +++++++ .../hooks/useProposeDelegationChange.ts | 8 +++++++ .../baseDAO/hooks/useProposeGuardianChange.ts | 8 +++++++ .../baseDAO/hooks/useRegistryPropose.ts | 2 ++ .../baseDAO/hooks/useTreasuryPropose.ts | 2 ++ src/services/utils/utils.ts | 23 +++++++++++++++++++ 11 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 env.example diff --git a/env.example b/env.example new file mode 100644 index 00000000..f864557f --- /dev/null +++ b/env.example @@ -0,0 +1,21 @@ +PORT=3000 +REACT_APP_BASEDAO_DOCKERISED_URL=http://localhost:8000/steps +REACT_APP_CORS_PROXY_URL=http://localhost:8001 +REACT_APP_DAO_DEPLOYER_API=http://localhost:3001 +REACT_APP_ENV=DEV +REACT_APP_HASURA_ADMIN_SECRET=your_hasura_admin_secret_here +REACT_APP_HASURA_ADMIN_SECRET_V2=your_hasura_admin_secret_v2_here +REACT_APP_HASURA_URL=http://localhost:8080/v1/graphql +REACT_APP_HASURA_URL_V2=http://localhost:8081/v1/graphql +REACT_APP_LAUNCH_DARKLY_SDK_DEV=your_launch_darkly_sdk_key_here + +REACT_APP_MIXPANEL_DEBUG_ENABLED=false +REACT_APP_MIXPANEL_TOKEN=your_mixpanel_token_here +REACT_APP_NETWORK=development +REACT_APP_URL=http://localhost:3000 +REACT_APP_V2_URL=http://localhost:3002 +REACT_APP_IS_NOT_TESTING=false + +REACT_APP_LAUNCH_DARKLY_SDK_PROD=your_launch_darkly_prod_key_here +REACT_APP_IGNORE_DAO_CYCLE_CHECK=false +REACT_APP_PROPOSAL_WEBHOOK_URL=http://localhost:8002/webhook \ No newline at end of file diff --git a/src/services/config/constants.ts b/src/services/config/constants.ts index 9ad023f6..c6e6e452 100644 --- a/src/services/config/constants.ts +++ b/src/services/config/constants.ts @@ -18,7 +18,8 @@ export enum EnvKey { REACT_APP_BASE_URL = "REACT_APP_BASE_URL", REACT_APP_DAO_DEPLOYER_API = "REACT_APP_DAO_DEPLOYER_API", REACT_APP_RPC_NETWORK_GHOSTNET = "REACT_APP_RPC_NETWORK_GHOSTNET", - REACT_APP_RPC_NETWORK_MAINNET = "REACT_APP_RPC_NETWORK_MAINNET" + REACT_APP_RPC_NETWORK_MAINNET = "REACT_APP_RPC_NETWORK_MAINNET", + REACT_APP_PROPOSAL_WEBHOOK_URL = "REACT_APP_PROPOSAL_WEBHOOK_URL" } export enum FeatureFlag { diff --git a/src/services/contracts/baseDAO/hooks/useLambdaAddPropose.ts b/src/services/contracts/baseDAO/hooks/useLambdaAddPropose.ts index 9f52b4ba..e34b0be9 100644 --- a/src/services/contracts/baseDAO/hooks/useLambdaAddPropose.ts +++ b/src/services/contracts/baseDAO/hooks/useLambdaAddPropose.ts @@ -6,6 +6,7 @@ import { useTezos } from "services/beacon/hooks/useTezos" import mixpanel from "mixpanel-browser" import { networkNameMap } from "../../../bakingBad" import { LambdaDAO } from "../lambdaDAO" +import { sendProposalCreatedEvent } from "services/utils/utils" export const useLambdaAddPropose = () => { const queryClient = useQueryClient() @@ -41,6 +42,8 @@ export const useLambdaAddPropose = () => { daoType: "Registry" }) + sendProposalCreatedEvent(network, account, dao.data.name, dao.data.address) + await data.confirmation(1) closeProposalNotification(proposalNotification) // setProposalDone() @@ -53,6 +56,7 @@ export const useLambdaAddPropose = () => { }) handleClose() + return data } catch (e) { console.log(e) diff --git a/src/services/contracts/baseDAO/hooks/useLambdaExecutePropose.ts b/src/services/contracts/baseDAO/hooks/useLambdaExecutePropose.ts index 15dd4b1f..d23cf9fc 100644 --- a/src/services/contracts/baseDAO/hooks/useLambdaExecutePropose.ts +++ b/src/services/contracts/baseDAO/hooks/useLambdaExecutePropose.ts @@ -6,6 +6,7 @@ import { useTezos } from "services/beacon/hooks/useTezos" import mixpanel from "mixpanel-browser" import { networkNameMap } from "../../../bakingBad" import { LambdaDAO } from "../lambdaDAO" +import { sendProposalCreatedEvent } from "services/utils/utils" export const useLambdaExecutePropose = () => { const queryClient = useQueryClient() @@ -42,6 +43,7 @@ export const useLambdaExecutePropose = () => { dao: dao.data.address, daoType: "Registry" }) + sendProposalCreatedEvent(network, account, dao.data.name, dao.data.address) await data.confirmation(1) closeProposalNotification(proposalNotification) diff --git a/src/services/contracts/baseDAO/hooks/useLambdaRemovePropose.ts b/src/services/contracts/baseDAO/hooks/useLambdaRemovePropose.ts index 1df24a59..26163a42 100644 --- a/src/services/contracts/baseDAO/hooks/useLambdaRemovePropose.ts +++ b/src/services/contracts/baseDAO/hooks/useLambdaRemovePropose.ts @@ -6,6 +6,7 @@ import { useTezos } from "services/beacon/hooks/useTezos" import mixpanel from "mixpanel-browser" import { networkNameMap } from "../../../bakingBad" import { LambdaDAO } from "../lambdaDAO" +import { sendProposalCreatedEvent } from "services/utils/utils" export const useLambdaRemovePropose = () => { const queryClient = useQueryClient() @@ -40,6 +41,7 @@ export const useLambdaRemovePropose = () => { dao: dao.data.address, daoType: "Registry" }) + sendProposalCreatedEvent(network, account, dao.data.name, dao.data.address) await data.confirmation(1) closeProposalNotification(proposalNotification) diff --git a/src/services/contracts/baseDAO/hooks/useProposeConfigChange.ts b/src/services/contracts/baseDAO/hooks/useProposeConfigChange.ts index 7dc58716..6e76ef98 100644 --- a/src/services/contracts/baseDAO/hooks/useProposeConfigChange.ts +++ b/src/services/contracts/baseDAO/hooks/useProposeConfigChange.ts @@ -5,6 +5,8 @@ import { useTezos } from "services/beacon/hooks/useTezos" import { BaseDAO } from "../class" import { ConfigProposalParams } from "../types" import { networkNameMap } from "../../../bakingBad" +import { sendProposalCreatedEvent } from "services/utils/utils" +import mixpanel from "mixpanel-browser" export const useProposeConfigChange = () => { const queryClient = useQueryClient() @@ -30,6 +32,12 @@ export const useProposeConfigChange = () => { } const data = await dao.proposeConfigChange(args, tezosToolkit) + mixpanel.track("Proposal Created", { + dao: dao.data.address, + daoType: "Registry" + }) + sendProposalCreatedEvent(network, account, dao.data.name, dao.data.address) + await data.confirmation(1) closeProposalNotification(proposalNotification) diff --git a/src/services/contracts/baseDAO/hooks/useProposeDelegationChange.ts b/src/services/contracts/baseDAO/hooks/useProposeDelegationChange.ts index ef842d70..99426edf 100644 --- a/src/services/contracts/baseDAO/hooks/useProposeDelegationChange.ts +++ b/src/services/contracts/baseDAO/hooks/useProposeDelegationChange.ts @@ -4,6 +4,8 @@ import { useNotification } from "modules/common/hooks/useNotification" import { useTezos } from "services/beacon/hooks/useTezos" import { BaseDAO } from "../class" import { networkNameMap } from "../../../bakingBad" +import mixpanel from "mixpanel-browser" +import { sendProposalCreatedEvent } from "services/utils/utils" export const useProposeDelegationChange = () => { const queryClient = useQueryClient() @@ -29,6 +31,12 @@ export const useProposeDelegationChange = () => { } const data = await dao.proposeDelegationChange(newDelegationAddress, tezosToolkit) + mixpanel.track("Proposal Created", { + dao: dao.data.address, + daoType: "Registry" + }) + sendProposalCreatedEvent(network, account, dao.data.name, dao.data.address) + await data.confirmation(1) closeProposalNotification(proposalNotification) diff --git a/src/services/contracts/baseDAO/hooks/useProposeGuardianChange.ts b/src/services/contracts/baseDAO/hooks/useProposeGuardianChange.ts index 7e610bea..9b2fd951 100644 --- a/src/services/contracts/baseDAO/hooks/useProposeGuardianChange.ts +++ b/src/services/contracts/baseDAO/hooks/useProposeGuardianChange.ts @@ -4,6 +4,8 @@ import { useNotification } from "modules/common/hooks/useNotification" import { useTezos } from "services/beacon/hooks/useTezos" import { BaseDAO } from "../class" import { networkNameMap } from "../../../bakingBad" +import { sendProposalCreatedEvent } from "services/utils/utils" +import mixpanel from "mixpanel-browser" export const useProposeGuardianChange = () => { const queryClient = useQueryClient() @@ -29,6 +31,12 @@ export const useProposeGuardianChange = () => { } const data = await dao.proposeGuardianChange(newGuardianAddress, tezosToolkit) + mixpanel.track("Proposal Created", { + dao: dao.data.address, + daoType: "Registry" + }) + sendProposalCreatedEvent(network, account, dao.data.name, dao.data.address) + await data.confirmation(1) closeProposalNotification(proposalNotification) diff --git a/src/services/contracts/baseDAO/hooks/useRegistryPropose.ts b/src/services/contracts/baseDAO/hooks/useRegistryPropose.ts index 5309b54b..7b5eaa1e 100644 --- a/src/services/contracts/baseDAO/hooks/useRegistryPropose.ts +++ b/src/services/contracts/baseDAO/hooks/useRegistryPropose.ts @@ -6,6 +6,7 @@ import { useTezos } from "services/beacon/hooks/useTezos" import { LambdaDAO } from "../lambdaDAO" import mixpanel from "mixpanel-browser" import { networkNameMap } from "../../../bakingBad" +import { sendProposalCreatedEvent } from "services/utils/utils" export const useRegistryPropose = () => { const queryClient = useQueryClient() @@ -36,6 +37,7 @@ export const useRegistryPropose = () => { dao: dao.data.address, daoType: "Registry" }) + sendProposalCreatedEvent(network, account, dao.data.name, dao.data.address) await data.confirmation(1) closeProposalNotification(proposalNotification) diff --git a/src/services/contracts/baseDAO/hooks/useTreasuryPropose.ts b/src/services/contracts/baseDAO/hooks/useTreasuryPropose.ts index f71bd52f..d62d2bf2 100644 --- a/src/services/contracts/baseDAO/hooks/useTreasuryPropose.ts +++ b/src/services/contracts/baseDAO/hooks/useTreasuryPropose.ts @@ -6,6 +6,7 @@ import { RegistryProposeArgs } from "../lambdaDAO/types" import mixpanel from "mixpanel-browser" import { networkNameMap } from "../../../bakingBad" import { LambdaDAO } from "../lambdaDAO" +import { sendProposalCreatedEvent } from "services/utils/utils" export const useTreasuryPropose = () => { const queryClient = useQueryClient() @@ -37,6 +38,7 @@ export const useTreasuryPropose = () => { dao: dao.data.address, daoType: "Treasury" }) + sendProposalCreatedEvent(network, account, dao.data.name, dao.data.address) await data.confirmation(1) closeProposalNotification(proposalNotification) diff --git a/src/services/utils/utils.ts b/src/services/utils/utils.ts index d9cabadc..9c43b49e 100644 --- a/src/services/utils/utils.ts +++ b/src/services/utils/utils.ts @@ -250,3 +250,26 @@ export const validateTokenAddress = (network: Network, tokenAddress: string) => if (network.startsWith("etherlink")) return isEtherAddress(tokenAddress) ? 3 : false return false } + +export const sendProposalCreatedEvent = async ( + network: Network, + proposerAddress: string, + daoName: string, + daoAddress: string +) => { + const url = getEnv(EnvKey.REACT_APP_PROPOSAL_WEBHOOK_URL) + const response = await fetch(url, { + method: "POST", + body: JSON.stringify({ + network, + proposer: proposerAddress, + dao_name: daoName, + dao_address: daoAddress + }) + }) + if (!response.ok) { + console.error("Failed to send proposal created event", response) + return false + } + return true +}