Skip to content

Commit 780e380

Browse files
committed
Revert "stash"
This reverts commit a4b4c09.
1 parent a4b4c09 commit 780e380

File tree

6 files changed

+37
-26
lines changed

6 files changed

+37
-26
lines changed

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

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

48-
const isMounted = useRef(true);
49-
5048
useEffect(() => {
5149
if (!contractExchangeRate && tokenAddress) {
5250
setExchangeRates((prev) => ({
5351
...prev,
5452
[tokenAddress]: LOADING,
5553
}));
5654
}
57-
return () => {
58-
isMounted.current = false;
59-
};
6055
}, [contractExchangeRate, tokenAddress]);
6156

6257
return useMemo(() => {
@@ -83,22 +78,18 @@ export default function useTokenExchangeRate(
8378
if (!contractExchangeRate) {
8479
fetchTokenExchangeRates(nativeCurrency, [tokenAddress], chainId)
8580
.then((addressToExchangeRate) => {
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-
}
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+
}));
9487
})
9588
.catch(() => {
96-
if (isMounted.current) {
97-
setExchangeRates((prev) => ({
98-
...prev,
99-
[tokenAddress]: FAILED,
100-
}));
101-
}
89+
setExchangeRates((prev) => ({
90+
...prev,
91+
[tokenAddress]: FAILED,
92+
}));
10293
});
10394
return undefined;
10495
}

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-
}, []);
34+
}, [abortControllerRef]);
3535

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

ui/hooks/useCurrencyRatePolling.ts

Lines changed: 8 additions & 1 deletion
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(true);
31+
const isMounted = useRef(false);
3232
const networkConfigurations = useSelector(getNetworkConfigurationsByChainId);
3333
const useSafeChainsListValidation = useSelector(
3434
getUseSafeChainsListValidation,
@@ -41,6 +41,13 @@ const useNativeCurrencies = (isPollingEnabled: boolean) => {
4141
? enabledChainIds
4242
: chainIds;
4343

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

ui/hooks/usePolling.ts

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

6266
export default usePolling;

ui/pages/confirmations/hooks/useAssetDetails.js

Lines changed: 12 additions & 2 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(true);
21+
const isMounted = useRef(false);
2222
const dispatch = useDispatch();
2323

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

4646
useEffect(() => {
47-
if (!tokenAddress && !userAddress && !transactionData) {
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+
) {
4858
return () => undefined;
4959
}
5060

ui/pages/confirmations/hooks/useGetTokenStandardAndDetails.ts

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

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

0 commit comments

Comments
 (0)