diff --git a/libs/remix-ui/run-tab/src/lib/actions/evmmap.ts b/libs/remix-ui/run-tab/src/lib/actions/evmmap.ts index 7943d7c9f3..a219fc9173 100644 --- a/libs/remix-ui/run-tab/src/lib/actions/evmmap.ts +++ b/libs/remix-ui/run-tab/src/lib/actions/evmmap.ts @@ -1,5 +1,5 @@ export type ChainInfo = { - id: number + id: number | string name: string } @@ -200,15 +200,22 @@ export const evmMap: Map = new Map([ ]) export function getCompatibleChains(fork: HardFork): ChainInfo[] { - const forkData = evmMap.get(fork); - return forkData ? forkData.chainId : []; + const forkData = evmMap.get(fork) + return forkData ? forkData.chainId : [] } export function isChainCompatible(fork: HardFork, chainId: number): boolean { - const compatibleChains = getCompatibleChains(fork); - return compatibleChains.some(chain => chain.id === chainId); + const compatibleChains = getCompatibleChains(fork) + return compatibleChains.some(chain => chain.id === chainId) } export function isChainCompatibleWithAnyFork(chainId: number, forks: HardFork[]): boolean { - return forks.some(fork => isChainCompatible(fork, chainId)); + return forks.some(fork => isChainCompatible(fork, chainId)) +} + +export function getCompatibleChain(fork: HardFork, chainId: number): ChainInfo | undefined { + const compatibleChains = getCompatibleChains(fork) + console.log('fork in getCompatibleChain', fork) + console.log('compatibleChains', compatibleChains) + return compatibleChains.find(chain => chain.id === chainId) } 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 7ccc8ce55b..a462ffe40c 100644 --- a/libs/remix-ui/run-tab/src/lib/components/contractDropdownUI.tsx +++ b/libs/remix-ui/run-tab/src/lib/components/contractDropdownUI.tsx @@ -462,6 +462,7 @@ export function ContractDropdownUI(props: ContractDropdownProps) {
{ + // if the evmVersion is not provided in the url, we use the default value + // and the default would be the latest evmFork, which is now cancun. + // checking both url and compiler details + const url = window.location.href + const regVersion = url.match(/evmVersion=([a-zA-Z]+)/)?.[1] + const fetched = await props.getCompilerDetails() + return { regVersion, fetched } + } + const handleActionClick = async () => { props.getVersion() + const { regVersion, fetched } = await checkUrlLocationForEvmVersion() + console.log('checkUrlLocationForEvmVersion', { regVersion, fetched }) 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/environment.tsx b/libs/remix-ui/run-tab/src/lib/components/environment.tsx index 1cb2a91918..55149a8e9d 100644 --- a/libs/remix-ui/run-tab/src/lib/components/environment.tsx +++ b/libs/remix-ui/run-tab/src/lib/components/environment.tsx @@ -1,5 +1,5 @@ // eslint-disable-next-line no-use-before-define -import React from 'react' +import React, { useEffect } from 'react' import { FormattedMessage } from 'react-intl' import { EnvironmentProps, Provider } from '../types' import { Dropdown } from 'react-bootstrap' 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 37253056f7..f1ef7ae6b8 100644 --- a/libs/remix-ui/run-tab/src/lib/components/instanceContainerUI.tsx +++ b/libs/remix-ui/run-tab/src/lib/components/instanceContainerUI.tsx @@ -62,6 +62,7 @@ export function InstanceContainerUI(props: InstanceContainerProps) { editInstance={props.editInstance} solcVersion={props.solcVersion} getVersion={props.getVersion} + getCompilerDetails={props.getCompilerDetails} /> ) })} diff --git a/libs/remix-ui/run-tab/src/lib/components/settingsUI.tsx b/libs/remix-ui/run-tab/src/lib/components/settingsUI.tsx index f9e09246f9..295e3f966d 100644 --- a/libs/remix-ui/run-tab/src/lib/components/settingsUI.tsx +++ b/libs/remix-ui/run-tab/src/lib/components/settingsUI.tsx @@ -12,7 +12,7 @@ export function SettingsUI(props: SettingsProps) { return (
- + { runTransaction(lookupOnly, funcABI, valArray, inputsValues, index) 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 c4cd395055..5778da720b 100644 --- a/libs/remix-ui/run-tab/src/lib/run-tab.tsx +++ b/libs/remix-ui/run-tab/src/lib/run-tab.tsx @@ -56,6 +56,7 @@ import { PassphrasePrompt } from './components/passphrase' import { MainnetPrompt } from './components/mainnet' import { ScenarioPrompt } from './components/scenario' import { setIpfsCheckedState, setRemixDActivated } from './actions/payload' +import { getCompatibleChain, getCompatibleChains, HardFork, isChainCompatible, isChainCompatibleWithAnyFork } from './actions/evmmap' export function RunTabUI(props: RunTabProps) { const { plugin } = props @@ -85,6 +86,7 @@ export function RunTabUI(props: RunTabProps) { const REACT_API = { runTab } const currentfile = plugin.config.get('currentFile') const [solcVersion, setSolcVersion] = useState<{version: string, canReceive: boolean}>({ version: '', canReceive: true }) + const [chainEvmCompat, setChainEvmCompat] = useState() const getVersion = () => { let version = '0.8.25' @@ -102,6 +104,64 @@ export function RunTabUI(props: RunTabProps) { } } + const getCompilerDetails = async () => await checkEvmChainCompatibility() + + const returnCompatibleChain = async (evmVersion: HardFork, targetChainId: number) => { + return getCompatibleChain(evmVersion ?? 'cancun', targetChainId) + } + + const checkEvmChainCompatibilityOkFunction = async (targetChainId: number, fetchDetails: any, currentFile: string) => { + () => { + const compatibleChain = returnCompatibleChain(fetchDetails.evmVersion, targetChainId) + console.log('compatibleChain', compatibleChain) + plugin.call('manager', 'activatePlugin', 'environmentExplorer') + plugin.call('tabs', 'focus', 'environmentExplorer') + plugin.call('environmentExplorer', 'setChain', compatibleChain) + plugin.call('environmentExplorer', 'setEvmVersion', 'paris') + plugin.call('solidity', 'compile', currentFile) + } + } + + const checkEvmChainCompatibilityCancelFunction = async (targetChainId: number, fetchDetails: any, currentFile: string) => { + () => { + plugin.call('manager', 'activatePlugin', 'environmentExplorer') + plugin.call('tabs', 'focus', 'environmentExplorer') + plugin.call('environmentExplorer', 'setChain', targetChainId) + plugin.call('environmentExplorer', 'setEvmVersion', fetchDetails.evmVersion) + plugin.call('solidity', 'compile', currentFile) + } + } + + const checkEvmChainCompatibility = async () => { + const isVm = await plugin.call('blockchain', 'getProvider') // vms are exempt from this treatment + const fetchDetails = await plugin.call('solidity', 'getCompilerQueryParameters') //compiler details including evmVersion + console.log('isVm', isVm) + if (!isVm.startsWith('vm')) { + const targetChainId = runTab.chainId ? parseInt(runTab.chainId) : runTab.chainId + console.log('targetChainId', runTab.chainId) + + const IsCompatible = isChainCompatible(fetchDetails.evmVersion ?? 'cancun', targetChainId) + console.log('evmVersion matches everywhere', fetchDetails.evmVersion) + console.log('compiler stuff', fetchDetails) + console.log('chain is compatible', IsCompatible) + const currentFile = await plugin.call('fileManager', 'getCurrentFile') + if (!IsCompatible) { + console.log('chain is undefined') + //show modal + plugin.call('notification', 'modal', { + id: 'evm-incompatible', + title: 'Incompatible EVM - ChainId Detected', + message: `The selected chain is not compatible with the selected compiler version. Please select a one of the two options below.`, + modalType: 'modal', + okLabel: 'Switch EVM and Recompile', + cancelLabel: 'Do not Switch EVM', + okFn: checkEvmChainCompatibilityOkFunction, + cancelFn: checkEvmChainCompatibilityCancelFunction + }) + } + } + } + useEffect(() => { if (!props.initialState) { initRunTab(plugin, true)(dispatch) @@ -294,6 +354,7 @@ export function RunTabUI(props: RunTabProps) { gasLimit={runTab.gasLimit} setGasFee={setGasFeeAmount} providers={runTab.providers} + runTabPlugin={plugin} setExecutionContext={setExecutionEnvironment} createNewBlockchainAccount={createNewAddress} setPassphrase={setPassphraseModal} @@ -331,6 +392,7 @@ export function RunTabUI(props: RunTabProps) { solCompilerVersion={solcVersion} setCompilerVersion={setSolcVersion} getCompilerVersion={getVersion} + getCompilerDetails={getCompilerDetails} /> , @@ -158,6 +159,7 @@ export interface SettingsProps { } export interface EnvironmentProps { + runTabPlugin: RunTab, selectedEnv: string, providers: { providerList: Provider[], @@ -228,6 +230,7 @@ export type MainnetPrompt = ( ) => JSX.Element export interface ContractDropdownProps { + getCompilerDetails: () => Promise selectedAccount: string, exEnvironment: string, contracts: { @@ -292,6 +295,7 @@ export interface RecorderProps { } export interface InstanceContainerProps { + getCompilerDetails: () => Promise instances: { instanceList: { contractData?: ContractData, @@ -373,6 +377,7 @@ export interface DeployOptions { } export interface ContractGUIProps { + getCompilerDetails: () => Promise title?: string, funcABI: FuncABI, inputs: string, @@ -412,6 +417,7 @@ export interface MainnetProps { } export interface UdappProps { + getCompilerDetails: () => Promise instance: { contractData?: ContractData, address: string,