on master help sign in
metamask: use injected provider for sending txs

Similar to #630, we opt into using the injected provider directly instead of going through Web3. While reproduction is difficult for this case, this kind of change worked for the other one, so we go ahead and apply it here. Certainly can't hurt us more than the bug itself already does.

commit2b5e3d33e30b31de429bb7beeca47ab93c073f3c authorfang <git@fang.io> dateTue 5 Oct 2021, 15:02 (5 years ago) parentff25fde
1 file changed+20−7
src/lib/metamask.ts+20−7
src/lib/metamask.ts+20−7
@@ -26,11 +26,24 @@ const metamaskSendTransaction = async (txn: FakeSignableTx, web3: Web3) => {
2626 from: toHex(txn.from),
2727 };
2828
29− //NOTE since this gives us a receipt instead of just the hash of the signed
30− // tx, it makes us wait for confirmation outside of our own
31− // waitForTransactionConfirm. because of this the progress bar loses
32− // its progressiveness for metamask users.
33− //TODO can we do better?
34− const receipt = await web3.eth.sendTransaction(metamaskFormattedTxn);
35− return receipt.transactionHash;
29+ let txHash;
30+ if (window.ethereum) {
31+ //NOTE see also #596, #630, #646
32+ // no idea what's going on, we should figure it out,
33+ // but we apply this bandaid to hopefully stop the bleeding.
34+ // at least it also helps with the NOTE of the other branch.
35+ txHash = await window.ethereum.request({
36+ method: 'eth_sendTransaction',
37+ params: [metamaskFormattedTxn],
38+ from: txn.from,
39+ });
40+ } else {
41+ //NOTE since this gives us a receipt instead of just the hash of the
42+ // signed tx, it makes us wait for confirmation outside of our own
43+ // waitForTransactionConfirm. because of this the progress bar loses
44+ // its progressiveness for metamask users.
45+ let receipt = await await web3.eth.sendTransaction(metamaskFormattedTxn);
46+ txHash = receipt.transactionHash;
47+ }
48+ return txHash;
3649};