Skip to content

Commit

Permalink
refactor: remove circular dependency between actions.ts and `swaps.…
Browse files Browse the repository at this point in the history
…util.ts` (#30306)

This PR solves an issue with circular dependencies. It does not change
the behavior of the application. It only rearranges functions/files to
avoid circular references.

<!--
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**


[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/30306?quickstart=1)

## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

### **Before**


### **After**

## **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.
-->
  • Loading branch information
davidmurdoch authored Feb 19, 2025
1 parent f28216f commit e04e2f7
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 22 deletions.
4 changes: 0 additions & 4 deletions development/circular-deps.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,5 @@
"ui/pages/snap-account-redirect/components/snap-account-redirect-message.tsx",
"ui/pages/snap-account-redirect/components/url-display-box.tsx",
"ui/pages/snap-account-redirect/snap-account-redirect.tsx"
],
[
"ui/pages/swaps/swaps.util.ts",
"ui/store/actions.ts"
]
]
15 changes: 15 additions & 0 deletions ui/pages/swaps/swaps.util.gas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { NetworkClientId } from '@metamask/network-controller';
import {
GasFeeEstimates,
TransactionParams,
} from '@metamask/transaction-controller';
import { Hex } from '@metamask/utils';
import { submitRequestToBackground } from '../../store/background-connection';

export function estimateGasFee(request: {
transactionParams: TransactionParams;
chainId?: Hex;
networkClientId?: NetworkClientId;
}): Promise<{ estimates: GasFeeEstimates }> {
return submitRequestToBackground('estimateGasFee', [request]);
}
16 changes: 8 additions & 8 deletions ui/pages/swaps/swaps.util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ import {
LINEA,
BASE,
} from '../../../shared/constants/swaps';
import { estimateGasFee } from '../../store/actions';
import {
TOKENS,
EXPECTED_TOKENS_RESULT,
AGGREGATOR_METADATA,
TOP_ASSETS,
} from './swaps-util-test-constants';
import {
fetchTokens,
fetchAggregatorMetadata,
Expand All @@ -39,13 +32,20 @@ import {
fetchTopAssetsList,
getSwap1559GasFeeEstimates,
} from './swaps.util';
import { estimateGasFee } from './swaps.util.gas';
import {
TOKENS,
EXPECTED_TOKENS_RESULT,
AGGREGATOR_METADATA,
TOP_ASSETS,
} from './swaps-util-test-constants';

jest.mock('../../../shared/lib/storage-helpers', () => ({
getStorageItem: jest.fn(),
setStorageItem: jest.fn(),
}));

jest.mock('../../store/actions', () => ({
jest.mock('./swaps.util.gas', () => ({
estimateGasFee: jest.fn(),
}));

Expand Down
2 changes: 1 addition & 1 deletion ui/pages/swaps/swaps.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import {
sumHexes,
} from '../../../shared/modules/conversion.utils';
import { EtherDenomination } from '../../../shared/constants/common';
import { estimateGasFee } from '../../store/actions';
import { estimateGasFee } from './swaps.util.gas';

const CACHE_REFRESH_FIVE_MINUTES = 300000;
const USD_CURRENCY_CODE = 'usd';
Expand Down
9 changes: 0 additions & 9 deletions ui/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
UpdateProposedNamesResult,
} from '@metamask/name-controller';
import {
GasFeeEstimates,
TransactionMeta,
TransactionParams,
TransactionType,
Expand Down Expand Up @@ -4511,14 +4510,6 @@ export function estimateGas(params: TransactionParams): Promise<Hex> {
return submitRequestToBackground('estimateGas', [params]);
}

export function estimateGasFee(request: {
transactionParams: TransactionParams;
chainId?: Hex;
networkClientId?: NetworkClientId;
}): Promise<{ estimates: GasFeeEstimates }> {
return submitRequestToBackground('estimateGasFee', [request]);
}

export async function updateTokenType(
tokenAddress: string,
): Promise<Token | undefined> {
Expand Down

0 comments on commit e04e2f7

Please sign in to comment.