diff --git a/libs/remix-core-plugin/src/lib/openzeppelin-proxy.ts b/libs/remix-core-plugin/src/lib/openzeppelin-proxy.ts index fc4b3d5ac0..684b4334d2 100644 --- a/libs/remix-core-plugin/src/lib/openzeppelin-proxy.ts +++ b/libs/remix-core-plugin/src/lib/openzeppelin-proxy.ts @@ -130,8 +130,7 @@ export class OpenZeppelinProxy extends Plugin { if (initializeInput) { inputs[name] = { inputs: initializeInput, - initializeInputs: this.blockchain.getInputs(initializeInput), - options: [{ title: 'Deploy with Proxy', active: false }, { title: 'Upgrade Proxy', active: false }] + initializeInputs: this.blockchain.getInputs(initializeInput) } } }) diff --git a/libs/remix-ui/run-tab/src/lib/actions/events.ts b/libs/remix-ui/run-tab/src/lib/actions/events.ts index ffa81a8a59..26f7d33b74 100644 --- a/libs/remix-ui/run-tab/src/lib/actions/events.ts +++ b/libs/remix-ui/run-tab/src/lib/actions/events.ts @@ -2,7 +2,7 @@ import { envChangeNotification } from "@remix-ui/helper" import { RunTab } from "../types/run-tab" import { setExecutionContext, setFinalContext, updateAccountBalances } from "./account" import { addExternalProvider, addInstance, removeExternalProvider, setNetworkNameFromProvider } from "./actions" -import { clearAllInstances, clearRecorderCount, fetchContractListSuccess, resetUdapp, setCurrentFile, setDeployOptions, setLoadType, setRecorderCount, setSendValue } from "./payload" +import { clearAllInstances, clearRecorderCount, fetchContractListSuccess, resetUdapp, setCurrentContract, setCurrentFile, setDeployOptions, setLoadType, setRecorderCount, setSendValue } from "./payload" import { CompilerAbstract } from '@remix-project/remix-solidity' import * as ethJSUtil from 'ethereumjs-util' import Web3 from 'web3' @@ -100,16 +100,20 @@ const broadcastCompilationResult = async (plugin: RunTab, dispatch: React.Dispat const contracts = getCompiledContracts(compiler).map((contract) => { return { name: languageVersion, alias: contract.name, file: contract.file, compiler } }) + const index = contracts.findIndex(contract => contract.alias === plugin.REACT_API.contracts.currentContract) + + if (index < 0) dispatch(setCurrentContract(contracts[0].alias)) const isUpgradeable = await plugin.call('openzeppelin-proxy', 'isConcerned', data.sources[file].ast) if (isUpgradeable) { const options = await plugin.call('openzeppelin-proxy', 'getDeployOptions', data.contracts[file]) - dispatch(setDeployOptions(options)) + dispatch(setDeployOptions({ options: [{ title: 'Deploy with Proxy', active: false }, { title: 'Upgrade Proxy', active: false }], initializeOptions: options })) } - else dispatch(setDeployOptions({})) + else dispatch(setDeployOptions({} as any)) dispatch(fetchContractListSuccess({ [file]: contracts })) dispatch(setCurrentFile(file)) + // TODO: set current contract } const getCompiledContracts = (compiler) => { 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 179eb80b92..eaee7eda69 100644 --- a/libs/remix-ui/run-tab/src/lib/components/contractDropdownUI.tsx +++ b/libs/remix-ui/run-tab/src/lib/components/contractDropdownUI.tsx @@ -226,7 +226,18 @@ export function ContractDropdownUI (props: ContractDropdownProps) {
{ ((contractList[currentFile] && contractList[currentFile].filter(contract => contract)) || []).length <= 0 ? 'No compiled contracts' : loadedContractData ?
- +
el !== null && el !== undefined).forEach((el) => el.value = '') multiFields.current = [] const hasArgs = (props.funcABI.inputs && props.funcABI.inputs.length > 0) || (props.funcABI.type === 'fallback') || (props.funcABI.type === 'receive') || - (props.isDeploy && props.deployOption && (props.deployOption.options.length > 0)) + (props.isDeploy && props.initializerOptions && props.initializerOptions.inputs && (props.initializerOptions.inputs.inputs.length > 0)) setHasArgs(hasArgs) }, [props.title, props.funcABI]) @@ -191,37 +191,36 @@ export function ContractGUI (props: ContractGUIProps) {
{ - props.isDeploy && props.deployOption && (props.deployOption.options || []).length > 0 ? + props.isDeploy && (props.deployOption || []).length > 0 ? { - (props.deployOption.options).map(({ title, active }, index) => setSelectedDeploy(index)}> { selectedDeployIndex.includes(index) ? ✓ {title} : {title} }) + (props.deployOption).map(({ title, active }, index) => setSelectedDeploy(index)}> { selectedDeployIndex.includes(index) ? ✓ {title} : {title} }) } : } { - props.isDeploy && props.deployOption && props.deployOption.inputs.inputs.length > 0 && + props.isDeploy && props.initializerOptions && (props.initializerOptions.inputs.inputs.length > 0) ? <> 0) || (props.deployOption.inputs.type === 'fallback') || (props.deployOption.inputs.type === 'receive')) ? 'hidden' : 'visible' }} /> + style={{ visibility: !((props.initializerOptions.inputs.inputs && props.initializerOptions.inputs.inputs.length > 0) || (props.initializerOptions.inputs.type === 'fallback') || (props.initializerOptions.inputs.type === 'receive')) ? 'hidden' : 'visible' }} /> 0) ? 'hidden' : 'visible' }}> + style={{ visibility: !(props.initializerOptions.inputs.inputs && props.initializerOptions.inputs.inputs.length > 0) ? 'hidden' : 'visible' }}> - - } - { !props.deployOption && <> + : + <> { - props.isDeploy && props.deployOption && props.deployOption.inputs.inputs.length > 0 && + props.isDeploy && props.initializerOptions && (props.initializerOptions.inputs.inputs.length > 0) ?
@@ -248,7 +247,7 @@ export function ContractGUI (props: ContractGUIProps) {
- {props.deployOption.inputs.inputs.map((inp, index) => { + {props.initializerOptions.inputs.inputs.map((inp, index) => { return (
@@ -261,9 +260,7 @@ export function ContractGUI (props: ContractGUIProps) {
-
- } - { !props.deployOption && +
:
diff --git a/libs/remix-ui/run-tab/src/lib/reducers/runTab.ts b/libs/remix-ui/run-tab/src/lib/reducers/runTab.ts index 03a47b3214..41950fc4e1 100644 --- a/libs/remix-ui/run-tab/src/lib/reducers/runTab.ts +++ b/libs/remix-ui/run-tab/src/lib/reducers/runTab.ts @@ -1,6 +1,6 @@ import { CompilerAbstract } from '@remix-project/remix-solidity-ts' import { ContractData } from '@remix-project/core-plugin' -import { DeployOption, DeployOptions } from '../types' +import { DeployMode, DeployOption, DeployOptions } from '../types' import { ADD_DEPLOY_OPTION, ADD_INSTANCE, ADD_PROVIDER, CLEAR_INSTANCES, CLEAR_RECORDER_COUNT, DISPLAY_NOTIFICATION, DISPLAY_POPUP_MESSAGE, FETCH_ACCOUNTS_LIST_FAILED, FETCH_ACCOUNTS_LIST_REQUEST, FETCH_ACCOUNTS_LIST_SUCCESS, FETCH_CONTRACT_LIST_FAILED, FETCH_CONTRACT_LIST_REQUEST, FETCH_CONTRACT_LIST_SUCCESS, FETCH_PROVIDER_LIST_FAILED, FETCH_PROVIDER_LIST_REQUEST, FETCH_PROVIDER_LIST_SUCCESS, HIDE_NOTIFICATION, HIDE_POPUP_MESSAGE, REMOVE_DEPLOY_OPTION, REMOVE_INSTANCE, REMOVE_PROVIDER, RESET_STATE, SET_BASE_FEE_PER_GAS, SET_CONFIRM_SETTINGS, SET_CURRENT_CONTRACT, SET_CURRENT_FILE, SET_DECODED_RESPONSE, SET_DEPLOY_OPTIONS, SET_EXECUTION_ENVIRONMENT, SET_EXTERNAL_WEB3_ENDPOINT, SET_GAS_LIMIT, SET_GAS_PRICE, SET_GAS_PRICE_STATUS, SET_IPFS_CHECKED_STATE, SET_LOAD_TYPE, SET_MATCH_PASSPHRASE, SET_MAX_FEE, SET_MAX_PRIORITY_FEE, SET_NETWORK_NAME, SET_PASSPHRASE, SET_PATH_TO_SCENARIO, SET_PERSONAL_MODE, SET_RECORDER_COUNT, SET_SELECTED_ACCOUNT, SET_SEND_UNIT, SET_SEND_VALUE, SET_TX_FEE_CONTENT } from '../constants' interface Action { type: string @@ -158,7 +158,7 @@ export const runTabInitialState: RunTabState = { matchPassphrase: '', contracts: { contractList: {}, - deployOptions: {}, + deployOptions: {} as any, loadType: 'other', currentFile: '', currentContract: '', @@ -684,25 +684,34 @@ export const runTabReducer = (state: RunTabState = runTabInitialState, action: A } case ADD_DEPLOY_OPTION: { - const payload: DeployOptions = action.payload + const payload: { title: DeployMode, active: boolean } = action.payload return { ...state, contracts: { ...state.contracts, - deployOptions: { ...state.contracts.deployOptions, ...payload } + deployOptions: { + ...state.contracts.deployOptions, + options: [...state.contracts.deployOptions.options, payload] + } } } } case REMOVE_DEPLOY_OPTION: { const payload: string = action.payload - const options = state.contracts.deployOptions + const options = state.contracts.deployOptions.options.filter(val => val.title !== payload) - delete options[payload] + return { ...state, - deployOptions: options + contracts: { + ...state.contracts, + deployOptions: { + ...state.contracts.deployOptions, + options + } + } } } 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 8a3a98190a..9d03574518 100644 --- a/libs/remix-ui/run-tab/src/lib/types/index.ts +++ b/libs/remix-ui/run-tab/src/lib/types/index.ts @@ -226,7 +226,6 @@ export interface Modal { export type DeployMode = 'Deploy with Proxy' | 'Upgrade Proxy' export type DeployOption = { - options: { title: DeployMode, active: boolean }[], initializeInputs: string, inputs: { inputs: [ @@ -243,7 +242,10 @@ export type DeployOption = { } } export interface DeployOptions { - [key: string]: DeployOption + initializeOptions: { + [key: string]: DeployOption + }, + options: { title: DeployMode, active: boolean }[], } export interface ContractGUIProps { @@ -256,7 +258,8 @@ export interface ContractGUIProps { lookupOnly: boolean, disabled?: boolean, isDeploy?: boolean, - deployOption?: DeployOption + deployOption?: { title: DeployMode, active: boolean }[], + initializerOptions: DeployOption } export interface MainnetProps { network: Network,