Skip to content

Commit

Permalink
Fixed Other UI Issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ashutoshpw committed Nov 5, 2024
1 parent 7d58fc5 commit ef80324
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 67 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo, useState } from "react"
import React, { useEffect, useMemo, useState } from "react"
import {
CircularProgress,
Grid,
Expand All @@ -22,20 +22,18 @@ import { useArbitraryContractData } from "services/aci/useArbitratyContractData"
import { useTezos } from "services/beacon/hooks/useTezos"
import { ArbitraryContract } from "models/Contract"
import { evalTaquitoParam, generateExecuteContractMichelson } from "services/aci"
import { emitMicheline, MichelsonType, Parser } from "@taquito/michel-codec"
import { emitMicheline, Parser } from "@taquito/michel-codec"
import ProposalExecuteForm from "./ProposalExecuteForm"
import { useLambdaExecutePropose } from "services/contracts/baseDAO/hooks/useLambdaExecutePropose"
import { Expr, MichelsonData, packDataBytes } from "@taquito/michel-codec"
import { BaseDAO, getContract } from "services/contracts/baseDAO"
import { Expr, MichelsonData } from "@taquito/michel-codec"
import { getContract } from "services/contracts/baseDAO"
import { TezosToolkit } from "@taquito/taquito"
import { Schema } from "@taquito/michelson-encoder"
import BigNumber from "bignumber.js"
import { useDAO } from "services/services/dao/hooks/useDAO"
import { useDAOID } from "../pages/DAO/router"
import AppConfig from "config"
import { Link } from "react-router-dom"
import { Button } from "components/ui/Button"
import { ResponsiveDialog } from "./ResponsiveDialog"
import { useNotification } from "modules/common/hooks/useNotification"

// Base ACI Lambda
const aciBaseLambda = {
Expand Down Expand Up @@ -205,6 +203,7 @@ const ContractInteractionForm = ({
daoLambdas
}: any) => {
const daoId = useDAOID()
const nofity = useNotification()
const [state, setState] = useState<Status>(Status.NEW_INTERACTION)
const [formState, setFormState] = useState<any>({ address: "", amount: 0, shape: {} })
const [endpoint, setEndpoint] = useState<ContractEndpoint | undefined>(undefined)
Expand Down Expand Up @@ -444,12 +443,11 @@ const ContractInteractionForm = ({
console.log({ formState })

try {
// debugger
let entrypoint = formState.shape.token.initValue // accept_ownership | default etc
let taquitoParam

setIsLoading(true)
// debugger

const execContract = formState.shape.contract
const taquitoFullParam = evalTaquitoParam(formState.shape.token, formState.shape)
if (execContract?.parameterSchema.isMultipleEntryPoint) {
Expand All @@ -469,10 +467,6 @@ const ContractInteractionForm = ({
? execContract?.entrypoints.entrypoints[entrypoint]
: execContract?.parameterSchema.root.val

// const micheline_type = values.destination_contract?.parameterSchema.isMultipleEntryPoint
// ? values.destination_contract.entrypoints.entrypoints[entrypoint]
// : values.destination_contract?.parameterSchema.root.val

const p = new Parser()
const type = emitMicheline(p.parseJSON(micheline_type), {
indent: "",
Expand All @@ -488,9 +482,6 @@ const ContractInteractionForm = ({
param
})

console.log("Lambda Code", lambda)
console.log("DaoDetails", daoDetails)

const finalPackedDataBytes = await prepareContractData(tezos, lambda, aciLambda.type)
const contract = await getContract(tezos, daoDetails?.data?.address as string)

Expand All @@ -505,20 +496,25 @@ const ContractInteractionForm = ({
daoDetails?.data?.token?.decimals as number
)

console.log("Frozen Token", frozenToken)

const contractMethod = contract.methods.propose(
await tezos.wallet.pkh(),
frozenToken,
finalPackedDataBytes
)

const result = await contractMethod.send()
debugger

await result.confirmation(1)
window.location.reload()
console.log("RESULT", result)
} catch (error) {
console.log("ERROR", error)
const errorMessage = error instanceof Error ? error.message : "An unknown error occurred"
nofity({
message: `Error: ${errorMessage}`,
autoHideDuration: 3000,
variant: "error"
})
} finally {
setIsLoading(false)
}
Expand All @@ -541,7 +537,6 @@ export const ArbitraryContractInteractionForm: React.FC<{
}> = ({ daoLambdas, showHeader }) => {
const daoId = useDAOID()
const [aciProposalOpen, setAciProposalOpen] = useState(false)
const { mutate: executeProposeLambda } = useLambdaExecutePropose()
const isInvalidKtOrTzAddress = (address: string) => validateContractAddress(address) !== 3

const initialValue: ACIValues = {
Expand Down Expand Up @@ -581,6 +576,10 @@ export const ArbitraryContractInteractionForm: React.FC<{
console.log("saveInfo")
}

useEffect(() => {
console.log({ daoLambdas })
}, [daoLambdas])

const isAciDeployerDeployed = daoLambdas?.find((lambda: any) => lambda.key === AppConfig.ACI.EXECUTOR_FUNCTION_NAME)

return (
Expand Down Expand Up @@ -617,21 +616,23 @@ export const ArbitraryContractInteractionForm: React.FC<{
showHeader={showHeader}
daoLambdas={daoLambdas}
/>
<ResponsiveDialog
open={!isAciDeployerDeployed}
onClose={() => setAciProposalOpen(false)}
title={"Proposal to Enable Arbitrary Contract Interaction"}
template="sm"
>
<Typography>In order to use open-ended Contract Calls, the DAO contract must be amended.</Typography>
<Typography>
If you have the minimum amount of tokens for the proposal fee, click Submit to create a proposal for
adding the ACI capability.
</Typography>
<Link to={`/explorer/dao/${daoId}/proposals?type=add-function`}>
<Button>Submit</Button>
</Link>
</ResponsiveDialog>
{daoLambdas !== undefined && (
<ResponsiveDialog
open={!isAciDeployerDeployed}
onClose={() => setAciProposalOpen(false)}
title={"Proposal to Enable Arbitrary Contract Interaction"}
template="sm"
>
<Typography>In order to use open-ended Contract Calls, the DAO contract must be amended.</Typography>
<Typography>
If you have the minimum amount of tokens for the proposal fee, click Submit to create a proposal for
adding the ACI capability.
</Typography>
<Link to={`/explorer/dao/${daoId}/proposals?type=add-function`}>
<Button>Submit</Button>
</Link>
</ResponsiveDialog>
)}
</Form>
)
}}
Expand Down
6 changes: 3 additions & 3 deletions src/modules/explorer/components/ProposalActionsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,9 @@ export const ProposalActionsDialog: React.FC<Props> = ({ open, handleClose, quer
</TitleContainer>
<Grid container spacing={2}>
<Grid item xs={isMobileSmall ? 12 : 4}>
<OptionContainer onClick={() => handleAciProposal()}>
<ActionText color={"textPrimary"}>Contract Call</ActionText>
<ActionDescriptionText color={"textPrimary"}>
<OptionContainer onClick={() => !shouldDisable && handleAciProposal()}>
<ActionText color={shouldDisable ? "textSecondary" : "textPrimary"}>Contract Call</ActionText>
<ActionDescriptionText color={shouldDisable ? "textSecondary" : "textPrimary"}>
Invoke an endpoint on a deployed contract
</ActionDescriptionText>
</OptionContainer>
Expand Down
34 changes: 5 additions & 29 deletions src/modules/explorer/components/ProposalExecuteForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Form, Formik } from "formik"
import React, { Context, createContext, useContext, useEffect } from "react"
import React, { useEffect } from "react"
import { genLambda, parseContract } from "../../../services/aci"
import { RenderItem } from "./aci/Fields"
import type { TezosToolkit } from "@taquito/taquito"
Expand All @@ -9,8 +9,6 @@ import { useTezos } from "services/beacon/hooks/useTezos"
import { SmallButtonDialog } from "modules/common/SmallButton"
import { useDAOID } from "../pages/DAO/router"
import { useDAO } from "services/services/dao/hooks/useDAO"
// import ErrorMessage from "./ErrorMessage"
// import renderError from "./formUtils"

type contractStorage = { version: string } & {
[key: string]: any
Expand All @@ -29,8 +27,6 @@ type tezosState = {
currentStorage: contractStorage | null
}

// const AppStateContext: Context<tezosState | null> = createContext<tezosState | null>(null)

function ProposalExecuteForm(
props: React.PropsWithoutRef<{
address: string // Input contract Address
Expand All @@ -49,12 +45,10 @@ function ProposalExecuteForm(
const { data: dao } = useDAO(daoId)

const address = props.address
const setLoading = props.setLoading
const loading = props.loading
const { tezos } = useTezos()

useEffect(() => {
// debugger
if (!Object.keys(props.shape).length && !loading) {
;(async () => {
try {
Expand All @@ -67,9 +61,7 @@ function ProposalExecuteForm(
}
})()
}
}, [address, loading, props.shape])

// return <>Proposal Execute Form</>
}, [address, loading, props, props.shape, tezos.contract])

return (
<div className="w-full text-white proposal-execute-form">
Expand All @@ -80,28 +72,22 @@ function ProposalExecuteForm(
onSubmit={() => {}}
validateOnMount={true}
validate={values => {
// console.log("Validate For ProposalExecuteForm", dao?.data)
props.onShapeChange(values)
// debugger;
try {
// ACI: This sets the lambda and metadata fields
// if (state?.contracts[state?.currentContract ?? ""]?.version) {
if (dao?.data?.address) {
genLambda("1.0.0", props, values)
}
if (dao?.data?.address) genLambda("1.0.0", props, values)
} catch (e) {
// setSubmitError((e as Error).message);
}
}}
>
{_ => {
// debugger;
return (
<Form className="align-self-center col-span-2 flex w-full grow flex-col items-center justify-center justify-self-center">
<div className="h-fit-content md:min-h-96 mb-2 grid w-full grid-flow-row items-start gap-4 overflow-y-auto">
{!!props.shape.token && <RenderItem token={props.shape?.token} showTitle={false} />}
</div>
<div style={{ marginTop: "10px" }}>
{/* <div style={{ marginTop: "10px" }}>
<SmallButtonDialog
variant="contained"
onClick={e => {
Expand All @@ -112,17 +98,7 @@ function ProposalExecuteForm(
>
Reset
</SmallButtonDialog>
{/* <button
className="rounded bg-primary p-2 font-medium text-white hover:bg-red-500 hover:outline-none focus:bg-red-500"
onClick={e => {
e.preventDefault()
props.reset()
props.onReset?.()
}}
>
Reset
</button> */}
</div>
</div> */}
</Form>
)
}}
Expand Down

0 comments on commit ef80324

Please sign in to comment.