Skip to content

Commit

Permalink
Send Notification to a URL on proposal created (#877)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashutoshpw authored Dec 16, 2024
1 parent e76d39a commit 489c5a3
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 1 deletion.
21 changes: 21 additions & 0 deletions env.example
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion src/services/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions src/services/contracts/baseDAO/hooks/useLambdaAddPropose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -53,6 +56,7 @@ export const useLambdaAddPropose = () => {
})

handleClose()

return data
} catch (e) {
console.log(e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions src/services/contracts/baseDAO/hooks/useRegistryPropose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/services/contracts/baseDAO/hooks/useTreasuryPropose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
23 changes: 23 additions & 0 deletions src/services/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 489c5a3

Please sign in to comment.