Merge pull request #2987 from ethereum/dropdowncontracts

Dropdowncontracts
pull/2990/head
bunsenstraat 2 years ago committed by GitHub
commit 21f68ba9bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      libs/remix-ui/run-tab/src/lib/actions/events.ts
  2. 16
      libs/remix-ui/run-tab/src/lib/actions/payload.ts
  3. 26
      libs/remix-ui/run-tab/src/lib/components/contractDropdownUI.tsx
  4. 2
      libs/remix-ui/run-tab/src/lib/constants/index.ts
  5. 30
      libs/remix-ui/run-tab/src/lib/reducers/runTab.ts
  6. 3
      libs/remix-ui/run-tab/src/lib/run-tab.tsx
  7. 1
      libs/remix-ui/run-tab/src/lib/types/index.ts
  8. 18
      libs/remixd/src/services/hardhatClient.ts

@ -2,10 +2,11 @@ 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 { addDeployOption, clearAllInstances, clearRecorderCount, fetchContractListSuccess, resetUdapp, setCompilationSource, setCurrentContract, setCurrentFile, setLoadType, setProxyEnvAddress, setRecorderCount, setSendValue } from "./payload"
import { addDeployOption, clearAllInstances, clearRecorderCount, fetchContractListSuccess, resetUdapp, setCurrentContract, setCurrentFile, setLoadType, setProxyEnvAddress, setRecorderCount, setRemixDActivated, setSendValue } from "./payload"
import { CompilerAbstract } from '@remix-project/remix-solidity'
import * as ethJSUtil from 'ethereumjs-util'
import Web3 from 'web3'
import { Plugin } from "@remixproject/engine"
const _paq = window._paq = window._paq || []
export const setupEvents = (plugin: RunTab, dispatch: React.Dispatch<any>) => {
@ -74,6 +75,21 @@ export const setupEvents = (plugin: RunTab, dispatch: React.Dispatch<any>) => {
plugin.on('filePanel', 'setWorkspace', () => {
dispatch(resetUdapp())
resetAndInit(plugin)
plugin.call('manager', 'isActive', 'remixd').then((activated) => {
dispatch(setRemixDActivated(activated))
})
})
plugin.on('manager', 'pluginActivated', (plugin: Plugin) => {
if (plugin.name === 'remixd') {
dispatch(setRemixDActivated(true))
}
})
plugin.on('manager', 'pluginDeactivated', (plugin: Plugin) => {
if (plugin.name === 'remixd') {
dispatch(setRemixDActivated(false))
}
})
plugin.fileManager.events.on('currentFileChanged', (currentFile: string) => {
@ -107,7 +123,7 @@ const broadcastCompilationResult = async (compilerName: string, plugin: RunTab,
plugin.compilersArtefacts.__last = compiler
const contracts = getCompiledContracts(compiler).map((contract) => {
return { name: languageVersion, alias: contract.name, file: contract.file, compiler }
return { name: languageVersion, alias: contract.name, file: contract.file, compiler, compilerName }
})
if ((contracts.length > 0)) {
const contractsInCompiledFile = contracts.filter(obj => obj.file === file)
@ -127,7 +143,6 @@ const broadcastCompilationResult = async (compilerName: string, plugin: RunTab,
}
dispatch(fetchContractListSuccess({ [file]: contracts }))
dispatch(setCurrentFile(file))
dispatch(setCompilationSource(compilerName))
// TODO: set current contract
}

@ -1,6 +1,6 @@
import { ContractList } from '../reducers/runTab'
import { ContractData } from '@remix-project/core-plugin'
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, 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_COMPILATION_SOURCE, 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_PROXY_ENV_ADDRESS, SET_RECORDER_COUNT, SET_SELECTED_ACCOUNT, SET_SEND_UNIT, SET_SEND_VALUE } from '../constants'
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, 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_PROXY_ENV_ADDRESS, SET_RECORDER_COUNT, SET_SELECTED_ACCOUNT, SET_SEND_UNIT, SET_SEND_VALUE, SET_REMIXD_ACTIVATED } from '../constants'
import { DeployMode, DeployOptions } from '../types'
export const fetchAccountsListRequest = () => {
@ -168,13 +168,6 @@ export const setCurrentFile = (file: string) => {
}
}
export const setCompilationSource = (source: string) => {
return {
type: SET_COMPILATION_SOURCE,
payload: source
}
}
export const setIpfsCheckedState = (state: boolean) => {
return {
type: SET_IPFS_CHECKED_STATE,
@ -315,3 +308,10 @@ export const setProxyEnvAddress = (key: string) => {
type: SET_PROXY_ENV_ADDRESS
}
}
export const setRemixDActivated = (activated: boolean) => {
return {
payload: activated,
type: SET_REMIXD_ACTIVATED
}
}

@ -28,6 +28,7 @@ export function ContractDropdownUI (props: ContractDropdownProps) {
const [loadedContractData, setLoadedContractData] = useState<ContractData>(null)
const [constructorInterface, setConstructorInterface] = useState<FuncABI>(null)
const [constructorInputs, setConstructorInputs] = useState(null)
const [compilerName, setCompilerName] = useState<string>('')
const contractsRef = useRef<HTMLSelectElement>(null)
const atAddressValue = useRef<HTMLInputElement>(null)
const { contractList, loadType, currentFile, compilationSource, currentContract, compilationCount, deployOptions, proxyKey } = props.contracts
@ -98,6 +99,7 @@ export function ContractDropdownUI (props: ContractDropdownProps) {
useEffect(() => {
initSelectedContract()
updateCompilerName()
}, [contractList])
useEffect(() => {
@ -107,11 +109,13 @@ export function ContractDropdownUI (props: ContractDropdownProps) {
if (contracts && contracts.length > 0) {
props.setSelectedContract(contracts[0].alias)
}
updateCompilerName()
}, [currentFile])
const initSelectedContract = () => {
const contracts = contractList[currentFile]
if (contracts && contracts.length > 0) {
const contract = contracts.find(contract => contract.alias === currentContract)
@ -212,9 +216,21 @@ export function ContractDropdownUI (props: ContractDropdownProps) {
window.localStorage.setItem(`ipfs/${props.exEnvironment}/${props.networkName}`, checkedState.toString())
}
const updateCompilerName = () => {
if (contractsRef.current.value) {
contractList[currentFile].forEach(contract => {
if (contract.alias === contractsRef.current.value) {
setCompilerName(contract.compilerName)
}
})
} else{
setCompilerName('')
}
}
const handleContractChange = (e) => {
const value = e.target.value
updateCompilerName()
props.setSelectedContract(value)
}
@ -241,8 +257,9 @@ export function ContractDropdownUI (props: ContractDropdownProps) {
<div className='d-flex justify-content-between'>
<div className="d-flex justify-content-between align-items-end">
<label className="udapp_settingsLabel pr-1">Contract</label>
<div className="d-flex">{ Object.keys(props.contracts.contractList).length > 0 && compilationSource !== '' && <label className="text-capitalize" style={{maxHeight: '0.6rem', lineHeight: '1rem'}} data-id="udappCompiledBy">(Compiled by {compilationSource})</label>}</div>
<div className="d-flex">{compilerName && compilerName !== '' && <label className="text-capitalize" style={{ maxHeight: '0.6rem', lineHeight: '1rem' }} data-id="udappCompiledBy">(Compiled by {compilerName})</label>}</div>
</div>
{props.remixdActivated ?
<OverlayTrigger placement={'right'} overlay={
<Tooltip className="text-nowrap" id="info-sync-compiled-contract">
<div>Click here to import contracts compiled from an external framework.</div>
@ -256,11 +273,14 @@ export function ContractDropdownUI (props: ContractDropdownProps) {
<i style={{ cursor: 'pointer' }} className="fa fa-refresh mr-2 mt-2" aria-hidden="true"></i>
</button>
</OverlayTrigger>
: null}
</div>
<div className="udapp_subcontainer">
<select ref={contractsRef} value={currentContract} onChange={handleContractChange} className="udapp_contractNames custom-select" disabled={contractOptions.disabled} title={contractOptions.title} style={{ display: loadType === 'abi' && !isContractFile(currentFile) ? 'none' : 'block' }}>
{(contractList[currentFile] || []).map((contract, index) => {
return <option key={index} value={contract.alias}>{contract.alias} - {contract.file}</option>
return <option key={index} value={contract.alias}>
{contract.alias} - {contract.file}
</option>
})}
</select>
<span className="py-1" style={{ display: abiLabel.display }}>{abiLabel.content}</span>

@ -25,7 +25,6 @@ export const FETCH_CONTRACT_LIST_SUCCESS = 'FETCH_CONTRACT_LIST_SUCCESS'
export const FETCH_CONTRACT_LIST_FAILED = 'FETCH_CONTRACT_LIST_FAILED'
export const SET_LOAD_TYPE = 'SET_LOAD_TYPE'
export const SET_CURRENT_FILE = 'SET_CURRENT_FILE'
export const SET_COMPILATION_SOURCE = 'SET_COMPILATION_SOURCE'
export const SET_IPFS_CHECKED_STATE = 'SET_IPFS_CHECKED_STATE'
export const SET_GAS_PRICE_STATUS = 'SET_GAS_PRICE_STATUS'
export const SET_CONFIRM_SETTINGS = 'SET_CONFIRM_SETTINGS'
@ -46,3 +45,4 @@ export const REMOVE_DEPLOY_OPTION = 'REMOVE_DEPLOY_OPTION'
export const SET_DEPLOY_OPTIONS = 'SET_DEPLOY_OPTIONS'
export const SET_CURRENT_CONTRACT = 'SET_CURRENT_CONTRACT'
export const SET_PROXY_ENV_ADDRESS = 'SET_PROXY_ENV_ADDRESS'
export const SET_REMIXD_ACTIVATED = 'SET_REMIXD_ACTIVATED'

@ -1,7 +1,7 @@
import { CompilerAbstract } from '@remix-project/remix-solidity-ts'
import { ContractData } from '@remix-project/core-plugin'
import { DeployOptions } from '../types'
import { 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_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_PROXY_ENV_ADDRESS, ADD_DEPLOY_OPTION, REMOVE_DEPLOY_OPTION, SET_COMPILATION_SOURCE } from '../constants'
import { 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_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_PROXY_ENV_ADDRESS, ADD_DEPLOY_OPTION, REMOVE_DEPLOY_OPTION, SET_REMIXD_ACTIVATED } from '../constants'
declare const window: any
interface Action {
@ -12,7 +12,8 @@ export interface Contract {
name: string,
alias: string,
file: string,
compiler: CompilerAbstract
compiler: CompilerAbstract,
compilerName: string
}
export interface ContractList {
@ -64,6 +65,7 @@ export interface RunTabState {
alias: string,
file: string,
compiler: CompilerAbstract
compilerName: string
}[]
},
deployOptions: { [file: string]: { [name: string]: DeployOptions } },
@ -99,6 +101,7 @@ export interface RunTabState {
pathToScenario: string,
transactionCount: number
}
remixdActivated: boolean
}
export const runTabInitialState: RunTabState = {
@ -180,7 +183,8 @@ export const runTabInitialState: RunTabState = {
recorder: {
pathToScenario: 'scenario.json',
transactionCount: 0
}
},
remixdActivated: false
}
type AddProvider = {
@ -519,18 +523,6 @@ export const runTabReducer = (state: RunTabState = runTabInitialState, action: A
}
}
case SET_COMPILATION_SOURCE: {
const payload: string = action.payload
return {
...state,
contracts: {
...state.contracts,
compilationSource: payload,
}
}
}
case SET_IPFS_CHECKED_STATE: {
const payload: boolean = action.payload
@ -734,6 +726,14 @@ export const runTabReducer = (state: RunTabState = runTabInitialState, action: A
}
}
case SET_REMIXD_ACTIVATED: {
const payload: boolean = action.payload
return {
...state,
remixdActivated: payload
}
}
default:
return state
}

@ -34,7 +34,7 @@ import { PublishToStorage } from '@remix-ui/publish-to-storage'
import { PassphrasePrompt } from './components/passphrase'
import { MainnetPrompt } from './components/mainnet'
import { ScenarioPrompt } from './components/scenario'
import { setIpfsCheckedState } from './actions/payload'
import { setIpfsCheckedState, setRemixDActivated } from './actions/payload'
export function RunTabUI (props: RunTabProps) {
const { plugin } = props
@ -241,6 +241,7 @@ export function RunTabUI (props: RunTabProps) {
networkName={runTab.networkName}
setNetworkName={setNetworkName}
setSelectedContract={updateSelectedContract}
remixdActivated={runTab.remixdActivated}
/>
<RecorderUI
gasEstimationPrompt={gasEstimationPrompt}

@ -165,6 +165,7 @@ export interface ContractDropdownProps {
networkName: string,
setNetworkName: (name: string) => void,
setSelectedContract: (contractName: string) => void
remixdActivated: boolean
}
export interface RecorderProps {

@ -3,7 +3,7 @@ import { PluginClient } from '@remixproject/plugin'
import * as chokidar from 'chokidar'
import * as utils from '../utils'
import * as fs from 'fs-extra'
import { basename, join } from 'path'
import { join } from 'path'
const { spawn } = require('child_process') // eslint-disable-line
export class HardhatClient extends PluginClient {
@ -63,6 +63,7 @@ export class HardhatClient extends PluginClient {
private async processArtifact() {
// resolving the files
const folderFiles = await fs.readdir(this.buildPath)
const targetsSynced = []
// name of folders are file names
for (const file of folderFiles) { // ["artifacts/contracts/Greeter.sol/"]
const contractFilePath = join(this.buildPath, file)
@ -87,14 +88,18 @@ export class HardhatClient extends PluginClient {
const jsonStd = JSON.parse(contentStd)
compilationResult.target = jsonStd.sourceName
// this is the full compilation result
console.log('Processing Hardhat artifact for file: ', file)
targetsSynced.push(compilationResult.target)
const path = join(contractFilePath, jsonDbg.buildInfo)
const content = await fs.readFile(path, { encoding: 'utf-8' })
await this.feedContractArtifactFile(content, compilationResult)
}
if (compilationResult.target) {
// we are only interested in the contracts that are in the target of the compilation
compilationResult.output = {
...compilationResult.output,
contracts: { [compilationResult.target]: compilationResult.output.contracts[compilationResult.target] }
}
this.emit('compilationFinished', compilationResult.target, { sources: compilationResult.input }, 'soljson', compilationResult.output, compilationResult.solcVersion)
}
}
@ -104,6 +109,11 @@ export class HardhatClient extends PluginClient {
this.call('terminal', 'log', 'receiving compilation result from Hardhat')
this.warnLog = true
}
if (targetsSynced.length) {
console.log(`Processing artifacts for files: ${[...new Set(targetsSynced)].join(', ')}`)
// @ts-ignore
this.call('terminal', 'log', `synced with Hardhat: ${[...new Set(targetsSynced)].join(', ')}`)
}
}
listenOnHardhatCompilation() {
@ -122,8 +132,6 @@ export class HardhatClient extends PluginClient {
async sync() {
console.log('syncing from Hardhat')
this.processArtifact()
// @ts-ignore
this.call('terminal', 'log', 'synced with Hardhat')
}
async feedContractArtifactFile(artifactContent, compilationResultPart) {

Loading…
Cancel
Save