diff --git a/apps/debugger/src/app/debugger-api.ts b/apps/debugger/src/app/debugger-api.ts index 8528759d14..2b5a149d16 100644 --- a/apps/debugger/src/app/debugger-api.ts +++ b/apps/debugger/src/app/debugger-api.ts @@ -119,17 +119,17 @@ export const DebuggerApiMixin = (Base) => class extends Base { debug (hash) { this.debugHash = hash - this.onDebugRequestedListener(hash) + if (this.onDebugRequestedListener) this.onDebugRequestedListener(hash) } onActivation () { - this.on('editor', 'breakpointCleared', (fileName, row) => this.onBreakpointClearedListener(fileName, row)) - this.on('editor', 'breakpointAdded', (fileName, row) => this.onBreakpointAddedListener(fileName, row)) - this.on('editor', 'contentChanged', () => this.onEditorContentChangedListener()) + this.on('editor', 'breakpointCleared', (fileName, row) => { if (this.onBreakpointClearedListener) this.onBreakpointClearedListener(fileName, row) }) + this.on('editor', 'breakpointAdded', (fileName, row) => { if (this.onBreakpointAddedListener) this.onBreakpointAddedListener(fileName, row) }) + this.on('editor', 'contentChanged', () => { if (this.onEditorContentChangedListener) this.onEditorContentChangedListener() }) } onDeactivation () { - this.onRemoveHighlightsListener() + if (this.onRemoveHighlightsListener) this.onRemoveHighlightsListener() this.off('editor', 'breakpointCleared') this.off('editor', 'breakpointAdded') this.off('editor', 'contentChanged') diff --git a/apps/remix-ide/src/app/editor/editor.js b/apps/remix-ide/src/app/editor/editor.js index 88466a6e26..92b4b0cb8d 100644 --- a/apps/remix-ide/src/app/editor/editor.js +++ b/apps/remix-ide/src/app/editor/editor.js @@ -49,7 +49,7 @@ const profile = { name: 'editor', description: 'service - editor', version: packageJson.version, - methods: ['highlight', 'discardHighlight', 'discardHighlightAt', 'clearAnnotations', 'addAnnotation'] + methods: ['highlight', 'discardHighlight', 'discardHighlightAt', 'clearAnnotations', 'addAnnotation', 'gotoLine'] } class Editor extends Plugin { diff --git a/apps/remix-ide/src/app/tabs/compile-tab.js b/apps/remix-ide/src/app/tabs/compile-tab.js index 6d84a9721f..14ca4ae30e 100644 --- a/apps/remix-ide/src/app/tabs/compile-tab.js +++ b/apps/remix-ide/src/app/tabs/compile-tab.js @@ -52,15 +52,7 @@ class CompileTab extends ViewPlugin { eventHandlers: {}, loading: false } - this.compileTabLogic = new CompileTabLogic( - this.queryParams, - this.fileManager, - this.editor, - this.config, - this.fileProvider, - this.contentImport, - this.setCompileErrors.bind(this) - ) + this.compileTabLogic = new CompileTabLogic(this, this.contentImport) this.compiler = this.compileTabLogic.compiler this.compileTabLogic.init() this.contractMap = {} @@ -203,6 +195,10 @@ class CompileTab extends ViewPlugin { return this.compileTabLogic.compiler.state.lastCompilationResult } + addExternalFile (fileName, content) { + this.fileProvider.addExternal(fileName, content) + } + /** * compile using @arg fileName. * The module UI will be updated accordingly to the new compilation result. @@ -278,6 +274,50 @@ class CompileTab extends ViewPlugin { , this.el) } + getParameters () { + return this.queryParams.get() + } + + setParameters (params) { + this.queryParams.update(params) + } + + getConfiguration (name) { + return this.config.get(name) + } + + setConfiguration (name, value) { + this.config.set(name, value) + } + + fileProviderOf (fileName) { + return this.fileManager.fileProviderOf(fileName) + } + + getFileManagerMode () { + return this.fileManager.mode + } + + fileExists (fileName) { + return this.call('fileManager', 'exists', fileName) + } + + writeFile (fileName, content) { + return this.call('fileManager', 'writeFile', fileName, content) + } + + readFile (fileName) { + return this.call('fileManager', 'readFile', fileName) + } + + saveCurrentFile () { + return this.fileManager.saveCurrentFile() + } + + open (fileName) { + return this.call('fileManager', 'open', fileName) + } + onActivation () { this.call('manager', 'activatePlugin', 'solidity-logic') this.listenToEvents() diff --git a/apps/remix-ide/src/app/ui/TreeView.js b/apps/remix-ide/src/app/ui/TreeView.js index 413f49f667..a282cafbd6 100644 --- a/apps/remix-ide/src/app/ui/TreeView.js +++ b/apps/remix-ide/src/app/ui/TreeView.js @@ -27,7 +27,7 @@ var css = csjs` word-break: break-all; } .label_key { - min-width: 15%; + min-width: max-content; max-width: 80%; word-break: break-word; } diff --git a/apps/remix-ide/src/app/ui/landing-page/landing-page.js b/apps/remix-ide/src/app/ui/landing-page/landing-page.js index 60d762472f..744b5c988b 100644 --- a/apps/remix-ide/src/app/ui/landing-page/landing-page.js +++ b/apps/remix-ide/src/app/ui/landing-page/landing-page.js @@ -538,7 +538,6 @@ export class LandingPage extends ViewPlugin {
-
diff --git a/libs/remix-debug/src/solidity-decoder/localDecoder.ts b/libs/remix-debug/src/solidity-decoder/localDecoder.ts index 9564efc93b..70df3e9715 100644 --- a/libs/remix-debug/src/solidity-decoder/localDecoder.ts +++ b/libs/remix-debug/src/solidity-decoder/localDecoder.ts @@ -21,7 +21,7 @@ export async function solidityLocals (vmtraceIndex, internalTreeCall, stack, mem locals[name] = await variable.type.decodeFromStack(variable.stackDepth, stack, memory, storageResolver, calldata, cursor, variable) } catch (e) { console.log(e) - locals[name] = '' + locals[name] = { error: '' } } } } diff --git a/libs/remix-debug/src/solidity-decoder/stateDecoder.ts b/libs/remix-debug/src/solidity-decoder/stateDecoder.ts index b7908da3c3..709faff99c 100644 --- a/libs/remix-debug/src/solidity-decoder/stateDecoder.ts +++ b/libs/remix-debug/src/solidity-decoder/stateDecoder.ts @@ -25,7 +25,7 @@ export async function decodeState (stateVars, storageResolver) { ret[stateVar.name] = decoded } catch (e) { console.log(e) - ret[stateVar.name] = '' + ret[stateVar.name] = { error: '' } } } return ret @@ -64,6 +64,6 @@ export async function solidityState (storageResolver, astList, contractName) { try { return await decodeState(stateVars, storageResolver) } catch (e) { - return '' + return { error: '' } } } diff --git a/libs/remix-debug/src/solidity-decoder/types/ArrayType.ts b/libs/remix-debug/src/solidity-decoder/types/ArrayType.ts index 3792579531..eb5eff4d30 100644 --- a/libs/remix-debug/src/solidity-decoder/types/ArrayType.ts +++ b/libs/remix-debug/src/solidity-decoder/types/ArrayType.ts @@ -36,7 +36,7 @@ export class ArrayType extends RefType { } catch (e) { console.log(e) return { - value: '', + error: '', type: this.typeName } } @@ -56,7 +56,7 @@ export class ArrayType extends RefType { ret.push(await this.underlyingType.decodeFromStorage(currentLocation, storageResolver)) } catch (e) { return { - value: '', + error: '', type: this.typeName } } @@ -84,7 +84,7 @@ export class ArrayType extends RefType { } if (isNaN(length)) { return { - value: '', + error: '', type: 'Error' } } diff --git a/libs/remix-debug/src/solidity-decoder/types/DynamicByteArray.ts b/libs/remix-debug/src/solidity-decoder/types/DynamicByteArray.ts index 5ac37c1ea2..85cf69ef88 100644 --- a/libs/remix-debug/src/solidity-decoder/types/DynamicByteArray.ts +++ b/libs/remix-debug/src/solidity-decoder/types/DynamicByteArray.ts @@ -16,7 +16,7 @@ export class DynamicByteArray extends RefType { value = await extractHexValue(location, storageResolver, this.storageBytes) } catch (e) { console.log(e) - return { value: '', type: this.typeName } + return { error: '', type: this.typeName } } const length = new BN(value, 16) if (length.testn(0)) { @@ -27,7 +27,7 @@ export class DynamicByteArray extends RefType { currentSlot = await readFromStorage(dataPos, storageResolver) } catch (e) { console.log(e) - return { value: '', type: this.typeName } + return { error: '', type: this.typeName } } while (length.gt(new BN(ret.length)) && ret.length < 32000) { currentSlot = currentSlot.replace('0x', '') @@ -37,7 +37,7 @@ export class DynamicByteArray extends RefType { currentSlot = await readFromStorage(dataPos, storageResolver) } catch (e) { console.log(e) - return { value: '', type: this.typeName } + return { error: '', type: this.typeName } } } return { value: '0x' + ret.replace(/(00)+$/, ''), length: '0x' + length.toString(16), type: this.typeName } diff --git a/libs/remix-debug/src/solidity-decoder/types/StringType.ts b/libs/remix-debug/src/solidity-decoder/types/StringType.ts index 8e31b3d17f..849b8f65a3 100644 --- a/libs/remix-debug/src/solidity-decoder/types/StringType.ts +++ b/libs/remix-debug/src/solidity-decoder/types/StringType.ts @@ -15,17 +15,17 @@ export class StringType extends DynamicByteArray { decoded = await super.decodeFromStorage(location, storageResolver) } catch (e) { console.log(e) - return '' + return { error: '' } } return format(decoded) } - async decodeFromStack (stackDepth, stack, memory, calldata, variableDetails?) { + async decodeFromStack (stackDepth, stack, memory, storageResolver, calldata, cursor, variableDetails?) { try { - return await super.decodeFromStack(stackDepth, stack, memory, null, calldata, variableDetails) + return await super.decodeFromStack(stackDepth, stack, memory, storageResolver, calldata, cursor, variableDetails) } catch (e) { console.log(e) - return '' + return { error: '' } } } diff --git a/libs/remix-debug/src/solidity-decoder/types/Struct.ts b/libs/remix-debug/src/solidity-decoder/types/Struct.ts index f6ea2748bc..1995471ffb 100644 --- a/libs/remix-debug/src/solidity-decoder/types/Struct.ts +++ b/libs/remix-debug/src/solidity-decoder/types/Struct.ts @@ -22,7 +22,7 @@ export class Struct extends RefType { ret[item.name] = await item.type.decodeFromStorage(globalLocation, storageResolver) } catch (e) { console.log(e) - ret[item.name] = '' + ret[item.name] = { error: '' } } } return { value: ret, type: this.typeName } diff --git a/libs/remix-debug/src/solidity-decoder/types/ValueType.ts b/libs/remix-debug/src/solidity-decoder/types/ValueType.ts index 63bd4ae0f0..60d3a8ebed 100644 --- a/libs/remix-debug/src/solidity-decoder/types/ValueType.ts +++ b/libs/remix-debug/src/solidity-decoder/types/ValueType.ts @@ -31,7 +31,7 @@ export class ValueType { return { value: this.decodeValue(value), type: this.typeName } } catch (e) { console.log(e) - return { value: '', type: this.typeName } + return { error: '', type: this.typeName } } } @@ -43,7 +43,7 @@ export class ValueType { * @param {String} - memory * @return {Object} - decoded value */ - async decodeFromStack (stackDepth, stack, memory, calldata, variableDetails?) { + async decodeFromStack (stackDepth, stack, memory, storageResolver, calldata, cursor, variableDetails?) { let value if (stackDepth >= stack.length) { value = this.decodeValue('') diff --git a/libs/remix-simulator/src/methods/blocks.ts b/libs/remix-simulator/src/methods/blocks.ts index 7ac7bc179f..d40f13c491 100644 --- a/libs/remix-simulator/src/methods/blocks.ts +++ b/libs/remix-simulator/src/methods/blocks.ts @@ -41,6 +41,7 @@ export class Blocks { } const b = { + baseFeePerGas: '0x01', number: this.toHex(block.header.number), hash: this.toHex(block.hash()), parentHash: this.toHex(block.header.parentHash), @@ -73,6 +74,7 @@ export class Blocks { const block = this.vmContext.blocks[payload.params[0]] const b = { + baseFeePerGas: '0x01', number: this.toHex(block.header.number), hash: this.toHex(block.hash()), parentHash: this.toHex(block.header.parentHash), diff --git a/libs/remix-simulator/src/methods/transactions.ts b/libs/remix-simulator/src/methods/transactions.ts index 91f1f00a30..90e3df270f 100644 --- a/libs/remix-simulator/src/methods/transactions.ts +++ b/libs/remix-simulator/src/methods/transactions.ts @@ -193,6 +193,7 @@ export class Transactions { blockNumber: '0x' + txBlock.header.number.toString('hex'), from: receipt.from, gas: Web3.utils.toHex(receipt.gas), + chainId: '0xd05', // 'gasPrice': '2000000000000', // 0x123 gasPrice: '0x4a817c800', // 20000000000 hash: receipt.transactionHash, @@ -239,6 +240,7 @@ export class Transactions { blockNumber: '0x' + txBlock.header.number.toString('hex'), from: receipt.from, gas: Web3.utils.toHex(receipt.gas), + chainId: '0xd05', // 'gasPrice': '2000000000000', // 0x123 gasPrice: '0x4a817c800', // 20000000000 hash: receipt.transactionHash, @@ -282,6 +284,7 @@ export class Transactions { from: receipt.from, gas: Web3.utils.toHex(receipt.gas), // 'gasPrice': '2000000000000', // 0x123 + chainId: '0xd05', gasPrice: '0x4a817c800', // 20000000000 hash: receipt.transactionHash, input: receipt.input, diff --git a/libs/remix-simulator/test/blocks.ts b/libs/remix-simulator/test/blocks.ts index 7a78b44ed8..9ef7df7537 100644 --- a/libs/remix-simulator/test/blocks.ts +++ b/libs/remix-simulator/test/blocks.ts @@ -18,6 +18,7 @@ describe('blocks', () => { const block = await web3.eth.getBlock(0) const expectedBlock = { + baseFeePerGas: '0x01', difficulty: '69762765929000', extraData: '0x0', gasLimit: 8000000, diff --git a/libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx b/libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx index ac802457e2..0def604fdc 100644 --- a/libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx +++ b/libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx @@ -20,6 +20,8 @@ export const DebuggerUI = (props: DebuggerUIProps) => { contractAddress: null, to: null }, + currentBlock: null, + currentTransaction: null, blockNumber: null, txNumber: '', debugging: false, @@ -137,6 +139,8 @@ export const DebuggerUI = (props: DebuggerUIProps) => { contractAddress: null, to: null }, + currentBlock: null, + currentTransaction: null, blockNumber: null, ready: { vmDebugger: false, @@ -182,8 +186,12 @@ export const DebuggerUI = (props: DebuggerUIProps) => { console.error(e) } let currentReceipt + let currentBlock + let currentTransaction try { currentReceipt = await web3.eth.getTransactionReceipt(txNumber) + currentBlock = await web3.eth.getBlock(currentReceipt.blockHash) + currentTransaction = await web3.eth.getTransaction(txNumber) } catch (e) { setState(prevState => { return { @@ -220,6 +228,8 @@ export const DebuggerUI = (props: DebuggerUIProps) => { txNumber, debugging: true, currentReceipt, + currentBlock, + currentTransaction, debugger: debuggerInstance, toastMessage: `debugging ${txNumber}`, validationError: '' @@ -293,7 +303,7 @@ export const DebuggerUI = (props: DebuggerUIProps) => { { state.debugging && } { state.debugging && } - { state.debugging && } + { state.debugging && } ) } diff --git a/libs/remix-ui/debugger-ui/src/lib/vm-debugger/global-variables.tsx b/libs/remix-ui/debugger-ui/src/lib/vm-debugger/global-variables.tsx new file mode 100644 index 0000000000..db26cf980b --- /dev/null +++ b/libs/remix-ui/debugger-ui/src/lib/vm-debugger/global-variables.tsx @@ -0,0 +1,27 @@ +import React from 'react' // eslint-disable-line +import DropdownPanel from './dropdown-panel' // eslint-disable-line +import { BN } from 'ethereumjs-util' + +export const GlobalVariables = ({ block, receipt, tx }) => { + // see https://docs.soliditylang.org/en/latest/units-and-global-variables.html#block-and-transaction-properties + const globals = { + 'block.basefee': (new BN(block.baseFeePerGas.replace('0x', ''), 'hex')).toString(10) + ` Wei (${block.baseFeePerGas})`, + 'block.chainid': tx.chainId, + 'block.coinbase': block.miner, + 'block.difficulty': block.difficulty, + 'block.gaslimit': block.gasLimit, + 'block.number': block.number, + 'block.timestamp': block.timestamp, + 'msg.sender': tx.from, + 'msg.sig': tx.input.substring(0, 10), + 'msg.value': tx.value + ' Wei', + 'tx.origin': tx.from + } + return ( +
+ +
+ ) +} + +export default GlobalVariables diff --git a/libs/remix-ui/debugger-ui/src/lib/vm-debugger/vm-debugger-head.tsx b/libs/remix-ui/debugger-ui/src/lib/vm-debugger/vm-debugger-head.tsx index 8a951cf4fa..3a58c1d2f4 100644 --- a/libs/remix-ui/debugger-ui/src/lib/vm-debugger/vm-debugger-head.tsx +++ b/libs/remix-ui/debugger-ui/src/lib/vm-debugger/vm-debugger-head.tsx @@ -15,6 +15,7 @@ export const VmDebuggerHead = ({ vmDebugger: { registerEvent, triggerEvent } }) 'remaining gas': '-', 'loaded address': '-' }) + const [solidityState, setSolidityState] = useState({ calldata: null, message: null diff --git a/libs/remix-ui/debugger-ui/src/lib/vm-debugger/vm-debugger.tsx b/libs/remix-ui/debugger-ui/src/lib/vm-debugger/vm-debugger.tsx index a02b95a377..5bfad2c186 100644 --- a/libs/remix-ui/debugger-ui/src/lib/vm-debugger/vm-debugger.tsx +++ b/libs/remix-ui/debugger-ui/src/lib/vm-debugger/vm-debugger.tsx @@ -6,8 +6,9 @@ import StackPanel from './stack-panel' // eslint-disable-line import StoragePanel from './storage-panel' // eslint-disable-line import ReturnValuesPanel from './dropdown-panel' // eslint-disable-line import FullStoragesChangesPanel from './full-storages-changes' // eslint-disable-line +import GlobalVariables from './global-variables' // eslint-disable-line -export const VmDebugger = ({ vmDebugger: { registerEvent } }) => { +export const VmDebugger = ({ vmDebugger: { registerEvent }, currentBlock, currentReceipt, currentTransaction }) => { const [calldataPanel, setCalldataPanel] = useState(null) const [memoryPanel, setMemoryPanel] = useState(null) const [callStackPanel, setCallStackPanel] = useState(null) @@ -58,6 +59,7 @@ export const VmDebugger = ({ vmDebugger: { registerEvent } }) => { + diff --git a/libs/remix-ui/publish-to-storage/src/lib/publish-to-storage.tsx b/libs/remix-ui/publish-to-storage/src/lib/publish-to-storage.tsx index de14a65a2f..f8f5878aa0 100644 --- a/libs/remix-ui/publish-to-storage/src/lib/publish-to-storage.tsx +++ b/libs/remix-ui/publish-to-storage/src/lib/publish-to-storage.tsx @@ -5,7 +5,7 @@ import { publishToIPFS } from './publishToIPFS' import { publishToSwarm } from './publishOnSwarm' export const PublishToStorage = (props: RemixUiPublishToStorageProps) => { - const { storage, fileProvider, fileManager, contract, resetStorage } = props + const { api, storage, contract, resetStorage } = props const [state, setState] = useState({ modal: { title: '', @@ -25,11 +25,11 @@ export const PublishToStorage = (props: RemixUiPublishToStorageProps) => { } else { if (storage === 'swarm') { try { - const result = await publishToSwarm(contract, fileManager) + const result = await publishToSwarm(contract, api) modal(`Published ${contract.name}'s Metadata`, publishMessage(result.uploaded)) // triggered each time there's a new verified publish (means hash correspond) - fileProvider.addExternal('swarm/' + result.item.hash, result.item.content) + api.addExternalFile('swarm/' + result.item.hash, result.item.content) } catch (err) { let parseError = err try { @@ -39,11 +39,11 @@ export const PublishToStorage = (props: RemixUiPublishToStorageProps) => { } } else { try { - const result = await publishToIPFS(contract, fileManager) + const result = await publishToIPFS(contract, api) modal(`Published ${contract.name}'s Metadata`, publishMessage(result.uploaded)) // triggered each time there's a new verified publish (means hash correspond) - fileProvider.addExternal('ipfs/' + result.item.hash, result.item.content) + api.addExternalFile('ipfs/' + result.item.hash, result.item.content) } catch (err) { modal('IPFS Publish Failed', publishMessageFailed(storage, err)) } diff --git a/libs/remix-ui/publish-to-storage/src/lib/publishOnSwarm.tsx b/libs/remix-ui/publish-to-storage/src/lib/publishOnSwarm.tsx index 785d00b895..a8a39343a9 100644 --- a/libs/remix-ui/publish-to-storage/src/lib/publishOnSwarm.tsx +++ b/libs/remix-ui/publish-to-storage/src/lib/publishOnSwarm.tsx @@ -2,7 +2,7 @@ import swarm from 'swarmgw' const swarmgw = swarm() -export const publishToSwarm = async (contract, fileManager) => { +export const publishToSwarm = async (contract, api) => { // gather list of files to publish const sources = [] let metadata @@ -38,16 +38,14 @@ export const publishToSwarm = async (contract, fileManager) => { throw new Error('Error while extracting the hash from metadata.json') } - fileManager.fileProviderOf(fileName).get(fileName, (error, content) => { - if (error) { - console.log(error) - } else { - sources.push({ - content: content, - hash: hash, - filename: fileName - }) - } + api.readFile(fileName).then((content) => { + sources.push({ + content: content, + hash: hash, + filename: fileName + }) + }).catch((error) => { + console.log(error) }) })) // publish the list of sources in order, fail if any failed diff --git a/libs/remix-ui/publish-to-storage/src/lib/publishToIPFS.tsx b/libs/remix-ui/publish-to-storage/src/lib/publishToIPFS.tsx index 8b9a369565..605157c552 100644 --- a/libs/remix-ui/publish-to-storage/src/lib/publishToIPFS.tsx +++ b/libs/remix-ui/publish-to-storage/src/lib/publishToIPFS.tsx @@ -6,7 +6,7 @@ const ipfsNodes = [ new IpfsClient({ host: '127.0.0.1', port: 5001, protocol: 'http' }) ] -export const publishToIPFS = async (contract, fileManager) => { +export const publishToIPFS = async (contract, api) => { // gather list of files to publish const sources = [] let metadata @@ -42,16 +42,14 @@ export const publishToIPFS = async (contract, fileManager) => { throw new Error('Error while extracting the hash from metadata.json') } - fileManager.fileProviderOf(fileName).get(fileName, (error, content) => { - if (error) { - console.log(error) - } else { - sources.push({ - content: content, - hash: hash, - filename: fileName - }) - } + api.readFile(fileName).then((content) => { + sources.push({ + content: content, + hash: hash, + filename: fileName + }) + }).catch((error) => { + console.log(error) }) })) // publish the list of sources in order, fail if any failed diff --git a/libs/remix-ui/publish-to-storage/src/lib/types/index.ts b/libs/remix-ui/publish-to-storage/src/lib/types/index.ts index 928315c621..53a351baee 100644 --- a/libs/remix-ui/publish-to-storage/src/lib/types/index.ts +++ b/libs/remix-ui/publish-to-storage/src/lib/types/index.ts @@ -1,7 +1,6 @@ export interface RemixUiPublishToStorageProps { + api: any, storage: string, - fileProvider: any, - fileManager: any, contract: any, resetStorage: () => void } diff --git a/libs/remix-ui/renderer/src/lib/renderer.tsx b/libs/remix-ui/renderer/src/lib/renderer.tsx index 4f0795875c..8b4799a4f0 100644 --- a/libs/remix-ui/renderer/src/lib/renderer.tsx +++ b/libs/remix-ui/renderer/src/lib/renderer.tsx @@ -4,12 +4,9 @@ interface RendererProps { message: any; opt?: any, plugin: any, - editor: any, - config: any, - fileManager: any } -export const Renderer = ({ message, opt = {}, editor, config, fileManager, plugin }: RendererProps) => { +export const Renderer = ({ message, opt = {}, plugin }: RendererProps) => { const [messageText, setMessageText] = useState(null) const [editorOptions, setEditorOptions] = useState({ useSpan: false, @@ -57,7 +54,7 @@ export const Renderer = ({ message, opt = {}, editor, config, fileManager, plugi setMessageText(text) setEditorOptions(options) setClose(false) - }, [message]) + }, [message, opt]) const getPositionDetails = (msg: any) => { const result = { } as Record @@ -77,7 +74,7 @@ export const Renderer = ({ message, opt = {}, editor, config, fileManager, plugi } const addAnnotation = (file, error) => { - if (file === config.get('currentFile')) { + if (file === plugin.getConfiguration('currentFile')) { plugin.call('editor', 'addAnnotation', error, file) } } @@ -95,19 +92,19 @@ export const Renderer = ({ message, opt = {}, editor, config, fileManager, plugi } const _errorClick = (errFile, errLine, errCol) => { - if (errFile !== config.get('currentFile')) { + if (errFile !== plugin.getConfiguration('currentFile')) { // TODO: refactor with this._components.contextView.jumpTo - const provider = fileManager.fileProviderOf(errFile) + const provider = plugin.fileProviderOf(errFile) if (provider) { provider.exists(errFile).then(() => { - fileManager.open(errFile) - editor.gotoLine(errLine, errCol) + plugin.open(errFile) + plugin.call('editor', 'gotoLine', errLine, errCol) }).catch(error => { if (error) return console.log(error) }) } } else { - editor.gotoLine(errLine, errCol) + plugin.call('editor', 'gotoLine', errLine, errCol) } } diff --git a/libs/remix-ui/solidity-compiler/src/lib/actions/compiler.ts b/libs/remix-ui/solidity-compiler/src/lib/actions/compiler.ts index 1cba2adff9..e0e2a46498 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/actions/compiler.ts +++ b/libs/remix-ui/solidity-compiler/src/lib/actions/compiler.ts @@ -26,8 +26,8 @@ export const resetCompilerMode = () => (dispatch: React.Dispatch) => { }) } -export const listenToEvents = (editor, compileTabLogic) => (dispatch: React.Dispatch) => { - editor.event.register('sessionSwitched', () => { +export const listenToEvents = (compileTabLogic, api) => (dispatch: React.Dispatch) => { + api.on('editor', 'sessionSwitched', () => { dispatch(setEditorMode('sessionSwitched')) }) @@ -39,7 +39,7 @@ export const listenToEvents = (editor, compileTabLogic) => (dispatch: React.Disp dispatch(setCompilerMode('compilationDuration', speed)) }) - editor.event.register('contentChanged', () => { + api.on('editor', 'contentChanged', () => { dispatch(setEditorMode('contentChanged')) }) diff --git a/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx b/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx index 882899a34e..104a515a39 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx +++ b/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx @@ -18,7 +18,7 @@ declare global { const _paq = window._paq = window._paq || [] //eslint-disable-line export const CompilerContainer = (props: CompilerContainerProps) => { - const { editor, config, queryParams, compileTabLogic, tooltip, modal, compiledFileName, setHardHatCompilation, updateCurrentVersion, isHardHatProject, configurationSettings } = props // eslint-disable-line + const { api, compileTabLogic, tooltip, modal, compiledFileName, updateCurrentVersion, configurationSettings } = props // eslint-disable-line const [state, setState] = useState({ hideWarnings: false, autoCompile: false, @@ -56,26 +56,26 @@ export const CompilerContainer = (props: CompilerContainerProps) => { _updateVersionSelector(selectedVersion) } }) - const currentFileName = config.get('currentFile') + const currentFileName = api.getConfiguration('currentFile') currentFile(currentFileName) - listenToEvents(editor, compileTabLogic)(dispatch) + listenToEvents(compileTabLogic, api)(dispatch) }, []) useEffect(() => { if (compileTabLogic && compileTabLogic.compiler) { setState(prevState => { - const params = queryParams.get() + const params = api.getParameters() const optimize = params.optimize === 'false' ? false : params.optimize === 'true' ? true : null const runs = params.runs const evmVersion = params.evmVersion return { ...prevState, - hideWarnings: config.get('hideWarnings') || false, - autoCompile: config.get('autoCompile') || false, - includeNightlies: config.get('includeNightlies') || false, - optimise: (optimize !== null) && (optimize !== undefined) ? optimize : config.get('optimise') || false, + hideWarnings: api.getConfiguration('hideWarnings') || false, + autoCompile: api.getConfiguration('autoCompile') || false, + includeNightlies: api.getConfiguration('includeNightlies') || false, + optimise: (optimize !== null) && (optimize !== undefined) ? optimize : api.getConfiguration('optimise') || false, runs: (runs !== null) && (runs !== 'null') && (runs !== undefined) && (runs !== 'undefined') ? runs : 200, evmVersion: (evmVersion !== null) && (evmVersion !== 'null') && (evmVersion !== undefined) && (evmVersion !== 'undefined') ? evmVersion : 'default' } @@ -152,7 +152,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => { allVersions = [...allVersions, ...versions] selectedVersion = state.defaultVersion - if (queryParams.get().version) selectedVersion = queryParams.get().version + if (api.getParameters().version) selectedVersion = api.getParameters().version // Check if version is a URL and corresponding filename starts with 'soljson' if (selectedVersion.startsWith('https://')) { const urlArr = selectedVersion.split('/') @@ -197,7 +197,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => { // Load solc compiler version according to pragma in contract file const _setCompilerVersionFromPragma = (filename: string) => { if (!state.allversions) return - compileTabLogic.fileManager.readFile(filename).then(data => { + api.readFile(filename).then(data => { const pragmaArr = data.match(/(pragma solidity (.+?);)/g) if (pragmaArr && pragmaArr.length === 1) { const pragmaStr = pragmaArr[0].replace('pragma solidity', '').trim() @@ -228,7 +228,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => { } const isSolFileSelected = (currentFile = '') => { - if (!currentFile) currentFile = config.get('currentFile') + if (!currentFile) currentFile = api.getConfiguration('currentFile') if (!currentFile) return false const extention = currentFile.substr(currentFile.length - 3, currentFile.length) return extention.toLowerCase() === 'sol' || extention.toLowerCase() === 'yul' @@ -297,7 +297,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => { } const compile = () => { - const currentFile = config.get('currentFile') + const currentFile = api.getConfiguration('currentFile') if (!isSolFileSelected()) return @@ -321,7 +321,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => { }) } updateCurrentVersion(selectedVersion) - queryParams.update({ version: selectedVersion }) + api.setParameters({ version: selectedVersion }) let url if (customUrl !== '') { @@ -331,7 +331,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => { }) updateCurrentVersion(selectedVersion) url = customUrl - queryParams.update({ version: selectedVersion }) + api.setParameters({ version: selectedVersion }) } else if (selectedVersion === 'builtin') { let location: string | Location = window.document.location let path = location.pathname @@ -406,7 +406,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => { const handleAutoCompile = (e) => { const checked = e.target.checked - config.set('autoCompile', checked) + api.setConfiguration('autoCompile', checked) setState(prevState => { return { ...prevState, autoCompile: checked } }) @@ -415,7 +415,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => { const handleOptimizeChange = (value) => { const checked = !!value - config.set('optimise', checked) + api.setConfiguration('optimise', checked) compileTabLogic.setOptimize(checked) if (compileTabLogic.optimize) { compileTabLogic.setRuns(parseInt(state.runs)) @@ -441,7 +441,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => { const handleHideWarningsChange = (e) => { const checked = e.target.checked - config.set('hideWarnings', checked) + api.setConfiguration('hideWarnings', checked) state.autoCompile && compile() setState(prevState => { return { ...prevState, hideWarnings: checked } @@ -452,7 +452,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => { const checked = e.target.checked if (!checked) handleLoadVersion(state.defaultVersion) - config.set('includeNightlies', checked) + api.setConfiguration('includeNightlies', checked) setState(prevState => { return { ...prevState, includeNightlies: checked } }) @@ -483,7 +483,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => { const checked = event.target.checked sethhCompilation(checked) - setHardHatCompilation(checked) + api.setHardHatCompilation(checked) } /* @@ -574,7 +574,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => { { - isHardHatProject && + api.isHardHatProject &&
diff --git a/libs/remix-ui/solidity-compiler/src/lib/contract-selection.tsx b/libs/remix-ui/solidity-compiler/src/lib/contract-selection.tsx index 489707b28e..7b85038aa6 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/contract-selection.tsx +++ b/libs/remix-ui/solidity-compiler/src/lib/contract-selection.tsx @@ -7,7 +7,7 @@ import { CopyToClipboard } from '@remix-ui/clipboard' // eslint-disable-line import './css/style.css' export const ContractSelection = (props: ContractSelectionProps) => { - const { contractMap, fileProvider, fileManager, contractsDetails, modal } = props + const { api, contractMap, contractsDetails, modal } = props const [contractList, setContractList] = useState([]) const [selectedContract, setSelectedContract] = useState('') const [storage, setStorage] = useState(null) @@ -234,7 +234,7 @@ export const ContractSelection = (props: ContractSelectionProps) => { No Contract Compiled Yet } - + ) } diff --git a/libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts b/libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts index 83b688f104..4b9be01c92 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts +++ b/libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts @@ -18,46 +18,46 @@ export class CompileTab extends Plugin { public compilerImport public event - constructor (public queryParams, public fileManager, public editor, public config, public fileProvider, public contentImport) { + constructor (public api, public contentImport) { super(profile) this.event = new EventEmitter() this.compiler = new Compiler((url, cb) => this.call('contentImport', 'resolveAndSave', url).then((result) => cb(null, result)).catch((error) => cb(error.message))) } init () { - this.optimize = this.queryParams.get().optimize + this.optimize = this.api.getParameters().optimize this.optimize = this.optimize === 'true' - this.queryParams.update({ optimize: this.optimize }) + this.api.setParameters({ optimize: this.optimize }) this.compiler.set('optimize', this.optimize) - this.runs = this.queryParams.get().runs + this.runs = this.api.getParameters().runs this.runs = this.runs && this.runs !== 'undefined' ? this.runs : 200 - this.queryParams.update({ runs: this.runs }) + this.api.setParameters({ runs: this.runs }) this.compiler.set('runs', this.runs) - this.evmVersion = this.queryParams.get().evmVersion + this.evmVersion = this.api.getParameters().evmVersion if (this.evmVersion === 'undefined' || this.evmVersion === 'null' || !this.evmVersion) { this.evmVersion = null } - this.queryParams.update({ evmVersion: this.evmVersion }) + this.api.setParameters({ evmVersion: this.evmVersion }) this.compiler.set('evmVersion', this.evmVersion) } setOptimize (newOptimizeValue) { this.optimize = newOptimizeValue - this.queryParams.update({ optimize: this.optimize }) + this.api.setParameters({ optimize: this.optimize }) this.compiler.set('optimize', this.optimize) } setRuns (runs) { this.runs = runs - this.queryParams.update({ runs: this.runs }) + this.api.setParameters({ runs: this.runs }) this.compiler.set('runs', this.runs) } setEvmVersion (newEvmVersion) { this.evmVersion = newEvmVersion - this.queryParams.update({ evmVersion: this.evmVersion }) + this.api.setParameters({ evmVersion: this.evmVersion }) this.compiler.set('evmVersion', this.evmVersion) } @@ -79,7 +79,7 @@ export class CompileTab extends Plugin { */ compileFile (target) { if (!target) throw new Error('No target provided for compiliation') - const provider = this.fileManager.fileProviderOf(target) + const provider = this.api.fileProviderOf(target) if (!provider) throw new Error(`cannot compile ${target}. Does not belong to any explorer`) return new Promise((resolve, reject) => { provider.get(target, (error, content) => { @@ -93,14 +93,14 @@ export class CompileTab extends Plugin { } async isHardhatProject () { - if (this.fileManager.mode === 'localhost') { - return await this.fileManager.exists('hardhat.config.js') + if (this.api.getFileManagerMode() === 'localhost') { + return await this.api.fileExists('hardhat.config.js') } else return false } runCompiler (hhCompilation) { try { - if (this.fileManager.mode === 'localhost' && hhCompilation) { + if (this.api.getFileManagerMode() === 'localhost' && hhCompilation) { const { currentVersion, optimize, runs } = this.compiler.state if (currentVersion) { const fileContent = `module.exports = { @@ -114,7 +114,7 @@ export class CompileTab extends Plugin { } ` const configFilePath = 'remix-compiler.config.js' - this.fileManager.setFileContent(configFilePath, fileContent) + this.api.writeFile(configFilePath, fileContent) this.call('hardhat', 'compile', configFilePath).then((result) => { this.call('terminal', 'log', { type: 'info', value: result }) }).catch((error) => { @@ -122,9 +122,9 @@ export class CompileTab extends Plugin { }) } } - this.fileManager.saveCurrentFile() + this.api.saveCurrentFile() this.event.emit('removeAnnotations') - var currentFile = this.config.get('currentFile') + var currentFile = this.api.getConfiguration('currentFile') return this.compileFile(currentFile) } catch (err) { console.error(err) diff --git a/libs/remix-ui/solidity-compiler/src/lib/solidity-compiler.tsx b/libs/remix-ui/solidity-compiler/src/lib/solidity-compiler.tsx index 3fd3f800fb..46c032d582 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/solidity-compiler.tsx +++ b/libs/remix-ui/solidity-compiler/src/lib/solidity-compiler.tsx @@ -9,7 +9,7 @@ import { Renderer } from '@remix-ui/renderer' // eslint-disable-line import './css/style.css' export const SolidityCompiler = (props: SolidityCompilerProps) => { - const { plugin, plugin: { editor, config, queryParams, compileTabLogic, currentFile, fileProvider, fileManager, contractsDetails, contractMap, compileErrors, isHardHatProject, setHardHatCompilation, configurationSettings } } = props + const { plugin, plugin: { compileTabLogic, contractsDetails, contractMap, compileErrors, configurationSettings } } = props const [state, setState] = useState({ contractsDetails: {}, eventHandlers: {}, @@ -75,22 +75,23 @@ export const SolidityCompiler = (props: SolidityCompilerProps) => {
) + const currentFile = plugin.getConfiguration('currentFile') return ( <>
- - + +
- { compileErrors.error && } + { compileErrors.error && } { compileErrors.error && (compileErrors.error.mode === 'panic') && modal('Error', panicMessage(compileErrors.error.formattedMessage), 'Close', null) } { compileErrors.errors && compileErrors.errors.length && compileErrors.errors.map((err, index) => { - if (config.get('hideWarnings')) { + if (plugin.getConfiguration('hideWarnings')) { if (err.severity !== 'warning') { - return + return } } else { - return + return } }) }
diff --git a/libs/remix-ui/solidity-compiler/src/lib/types/index.ts b/libs/remix-ui/solidity-compiler/src/lib/types/index.ts index 31c95e9e1f..a2106e2205 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/types/index.ts +++ b/libs/remix-ui/solidity-compiler/src/lib/types/index.ts @@ -4,43 +4,32 @@ export interface SolidityCompilerProps { file: string } | Record compileErrors: any, - isHardHatProject: boolean, - queryParams: any, compileTabLogic: any, - currentFile: string, contractsDetails: Record, - editor: any, - config: any, - fileProvider: any, - fileManager: any, contentImport: any, call: (...args) => void on: (...args) => void, - setHardHatCompilation: (value: boolean) => void, setSelectedVersion: (value: string) => void, - configurationSettings: ConfigurationSettings + configurationSettings: ConfigurationSettings, + getConfiguration: (value: string) => string, + setConfiguration: (name: string, value: string) => void }, } export interface CompilerContainerProps { - editor: any, - config: any, - queryParams: any, + api: any, compileTabLogic: any, tooltip: (message: string | JSX.Element) => void, modal: (title: string, message: string | JSX.Element, okLabel: string, okFn: () => void, cancelLabel?: string, cancelFn?: () => void) => void, compiledFileName: string, - setHardHatCompilation: (value: boolean) => void, updateCurrentVersion: any, - isHardHatProject: boolean, configurationSettings: ConfigurationSettings } export interface ContractSelectionProps { + api: any, contractMap: { file: string } | Record, - fileManager: any, - fileProvider: any, modal: (title: string, message: string | JSX.Element, okLabel: string, okFn: () => void, cancelLabel?: string, cancelFn?: () => void) => void, contractsDetails: Record } diff --git a/libs/remix-ui/tree-view/src/lib/remix-ui-tree-view.css b/libs/remix-ui/tree-view/src/lib/remix-ui-tree-view.css index 7e8fbee405..97b2f4fd48 100644 --- a/libs/remix-ui/tree-view/src/lib/remix-ui-tree-view.css +++ b/libs/remix-ui/tree-view/src/lib/remix-ui-tree-view.css @@ -23,7 +23,7 @@ word-break: break-all; } .label_key { - min-width: 15%; + min-width: max-content; max-width: 80%; word-break: break-word; }