From c2e9c13bec51f700786e409b4e7811a66093582d Mon Sep 17 00:00:00 2001 From: David Disu Date: Thu, 30 Dec 2021 12:01:22 +0100 Subject: [PATCH] retrieve function inputs --- libs/remix-ui/run-tab/src/lib/actions/index.ts | 4 ++++ .../src/lib/components/contractDropdownUI.tsx | 13 ++++++++++--- .../src/lib/components/instanceContainerUI.tsx | 1 + .../run-tab/src/lib/components/universalDappUI.tsx | 3 +-- libs/remix-ui/run-tab/src/lib/run-tab.tsx | 4 +++- libs/remix-ui/run-tab/src/lib/types/index.ts | 6 ++++-- workspace.json | 2 +- 7 files changed, 24 insertions(+), 9 deletions(-) diff --git a/libs/remix-ui/run-tab/src/lib/actions/index.ts b/libs/remix-ui/run-tab/src/lib/actions/index.ts index dfd5e19440..dc0cae242a 100644 --- a/libs/remix-ui/run-tab/src/lib/actions/index.ts +++ b/libs/remix-ui/run-tab/src/lib/actions/index.ts @@ -717,3 +717,7 @@ export const runCurrentScenario = (gasEstimationPrompt: (msg: string) => JSX.Ele export const updateScenarioPath = (path: string) => { dispatch(setPathToScenario(path)) } + +export const getFuncABIInputs = (funcABI: FuncABI) => { + return plugin.blockchain.getInputs(funcABI) +} diff --git a/libs/remix-ui/run-tab/src/lib/components/contractDropdownUI.tsx b/libs/remix-ui/run-tab/src/lib/components/contractDropdownUI.tsx index 269c55f09c..595f8ae22b 100644 --- a/libs/remix-ui/run-tab/src/lib/components/contractDropdownUI.tsx +++ b/libs/remix-ui/run-tab/src/lib/components/contractDropdownUI.tsx @@ -1,6 +1,6 @@ // eslint-disable-next-line no-use-before-define import React, { useEffect, useState } from 'react' -import { ContractData, ContractDropdownProps } from '../types' +import { ContractData, ContractDropdownProps, FuncABI } from '../types' import * as ethJSUtil from 'ethereumjs-util' import { ContractGUI } from './contractGUI' @@ -25,6 +25,8 @@ export function ContractDropdownUI (props: ContractDropdownProps) { const [selectedContract, setSelectedContract] = useState('') const [compFails, setCompFails] = useState<'none' | 'block'>('none') const [loadedContractData, setLoadedContractData] = useState(null) + const [constructorInterface, setConstructorInterface] = useState(null) + const [constructorInputs, setConstructorInputs] = useState(null) const { contractList, loadType, currentFile } = props.contracts useEffect(() => { @@ -79,8 +81,13 @@ export function ContractDropdownUI (props: ContractDropdownProps) { useEffect(() => { if (selectedContract) { const contract = contractList.find(contract => contract.alias === selectedContract) + const loadedContractData = props.getSelectedContract(selectedContract, contract.name) - setLoadedContractData(props.getSelectedContract(selectedContract, contract.name)) + if (loadedContractData) { + setLoadedContractData(loadedContractData) + setConstructorInterface(loadedContractData.getConstructorInterface()) + setConstructorInputs(loadedContractData.getConstructorInputs()) + } } }, [selectedContract]) @@ -193,7 +200,7 @@ export function ContractDropdownUI (props: ContractDropdownProps) {
{ contractList.length <= 0 ? 'No compiled contracts' : loadedContractData ?
- +
}) }
diff --git a/libs/remix-ui/run-tab/src/lib/components/universalDappUI.tsx b/libs/remix-ui/run-tab/src/lib/components/universalDappUI.tsx index de6014711c..bdd5d2317b 100644 --- a/libs/remix-ui/run-tab/src/lib/components/universalDappUI.tsx +++ b/libs/remix-ui/run-tab/src/lib/components/universalDappUI.tsx @@ -18,7 +18,6 @@ export function UniversalDappUI (props: UdappProps) { const [expandPath, setExpandPath] = useState([]) const [llIError, setLlIError] = useState('') const [calldataValue, setCalldataValue] = useState('') - const [inputs, setInputs] = useState(null) const [evmBC, setEvmBC] = useState(null) useEffect(() => { @@ -43,7 +42,6 @@ export function UniversalDappUI (props: UdappProps) { useEffect(() => { if (props.instance.contractData) { - setInputs(props.instance.contractData.getConstructorInputs()) setEvmBC(props.instance.contractData.bytecodeObject) } }, [props.instance.contractData]) @@ -235,6 +233,7 @@ export function UniversalDappUI (props: UdappProps) { if (funcABI.type !== 'function') return null const isConstant = funcABI.constant !== undefined ? funcABI.constant : false const lookupOnly = funcABI.stateMutability === 'view' || funcABI.stateMutability === 'pure' || isConstant + const inputs = props.getFuncABIInputs(funcABI) return
diff --git a/libs/remix-ui/run-tab/src/lib/types/index.ts b/libs/remix-ui/run-tab/src/lib/types/index.ts index 78216a91ab..1e83888100 100644 --- a/libs/remix-ui/run-tab/src/lib/types/index.ts +++ b/libs/remix-ui/run-tab/src/lib/types/index.ts @@ -225,7 +225,8 @@ export interface InstanceContainerProps { logBuilder: (msg: string) => JSX.Element, passphrasePrompt: (message: string) => JSX.Element, mainnetPrompt: (tx: Tx, network: Network, amount: string, gasEstimation: string, gasFees: (maxFee: string, cb: (txFeeText: string, priceStatus: boolean) => void) => void, determineGasPrice: (cb: (txFeeText: string, gasPriceValue: string, gasPriceStatus: boolean) => void) => void) => JSX.Element, - sendValue: string + sendValue: string, + getFuncABIInputs: (funcABI: FuncABI) => string } export interface Modal { @@ -295,5 +296,6 @@ export interface UdappProps { mainnetPrompt: MainnetPrompt, gasEstimationPrompt: (msg: string) => JSX.Element, passphrasePrompt: (msg: string) => JSX.Element) => void, - sendValue: string + sendValue: string, + getFuncABIInputs: (funcABI: FuncABI) => string } diff --git a/workspace.json b/workspace.json index b175a6915b..fa7930463c 100644 --- a/workspace.json +++ b/workspace.json @@ -1166,7 +1166,7 @@ "options": { "linter": "eslint", "tsConfig": ["libs/remix-ui/run-tab/tsconfig.lib.json"], - "exclude": ["**/node_modules/**", "!libs/remix-ui/run-tab/**/*"] + "exclude": ["**/node_modules/**", "libs/remix-ui/run-tab/**/*.d.ts", "!libs/remix-ui/run-tab/**/*"] } } }