From 6fbc1d1fe8dc67db17526552a984676930ccb723 Mon Sep 17 00:00:00 2001 From: SteveM Date: Mon, 4 Jan 2021 14:53:45 -0800 Subject: [PATCH] handle send with two arguments instead of properly formatted payload --- example/app/src/App.vue | 6 +++- package-lock.json | 2 +- .../web3Provider/MEWconnect/index.js | 1 + .../web3-provider/methods/eth_accounts.js | 1 - .../methods/eth_requestAccounts.js | 16 +++++++++ .../methods/eth_signTransaction.js | 3 ++ .../web3-provider/providers/ws-provider.js | 33 ++++++++++++++++++- .../web3Provider/web3-provider/web3Calls.js | 10 ++++++ 8 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 src/connectProvider/web3Provider/web3-provider/methods/eth_requestAccounts.js diff --git a/example/app/src/App.vue b/example/app/src/App.vue index bf0e70e1..450646ba 100644 --- a/example/app/src/App.vue +++ b/example/app/src/App.vue @@ -490,7 +490,11 @@ export default { // .on('error', err => { // console.log(['Error', err]); // }) - .then(txhash => console.log('THEN: ', txhash)) + .then(txhash => { + console.log('THEN: ', txhash) + this.web3.eth.sendSignedTransaction(txhash) + .then(result => console.log('RESULT', result)) + }) .catch(console.error); }, signTx() { diff --git a/package-lock.json b/package-lock.json index ee728779..2428a80e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@myetherwallet/mewconnect-web-client", - "version": "2.1.18", + "version": "2.1.19", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/connectProvider/web3Provider/MEWconnect/index.js b/src/connectProvider/web3Provider/MEWconnect/index.js index c838098a..665803cd 100644 --- a/src/connectProvider/web3Provider/MEWconnect/index.js +++ b/src/connectProvider/web3Provider/MEWconnect/index.js @@ -90,6 +90,7 @@ class MEWconnectWallet { async init(qrcodeListener = () => {}) { this.mewConnect.on('codeDisplay', qrcodeListener); const txSigner = async tx => { + console.log('deeper tx', tx); // todo remove dev item let tokenInfo; if ( tx.data.slice(0, 10) === '0xa9059cbb' || diff --git a/src/connectProvider/web3Provider/web3-provider/methods/eth_accounts.js b/src/connectProvider/web3Provider/web3-provider/methods/eth_accounts.js index 9e111cf4..ee814105 100644 --- a/src/connectProvider/web3Provider/web3-provider/methods/eth_accounts.js +++ b/src/connectProvider/web3Provider/web3-provider/methods/eth_accounts.js @@ -13,5 +13,4 @@ export default async ({ payload, store }, res, next) => { res(null, toPayload(payload.id, [])); } } - }; diff --git a/src/connectProvider/web3Provider/web3-provider/methods/eth_requestAccounts.js b/src/connectProvider/web3Provider/web3-provider/methods/eth_requestAccounts.js new file mode 100644 index 00000000..c87cbd08 --- /dev/null +++ b/src/connectProvider/web3Provider/web3-provider/methods/eth_requestAccounts.js @@ -0,0 +1,16 @@ +import { toPayload } from '../jsonrpc'; + +export default async ({ payload, store }, res, next) => { + if (payload.method !== 'eth_requestAccounts') return next(); + if(store.state.wallet){ + res(null, toPayload(payload.id, [store.state.wallet.getAddressString()])); + } else { + try { + store.state.enable().then(accounts =>{ + res(null, toPayload(payload.id, accounts)); + }) + } catch (e) { + res(null, toPayload(payload.id, [])); + } + } +}; diff --git a/src/connectProvider/web3Provider/web3-provider/methods/eth_signTransaction.js b/src/connectProvider/web3Provider/web3-provider/methods/eth_signTransaction.js index e6419a63..f06a061b 100644 --- a/src/connectProvider/web3Provider/web3-provider/methods/eth_signTransaction.js +++ b/src/connectProvider/web3Provider/web3-provider/methods/eth_signTransaction.js @@ -15,7 +15,10 @@ export default async ( res, next ) => { + console.log('sign tx MC payload 1', payload); // todo remove dev item if (payload.method !== 'eth_signTransaction') return next(); + console.log('sign tx MC', payload); // todo remove dev item + console.log('chainId', payload.params[0].chainId); // todo remove dev item const tx = payload.params[0]; const localTx = Object.assign({}, tx); delete localTx['gas']; diff --git a/src/connectProvider/web3Provider/web3-provider/providers/ws-provider.js b/src/connectProvider/web3Provider/web3-provider/providers/ws-provider.js index 363a4eb7..22616e6a 100644 --- a/src/connectProvider/web3Provider/web3-provider/providers/ws-provider.js +++ b/src/connectProvider/web3Provider/web3-provider/providers/ws-provider.js @@ -47,11 +47,13 @@ class WSProvider { const _this = this.wsProvider; delete this.wsProvider['send']; const rawSend = (payload, callback) => { + console.log('payload check', payload, callback); // todo remove dev item + this.lastMessage = new Date().getTime(); if (_this.connection.readyState === _this.connection.CONNECTING) { setTimeout(() => { this.wsProvider.send(payload, callback); - }, 10); + }, 100); return; } if (_this.connection.readyState !== _this.connection.OPEN) { @@ -61,6 +63,7 @@ class WSProvider { callback(new Error('connection not open')); return; } + const req = { payload, store, @@ -101,8 +104,36 @@ class WSProvider { }; target(payload, callback); }); + } else if(typeof argumentsList[0] === 'string' && typeof argumentsList){ + } } + + if(typeof argumentsList[0] === 'string' && typeof argumentsList[1] !== 'function'){ + return new Promise((resolve, reject) => { + const callback = (err, response) => { + if (err) reject(err); + else resolve(response.result); + }; + let params = []; + if (argumentsList.length === 2) { + params = Array.isArray(argumentsList[1]) + ? argumentsList[1] + : argumentsList[1] !== undefined + ? [argumentsList[1]] + : [] + } + const payload = { + jsonrpc: "2.0", + id: 1, + method: argumentsList[0], + params: params + }; + target(payload, callback); + }); + } + + console.log(argumentsList); // todo remove dev item return target(argumentsList[0], argumentsList[1]); } }; diff --git a/src/connectProvider/web3Provider/web3-provider/web3Calls.js b/src/connectProvider/web3Provider/web3-provider/web3Calls.js index ed4c498c..b7fb7d07 100644 --- a/src/connectProvider/web3Provider/web3-provider/web3Calls.js +++ b/src/connectProvider/web3Provider/web3-provider/web3Calls.js @@ -4,6 +4,10 @@ import { formatters } from 'web3-core-helpers'; class Web3Calls { constructor(requestManager) { + const formatter = (options) =>{ + console.log('formatter', options); // todo remove dev item + return formatters.inputTransactionFormatter(options) + } const ethereumCalls = [ new Method({ name: 'getId', @@ -33,6 +37,12 @@ class Web3Calls { inputFormatter: [formatters.inputCallFormatter], outputFormatter: utils.hexToNumber }), + new Method({ + name: 'signTransaction', + call: 'eth_signTransaction', + params: 1, + inputFormatter: [formatter] + }), new Method({ name: 'sendSignedTransaction', call: 'eth_sendRawTransaction',