Load compiled contracts for opened files

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

@ -1,3 +1,4 @@
import { ContractList } from '../reducers/runTab'
import { ContractData } from '../types'
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 {
type: 'FETCH_CONTRACT_LIST_SUCCESS',
payload: contracts

@ -75,11 +75,11 @@ export function ContractDropdownUI (props: ContractDropdownProps) {
}, [loadType, currentFile, compilationCount])
useEffect(() => {
if (selectedContract) {
const contract = contractList.find(contract => contract.alias === selectedContract)
if (selectedContract && contractList[currentFile]) {
const contract = contractList[currentFile].find(contract => contract.alias === selectedContract)
if (contract) {
const loadedContractData = props.getSelectedContract(selectedContract, contract.name)
const loadedContractData = props.getSelectedContract(selectedContract, contract.compiler)
if (loadedContractData) {
setLoadedContractData(loadedContractData)
@ -95,10 +95,10 @@ export function ContractDropdownUI (props: ContractDropdownProps) {
}, [contractList])
const initSelectedContract = () => {
if (contractList.length > 0) {
const contract = contractList.find(contract => contract.alias === selectedContract)
if (contractList[currentFile] && contractList[currentFile].length > 0) {
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>
<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' }}>
{ contractList.map((contract, index) => {
{ contractList[currentFile] && contractList[currentFile].map((contract, index) => {
return <option key={index} value={contract.alias}>{contract.alias} - {contract.file}</option>
}) }
</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>
</div>
<div>
<div className="udapp_deployDropdown">
{ contractList.length <= 0 ? 'No compiled contracts'
{ contractList[currentFile] && contractList[currentFile].length <= 0 ? 'No compiled contracts'
: loadedContractData ? <div>
<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">

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

@ -1,3 +1,5 @@
import { CompilerAbstract } from '@remix-project/remix-solidity-ts'
import { ContractList } from '../reducers/runTab'
import { RunTab } from './run-tab'
export interface RunTabProps {
plugin: RunTab
@ -147,11 +149,7 @@ export type MainnetPrompt = (
export interface ContractDropdownProps {
exEnvironment: string,
contracts: {
contractList: {
name: string,
alias: string,
file: string
}[],
contractList: ContractList,
loadType: 'abi' | 'sol' | 'other',
currentFile: string,
compilationCount: number,
@ -159,7 +157,7 @@ export interface ContractDropdownProps {
isSuccessful: boolean,
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,
passphrase: string,
setPassphrase: (passphrase: string) => void,

Loading…
Cancel
Save