From 4043098b108fa114d2cabb8b952a0d53d4f3f572 Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 8 Oct 2024 17:19:33 +0200 Subject: [PATCH] run-tab to ts --- .../src/app/providers/abstract-provider.tsx | 2 + .../src/app/udapp/{run-tab.js => run-tab.tsx} | 47 +++++++++++++++---- apps/remix-ide/src/blockchain/providers/vm.ts | 3 -- libs/remix-ui/run-tab/src/lib/css/run-tab.css | 5 -- .../run-tab/src/lib/types/blockchain.d.ts | 8 ++-- .../src/lib/types/execution-context.d.ts | 1 - libs/remix-ui/run-tab/src/lib/types/index.ts | 2 +- .../run-tab/src/lib/types/run-tab.d.ts | 21 ++------- 8 files changed, 46 insertions(+), 43 deletions(-) rename apps/remix-ide/src/app/udapp/{run-tab.js => run-tab.tsx} (88%) diff --git a/apps/remix-ide/src/app/providers/abstract-provider.tsx b/apps/remix-ide/src/app/providers/abstract-provider.tsx index 01e26df1f4..e740c6139b 100644 --- a/apps/remix-ide/src/app/providers/abstract-provider.tsx +++ b/apps/remix-ide/src/app/providers/abstract-provider.tsx @@ -126,9 +126,11 @@ export abstract class AbstractProvider extends Plugin implements IProvider { private async sendAsyncInternal(data: JsonDataRequest, resolve: SuccessRequest, reject: RejectRequest): Promise { if (this.provider) { try { + console.log('sendAsyncInternal', data) const result = await this.provider.send(data.method, data.params) resolve({ jsonrpc: '2.0', result, id: data.id }) } catch (error) { + console.log('CATCH', error.message) if (error && error.message && error.message.includes('net_version') && error.message.includes('SERVER_ERROR')) { this.switchAway(true) } diff --git a/apps/remix-ide/src/app/udapp/run-tab.js b/apps/remix-ide/src/app/udapp/run-tab.tsx similarity index 88% rename from apps/remix-ide/src/app/udapp/run-tab.js rename to apps/remix-ide/src/app/udapp/run-tab.tsx index 4e768c869d..0980499917 100644 --- a/apps/remix-ide/src/app/udapp/run-tab.js +++ b/apps/remix-ide/src/app/udapp/run-tab.tsx @@ -6,8 +6,11 @@ import {addressToString} from '@remix-ui/helper' import {InjectedProviderDefault} from '../providers/injected-provider-default' import {InjectedCustomProvider} from '../providers/injected-custom-provider' import * as packageJson from '../../../../../package.json' - -const EventManager = require('../../lib/events') +import { EventManager } from '@remix-project/remix-lib' +import type { Blockchain } from '../../blockchain/blockchain' +import type { CompilerArtefacts } from '@remix-project/core-plugin' +// import type { NetworkModule } from '../tabs/network-module' +// import type FileProvider from '../files/fileProvider' const Recorder = require('../tabs/runTab/model/recorder.js') const _paq = (window._paq = window._paq || []) @@ -37,7 +40,20 @@ const profile = { } export class RunTab extends ViewPlugin { - constructor(blockchain, config, fileManager, editor, filePanel, compilersArtefacts, networkModule, fileProvider, engine) { + event: EventManager + engine: any + config: any + blockchain: Blockchain + fileManager: any + editor: any + filePanel: any + compilersArtefacts: CompilerArtefacts + networkModule: any + fileProvider: any + recorder: any + REACT_API: any + el: any + constructor(blockchain: Blockchain, config: any, fileManager: any, editor: any, filePanel: any, compilersArtefacts: CompilerArtefacts, networkModule: any, fileProvider: any, engine: any) { super(profile) this.event = new EventManager() this.engine = engine @@ -83,7 +99,7 @@ export class RunTab extends ViewPlugin { this.emit('clearAllInstancesReducer') } - addInstance(address, abi, name, contractData) { + addInstance(address, abi, name, contractData?) { this.emit('addInstanceReducer', address, abi, name, contractData) } @@ -180,27 +196,38 @@ export class RunTab extends ViewPlugin { }, provider: { sendAsync (payload) { + console.log('sendAsync', payload) return udapp.call(name, 'sendAsync', payload) }, async request (payload) { - const requestResult = await udapp.call(name, 'sendAsync', payload) - if (requestResult.error) throw new Error(requestResult.error.message) - return requestResult.result + console.log('REQUEST', payload) + try { + const requestResult = await udapp.call(name, 'sendAsync', payload) + console.log('run ok', requestResult) + if (requestResult.error) { + console.log('inner error', requestResult.error) + throw new Error(requestResult.error.message) + } + return requestResult.result + } catch (err) { + console.log('run failed', err) + throw new Error(err.error.message) + } } } }) } - const addCustomInjectedProvider = async (position, event, name, displayName, networkId, urls, nativeCurrency) => { + const addCustomInjectedProvider = async (position, event, name, displayName, networkId, urls, nativeCurrency?) => { // name = `${name} through ${event.detail.info.name}` await this.engine.register([new InjectedCustomProvider(event.detail.provider, name, networkId, urls, nativeCurrency)]) - await addProvider(position, name, displayName, true, false, false) + await addProvider(position, name, displayName, true, false) } const registerInjectedProvider = async (event) => { const name = 'injected-' + event.detail.info.name const displayName = 'Injected Provider - ' + event.detail.info.name await this.engine.register([new InjectedProviderDefault(event.detail.provider, name)]) - await addProvider(0, name, displayName, true, false, false) + await addProvider(0, name, displayName, true, false) if (event.detail.info.name === 'MetaMask') { await addCustomInjectedProvider(7, event, 'injected-metamask-optimism', 'L2 - Optimism - ' + event.detail.info.name, '0xa', ['https://mainnet.optimism.io']) diff --git a/apps/remix-ide/src/blockchain/providers/vm.ts b/apps/remix-ide/src/blockchain/providers/vm.ts index ccd8b391e2..f079c3d467 100644 --- a/apps/remix-ide/src/blockchain/providers/vm.ts +++ b/apps/remix-ide/src/blockchain/providers/vm.ts @@ -38,7 +38,6 @@ export class VMProvider { return new Promise((resolve, reject) => { this.worker.addEventListener('message', (msg) => { - console.log('message', msg) if (msg.data.cmd === 'requestResult' && stamps[msg.data.stamp]) { if (msg.data.error) { stamps[msg.data.stamp].reject(msg.data.error) @@ -63,7 +62,6 @@ export class VMProvider { const stamp = Date.now() + incr incr++ stamps[stamp] = { callback, resolve, reject } - console.log('sendAsync', query, stamp) this.worker.postMessage({ cmd: 'sendAsync', query, stamp }) }) }, @@ -72,7 +70,6 @@ export class VMProvider { const stamp = Date.now() + incr incr++ stamps[stamp] = { resolve, reject } - console.log('request', query, stamp) this.worker.postMessage({ cmd: 'request', query, stamp }) }) } diff --git a/libs/remix-ui/run-tab/src/lib/css/run-tab.css b/libs/remix-ui/run-tab/src/lib/css/run-tab.css index d2f1ffc474..16900d83f0 100644 --- a/libs/remix-ui/run-tab/src/lib/css/run-tab.css +++ b/libs/remix-ui/run-tab/src/lib/css/run-tab.css @@ -141,11 +141,6 @@ .udapp_input { font-size: 10px !important; } -.udapp_noInstancesText { - font-style: italic; - text-align: left; - padding-left: 15px; -} .udapp_pendingTxsText { font-style: italic; display: flex; diff --git a/libs/remix-ui/run-tab/src/lib/types/blockchain.d.ts b/libs/remix-ui/run-tab/src/lib/types/blockchain.d.ts index dbfa9ac9eb..428c782a8e 100644 --- a/libs/remix-ui/run-tab/src/lib/types/blockchain.d.ts +++ b/libs/remix-ui/run-tab/src/lib/types/blockchain.d.ts @@ -17,12 +17,11 @@ export class Blockchain extends Plugin { }; setupEvents(): void; getCurrentNetworkStatus(): { - name: string; - id: string; network?: { name: string; id: string; }; + error?: string; }; setupProviders(): void; providers: any; @@ -35,8 +34,8 @@ export class Blockchain extends Plugin { determineGasPrice(cb: any): void; getInputs(funABI: any): any; fromWei(value: any, doTypeConversion: any, unit: any): string; - toWei(value: any, unit: any): import("bn.js"); - calculateFee(gas: any, gasPrice: any, unit: any): import("bn.js"); + toWei(value: any, unit: any): string; + calculateFee(gas: any, gasPrice: any, unit: any): bigint; determineGasFees(tx: any): (gasPrice: any, cb: any) => void; changeExecutionContext(context: any, confirmCb: any, infoCb: any, cb: any): Promise; detectNetwork(cb: any): void; @@ -58,7 +57,6 @@ export class Blockchain extends Plugin { removeProvider(name: any): void; /** Listen on New Transaction. (Cannot be done inside constructor because txlistener doesn't exist yet) */ startListening(txlistener: any): void; - resetEnvironment(): Promise; /** * Create a VM Account * @param {{privateKey: string, balance: string}} newAccount The new account to create diff --git a/libs/remix-ui/run-tab/src/lib/types/execution-context.d.ts b/libs/remix-ui/run-tab/src/lib/types/execution-context.d.ts index 83d3df2d55..598c4f8f7d 100644 --- a/libs/remix-ui/run-tab/src/lib/types/execution-context.d.ts +++ b/libs/remix-ui/run-tab/src/lib/types/execution-context.d.ts @@ -14,7 +14,6 @@ export class ExecutionContext { txs: any; customWeb3: any; init(config: any): void; - askPermission(): void; getProvider(): any; getCurrentFork(): string; isVM(): boolean; diff --git a/libs/remix-ui/run-tab/src/lib/types/index.ts b/libs/remix-ui/run-tab/src/lib/types/index.ts index 94d997eae7..35229e6e31 100644 --- a/libs/remix-ui/run-tab/src/lib/types/index.ts +++ b/libs/remix-ui/run-tab/src/lib/types/index.ts @@ -6,7 +6,7 @@ import { SolcInput, SolcOutput } from '@openzeppelin/upgrades-core' import { LayoutCompatibilityReport } from '@openzeppelin/upgrades-core/dist/storage/report' export interface RunTabProps { plugin: RunTab, - initialState: RunTabState + initialState?: RunTabState } export interface Contract { diff --git a/libs/remix-ui/run-tab/src/lib/types/run-tab.d.ts b/libs/remix-ui/run-tab/src/lib/types/run-tab.d.ts index 91de380ad9..40ae73ac9e 100644 --- a/libs/remix-ui/run-tab/src/lib/types/run-tab.d.ts +++ b/libs/remix-ui/run-tab/src/lib/types/run-tab.d.ts @@ -1,11 +1,11 @@ -export class RunTab extends ViewPlugin { - constructor(blockchain: any, config: any, fileManager: any, editor: any, filePanel: any, compilersArtefacts: any, networkModule: any, mainView: any, fileProvider: any); +import type { CompilerArtefacts } from '@remix-project/core-plugin' +export interface RunTab extends ViewPlugin { + // constructor(blockchain: Blockchain, config: any, fileManager: any, editor: any, filePanel: any, compilersArtefacts: CompilerArtefacts, networkModule: any, fileProvider: any, engine: any); event: any; config: any; blockchain: Blockchain; fileManager: any; editor: any; - logCallback: (msg: any) => void; filePanel: any; compilersArtefacts: any; networkModule: any; @@ -19,24 +19,9 @@ export class RunTab extends ViewPlugin { sendTransaction(tx: any): any; getAccounts(cb: any): any; pendingTransactionsCount(): any; - renderInstanceContainer(): void; - instanceContainer: any; - noInstancesText: any; - renderSettings(): void; - settingsUI: any; - renderDropdown(udappUI: any, fileManager: any, compilersArtefacts: any, config: any, editor: any, logCallback: any): void; - contractDropdownUI: any; - renderRecorder(udappUI: any, fileManager: any, config: any, logCallback: any): void; - recorderCount: any; - recorderInterface: any; - renderRecorderCard(): void; - recorderCard: any; - udappUI: any; - renderComponent(): void; onReady(api: any): void; onInitDone(): void; recorder: Recorder; - // syncContracts(): void } import { ViewPlugin } from "@remixproject/engine-web"; import { Blockchain } from "./blockchain";