From a63d995cf55b8f0ce3cd5cc57eb31ba45890064d Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Fri, 7 Jun 2024 12:43:21 +0100 Subject: [PATCH] make compiler version part of state. update props --- .../src/lib/components/contractDropdownUI.tsx | 3 + .../src/lib/components/contractGUI.tsx | 17 +++++ .../lib/components/instanceContainerUI.tsx | 4 + .../src/lib/components/universalDappUI.tsx | 76 +++++++++---------- libs/remix-ui/run-tab/src/lib/run-tab.tsx | 21 +++++ libs/remix-ui/run-tab/src/lib/types/index.ts | 14 ++++ 6 files changed, 97 insertions(+), 38 deletions(-) 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 cc58d83f1f..e8c30598de 100644 --- a/libs/remix-ui/run-tab/src/lib/components/contractDropdownUI.tsx +++ b/libs/remix-ui/run-tab/src/lib/components/contractDropdownUI.tsx @@ -483,6 +483,9 @@ export function ContractDropdownUI(props: ContractDropdownProps) { isValidProxyUpgrade={isValidProxyUpgrade} modal={props.modal} disabled={props.selectedAccount === ''} + solcVersion={props.solCompilerVersion} + setSolcVersion={props.setCompilerVersion} + getVersion={props.getCompilerVersion} />
>([]) const basicInputRef = useRef() const intl = useIntl() + // const [solcVersion, setSolcVersion] = useState({ version: '', canReceive: true }) + + // const getVersion = () => { + // let version = '' + // try { + // version = window.location.href.split('=')[5].split('+')[0].split('-')[1].slice(1) + // if (parseFloat(version) < 0.6) { + // setSolcVersion({ version: version, canReceive: false }) + // } + // setSolcVersion({ version: version, canReceive: false }) + // } catch (e) { + // version = window.location.href.split('=')[5].split('+')[0].split('-')[1].slice(1) + // console.log(e) + // } + // return version + // } useEffect(() => { if (props.deployOption && Array.isArray(props.deployOption)) { @@ -173,6 +189,7 @@ export function ContractGUI(props: ContractGUIProps) { } const handleActionClick = async () => { + props.getVersion() if (deployState.deploy) { const proxyInitializeString = getMultiValsString(initializeFields.current) props.clickCallBack(props.initializerOptions.inputs.inputs, proxyInitializeString, ['Deploy with Proxy']) diff --git a/libs/remix-ui/run-tab/src/lib/components/instanceContainerUI.tsx b/libs/remix-ui/run-tab/src/lib/components/instanceContainerUI.tsx index 7ebf00fc68..2d247e0d4c 100644 --- a/libs/remix-ui/run-tab/src/lib/components/instanceContainerUI.tsx +++ b/libs/remix-ui/run-tab/src/lib/components/instanceContainerUI.tsx @@ -44,6 +44,8 @@ export function InstanceContainerUI(props: InstanceContainerProps) { plugin={props.plugin} exEnvironment={props.exEnvironment} editInstance={props.editInstance} + solcVersion={props.solcVersion} + getVersion={props.getVersion} /> ) })} @@ -92,6 +94,8 @@ export function InstanceContainerUI(props: InstanceContainerProps) { plugin={props.plugin} exEnvironment={props.exEnvironment} editInstance={props.editInstance} + solcVersion={props.solcVersion} + getVersion={props.getVersion} /> ) })} 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 8381266053..40b36f8e0c 100644 --- a/libs/remix-ui/run-tab/src/lib/components/universalDappUI.tsx +++ b/libs/remix-ui/run-tab/src/lib/components/universalDappUI.tsx @@ -27,43 +27,22 @@ export function UniversalDappUI(props: UdappProps) { const [calldataValue, setCalldataValue] = useState('') const [evmBC, setEvmBC] = useState(null) const [instanceBalance, setInstanceBalance] = useState(0) - - const UrlLink = () => { - - const getVersion = () => { - let version = '' - try { - version = window.location.href.split('=')[5].split('+')[0].split('-')[1] - } catch { - version = window.location.href.split('=')[5].split('+')[0].split('-')[1] - } - return [version, parseFloat(version.slice(1))] - } - - return ( -
-
- -
- } - > - { // receive method added to solidity v0.6.x. use this as diff. - (getVersion()[1] as number) < 0.6 ? ( - - - - ) : - - - } - -
- ) - } + // const [solcVersion, setSolcVersion] = useState({ version: '', canReceive: true }) + + // const getVersion = () => { + // let version = '' + // try { + // version = window.location.href.split('=')[5].split('+')[0].split('-')[1].slice(1) + // if (parseFloat(version) < 0.6) { + // setSolcVersion({ version: version, canReceive: false }) + // } + // setSolcVersion({ version: version, canReceive: false }) + // } catch (e) { + // version = window.location.href.split('=')[5].split('+')[0].split('-')[1].slice(1) + // console.log(e) + // } + // return version + // } useEffect(() => { if (!props.instance.abi) { const abi = txHelper.sortAbiFunction(props.instance.contractData.abi) @@ -469,6 +448,7 @@ export function UniversalDappUI(props: UdappProps) { return (
{ runTransaction(lookupOnly, funcABI, valArray, inputsValues, index) @@ -499,7 +479,27 @@ export function UniversalDappUI(props: UdappProps) { })}
- +
+
+ +
+ } + > + { // receive method added to solidity v0.6.x. use this as diff. + props.solcVersion.canReceive === false ? ( + + + + ) : + + + } + +
diff --git a/libs/remix-ui/run-tab/src/lib/run-tab.tsx b/libs/remix-ui/run-tab/src/lib/run-tab.tsx index 26d87b7fc0..56f50b1b70 100644 --- a/libs/remix-ui/run-tab/src/lib/run-tab.tsx +++ b/libs/remix-ui/run-tab/src/lib/run-tab.tsx @@ -80,6 +80,22 @@ export function RunTabUI(props: RunTabProps) { const [runTab, dispatch] = useReducer(runTabReducer, initialState) const REACT_API = { runTab } const currentfile = plugin.config.get('currentFile') + const [solcVersion, setSolcVersion] = useState<{version: string, canReceive: boolean}>({ version: '', canReceive: true }) + + const getVersion = () => { + let version = '' + try { + version = window.location.href.split('=')[5].split('+')[0].split('-')[1].slice(1) + if (parseFloat(version) < 0.6) { + setSolcVersion({ version: version, canReceive: false }) + } + setSolcVersion({ version: version, canReceive: true }) + } catch (e) { + version = window.location.href.split('=')[5].split('+')[0].split('-')[1].slice(1) + console.log(e) + } + return version + } useEffect(() => { if (!props.initialState) { @@ -306,6 +322,9 @@ export function RunTabUI(props: RunTabProps) { isValidProxyAddress={isValidProxyAddress} isValidProxyUpgrade={isValidProxyUpgrade} proxy={runTab.proxy} + solCompilerVersion={solcVersion} + setCompilerVersion={setSolcVersion} + getCompilerVersion={getVersion} /> { 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 7e4ae84533..39c8fd5781 100644 --- a/libs/remix-ui/run-tab/src/lib/types/index.ts +++ b/libs/remix-ui/run-tab/src/lib/types/index.ts @@ -279,6 +279,11 @@ export interface ContractDropdownProps { isValidProxyAddress?: (address: string) => Promise, isValidProxyUpgrade?: (proxyAddress: string, contractName: string, solcInput: SolcInput, solcOuput: SolcOutput, solcVersion: string) => Promise, proxy: { deployments: { address: string, date: string, contractName: string }[] } + solCompilerVersion: { version: string, canReceive: boolean } + setCompilerVersion: React.Dispatch> + getCompilerVersion: () => string } export interface RecorderProps { @@ -343,6 +348,8 @@ export interface InstanceContainerProps { exEnvironment: string editInstance: (instance) => void plugin: RunTab + solcVersion: { version: string, canReceive: boolean } + getVersion: () => string } export interface Modal { @@ -397,6 +404,11 @@ export interface ContractGUIProps { isValidProxyAddress?: (address: string) => Promise, isValidProxyUpgrade?: (proxyAddress: string) => Promise, modal?: (title: string, message: string | JSX.Element, okLabel: string, okFn: () => void, cancelLabel?: string, cancelFn?: () => void, okBtnClass?: string, cancelBtnClass?: string) => void + solcVersion?: { version: string, canReceive: boolean } + setSolcVersion?: React.Dispatch> + getVersion: () => string } export interface MainnetProps { network: Network, @@ -452,6 +464,8 @@ export interface UdappProps { exEnvironment: string editInstance: (instance) => void plugin: RunTab + solcVersion: { version: string, canReceive: boolean } + getVersion: () => string } export interface DeployButtonProps {