run-tab to ts

pull/5298/head
yann300 1 month ago committed by Aniket
parent 07d516e7d6
commit 4043098b10
  1. 2
      apps/remix-ide/src/app/providers/abstract-provider.tsx
  2. 47
      apps/remix-ide/src/app/udapp/run-tab.tsx
  3. 3
      apps/remix-ide/src/blockchain/providers/vm.ts
  4. 5
      libs/remix-ui/run-tab/src/lib/css/run-tab.css
  5. 8
      libs/remix-ui/run-tab/src/lib/types/blockchain.d.ts
  6. 1
      libs/remix-ui/run-tab/src/lib/types/execution-context.d.ts
  7. 2
      libs/remix-ui/run-tab/src/lib/types/index.ts
  8. 21
      libs/remix-ui/run-tab/src/lib/types/run-tab.d.ts

@ -126,9 +126,11 @@ export abstract class AbstractProvider extends Plugin implements IProvider {
private async sendAsyncInternal(data: JsonDataRequest, resolve: SuccessRequest, reject: RejectRequest): Promise<void> {
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)
}

@ -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'])

@ -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 })
})
}

@ -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;

@ -17,12 +17,11 @@ export class Blockchain extends Plugin<any, any> {
};
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<any, any> {
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<any>;
detectNetwork(cb: any): void;
@ -58,7 +57,6 @@ export class Blockchain extends Plugin<any, any> {
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<void>;
/**
* Create a VM Account
* @param {{privateKey: string, balance: string}} newAccount The new account to create

@ -14,7 +14,6 @@ export class ExecutionContext {
txs: any;
customWeb3: any;
init(config: any): void;
askPermission(): void;
getProvider(): any;
getCurrentFork(): string;
isVM(): boolean;

@ -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 {

@ -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";

Loading…
Cancel
Save