Load compiled contracts for opened files

pull/5370/head
David Disu 3 years ago committed by yann300
parent 2b3d3c70fd
commit 792c719ed0
  1. 15
      libs/remix-ui/run-tab/src/lib/actions/index.ts
  2. 3
      libs/remix-ui/run-tab/src/lib/actions/payload.ts
  3. 18
      libs/remix-ui/run-tab/src/lib/components/contractDropdownUI.tsx
  4. 28
      libs/remix-ui/run-tab/src/lib/reducers/runTab.ts
  5. 10
      libs/remix-ui/run-tab/src/lib/types/index.ts

@ -8,6 +8,7 @@ import { RunTab } from '../types/run-tab'
import { CompilerAbstract } from '@remix-project/remix-solidity' import { CompilerAbstract } from '@remix-project/remix-solidity'
import * as remixLib from '@remix-project/remix-lib' import * as remixLib from '@remix-project/remix-lib'
import { ContractData, FuncABI, MainnetPrompt } from '../types' import { ContractData, FuncABI, MainnetPrompt } from '../types'
import { CompilerAbstract as CompilerAbstractType } from '@remix-project/remix-solidity-ts'
const txFormat = remixLib.execution.txFormat const txFormat = remixLib.execution.txFormat
declare global { declare global {
@ -95,6 +96,7 @@ const setupEvents = () => {
} else { } else {
dispatch(setLoadType('other')) dispatch(setLoadType('other'))
} }
dispatch(setCurrentFile(currentFile))
}) })
plugin.recorder.event.register('recorderCountChange', (count) => { plugin.recorder.event.register('recorderCountChange', (count) => {
@ -309,10 +311,10 @@ const broadcastCompilationResult = (file, source, languageVersion, data, input?)
plugin.compilersArtefacts.__last = compiler plugin.compilersArtefacts.__last = compiler
const contracts = getCompiledContracts(compiler).map((contract) => { const contracts = getCompiledContracts(compiler).map((contract) => {
return { name: languageVersion, alias: contract.name, file: contract.file } return { name: languageVersion, alias: contract.name, file: contract.file, compiler }
}) })
dispatch(fetchContractListSuccess(contracts)) dispatch(fetchContractListSuccess({ [file]: contracts }))
dispatch(setCurrentFile(file)) dispatch(setCurrentFile(file))
} }
@ -343,9 +345,9 @@ const getCompiledContracts = (compiler) => {
return contracts return contracts
} }
export const getSelectedContract = (contractName: string, compilerAtributeName: string) => { export const getSelectedContract = (contractName: string, compiler: CompilerAbstractType) => {
if (!contractName) return null if (!contractName) return null
const compiler = plugin.compilersArtefacts[compilerAtributeName] // const compiler = plugin.compilersArtefacts[compilerAtributeName]
if (!compiler) return null if (!compiler) return null
@ -571,8 +573,9 @@ export const loadAddress = (contract: ContractData, address: string) => {
return addInstance({ abi, address, name: '<at address>' }) return addInstance({ abi, address, name: '<at address>' })
} else if (loadType === 'instance') { } else if (loadType === 'instance') {
if (!contract) return dispatch(displayPopUp('No compiled contracts found.')) if (!contract) return dispatch(displayPopUp('No compiled contracts found.'))
const compiler = plugin.REACT_API.contracts.contractList.find(item => item.alias === contract.name) const currentFile = plugin.REACT_API.contracts.currentFile
const contractData = getSelectedContract(contract.name, compiler.name) const compiler = plugin.REACT_API.contracts.contractList[currentFile].find(item => item.alias === contract.name)
const contractData = getSelectedContract(contract.name, compiler.compiler)
return addInstance({ contractData, address, name: contract.name }) return addInstance({ contractData, address, name: contract.name })
} }
} }

@ -1,3 +1,4 @@
import { ContractList } from '../reducers/runTab'
import { ContractData } from '../types' import { ContractData } from '../types'
export const fetchAccountsListRequest = () => { export const fetchAccountsListRequest = () => {
@ -137,7 +138,7 @@ export const fetchContractListRequest = () => {
} }
} }
export const fetchContractListSuccess = (contracts: { name: string, alias: string, file: string }[]) => { export const fetchContractListSuccess = (contracts: ContractList) => {
return { return {
type: 'FETCH_CONTRACT_LIST_SUCCESS', type: 'FETCH_CONTRACT_LIST_SUCCESS',
payload: contracts payload: contracts

@ -75,11 +75,11 @@ export function ContractDropdownUI (props: ContractDropdownProps) {
}, [loadType, currentFile, compilationCount]) }, [loadType, currentFile, compilationCount])
useEffect(() => { useEffect(() => {
if (selectedContract) { if (selectedContract && contractList[currentFile]) {
const contract = contractList.find(contract => contract.alias === selectedContract) const contract = contractList[currentFile].find(contract => contract.alias === selectedContract)
if (contract) { if (contract) {
const loadedContractData = props.getSelectedContract(selectedContract, contract.name) const loadedContractData = props.getSelectedContract(selectedContract, contract.compiler)
if (loadedContractData) { if (loadedContractData) {
setLoadedContractData(loadedContractData) setLoadedContractData(loadedContractData)
@ -95,10 +95,10 @@ export function ContractDropdownUI (props: ContractDropdownProps) {
}, [contractList]) }, [contractList])
const initSelectedContract = () => { const initSelectedContract = () => {
if (contractList.length > 0) { if (contractList[currentFile] && contractList[currentFile].length > 0) {
const contract = contractList.find(contract => contract.alias === selectedContract) const contract = contractList[currentFile].find(contract => contract.alias === selectedContract)
if (!selectedContract || !contract) setSelectedContract(contractList[0].alias) if (!selectedContract || !contract) setSelectedContract(contractList[currentFile][0].alias)
} }
} }
@ -202,16 +202,16 @@ export function ContractDropdownUI (props: ContractDropdownProps) {
<label className="udapp_settingsLabel">Contract</label> <label className="udapp_settingsLabel">Contract</label>
<div className="udapp_subcontainer"> <div className="udapp_subcontainer">
<select value={selectedContract} onChange={handleContractChange} className="udapp_contractNames custom-select" disabled={contractOptions.disabled} title={contractOptions.title} style={{ display: loadType === 'abi' ? 'none' : 'block' }}> <select value={selectedContract} onChange={handleContractChange} className="udapp_contractNames custom-select" disabled={contractOptions.disabled} title={contractOptions.title} style={{ display: loadType === 'abi' ? 'none' : 'block' }}>
{ contractList.map((contract, index) => { { contractList[currentFile] && 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> </select>
{ (contractList.length <= 0) && <i style={{ display: compFails }} title="No contract compiled yet or compilation failed. Please check the compile tab for more information." className="m-2 ml-3 fas fa-times-circle udapp_errorIcon" ></i> } { (contractList[currentFile] && contractList[currentFile].length <= 0) && <i style={{ display: compFails }} title="No contract compiled yet or compilation failed. Please check the compile tab for more information." className="m-2 ml-3 fas fa-times-circle udapp_errorIcon" ></i> }
<span className="py-1" style={{ display: abiLabel.display }}>{ abiLabel.content }</span> <span className="py-1" style={{ display: abiLabel.display }}>{ abiLabel.content }</span>
</div> </div>
<div> <div>
<div className="udapp_deployDropdown"> <div className="udapp_deployDropdown">
{ contractList.length <= 0 ? 'No compiled contracts' { contractList[currentFile] && contractList[currentFile].length <= 0 ? 'No compiled contracts'
: loadedContractData ? <div> : loadedContractData ? <div>
<ContractGUI title='Deploy' funcABI={constructorInterface} clickCallBack={clickCallback} inputs={constructorInputs} widthClass='w-50' evmBC={loadedContractData.bytecodeObject} lookupOnly={false} /> <ContractGUI title='Deploy' 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"> <div className="d-flex py-1 align-items-center custom-control custom-checkbox">

@ -1,10 +1,19 @@
import { CompilerAbstract } from '@remix-project/remix-solidity-ts'
import { ContractData } from '../types' import { ContractData } from '../types'
interface Action { interface Action {
type: string type: string
payload: any payload: any
} }
export interface Contract {
name: string,
alias: string,
file: string,
compiler: CompilerAbstract
}
export interface ContractList {
[file: string]: Contract[]
}
export interface RunTabState { export interface RunTabState {
accounts: { accounts: {
loadedAccounts: Record<string, string>, loadedAccounts: Record<string, string>,
@ -46,10 +55,13 @@ export interface RunTabState {
matchPassphrase: string, matchPassphrase: string,
contracts: { contracts: {
contractList: { contractList: {
name: string, [file: string]: {
alias: string, name: string,
file: string alias: string,
}[], file: string,
compiler: CompilerAbstract
}[]
},
loadType: 'abi' | 'sol' | 'other' loadType: 'abi' | 'sol' | 'other'
currentFile: string, currentFile: string,
compilationCount: number, compilationCount: number,
@ -141,7 +153,7 @@ export const runTabInitialState: RunTabState = {
passphrase: '', passphrase: '',
matchPassphrase: '', matchPassphrase: '',
contracts: { contracts: {
contractList: [], contractList: {},
loadType: 'other', loadType: 'other',
currentFile: '', currentFile: '',
compilationCount: 0, compilationCount: 0,
@ -438,13 +450,13 @@ export const runTabReducer = (state: RunTabState = runTabInitialState, action: A
} }
case 'FETCH_CONTRACT_LIST_SUCCESS': { case 'FETCH_CONTRACT_LIST_SUCCESS': {
const payload: { name: string, alias: string, file: string }[] = action.payload const payload: ContractList = action.payload
return { return {
...state, ...state,
contracts: { contracts: {
...state.contracts, ...state.contracts,
contractList: payload, contractList: { ...state.contracts.contractList, ...payload },
isSuccessful: true, isSuccessful: true,
isRequesting: false, isRequesting: false,
error: null error: null

@ -1,3 +1,5 @@
import { CompilerAbstract } from '@remix-project/remix-solidity-ts'
import { ContractList } from '../reducers/runTab'
import { RunTab } from './run-tab' import { RunTab } from './run-tab'
export interface RunTabProps { export interface RunTabProps {
plugin: RunTab plugin: RunTab
@ -147,11 +149,7 @@ export type MainnetPrompt = (
export interface ContractDropdownProps { export interface ContractDropdownProps {
exEnvironment: string, exEnvironment: string,
contracts: { contracts: {
contractList: { contractList: ContractList,
name: string,
alias: string,
file: string
}[],
loadType: 'abi' | 'sol' | 'other', loadType: 'abi' | 'sol' | 'other',
currentFile: string, currentFile: string,
compilationCount: number, compilationCount: number,
@ -159,7 +157,7 @@ export interface ContractDropdownProps {
isSuccessful: boolean, isSuccessful: boolean,
error: string error: string
}, },
getSelectedContract: (contractName: string, compilerAtributeName: string) => ContractData, getSelectedContract: (contractName: string, compiler: CompilerAbstract) => ContractData,
modal: (title: string, message: string | JSX.Element, okLabel: string, okFn: () => void, cancelLabel?: string, cancelFn?: () => void) => void, modal: (title: string, message: string | JSX.Element, okLabel: string, okFn: () => void, cancelLabel?: string, cancelFn?: () => void) => void,
passphrase: string, passphrase: string,
setPassphrase: (passphrase: string) => void, setPassphrase: (passphrase: string) => void,

Loading…
Cancel
Save