Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Bump reselect to ^5.1.1 for heterogeneously-typed selectors support #29094

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions lavamoat/browserify/beta/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1710,10 +1710,10 @@
"@metamask/network-controller>@metamask/eth-block-tracker": true,
"@metamask/network-controller>@metamask/eth-json-rpc-infura": true,
"@metamask/network-controller>@metamask/swappable-obj-proxy": true,
"@metamask/network-controller>reselect": true,
"@metamask/rpc-errors": true,
"@metamask/utils": true,
"eslint>fast-deep-equal": true,
"reselect": true,
"uri-js": true,
"uuid": true
}
Expand Down Expand Up @@ -1772,13 +1772,6 @@
"semver": true
}
},
"@metamask/network-controller>reselect": {
"globals": {
"WeakRef": true,
"console.warn": true,
"unstable_autotrackMemoize": true
}
},
"@metamask/notification-controller>nanoid": {
"globals": {
"crypto.getRandomValues": true
Expand Down Expand Up @@ -5092,6 +5085,13 @@
"@babel/runtime": true
}
},
"reselect": {
"globals": {
"WeakRef": true,
"console.warn": true,
"unstable_autotrackMemoize": true
}
},
"semver": {
"globals": {
"console.error": true
Expand Down
16 changes: 8 additions & 8 deletions lavamoat/browserify/flask/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1710,10 +1710,10 @@
"@metamask/network-controller>@metamask/eth-block-tracker": true,
"@metamask/network-controller>@metamask/eth-json-rpc-infura": true,
"@metamask/network-controller>@metamask/swappable-obj-proxy": true,
"@metamask/network-controller>reselect": true,
"@metamask/rpc-errors": true,
"@metamask/utils": true,
"eslint>fast-deep-equal": true,
"reselect": true,
"uri-js": true,
"uuid": true
}
Expand Down Expand Up @@ -1772,13 +1772,6 @@
"semver": true
}
},
"@metamask/network-controller>reselect": {
"globals": {
"WeakRef": true,
"console.warn": true,
"unstable_autotrackMemoize": true
}
},
"@metamask/notification-controller>nanoid": {
"globals": {
"crypto.getRandomValues": true
Expand Down Expand Up @@ -5092,6 +5085,13 @@
"@babel/runtime": true
}
},
"reselect": {
"globals": {
"WeakRef": true,
"console.warn": true,
"unstable_autotrackMemoize": true
}
},
"semver": {
"globals": {
"console.error": true
Expand Down
16 changes: 8 additions & 8 deletions lavamoat/browserify/main/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1710,10 +1710,10 @@
"@metamask/network-controller>@metamask/eth-block-tracker": true,
"@metamask/network-controller>@metamask/eth-json-rpc-infura": true,
"@metamask/network-controller>@metamask/swappable-obj-proxy": true,
"@metamask/network-controller>reselect": true,
"@metamask/rpc-errors": true,
"@metamask/utils": true,
"eslint>fast-deep-equal": true,
"reselect": true,
"uri-js": true,
"uuid": true
}
Expand Down Expand Up @@ -1772,13 +1772,6 @@
"semver": true
}
},
"@metamask/network-controller>reselect": {
"globals": {
"WeakRef": true,
"console.warn": true,
"unstable_autotrackMemoize": true
}
},
"@metamask/notification-controller>nanoid": {
"globals": {
"crypto.getRandomValues": true
Expand Down Expand Up @@ -5092,6 +5085,13 @@
"@babel/runtime": true
}
},
"reselect": {
"globals": {
"WeakRef": true,
"console.warn": true,
"unstable_autotrackMemoize": true
}
},
"semver": {
"globals": {
"console.error": true
Expand Down
16 changes: 8 additions & 8 deletions lavamoat/browserify/mmi/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1802,10 +1802,10 @@
"@metamask/network-controller>@metamask/eth-block-tracker": true,
"@metamask/network-controller>@metamask/eth-json-rpc-infura": true,
"@metamask/network-controller>@metamask/swappable-obj-proxy": true,
"@metamask/network-controller>reselect": true,
"@metamask/rpc-errors": true,
"@metamask/utils": true,
"eslint>fast-deep-equal": true,
"reselect": true,
"uri-js": true,
"uuid": true
}
Expand Down Expand Up @@ -1864,13 +1864,6 @@
"semver": true
}
},
"@metamask/network-controller>reselect": {
"globals": {
"WeakRef": true,
"console.warn": true,
"unstable_autotrackMemoize": true
}
},
"@metamask/notification-controller>nanoid": {
"globals": {
"crypto.getRandomValues": true
Expand Down Expand Up @@ -5184,6 +5177,13 @@
"@babel/runtime": true
}
},
"reselect": {
"globals": {
"WeakRef": true,
"console.warn": true,
"unstable_autotrackMemoize": true
}
},
"semver": {
"globals": {
"console.error": true
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@
"redux": "^4.0.5",
"redux-thunk": "^2.3.0",
"remove-trailing-slash": "^0.1.1",
"reselect": "^3.0.1",
"reselect": "^5.1.1",
"ses": "^1.1.0",
"simple-git": "^3.20.0",
"single-call-balance-checker-abi": "^1.0.0",
Expand Down
2 changes: 2 additions & 0 deletions shared/modules/selectors/smart-transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export const getSmartTransactionsOptInStatusInternal = createSelector(
* @returns true if the user has explicitly opted in, false if they have opted out,
* or null if they have not explicitly opted in or out.
*/
// @ts-expect-error TODO: Fix types for `getSmartTransactionsOptInStatusInternal` once `getPreferences is converted to TypeScript
export const getSmartTransactionsOptInStatusForMetrics = createSelector(
getSmartTransactionsOptInStatusInternal,
(optInStatus: boolean): boolean => optInStatus,
Expand All @@ -96,6 +97,7 @@ export const getSmartTransactionsOptInStatusForMetrics = createSelector(
* @param state
* @returns
*/
// @ts-expect-error TODO: Fix types for `getSmartTransactionsOptInStatusInternal` once `getPreferences is converted to TypeScript
export const getSmartTransactionsPreferenceEnabled = createSelector(
getSmartTransactionsOptInStatusInternal,
(optInStatus: boolean): boolean => {
Expand Down
4 changes: 2 additions & 2 deletions shared/modules/selectors/util.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { TransactionStatus } from '@metamask/transaction-controller';
import { isEqual } from 'lodash';
import { createSelectorCreator, defaultMemoize } from 'reselect';
import { createSelectorCreator, lruMemoize } from 'reselect';

export const createDeepEqualSelector = createSelectorCreator(
defaultMemoize,
lruMemoize,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify, this implementation is the same under the hood right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! It was just renamed in v5.

Copy link
Contributor Author

@MajorLift MajorLift Dec 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isEqual,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const SnapAuthorshipPill: React.FC<SnapAuthorshipPillProps> = ({
onClick,
}) => {
const { name: snapName } = useSelector((state) =>
// @ts-expect-error ts is picking up the wrong type for the selector
getSnapMetadata(state, snapId),
);

Expand Down
1 change: 0 additions & 1 deletion ui/components/app/snaps/snap-icon/snap-icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export const SnapIcon: FunctionComponent<SnapIconProps> = ({
);

const { name: snapName } = useSelector((state) =>
/* @ts-expect-error wrong type on selector. */
getSnapMetadata(state, snapId),
);

Expand Down
42 changes: 27 additions & 15 deletions ui/ducks/bridge/selectors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import {
import { mockNetworkState } from '../../../test/stub/networks';
import mockErc20Erc20Quotes from '../../../test/data/bridge/mock-quotes-erc20-erc20.json';
import mockBridgeQuotesNativeErc20 from '../../../test/data/bridge/mock-quotes-native-erc20.json';
import { SortOrder } from '../../pages/bridge/types';
import {
QuoteMetadata,
QuoteResponse,
SortOrder,
} from '../../pages/bridge/types';
import {
getAllBridgeableNetworks,
getBridgeQuotes,
Expand Down Expand Up @@ -710,9 +714,11 @@ describe('Bridge selectors', () => {
{ valueInCurrency: new BigNumber('0.156562871410260918428') },
{ valueInCurrency: new BigNumber('0.33900008283534602') },
];
result.sortedQuotes.forEach((quote, idx) => {
expect(quote.cost).toStrictEqual(EXPECTED_SORTED_COSTS[idx]);
});
result.sortedQuotes.forEach(
(quote: QuoteMetadata & QuoteResponse, idx: number) => {
expect(quote.cost).toStrictEqual(EXPECTED_SORTED_COSTS[idx]);
},
);
expect(result).toStrictEqual({
sortedQuotes: expect.any(Array),
recommendedQuote: {
Expand Down Expand Up @@ -809,9 +815,11 @@ describe('Bridge selectors', () => {
{ valueInCurrency: new BigNumber('0.15656287141025952') },
{ valueInCurrency: new BigNumber('0.33900008283534464') },
];
result.sortedQuotes.forEach((quote, idx) => {
expect(quote.cost).toStrictEqual(EXPECTED_SORTED_COSTS[idx]);
});
result.sortedQuotes.forEach(
(quote: QuoteMetadata & QuoteResponse, idx: number) => {
expect(quote.cost).toStrictEqual(EXPECTED_SORTED_COSTS[idx]);
},
);

expect(result).toStrictEqual({
sortedQuotes: expect.any(Array),
Expand Down Expand Up @@ -880,14 +888,18 @@ describe('Bridge selectors', () => {
'381c23bc-e3e4-48fe-bc53-257471e388ad',
);
expect(sortedQuotes).toHaveLength(2);
sortedQuotes.forEach((quote, idx) => {
expect(
quoteMetadataKeys.every((k) => Object.keys(quote ?? {}).includes(k)),
).toBe(true);
expect(quote?.quote.requestId).toStrictEqual(
mockBridgeQuotesNativeErc20[idx]?.quote.requestId,
);
});
sortedQuotes.forEach(
(quote: QuoteMetadata & QuoteResponse, idx: number) => {
expect(
quoteMetadataKeys.every((k) =>
Object.keys(quote ?? {}).includes(k),
),
).toBe(true);
expect(quote?.quote.requestId).toStrictEqual(
mockBridgeQuotesNativeErc20[idx]?.quote.requestId,
);
},
);
});

it('should sort quotes by ETA', () => {
Expand Down
Loading
Loading