Skip to content

Commit

Permalink
API working
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiolalombardim committed May 19, 2024
1 parent 2d38549 commit 40cf3d1
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { validateContractAddress, validateAddress } from "@taquito/utils"
import { Field, FieldArray, Form, Formik, FormikErrors, getIn } from "formik"
import { SmallButtonDialog } from "modules/common/SmallButton"
import { ArrowBackIos } from "@material-ui/icons"
import { SearchEndpoints } from "./SearchEndpoints"
import { ContractEndpoint, SearchEndpoints } from "./SearchEndpoints"
import { toShortAddress } from "services/contracts/utils"
import { useArbitraryContractData } from "services/aci/useArbitratyContractData"
import { useTezos } from "services/beacon/hooks/useTezos"
Expand Down Expand Up @@ -124,7 +124,7 @@ const ContractInteractionForm = ({
showHeader
}: any) => {
const [state, setState] = useState<Status>(Status.NEW_INTERACTION)
const [endpoint, setEndpoint] = useState<ArbitraryContract | undefined>(undefined)
const [endpoint, setEndpoint] = useState<ContractEndpoint | undefined>(undefined)
const theme = useTheme()
const isMobileSmall = useMediaQuery(theme.breakpoints.down("sm"))
const { mutate: fetchContractData, data } = useArbitraryContractData()
Expand Down Expand Up @@ -152,9 +152,9 @@ const ContractInteractionForm = ({
})
}

const processParameters = (data: ArbitraryContract) => {
const processParameters = (data: ContractEndpoint) => {
setEndpoint(data)
setFieldValue("parameters", data.children)
setFieldValue("parameters", data.params)
setFieldValue("target_endpoint", data.name)
}

Expand Down Expand Up @@ -239,15 +239,15 @@ const ContractInteractionForm = ({
name="parameters"
render={arrayHelpers => (
<Container>
{endpoint.children.length > 0 &&
endpoint.children.map((param, index) => (
{endpoint.params.length > 0 &&
endpoint.params.map((param, index) => (
<div key={index}>
<ProposalFormInput label={`Parameter ${index + 1}`} key={`${param.name}`}>
<ProposalFormInput label={`Parameter ${index + 1}`} key={`${param.placeholder}`}>
<Field
component={CustomFormikTextField}
name={`parameters.${index}`}
type={param.type === "number" ? "number" : "string"}
placeholder={`${param.name}`}
type={param.type === "nat" || param.type === "init" ? "number" : "string"}
placeholder={`${param.placeholder}`}
onChange={(newValue: any) => {
setFieldValue(`parameters.${index}.value`, newValue.target.value, false)
if (newValue.target.value === "") {
Expand Down
7 changes: 6 additions & 1 deletion src/modules/explorer/components/ConfigProposalFormLambda.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -389,11 +389,16 @@ export const ProposalFormLambda: React.FC<Props> = ({ open, handleClose, action
)
}

const closeModal = () => {
setShowHeader(true)
handleClose()
}

return (
<FormProvider {...lambdaForm}>
<ResponsiveDialog
open={open}
onClose={handleClose}
onClose={closeModal}
title={ProposalAction[action] + " Function Proposal"}
template="md"
>
Expand Down
2 changes: 1 addition & 1 deletion src/modules/explorer/components/ProposalActionsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ export const ProposalActionsDialog: React.FC<Props> = ({ open, handleClose }) =>
onClick={() =>
elem.id === "off-chain"
? handleLiteProposal()
: true
: !shouldDisable
? elem.isLambda
? handleOpenCustomProposalModal(elem.id)
: handleOpenSupportedExecuteProposalModal(elem.id)
Expand Down
69 changes: 66 additions & 3 deletions src/modules/explorer/components/SearchEndpoints.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import React from "react"
import React, { useEffect, useState } from "react"
import { Grid, InputAdornment, makeStyles, styled, TextField, Theme, withStyles } from "@material-ui/core"
import { SearchOutlined } from "@material-ui/icons"
import { Autocomplete } from "@material-ui/lab"
import { ArbitraryContract } from "models/Contract"

export interface ContractEndpoint {
name: string
type: string
params: ContractParam[]
}
export interface ContractParam {
placeholder: string
type: string
}

const StyledType = styled(Grid)({
opacity: 0.65
})
Expand Down Expand Up @@ -80,13 +90,66 @@ export const SearchEndpoints: React.FC<{
}> = ({ endpoints, handleChange }) => {
useStyles()

const [formattedEndpoints, setFormattedEndpoints] = useState<ContractEndpoint[] | undefined>()

useEffect(() => {
const handleEndpointStructure = () => {
const formattedData = endpoints?.map(item => {
const endpoint: ContractEndpoint = {
name: item.name,
type: item.type,
params: []
}
switch (item.type) {
case "unit":
break
case "address":
const param = {
type: "address",
placeholder: "address"
}
endpoint.params.push(param)
break
case "pair":
item.children.map(child => {
const pairParam = {
type: child.type,
placeholder: child.name
}
endpoint.params.push(pairParam)
})
break
case "bool":
const paramBool = {
type: "bool",
placeholder: "bool"
}
endpoint.params.push(paramBool)
break
default:
const paramDefault = {
type: item.type,
placeholder: item.type
}
endpoint.params.push(paramDefault)
break
}
return endpoint
})
return formattedData
}

const data = handleEndpointStructure()
setFormattedEndpoints(data)
}, [endpoints])

return (
<>
{endpoints ? (
{formattedEndpoints ? (
<StyledInput
disablePortal
id="combo-box-demo"
options={endpoints}
options={formattedEndpoints}
getOptionLabel={(option: any) => option.name}
renderOption={(option: any, state: any) => (
<Grid container direction="row" justifyContent="space-between" {...state}>
Expand Down

0 comments on commit 40cf3d1

Please sign in to comment.