Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

Add MetaMask/Infura workaround for pending transactions #265

Merged
merged 2 commits into from
Jul 22, 2019

Conversation

JamesLefrere
Copy link
Contributor

This PR adds a workaround for an Infura issue (that becomes a problem with our MetaMask implementation) as documented here and more specifically here.

The crux of our issue is that purser-metamask's signTransaction method attempts to get the transaction that MetaMask sent in the callback of sendTransaction, when it is pending. With most providers, the getTransaction method will respond with the transaction when it is pending, but Infura recently started returning an empty response.

The workaround involves attempting to get the transaction immediately, and if that fails, using a web3 0.20.x-compatible package (await-transaction-mined) to wait for the transaction to be confirmed before getting the transaction.

This PR also makes some improvements to various defaults as suggested in #261 .

  • Update chain defaults

    • Add HARDFORKS defaults constant
    • Add NETWORK_NAMES defaults constant
    • Add tentative support for more chains for getChainDefinition
    • Rename NETWORK_IDS defaults constant to CHAIN_IDS
    • Use hardfork and network name constants getChainDefinition
  • Add MetaMask/Infura workaround

    • Add await-transaction-mined dependency
    • Define a method to get a pending MetaMask transaction and if necessary (given e.g. an Infura provider), wait for the transaction to be confirmed before getting it (otherwise, the provider will return null)

* Add `HARDFORKS` defaults constant
* Add `NETWORK_NAMES` defaults constant
* Add tentative support for more chains for `getChainDefinition`
* Rename `NETWORK_IDS` defaults constant to `CHAIN_IDS`
* Use hardfork and network name constants `getChainDefinition`
* Add `await-transaction-mined` dependency
* Define a method to get a pending MetaMask transaction and if necessary (given e.g. an Infura provider), wait for the transaction to be confirmed before getting it (otherwise, the provider will return null)
Copy link
Member

@rdig rdig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another quality @JamesLefrere release! 🥇

@@ -122,11 +122,39 @@ export const HTTPS_PROTOCOL: string = 'https:';
/*
* Chain IDs
*/
export const NETWORK_IDS: Object = {
export const CHAIN_IDS: Object = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@rdig rdig merged commit d3f2abc into master Jul 22, 2019
@rdig rdig deleted the fix/metamask-infura-workaround branch July 22, 2019 13:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants