Skip to content

Commit a4b4c09

Browse files
committed
stash
1 parent 911abc8 commit a4b4c09

File tree

6 files changed

+26
-37
lines changed

6 files changed

+26
-37
lines changed

ui/components/app/currency-input/hooks/useTokenExchangeRate.tsx

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useMemo, useState, useEffect } from 'react';
1+
import { useMemo, useState, useEffect, useRef } from 'react';
22
import { toChecksumAddress } from 'ethereumjs-util';
33
import { shallowEqual, useSelector } from 'react-redux';
44
import { getCurrentChainId } from '../../../../../shared/modules/selectors/networks';
@@ -45,13 +45,18 @@ export default function useTokenExchangeRate(
4545
? contractExchangeRates[tokenAddress] || exchangeRates[tokenAddress]
4646
: undefined;
4747

48+
const isMounted = useRef(true);
49+
4850
useEffect(() => {
4951
if (!contractExchangeRate && tokenAddress) {
5052
setExchangeRates((prev) => ({
5153
...prev,
5254
[tokenAddress]: LOADING,
5355
}));
5456
}
57+
return () => {
58+
isMounted.current = false;
59+
};
5560
}, [contractExchangeRate, tokenAddress]);
5661

5762
return useMemo(() => {
@@ -78,18 +83,22 @@ export default function useTokenExchangeRate(
7883
if (!contractExchangeRate) {
7984
fetchTokenExchangeRates(nativeCurrency, [tokenAddress], chainId)
8085
.then((addressToExchangeRate) => {
81-
setExchangeRates((prev) => ({
82-
...prev,
83-
// TODO: Fix in https://github.com/MetaMask/metamask-extension/issues/31880
84-
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
85-
[tokenAddress]: addressToExchangeRate[tokenAddress] || FAILED,
86-
}));
86+
if (isMounted.current) {
87+
setExchangeRates((prev) => ({
88+
...prev,
89+
// TODO: Fix in https://github.com/MetaMask/metamask-extension/issues/31880
90+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
91+
[tokenAddress]: addressToExchangeRate[tokenAddress] || FAILED,
92+
}));
93+
}
8794
})
8895
.catch(() => {
89-
setExchangeRates((prev) => ({
90-
...prev,
91-
[tokenAddress]: FAILED,
92-
}));
96+
if (isMounted.current) {
97+
setExchangeRates((prev) => ({
98+
...prev,
99+
[tokenAddress]: FAILED,
100+
}));
101+
}
93102
});
94103
return undefined;
95104
}

ui/components/multichain/asset-picker-amount/asset-picker-modal/hooks/useAssetMetadata.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const useAssetMetadata = (
3131
abortControllerRef.current?.abort();
3232
abortControllerRef.current = null;
3333
};
34-
}, [abortControllerRef]);
34+
}, []);
3535

3636
const { value: assetMetadata } = useAsyncResult<
3737
| {

ui/hooks/useCurrencyRatePolling.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const usePollingEnabled = () => {
2828
};
2929

3030
const useNativeCurrencies = (isPollingEnabled: boolean) => {
31-
const isMounted = useRef(false);
31+
const isMounted = useRef(true);
3232
const networkConfigurations = useSelector(getNetworkConfigurationsByChainId);
3333
const useSafeChainsListValidation = useSelector(
3434
getUseSafeChainsListValidation,
@@ -41,13 +41,6 @@ const useNativeCurrencies = (isPollingEnabled: boolean) => {
4141
? enabledChainIds
4242
: chainIds;
4343

44-
useEffect(() => {
45-
isMounted.current = true;
46-
return () => {
47-
isMounted.current = false;
48-
};
49-
}, []);
50-
5144
useEffect(() => {
5245
// Use validated currency tickers
5346
const fetchNativeCurrencies = async () => {

ui/hooks/usePolling.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,7 @@ const usePolling = <PollingInput>(
5656
prevPollingInputStringified.current = null;
5757
cleanup();
5858
};
59-
}, [
60-
usePollingOptions.input,
61-
hasPollingInputChanged,
62-
usePollingOptions.enabled,
63-
]);
59+
}, [usePollingOptions, hasPollingInputChanged, usePollingOptions.enabled]);
6460
};
6561

6662
export default usePolling;

ui/pages/confirmations/hooks/useAssetDetails.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function useAssetDetails(
1818
transactionData,
1919
chainId,
2020
) {
21-
const isMounted = useRef(false);
21+
const isMounted = useRef(true);
2222
const dispatch = useDispatch();
2323

2424
// state selectors
@@ -44,17 +44,7 @@ export function useAssetDetails(
4444
const prevTokenBalance = usePrevious(tokensWithBalances);
4545

4646
useEffect(() => {
47-
isMounted.current = true;
48-
return () => {
49-
isMounted.current = false;
50-
};
51-
});
52-
53-
useEffect(() => {
54-
if (
55-
!isMounted.current ||
56-
(!tokenAddress && !userAddress && !transactionData)
57-
) {
47+
if (!tokenAddress && !userAddress && !transactionData) {
5848
return () => undefined;
5949
}
6050

ui/pages/confirmations/hooks/useGetTokenStandardAndDetails.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export const useGetTokenStandardAndDetails = (
3232
if (!details) {
3333
return { decimalsNumber: undefined };
3434
}
35+
3536
const { decimals, standard } = details;
3637

3738
if (standard === TokenStandard.ERC20) {

0 commit comments

Comments
 (0)