-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: migrate swaps controller to typescript (#25063)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** This PR refactors the SwapsController class to be rewritten in typescript. For the sake of making sure all functionality stays the same, the tests have not been affected <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/25063?quickstart=1) ## **Related issues** Fixes: ## **Manual testing steps** Go to swaps. Swap on the following scenarios: ETH -> WETH WETH -> ETH ETH -> ERC20 ERC20 -> ETH ERC20 -> ERC20 ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> N/A ### **Before** <!-- [screenshots/recordings] --> N/A ### **After** <!-- [screenshots/recordings] --> N/A ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [x] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [x] 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.
- Loading branch information
Showing
5 changed files
with
932 additions
and
610 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { | ||
FALLBACK_SMART_TRANSACTIONS_MAX_FEE_MULTIPLIER, | ||
FALLBACK_SMART_TRANSACTIONS_REFRESH_TIME, | ||
} from '../../../shared/constants/smartTransactions'; | ||
import { MINUTE } from '../../../shared/constants/time'; | ||
|
||
import type { SwapsControllerState } from './swaps.types'; | ||
|
||
// The MAX_GAS_LIMIT is a number that is higher than the maximum gas costs we have observed on any aggregator | ||
export const MAX_GAS_LIMIT = 2500000; | ||
|
||
// To ensure that our serves are not spammed if MetaMask is left idle, we limit the number of fetches for quotes that are made on timed intervals. | ||
// 3 seems to be an appropriate balance of giving users the time they need when MetaMask is not left idle, and turning polling off when it is. | ||
export const POLL_COUNT_LIMIT = 3; | ||
|
||
// If for any reason the MetaSwap API fails to provide a refresh time, | ||
// provide a reasonable fallback to avoid further errors | ||
export const FALLBACK_QUOTE_REFRESH_TIME = MINUTE; | ||
|
||
export const swapsControllerInitialState: { swapsState: SwapsControllerState } = | ||
{ | ||
swapsState: { | ||
quotes: {}, | ||
quotesPollingLimitEnabled: false, | ||
fetchParams: null, | ||
tokens: null, | ||
tradeTxId: null, | ||
approveTxId: null, | ||
quotesLastFetched: null, | ||
customMaxGas: '', | ||
customGasPrice: null, | ||
customMaxFeePerGas: null, | ||
customMaxPriorityFeePerGas: null, | ||
swapsUserFeeLevel: '', | ||
selectedAggId: null, | ||
customApproveTxData: '', | ||
errorKey: '', | ||
topAggId: null, | ||
routeState: '', | ||
swapsFeatureIsLive: true, | ||
saveFetchedQuotes: false, | ||
swapsQuoteRefreshTime: FALLBACK_QUOTE_REFRESH_TIME, | ||
swapsQuotePrefetchingRefreshTime: FALLBACK_QUOTE_REFRESH_TIME, | ||
swapsStxBatchStatusRefreshTime: FALLBACK_SMART_TRANSACTIONS_REFRESH_TIME, | ||
swapsStxGetTransactionsRefreshTime: | ||
FALLBACK_SMART_TRANSACTIONS_REFRESH_TIME, | ||
swapsStxMaxFeeMultiplier: FALLBACK_SMART_TRANSACTIONS_MAX_FEE_MULTIPLIER, | ||
swapsFeatureFlags: {}, | ||
}, | ||
}; |
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
Oops, something went wrong.