Fixed current contract bug

pull/2260/head
David Disu 3 years ago
parent 76045efb2d
commit 998eedc1b7
  1. 3
      libs/remix-core-plugin/src/lib/openzeppelin-proxy.ts
  2. 10
      libs/remix-ui/run-tab/src/lib/actions/events.ts
  3. 13
      libs/remix-ui/run-tab/src/lib/components/contractDropdownUI.tsx
  4. 33
      libs/remix-ui/run-tab/src/lib/components/contractGUI.tsx
  5. 23
      libs/remix-ui/run-tab/src/lib/reducers/runTab.ts
  6. 9
      libs/remix-ui/run-tab/src/lib/types/index.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)
}
}
})

@ -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) => {

@ -226,7 +226,18 @@ export function ContractDropdownUI (props: ContractDropdownProps) {
<div className="udapp_deployDropdown">
{ ((contractList[currentFile] && contractList[currentFile].filter(contract => contract)) || []).length <= 0 ? 'No compiled contracts'
: loadedContractData ? <div>
<ContractGUI title='Deploy' isDeploy={true} deployOption={deployOptions[currentContract]} funcABI={constructorInterface} clickCallBack={clickCallback} inputs={constructorInputs} widthClass='w-50' evmBC={loadedContractData.bytecodeObject} lookupOnly={false} />
<ContractGUI
title='Deploy'
isDeploy={true}
deployOption={deployOptions.options}
initializerOptions={deployOptions.initializeOptions ? deployOptions.initializeOptions[currentContract] : null}
funcABI={constructorInterface}
clickCallBack={clickCallback}
inputs={constructorInputs}
widthClass='w-50'
evmBC={loadedContractData.bytecodeObject}
lookupOnly={false}
/>
<div className="d-flex py-1 align-items-center custom-control custom-checkbox">
<input
id="deployAndRunPublishToIPFS"

@ -32,14 +32,14 @@ export function ContractGUI (props: ContractGUIProps) {
}
setBasicInput('')
// we have the reset the fields before reseting the previous references.
basicInputRef.current.value = ''
if (basicInputRef.current) basicInputRef.current.value = ''
multiFields.current.filter((el) => 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) {
<div className={`udapp_contractProperty ${hasArgs ? 'udapp_hasArgs' : ''}`}>
<div className="udapp_contractActionsContainerSingle pt-2" style={{ display: toggleContainer ? 'none' : 'flex' }}>
{
props.isDeploy && props.deployOption && (props.deployOption.options || []).length > 0 ?
props.isDeploy && (props.deployOption || []).length > 0 ?
<Dropdown as={ButtonGroup} show={showOptions}>
<button onClick={handleActionClick} title={buttonOptions.title} className={`udapp_instanceButton ${props.widthClass} btn btn-sm ${buttonOptions.classList}`} data-id={buttonOptions.dataId}>Deploy</button>
<Dropdown.Toggle split id="dropdown-split-basic" className={`btn btn-sm dropdown-toggle dropdown-toggle-split ${buttonOptions.classList}`} style={{ maxWidth: 25, minWidth: 0, height: 32 }} onClick={toggleOptions} />
<Dropdown.Menu className="deploy-items border-0">
{
(props.deployOption.options).map(({ title, active }, index) => <Dropdown.Item onClick={() => setSelectedDeploy(index)}> { selectedDeployIndex.includes(index) ? <span>&#10003; {title} </span> : <span className="pl-3">{title}</span> }</Dropdown.Item>)
(props.deployOption).map(({ title, active }, index) => <Dropdown.Item onClick={() => setSelectedDeploy(index)}> { selectedDeployIndex.includes(index) ? <span>&#10003; {title} </span> : <span className="pl-3">{title}</span> }</Dropdown.Item>)
}
</Dropdown.Menu>
</Dropdown> : <button onClick={handleActionClick} title={buttonOptions.title} className={`udapp_instanceButton ${props.widthClass} btn btn-sm ${buttonOptions.classList}`} data-id={buttonOptions.dataId}>{title}</button>
}
{
props.isDeploy && props.deployOption && props.deployOption.inputs.inputs.length > 0 &&
props.isDeploy && props.initializerOptions && (props.initializerOptions.inputs.inputs.length > 0) ?
<>
<input
className="form-control"
data-id={props.deployOption.inputs.type === 'fallback' || props.deployOption.inputs.type === 'receive' ? `'(${props.deployOption.inputs.type}')` : 'multiParamManagerBasicInputField'}
placeholder={props.deployOption.initializeInputs}
title={props.deployOption.inputs.type === 'fallback' || props.deployOption.inputs.type === 'receive' ? `'(${props.deployOption.inputs.type}')` : props.deployOption.initializeInputs}
data-id={props.initializerOptions.inputs.type === 'fallback' || props.initializerOptions.inputs.type === 'receive' ? `'(${props.initializerOptions.inputs.type}')` : 'multiParamManagerBasicInputField'}
placeholder={props.initializerOptions.initializeInputs}
title={props.initializerOptions.inputs.type === 'fallback' || props.initializerOptions.inputs.type === 'receive' ? `'(${props.initializerOptions.inputs.type}')` : props.initializerOptions.initializeInputs}
onChange={handleBasicInput}
ref={basicInputRef}
style={{ visibility: !((props.deployOption.inputs.inputs && props.deployOption.inputs.inputs.length > 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' }} />
<i
className="fas fa-angle-down udapp_methCaret"
onClick={switchMethodViewOn}
title={title}
style={{ visibility: !(props.deployOption.inputs.inputs && props.deployOption.inputs.inputs.length > 0) ? 'hidden' : 'visible' }}>
style={{ visibility: !(props.initializerOptions.inputs.inputs && props.initializerOptions.inputs.inputs.length > 0) ? 'hidden' : 'visible' }}>
</i>
</>
}
{ !props.deployOption && <>
</> :
<>
<input
className="form-control"
data-id={props.funcABI.type === 'fallback' || props.funcABI.type === 'receive' ? `'(${props.funcABI.type}')` : 'multiParamManagerBasicInputField'}
@ -240,7 +239,7 @@ export function ContractGUI (props: ContractGUIProps) {
}
</div>
{
props.isDeploy && props.deployOption && props.deployOption.inputs.inputs.length > 0 &&
props.isDeploy && props.initializerOptions && (props.initializerOptions.inputs.inputs.length > 0) ?
<div className="udapp_contractActionsContainerMulti" style={{ display: toggleContainer ? 'flex' : 'none' }}>
<div className="udapp_contractActionsContainerMultiInner text-dark">
<div onClick={switchMethodViewOff} className="udapp_multiHeader">
@ -248,7 +247,7 @@ export function ContractGUI (props: ContractGUIProps) {
<i className='fas fa-angle-up udapp_methCaret'></i>
</div>
<div>
{props.deployOption.inputs.inputs.map((inp, index) => {
{props.initializerOptions.inputs.inputs.map((inp, index) => {
return (
<div className="udapp_multiArg" key={index}>
<label htmlFor={inp.name}> {inp.name}: </label>
@ -261,9 +260,7 @@ export function ContractGUI (props: ContractGUIProps) {
<button onClick={handleExpandMultiClick} title={buttonOptions.title} data-id={buttonOptions.dataId} className={`udapp_instanceButton ${buttonOptions.classList}`}>{ buttonOptions.content }</button>
</div>
</div>
</div>
}
{ !props.deployOption &&
</div> :
<div className="udapp_contractActionsContainerMulti" style={{ display: toggleContainer ? 'flex' : 'none' }}>
<div className="udapp_contractActionsContainerMultiInner text-dark">
<div onClick={switchMethodViewOff} className="udapp_multiHeader">

@ -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
}
}
}
}

@ -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,

Loading…
Cancel
Save