mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 09:57:02 +01:00
Fix fetching of swap quotes when initial network was testnet (#9726)
If the initial network when the extension is started is something other than Mainnet, the swaps controller will never successfully retrieve swap quotes. This is because the `ethers` provider used by the swaps controller doesn't allow network changes by default - it assumes that the network remains the same as when the provider was initialized. This was fixed by hard-coding Mainnet as the initial chain ID for this `ethers` provider used by the swaps controller. Some adjustments needed to be made to the `provider` stub to allow setting `1` as the network ID and chain ID in unit tests.
This commit is contained in:
parent
5e5d9e6c0a
commit
3bbc1d1fa4
@ -18,6 +18,7 @@ import {
|
|||||||
fetchTradesInfo as defaultFetchTradesInfo,
|
fetchTradesInfo as defaultFetchTradesInfo,
|
||||||
fetchSwapsFeatureLiveness as defaultFetchSwapsFeatureLiveness,
|
fetchSwapsFeatureLiveness as defaultFetchSwapsFeatureLiveness,
|
||||||
} from '../../../ui/app/pages/swaps/swaps.util'
|
} from '../../../ui/app/pages/swaps/swaps.util'
|
||||||
|
import { MAINNET_CHAIN_ID } from './network/enums'
|
||||||
|
|
||||||
const METASWAP_ADDRESS = '0x881d40237659c251811cec9c364ef91dc08d300c'
|
const METASWAP_ADDRESS = '0x881d40237659c251811cec9c364ef91dc08d300c'
|
||||||
|
|
||||||
@ -91,7 +92,8 @@ export default class SwapsController {
|
|||||||
|
|
||||||
this.indexOfNewestCallInFlight = 0
|
this.indexOfNewestCallInFlight = 0
|
||||||
|
|
||||||
this.ethersProvider = new ethers.providers.Web3Provider(provider)
|
// The chain ID is hard-coded as Mainnet because swaps is only used on Mainnet
|
||||||
|
this.ethersProvider = new ethers.providers.Web3Provider(provider, parseInt(MAINNET_CHAIN_ID, 16))
|
||||||
|
|
||||||
this._setupSwapsLivenessFetching()
|
this._setupSwapsLivenessFetching()
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,9 @@ export function createTestProviderTools (opts = {}) {
|
|||||||
// handle block tracker methods
|
// handle block tracker methods
|
||||||
engine.push(providerAsMiddleware(GanacheCore.provider({
|
engine.push(providerAsMiddleware(GanacheCore.provider({
|
||||||
mnemonic: getTestSeed(),
|
mnemonic: getTestSeed(),
|
||||||
|
network_id: opts.networkId,
|
||||||
|
_chainId: opts.chainId,
|
||||||
|
_chainIdRpc: opts.chainId,
|
||||||
})))
|
})))
|
||||||
// wrap in standard provider interface
|
// wrap in standard provider interface
|
||||||
const provider = providerFromEngine(engine)
|
const provider = providerFromEngine(engine)
|
||||||
|
@ -119,7 +119,7 @@ describe('SwapsController', function () {
|
|||||||
// by default, all accounts are external accounts (not contracts)
|
// by default, all accounts are external accounts (not contracts)
|
||||||
eth_getCode: '0x',
|
eth_getCode: '0x',
|
||||||
}
|
}
|
||||||
provider = createTestProviderTools({ scaffold: providerResultStub })
|
provider = createTestProviderTools({ scaffold: providerResultStub, networkId: 1, chainId: 1 })
|
||||||
.provider
|
.provider
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user