Skip to content

Commit

Permalink
handle send with two arguments instead of properly formatted payload
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveMieskoski committed Jan 4, 2021
1 parent 59a9481 commit 6fbc1d1
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 4 deletions.
6 changes: 5 additions & 1 deletion example/app/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/connectProvider/web3Provider/MEWconnect/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ export default async ({ payload, store }, res, next) => {
res(null, toPayload(payload.id, []));
}
}

};
Original file line number Diff line number Diff line change
@@ -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, []));
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -61,6 +63,7 @@ class WSProvider {
callback(new Error('connection not open'));
return;
}

const req = {
payload,
store,
Expand Down Expand Up @@ -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]);
}
};
Expand Down
10 changes: 10 additions & 0 deletions src/connectProvider/web3Provider/web3-provider/web3Calls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 6fbc1d1

Please sign in to comment.