fix external provider

pull/5343/head
yann300 3 weeks ago committed by Aniket
parent 876f381926
commit ee7b215f24
  1. 10
      apps/remix-ide/src/app/providers/abstract-provider.tsx
  2. 59
      apps/remix-ide/src/app/udapp/run-tab.tsx

@ -102,17 +102,15 @@ export abstract class AbstractProvider extends Plugin implements IProvider {
sendAsync(data: JsonDataRequest): Promise<JsonDataResult> {
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve, reject) => {
if (!this.provider) return reject({ jsonrpc: '2.0', id: data.id, error: { message: 'provider node set', code: -32603 } } as JsonDataResult)
if (!this.provider) return reject({ jsonrpc: '2.0', id: data.id, error: { message: 'provider not set', code: -32603 } } as JsonDataResult)
this.sendAsyncInternal(data, resolve, reject)
})
}
private async switchAway(showError: boolean, msg: string) {
if (!this.provider) return
this.provider = null
this.connected = false
if (showError) {
this.call('notification', 'toast', 'Error while querying the provider: ' + msg)
this.call('terminal', 'log', { type: 'error', value: 'Error while querying the provider: ' + msg })
}
return
}
@ -138,10 +136,8 @@ export abstract class AbstractProvider extends Plugin implements IProvider {
} catch (error) {
this.switchAway(true, error.message ? error.message : error.error ? error.error : error)
}
}
error.code = -32603
reject({ jsonrpc: '2.0', error, id: data.id })
reject({ jsonrpc: '2.0', error: { message: error.message, code: -32603 }, id: data.id })
}
} else {
const result = data.method === 'net_listening' ? 'canceled' : []

@ -194,24 +194,7 @@ export class RunTab extends ViewPlugin {
if (options['fork']) this.fork = options['fork']
}
},
provider: {
sendAsync (payload) {
return udapp.call(name, 'sendAsync', payload)
},
request (payload) {
return new Promise<any>((resolve, reject) => {
udapp.call(name, 'sendAsync', payload).then((response) => {
if (response.error) {
reject(response.error.message)
} else {
resolve(response)
}
}).catch((err) => {
reject(err)
})
})
}
}
provider: new Provider(udapp, name)
})
}
@ -304,3 +287,43 @@ export class RunTab extends ViewPlugin {
this.addInstance(address, contractObject.abi, contractObject.name)
}
}
class Provider {
udapp: RunTab
name: string
constructor(udapp, name) {
this.udapp = udapp
this.name = name
}
sendAsync (payload) {
return this.udapp.call(this.name, 'sendAsync', payload)
}
request (payload): Promise<any> {
return new Promise((resolve, reject) => {
this.udapp.call(this.name, 'sendAsync', payload).then((response) => {
if (response.error) {
reject(response.error.message)
} else {
resolve(response)
}
}).catch((err) => {
if (typeof err === 'string') {
reject(err)
} else if (err.error && err.error.message) {
reject(err.error.message)
} else if (err.error && typeof err.error === 'string') {
reject(err.error)
} else {
let e
try {
e = JSON.stringify(err)
} catch (e) {
reject('unknown error')
return
}
reject(e)
}
})
})
}
}

Loading…
Cancel
Save