on master help sign in
metamask: use injected provider for sending txs
2b5e3d3fang
src/lib/metamask.ts+20−7
@@ -26,11 +26,24 @@ const metamaskSendTransaction = async (txn: FakeSignableTx, web3: Web3) => {
26 from: toHex(txn.from),
26 from: toHex(txn.from),
27 };
27 };
28
28
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 {
29− //NOTE since this gives us a receipt instead of just the hash of the signed
41+ //NOTE since this gives us a receipt instead of just the hash of the
30− // tx, it makes us wait for confirmation outside of our own
42+ // signed tx, it makes us wait for confirmation outside of our own
31− // waitForTransactionConfirm. because of this the progress bar loses
43+ // waitForTransactionConfirm. because of this the progress bar loses
32− // its progressiveness for metamask users.
44+ // its progressiveness for metamask users.
33− //TODO can we do better?
34− const receipt = await web3.eth.sendTransaction(metamaskFormattedTxn);
45+ let receipt = await await web3.eth.sendTransaction(metamaskFormattedTxn);
35− return receipt.transactionHash;
46+ txHash = receipt.transactionHash;
47+ }
48+ return txHash;
36};
49};