diff --git a/libs/remix-ui/run-tab/src/lib/components/contractGUI.tsx b/libs/remix-ui/run-tab/src/lib/components/contractGUI.tsx index eb2d0a5a52..e759dd33e9 100644 --- a/libs/remix-ui/run-tab/src/lib/components/contractGUI.tsx +++ b/libs/remix-ui/run-tab/src/lib/components/contractGUI.tsx @@ -1,27 +1,38 @@ // eslint-disable-next-line no-use-before-define -import React, { useEffect, useRef, useState } from 'react' -import { FormattedMessage, useIntl } from 'react-intl' +import React, {useEffect, useRef, useState} from 'react' +import {FormattedMessage, useIntl} from 'react-intl' import * as remixLib from '@remix-project/remix-lib' -import { ContractGUIProps } from '../types' -import { CopyToClipboard } from '@remix-ui/clipboard' -import { CustomTooltip, ProxyAddressToggle, ProxyDropdownMenu, shortenDate, shortenProxyAddress, unavailableProxyLayoutMsg, upgradeReportMsg } from '@remix-ui/helper' -import { Dropdown } from 'react-bootstrap' +import {ContractGUIProps} from '../types' +import {CopyToClipboard} from '@remix-ui/clipboard' +import { + CustomTooltip, + ProxyAddressToggle, + ProxyDropdownMenu, + shortenDate, + shortenProxyAddress, + unavailableProxyLayoutMsg, + upgradeReportMsg +} from '@remix-ui/helper' +import {Dropdown} from 'react-bootstrap' const txFormat = remixLib.execution.txFormat const txHelper = remixLib.execution.txHelper -export function ContractGUI (props: ContractGUIProps) { +export function ContractGUI(props: ContractGUIProps) { const [title, setTitle] = useState('') const [basicInput, setBasicInput] = useState('') const [toggleContainer, setToggleContainer] = useState(false) const [buttonOptions, setButtonOptions] = useState<{ - title: string, - content: string, - classList: string, + title: string + content: string + classList: string dataId: string - }>({ title: '', content: '', classList: '', dataId: '' }) + }>({title: '', content: '', classList: '', dataId: ''}) const [toggleDeployProxy, setToggleDeployProxy] = useState(false) const [toggleUpgradeImp, setToggleUpgradeImp] = useState(false) - const [deployState, setDeployState] = useState<{ deploy: boolean, upgrade: boolean }>({ deploy: false, upgrade: false }) + const [deployState, setDeployState] = useState<{ + deploy: boolean + upgrade: boolean + }>({deploy: false, upgrade: false}) const [proxyAddress, setProxyAddress] = useState('') const [proxyAddressError, setProxyAddressError] = useState('') const [showDropdown, setShowDropdown] = useState(false) @@ -32,8 +43,18 @@ export function ContractGUI (props: ContractGUIProps) { useEffect(() => { if (props.deployOption && Array.isArray(props.deployOption)) { - if (props.deployOption[0] && props.deployOption[0].title === 'Deploy with Proxy' && props.deployOption[0].active) handleDeployProxySelect(true) - else if (props.deployOption[1] && props.deployOption[1].title === 'Upgrade with Proxy' && props.deployOption[1].active) handleUpgradeImpSelect(true) + if ( + props.deployOption[0] && + props.deployOption[0].title === 'Deploy with Proxy' && + props.deployOption[0].active + ) + handleDeployProxySelect(true) + else if ( + props.deployOption[1] && + props.deployOption[1].title === 'Upgrade with Proxy' && + props.deployOption[1].active + ) + handleUpgradeImpSelect(true) } }, [props.deployOption]) @@ -48,21 +69,26 @@ export function ContractGUI (props: ContractGUIProps) { setBasicInput('') // we have the reset the fields before reseting the previous references. basicInputRef.current.value = '' - multiFields.current.filter((el) => el !== null && el !== undefined).forEach((el) => el.value = '') + multiFields.current + .filter((el) => el !== null && el !== undefined) + .forEach((el) => (el.value = '')) multiFields.current = [] }, [props.title, props.funcABI]) useEffect(() => { if (props.lookupOnly) { - // // call. stateMutability is either pure or view + // // call. stateMutability is either pure or view setButtonOptions({ title: title + ' - call', content: 'call', classList: 'btn-info', dataId: title + ' - call' }) - } else if (props.funcABI.stateMutability === 'payable' || props.funcABI.payable) { - // // transact. stateMutability = payable + } else if ( + props.funcABI.stateMutability === 'payable' || + props.funcABI.payable + ) { + // // transact. stateMutability = payable setButtonOptions({ title: title + ' - transact (payable)', content: 'transact', @@ -70,7 +96,7 @@ export function ContractGUI (props: ContractGUIProps) { dataId: title + ' - transact (payable)' }) } else { - // // transact. stateMutability = nonpayable + // // transact. stateMutability = nonpayable setButtonOptions({ title: title + ' - transact (not payable)', content: 'transact', @@ -91,7 +117,8 @@ export function ContractGUI (props: ContractGUIProps) { const encodeObj = txFormat.encodeData( props.funcABI, multiJSON, - props.funcABI.type === 'constructor' ? props.evmBC : null) + props.funcABI.type === 'constructor' ? props.evmBC : null + ) if (encodeObj.error) { console.error(encodeObj.error) @@ -138,7 +165,10 @@ export function ContractGUI (props: ContractGUIProps) { valArrayTest.push(elVal) elVal = elVal.replace(/(^|,\s+|,)(\d+)(\s+,|,|$)/g, '$1"$2"$3') // replace non quoted number by quoted number - elVal = elVal.replace(/(^|,\s+|,)(0[xX][0-9a-fA-F]+)(\s+,|,|$)/g, '$1"$2"$3') // replace non quoted hex string by quoted hex string + elVal = elVal.replace( + /(^|,\s+|,)(0[xX][0-9a-fA-F]+)(\s+,|,|$)/g, + '$1"$2"$3' + ) // replace non quoted hex string by quoted hex string if (elVal) { try { JSON.parse(elVal) @@ -161,7 +191,8 @@ export function ContractGUI (props: ContractGUIProps) { const inputString = basicInput if (inputString) { - const inputJSON = remixLib.execution.txFormat.parseFunctionParams(inputString) + const inputJSON = + remixLib.execution.txFormat.parseFunctionParams(inputString) const multiInputs = multiFields.current for (let k = 0; k < multiInputs.length; k++) { @@ -175,26 +206,61 @@ export function ContractGUI (props: ContractGUIProps) { const handleActionClick = async () => { if (deployState.deploy) { const proxyInitializeString = getMultiValsString(initializeFields.current) - props.clickCallBack(props.initializerOptions.inputs.inputs, proxyInitializeString, ['Deploy with Proxy']) + props.clickCallBack( + props.initializerOptions.inputs.inputs, + proxyInitializeString, + ['Deploy with Proxy'] + ) } else if (deployState.upgrade) { if (proxyAddress === '') { setProxyAddressError('proxy address cannot be empty') } else { - const isValidProxyAddress = await props.isValidProxyAddress(proxyAddress) + const isValidProxyAddress = await props.isValidProxyAddress( + proxyAddress + ) if (isValidProxyAddress) { setProxyAddressError('') - const upgradeReport: any = await props.isValidProxyUpgrade(proxyAddress) + const upgradeReport: any = await props.isValidProxyUpgrade( + proxyAddress + ) if (upgradeReport.ok) { - !proxyAddressError && props.clickCallBack(props.funcABI.inputs, proxyAddress, ['Upgrade with Proxy']) + !proxyAddressError && + props.clickCallBack(props.funcABI.inputs, proxyAddress, [ + 'Upgrade with Proxy' + ]) } else { if (upgradeReport.warning) { - props.modal('Proxy Upgrade Warning', unavailableProxyLayoutMsg(), 'Proceed', () => { - !proxyAddressError && props.clickCallBack(props.funcABI.inputs, proxyAddress, ['Upgrade with Proxy']) - }, 'Cancel', () => {}, 'btn-warning', 'btn-secondary') + props.modal( + 'Proxy Upgrade Warning', + unavailableProxyLayoutMsg(), + 'Proceed', + () => { + !proxyAddressError && + props.clickCallBack(props.funcABI.inputs, proxyAddress, [ + 'Upgrade with Proxy' + ]) + }, + 'Cancel', + () => {}, + 'btn-warning', + 'btn-secondary' + ) } else { - props.modal('Proxy Upgrade Error', upgradeReportMsg(upgradeReport), 'Continue anyway ', () => { - !proxyAddressError && props.clickCallBack(props.funcABI.inputs, proxyAddress, ['Upgrade with Proxy']) - }, 'Cancel', () => {}, 'btn-warning', 'btn-secondary') + props.modal( + 'Proxy Upgrade Error', + upgradeReportMsg(upgradeReport), + 'Continue anyway ', + () => { + !proxyAddressError && + props.clickCallBack(props.funcABI.inputs, proxyAddress, [ + 'Upgrade with Proxy' + ]) + }, + 'Cancel', + () => {}, + 'btn-warning', + 'btn-secondary' + ) } } } else { @@ -229,7 +295,7 @@ export function ContractGUI (props: ContractGUIProps) { const handleDeployProxySelect = (value: boolean) => { if (value) setToggleUpgradeImp(false) setToggleDeployProxy(value) - setDeployState({ upgrade: false, deploy: value }) + setDeployState({upgrade: false, deploy: value}) } const handleToggleUpgradeImp = () => { @@ -241,7 +307,7 @@ export function ContractGUI (props: ContractGUIProps) { if (value) { setToggleDeployProxy(false) } - setDeployState({ deploy: false, upgrade: value }) + setDeployState({deploy: false, upgrade: value}) } const switchProxyAddress = (address: string) => { @@ -262,50 +328,58 @@ export function ContractGUI (props: ContractGUIProps) {
0) || - props.funcABI.type === "fallback" || - props.funcABI.type === "receive" - ? "udapp_hasArgs" - : "" + props.funcABI.type === 'fallback' || + props.funcABI.type === 'receive' + ? 'udapp_hasArgs' + : '' }`} >
-
+ - -
+ {title} + +
+ 0) || - props.funcABI.type === "fallback" || - props.funcABI.type === "receive" + props.funcABI.type === 'fallback' || + props.funcABI.type === 'receive' ) - ? "hidden" - : "visible", + ? 'hidden' + : 'visible' }} /> 0 ) - ? "hidden" - : "visible", + ? 'hidden' + : 'visible' }} >
@@ -357,7 +431,7 @@ export function ContractGUI (props: ContractGUIProps) { > { - multiFields.current[index] = el; + multiFields.current[index] = el }} className="form-control" placeholder={inp.type} @@ -366,14 +440,14 @@ export function ContractGUI (props: ContractGUIProps) { />
- ); + ) })}
-
+
@@ -439,14 +515,19 @@ export function ContractGUI (props: ContractGUIProps) { data-id="contractGUIDeployWithProxyLabel" className="m-0 form-check-label w-100 custom-control-label udapp_checkboxAlign" > - +
{props.initializerOptions && props.initializerOptions.initializeInputs ? ( - @@ -457,7 +538,7 @@ export function ContractGUI (props: ContractGUIProps) { props.initializerOptions.initializeInputs ? (
@@ -468,19 +549,19 @@ export function ContractGUI (props: ContractGUIProps) { className="mt-2 text-left d-block" htmlFor={inp.name} > - {" "} - {inp.name}:{" "} + {' '} + {inp.name}:{' '} { - initializeFields.current[index] = el; + initializeFields.current[index] = el }} - style={{ height: 32 }} + style={{height: 32}} className="form-control udapp_input" placeholder={inp.type} />
- ); + ) })}
@@ -500,15 +581,15 @@ export function ContractGUI (props: ContractGUIProps) { data-id="contractGUIUpgradeImplementationLabel" className="m-0 form-check-label custom-control-label udapp_checkboxAlign" > - +
@@ -516,50 +597,79 @@ export function ContractGUI (props: ContractGUIProps) {
- - - { props.proxy.deployments.length > 0 && - - { - props.proxy.deployments.map((deployment, index) => ( - + + {props.proxy.deployments.length > 0 && ( + + {props.proxy.deployments.map((deployment, index) => ( + + { + switchProxyAddress(deployment.address) + }} + data-id={`proxyAddress${index}`} > - { switchProxyAddress(deployment.address) }} - data-id={`proxyAddress${index}`} - > - - { proxyAddress === deployment.address ? - ✓ { deployment.contractName + ' ' + shortenProxyAddress(deployment.address) } - : { deployment.contractName + ' ' + shortenProxyAddress(deployment.address) } } - - - - )) - } + + {proxyAddress === deployment.address ? ( + + ✓{' '} + {deployment.contractName + + ' ' + + shortenProxyAddress(deployment.address)}{' '} + + ) : ( + + {deployment.contractName + + ' ' + + shortenProxyAddress(deployment.address)} + + )} + + + + ))} - } + )}
-
+
- { proxyAddressError && { proxyAddressError } } + {proxyAddressError && ( + + {proxyAddressError} + + )}
- + ) : null}
- ); + ) }