fix wallet connect

pull/4201/head
yann300 1 year ago committed by Aniket
parent 677bbfb742
commit 1e9049d42f
  1. 18
      apps/remix-ide/src/blockchain/blockchain.tsx
  2. 33
      apps/walletconnect/src/services/WalletConnectRemixClient.ts

@ -940,12 +940,20 @@ export class Blockchain extends Plugin {
cb(null, txResult, address, returnValue) cb(null, txResult, address, returnValue)
} catch (error) { } catch (error) {
if (this.isInjectedWeb3()) { const buildError = async (errorMessage, errorData) => {
const errorMessage = error.innerError ? error.innerError.message : error.message
const errorData = error.innerError ? error.innerError.data : error.data
const compiledContracts = await this.call('compilerArtefacts', 'getAllContractDatas') const compiledContracts = await this.call('compilerArtefacts', 'getAllContractDatas')
const injectedError = txExecution.checkError({ errorMessage, errorData }, compiledContracts) return txExecution.checkError({ errorMessage, errorData }, compiledContracts)
cb(injectedError.message) }
let errorMessage
let errorData
if (error.innerError) {
errorMessage = error.innerError.message
errorData = error.innerError.data
cb((await buildError(errorMessage, errorData)).message)
} else if (error.message || error.data) {
errorMessage = error.message
errorData = error.data
cb((await buildError(errorMessage, errorData)).message)
} else } else
cb(error) cb(error)
} }

@ -106,25 +106,40 @@ export class WalletConnectRemixClient extends PluginClient {
if (provider.isMetaMask) { if (provider.isMetaMask) {
return new Promise((resolve) => { return new Promise((resolve) => {
provider.sendAsync(data, (err, response) => { provider.sendAsync(data, (error, response) => {
if (err) { if (error) {
console.error(err) if (error.data && error.data.originalError && error.data.originalError.data) {
return resolve({jsonrpc: '2.0', result: [], id: data.id}) resolve({
jsonrpc: '2.0',
error: error.data.originalError,
id: data.id
})
} else if (error.data && error.data.message) {
resolve({
jsonrpc: '2.0',
error: error.data && error.data,
id: data.id
})
} else {
resolve({
jsonrpc: '2.0',
error,
id: data.id
})
}
} }
return resolve(response) return resolve(response)
}) })
}) })
} else { } else {
const message = await provider.request(data) const message = await provider.request(data)
return {jsonrpc: '2.0', result: message, id: data.id} return {jsonrpc: '2.0', result: message, id: data.id}
} }
} }
} else { } else {
console.error( const err = `Cannot make ${data.method} request. Remix client is not connected to walletconnect client`
`Cannot make ${data.method} request. Remix client is not connected to walletconnect client` console.error(err)
) return {jsonrpc: '2.0', error: { message: err, code: -32603 }, id: data.id}
return {jsonrpc: '2.0', result: [], id: data.id}
} }
} }

Loading…
Cancel
Save