Skip to content

Commit

Permalink
Merge pull request #647 from urbit/m/mm-direct-request
Browse files Browse the repository at this point in the history
metamask: use injected provider for sending txs
  • Loading branch information
Fang- committed Oct 6, 2021
2 parents 195561c + 2b5e3d3 commit ff9fd78
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/lib/metamask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,24 @@ const metamaskSendTransaction = async (txn: FakeSignableTx, web3: Web3) => {
from: toHex(txn.from),
};

//NOTE since this gives us a receipt instead of just the hash of the signed
// tx, it makes us wait for confirmation outside of our own
// waitForTransactionConfirm. because of this the progress bar loses
// its progressiveness for metamask users.
//TODO can we do better?
const receipt = await web3.eth.sendTransaction(metamaskFormattedTxn);
return receipt.transactionHash;
let txHash;
if (window.ethereum) {
//NOTE see also #596, #630, #646
// no idea what's going on, we should figure it out,
// but we apply this bandaid to hopefully stop the bleeding.
// at least it also helps with the NOTE of the other branch.
txHash = await window.ethereum.request({
method: 'eth_sendTransaction',
params: [metamaskFormattedTxn],
from: txn.from,
});
} else {
//NOTE since this gives us a receipt instead of just the hash of the
// signed tx, it makes us wait for confirmation outside of our own
// waitForTransactionConfirm. because of this the progress bar loses
// its progressiveness for metamask users.
let receipt = await await web3.eth.sendTransaction(metamaskFormattedTxn);
txHash = receipt.transactionHash;
}
return txHash;
};

0 comments on commit ff9fd78

Please sign in to comment.