Commit 642d0ad
authored
refactor: remove unused swap selectors and fix selector types (#38413)
<!--
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 cleans up `bridge` redux state, selectors and actions to prepare
for the AssetPicker refactor
- remove destination exchange rate management since the data now comes
from the bridge-controller
- `toTokenExchangeRate` and `toTokenUsdExchangeRate` from state
- update `useBridgeExchangeRates` to only fetch source exchange rates
- remove unused selectors: `getAllBridgeableNetworks`,
`getToTokenConversionRate`, `getIsBridgeTx`
- tighten selector parameter/return types
- replace `NetworkConfiguration` type references with `BridgeNetwork`
(minimal network object required by swaps) for better type safety
- use typed state overrides in unit test mock data builder (many unit
test mock data was updated as a result)
<!--
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?
-->
[](https://codespaces.new/MetaMask/metamask-extension/pull/38413?quickstart=1)
## **Changelog**
<!--
If this PR is not End-User-Facing and should not show up in the
CHANGELOG, you can choose to either:
1. Write `CHANGELOG entry: null`
2. Label with `no-changelog`
If this PR is End-User-Facing, please write a short User-Facing
description in the past tense like:
`CHANGELOG entry: Added a new tab for users to see their NFTs`
`CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker`
(This helps the Release Engineer do their job more quickly and
accurately)
-->
CHANGELOG entry: refactor: remove unused swap selectors and fix types
## **Related issues**
Fixes: N/A
## **Manual testing steps**
No user-facing changes
## **Screenshots/Recordings**
<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->
### **Before**
<!-- [screenshots/recordings] -->
### **After**
<!-- [screenshots/recordings] -->
## **Pre-merge author checklist**
- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/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-extension/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.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Cleans up bridge state and selectors by dropping destination
exchange-rate handling, tightening types (incl. BridgeNetwork),
simplifying actions/hooks, and updating tests/stories accordingly.
>
> - **State/Actions**:
> - Remove `toTokenExchangeRate` and `toTokenUsdExchangeRate` from
`bridge` state and related actions/thunks.
> - Simplify `setFromChain` to accept `chainId` (Hex/CAIP) and derive
network client id; auto-select native token for non‑EVM.
> - Keep only source exchange-rate fetching via
`setSrcTokenExchangeRates`.
> - **Selectors**:
> - Replace `getAllBridgeableNetworks` with record-based lookup from
`multichainNetworkConfigurationsByChainId`.
> - Remove unused selectors (`getToTokenConversionRate`,
`getIsBridgeTx`).
> - Tighten types and memoization; add `BridgeNetwork` type; refine
balances and validation logic; expose price impact thresholds and no-fee
assets via feature flags.
> - **Hooks/Utils**:
> - `useBridgeExchangeRates` now fetches only source token rates and
uses cache.
> - `useBridgeQueryParams` updated to work with new types and chain
selection flow.
> - Remove unused `useSolanaBridgeTransactionMapping` hook.
> - Improve `isQuoteExpiredOrInvalid`, `isNetworkAdded`, and
image/balance handling; add `safeAmountForCalc`.
> - **UI**:
> - Prepare page and quote card wired to new selector/state shape;
switch‑tokens enablement uses updated network checks.
> - **Tests/Stories**:
> - Update mocks to typed `featureFlagOverrides: { bridgeConfig }` and
`BridgeControllerState` fields; adjust snapshots and fixtures to new
shapes.
> - **Constants**:
> - Mark `ALLOWED_BRIDGE_CHAIN_IDS` as `const`; add
`SLIP44_ASSET_NAMESPACE`.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
92155e9. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 87eb2b8 commit 642d0ad
File tree
32 files changed
+368
-1635
lines changed- test
- data/bridge
- e2e/tests/settings
- ui
- ducks/bridge
- hooks
- bridge
- __snapshots__
- pages/bridge
- hooks
- prepare
- quotes
- __snapshots__
- utils
32 files changed
+368
-1635
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
| 82 | + | |
| 83 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
4 | 6 | | |
5 | 7 | | |
6 | 8 | | |
| |||
118 | 120 | | |
119 | 121 | | |
120 | 122 | | |
121 | | - | |
| 123 | + | |
122 | 124 | | |
123 | 125 | | |
124 | 126 | | |
125 | 127 | | |
126 | 128 | | |
127 | 129 | | |
128 | | - | |
129 | | - | |
| 130 | + | |
| 131 | + | |
130 | 132 | | |
131 | 133 | | |
132 | 134 | | |
133 | 135 | | |
134 | | - | |
135 | | - | |
136 | 136 | | |
137 | 137 | | |
138 | | - | |
139 | | - | |
140 | 138 | | |
141 | 139 | | |
142 | 140 | | |
| |||
352 | 350 | | |
353 | 351 | | |
354 | 352 | | |
355 | | - | |
356 | 353 | | |
357 | 354 | | |
358 | 355 | | |
| |||
361 | 358 | | |
362 | 359 | | |
363 | 360 | | |
364 | | - | |
365 | | - | |
366 | | - | |
| 361 | + | |
367 | 362 | | |
368 | 363 | | |
369 | 364 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | | - | |
114 | | - | |
115 | 113 | | |
116 | 114 | | |
117 | 115 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
| 12 | + | |
17 | 13 | | |
| 14 | + | |
18 | 15 | | |
19 | 16 | | |
20 | 17 | | |
| |||
23 | 20 | | |
24 | 21 | | |
25 | 22 | | |
26 | | - | |
27 | | - | |
28 | 23 | | |
29 | 24 | | |
30 | 25 | | |
31 | 26 | | |
32 | 27 | | |
33 | | - | |
34 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
35 | 31 | | |
36 | 32 | | |
37 | 33 | | |
| |||
52 | 48 | | |
53 | 49 | | |
54 | 50 | | |
55 | | - | |
56 | | - | |
57 | 51 | | |
58 | 52 | | |
59 | 53 | | |
| |||
145 | 139 | | |
146 | 140 | | |
147 | 141 | | |
148 | | - | |
149 | | - | |
| 142 | + | |
150 | 143 | | |
151 | 144 | | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
| 145 | + | |
157 | 146 | | |
158 | 147 | | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
164 | 152 | | |
165 | | - | |
| 153 | + | |
166 | 154 | | |
167 | 155 | | |
168 | 156 | | |
169 | | - | |
| 157 | + | |
170 | 158 | | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
175 | 162 | | |
176 | 163 | | |
177 | 164 | | |
| |||
182 | 169 | | |
183 | 170 | | |
184 | 171 | | |
185 | | - | |
| 172 | + | |
186 | 173 | | |
187 | 174 | | |
188 | 175 | | |
189 | 176 | | |
190 | | - | |
| 177 | + | |
191 | 178 | | |
192 | 179 | | |
193 | 180 | | |
194 | 181 | | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | 182 | | |
214 | 183 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | 8 | | |
10 | | - | |
11 | 9 | | |
12 | | - | |
13 | 10 | | |
14 | 11 | | |
15 | 12 | | |
| |||
23 | 20 | | |
24 | 21 | | |
25 | 22 | | |
26 | | - | |
27 | 23 | | |
28 | 24 | | |
29 | 25 | | |
| |||
110 | 106 | | |
111 | 107 | | |
112 | 108 | | |
113 | | - | |
114 | 109 | | |
115 | 110 | | |
116 | 111 | | |
| |||
144 | 139 | | |
145 | 140 | | |
146 | 141 | | |
147 | | - | |
148 | 142 | | |
149 | 143 | | |
150 | 144 | | |
151 | | - | |
152 | 145 | | |
153 | 146 | | |
154 | 147 | | |
| |||
245 | 238 | | |
246 | 239 | | |
247 | 240 | | |
248 | | - | |
249 | 241 | | |
250 | | - | |
251 | 242 | | |
252 | 243 | | |
253 | 244 | | |
254 | 245 | | |
255 | 246 | | |
256 | 247 | | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | | - | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | | - | |
353 | | - | |
354 | | - | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | 248 | | |
362 | 249 | | |
363 | 250 | | |
| |||
0 commit comments