@@ -5,20 +5,23 @@ import { useRouter } from 'next/router'
55import { useState } from 'react'
66import useSWR from 'swr'
77import { encodeFunctionData , formatEther } from 'viem'
8+ import { useDaoStore } from 'src/modules/dao'
89
910import SWR_KEYS from 'src/constants/swrKeys'
1011import { ProposalsResponse } from 'src/data/subgraph/requests/proposalsQuery'
1112import { getProposals } from 'src/data/subgraph/requests/proposalsQuery'
1213import { TransactionType } from 'src/modules/create-proposal/constants'
1314import { useProposalStore } from 'src/modules/create-proposal/stores'
1415import { getChainFromLocalStorage } from 'src/utils/getChainFromLocalStorage'
16+ import { InvoiceMetadata , Milestone as MilestoneMetadata } from '@smartinvoicexyz/types'
1517
1618import EscrowForm from './EscrowForm'
1719import { EscrowFormValues } from './EscrowForm.schema'
1820import {
19- createEscrowData ,
21+ encodeEscrowData ,
2022 deployEscrowAbi ,
2123 getEscrowBundler ,
24+ ESCROW_TYPE ,
2225} from './EscrowUtils'
2326
2427export const Escrow : React . FC = ( ) => {
@@ -31,6 +34,10 @@ export const Escrow: React.FC = () => {
3134
3235 const addTransaction = useProposalStore ( ( state ) => state . addTransaction )
3336
37+ const {
38+ addresses : { treasury } ,
39+ } = useDaoStore ( )
40+
3441 const { data } = useSWR < ProposalsResponse > (
3542 isReady ? [ SWR_KEYS . PROPOSALS , chainId , query . token , '0' ] : null ,
3643 ( _ , chainId , token , _page ) => getProposals ( chainId , token , 1 , Number ( 0 ) )
@@ -40,7 +47,10 @@ export const Escrow: React.FC = () => {
4047
4148 const handleEscrowTransaction = useCallback (
4249 async ( values : EscrowFormValues ) => {
43- const ipfsDataToUpload = {
50+ if ( ! treasury ) {
51+ return ;
52+ }
53+ const ipfsDataToUpload : InvoiceMetadata = {
4454 title : 'Proposal #' + ( lastProposalId + 1 ) ,
4555 description : window ?. location . href . replace (
4656 '/proposal/create' ,
@@ -72,7 +82,7 @@ export const Escrow: React.FC = () => {
7282 ] ,
7383 }
7484 : { } ) ,
75- } ) ) ,
85+ } as MilestoneMetadata ) ) ,
7686 }
7787
7888 const jsonDataToUpload = JSON . stringify ( ipfsDataToUpload , null , 2 )
@@ -108,7 +118,7 @@ export const Escrow: React.FC = () => {
108118 }
109119
110120 // create bundler transaction data
111- const escrowData = createEscrowData ( values , cid , chainId )
121+ const escrowData = encodeEscrowData ( values , treasury , cid , chainId )
112122 const milestoneAmounts = values . milestones . map ( ( x ) => x . amount * 10 ** 18 )
113123 const fundAmount = milestoneAmounts . reduce ( ( acc , x ) => acc + x , 0 )
114124
@@ -118,30 +128,25 @@ export const Escrow: React.FC = () => {
118128 calldata : encodeFunctionData ( {
119129 abi : deployEscrowAbi ,
120130 functionName : 'deployEscrow' ,
121- args : [ milestoneAmounts , escrowData , fundAmount ] ,
131+ args : [ values . recipientAddress , milestoneAmounts , escrowData , ESCROW_TYPE , fundAmount ] ,
122132 } ) ,
123133 value : formatEther ( BigInt ( fundAmount ) ) ,
124134 }
125135
126136 try {
127- // add 2.5s delay here before adding to queue
128- setTimeout (
129- ( ) =>
130- addTransaction ( {
131- type : TransactionType . ESCROW ,
132- summary : `Create and fund new Escrow with ${ formatEther (
133- BigInt ( fundAmount )
134- ) } ETH`,
135- transactions : [ escrow ] ,
136- } ) ,
137- 2500
138- )
137+ addTransaction ( {
138+ type : TransactionType . ESCROW ,
139+ summary : `Create and fund new Escrow with ${ formatEther (
140+ BigInt ( fundAmount )
141+ ) } ETH`,
142+ transactions : [ escrow ] ,
143+ } )
139144 } catch ( err ) {
140- console . log ( 'Error' , err )
145+ console . log ( 'Error Adding Transaction ' , err )
141146 }
142147 setIsSubmitting ( false )
143148 } ,
144- [ addTransaction , chainId , lastProposalId ]
149+ [ addTransaction , chainId , lastProposalId , treasury ]
145150 )
146151
147152 return (
0 commit comments