-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update gas fee controller to 15.1.2 (#9693)
## **Description** This PR upgrades `gas-fee-controller` from version 13 to version 15.1.2 and fixes the breaking changes associated with the upgrade. ## **Related issues** Fixes: MetaMask/mobile-planning#1785 ## **Manual testing steps** 1. Create a transaction to send tokens from one wallet to another. Verify that the gas fee looks agreeable. ## **Screenshots/Recordings** ### Regular Transactions Before: ![Screenshot 2024-05-20 at 6 04 52 PM](https://github.com/MetaMask/metamask-mobile/assets/6249205/2da41805-2fe5-4382-9f3b-c3465f20af7a) After: ![Screenshot 2024-05-20 at 5 54 26 PM](https://github.com/MetaMask/metamask-mobile/assets/6249205/dd8b5960-0d73-45c2-b0b7-b07cc29b64c2) ### Dapp Transaction Before: ![Screenshot 2024-05-21 at 5 59 42 PM](https://github.com/MetaMask/metamask-mobile/assets/6249205/3934e897-fc70-4f51-9c75-41c603aecf0b) After: ![Screenshot 2024-05-21 at 6 12 47 PM](https://github.com/MetaMask/metamask-mobile/assets/6249205/09e25ef7-4b5b-4cd2-ae16-36ab66953fab) Reported prices (app vs Etherscan) ETH Mainnet: .00017 ETH vs 0.00017017 Linea mainnet: < .00001 ETH vs .000001 ETH Sepolia testnet: .00023 ETH vs 0.00022519 ## **Pre-merge author checklist** - [ ] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --------- Co-authored-by: tommasini <tommasini15@gmail.com> Co-authored-by: Aslau Mario-Daniel <marioaslau@gmail.com>
- Loading branch information
1 parent
cef2d09
commit 31fbfa4
Showing
9 changed files
with
153 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import migration from './042'; | ||
import { merge } from 'lodash'; | ||
import initialRootState from '../../util/test/initial-root-state'; | ||
import { captureException } from '@sentry/react-native'; | ||
|
||
const oldState = { | ||
engine: { | ||
backgroundState: { | ||
GasFeeController: { | ||
gasFeeEstimates: {}, | ||
estimatedGasFeeTimeBounds: {}, | ||
gasEstimateType: 'none', | ||
gasFeeEstimatesByChainId: {}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const expectedNewState = { | ||
engine: { | ||
backgroundState: { | ||
GasFeeController: { | ||
gasFeeEstimates: {}, | ||
estimatedGasFeeTimeBounds: {}, | ||
gasEstimateType: 'none', | ||
gasFeeEstimatesByChainId: {}, | ||
nonRPCGasFeeApisDisabled: false, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
jest.mock('@sentry/react-native', () => ({ | ||
captureException: jest.fn(), | ||
})); | ||
const mockedCaptureException = jest.mocked(captureException); | ||
|
||
describe('Migration #42', () => { | ||
beforeEach(() => { | ||
jest.restoreAllMocks(); | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
const invalidStates = [ | ||
{ | ||
state: merge({}, initialRootState, { | ||
engine: null, | ||
}), | ||
errorMessage: | ||
"FATAL ERROR: Migration 42: Invalid engine state error: 'object'", | ||
scenario: 'engine state is invalid', | ||
}, | ||
{ | ||
state: merge({}, initialRootState, { | ||
engine: { | ||
backgroundState: null, | ||
}, | ||
}), | ||
errorMessage: | ||
"FATAL ERROR: Migration 42: Invalid engine backgroundState error: 'object'", | ||
scenario: 'backgroundState is invalid', | ||
}, | ||
{ | ||
state: merge({}, initialRootState, { | ||
engine: { | ||
backgroundState: { | ||
GasFeeController: null, | ||
}, | ||
}, | ||
}), | ||
errorMessage: | ||
"FATAL ERROR: Migration 42: Invalid GasFeeController state error: 'null'", | ||
scenario: 'GasFeeController state is invalid', | ||
}, | ||
]; | ||
|
||
for (const { errorMessage, scenario, state } of invalidStates) { | ||
it(`should capture exception if ${scenario}`, async () => { | ||
const newState = await migration(state); | ||
|
||
expect(newState).toStrictEqual(state); | ||
expect(mockedCaptureException).toHaveBeenCalledWith(expect.any(Error)); | ||
expect(mockedCaptureException.mock.calls[0][0].message).toBe( | ||
errorMessage, | ||
); | ||
}); | ||
} | ||
|
||
it('should contain new property nonRPCGasFeeApisDisabled = false in GasFeeController state ', async () => { | ||
const newState = await migration(oldState); | ||
expect(newState).toStrictEqual(expectedNewState); | ||
|
||
expect( | ||
// @ts-expect-error: ignore for testing purposes: new state is type unknown | ||
newState.engine.backgroundState.GasFeeController.nonRPCGasFeeApisDisabled, | ||
).toEqual(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { captureException } from '@sentry/react-native'; | ||
import { isObject } from '@metamask/utils'; | ||
import { ensureValidState } from './util'; | ||
|
||
/** | ||
* Migration to update state of GasFeeController | ||
* | ||
* @param state Persisted Redux state | ||
* @returns | ||
*/ | ||
export default function migrate(state: unknown) { | ||
if (!ensureValidState(state, 42)) { | ||
return state; | ||
} | ||
|
||
const gasFeeControllerState = state.engine.backgroundState.GasFeeController; | ||
|
||
if (!isObject(gasFeeControllerState)) { | ||
captureException( | ||
new Error( | ||
`FATAL ERROR: Migration 42: Invalid GasFeeController state error: '${JSON.stringify( | ||
gasFeeControllerState, | ||
)}'`, | ||
), | ||
); | ||
return state; | ||
} | ||
|
||
gasFeeControllerState.nonRPCGasFeeApisDisabled = false; | ||
|
||
return state; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters