mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Do case-insensitive comparisons of token addresses in view-quote and build-quote (#12315)
This commit is contained in:
parent
3d36fbd8ce
commit
18ca9d14e0
@ -51,7 +51,10 @@ import {
|
||||
hexToDecimal,
|
||||
} from '../../../helpers/utils/conversions.util';
|
||||
import { calcTokenAmount } from '../../../helpers/utils/token-util';
|
||||
import { getURLHostName } from '../../../helpers/utils/util';
|
||||
import {
|
||||
getURLHostName,
|
||||
isEqualCaseInsensitive,
|
||||
} from '../../../helpers/utils/util';
|
||||
import { usePrevious } from '../../../hooks/usePrevious';
|
||||
import { useTokenTracker } from '../../../hooks/useTokenTracker';
|
||||
import { useTokenFiatAmount } from '../../../hooks/useTokenFiatAmount';
|
||||
@ -169,8 +172,9 @@ export default function BuildQuote({
|
||||
shuffledTokensList,
|
||||
});
|
||||
const selectedToToken =
|
||||
tokensToSearch.find(({ address }) => address === toToken?.address) ||
|
||||
toToken;
|
||||
tokensToSearch.find(({ address }) =>
|
||||
isEqualCaseInsensitive(address, toToken?.address),
|
||||
) || toToken;
|
||||
const toTokenIsNotDefault =
|
||||
selectedToToken?.address &&
|
||||
!isSwapsDefaultTokenAddress(selectedToToken?.address, chainId);
|
||||
@ -226,8 +230,8 @@ export default function BuildQuote({
|
||||
}
|
||||
if (
|
||||
token?.address &&
|
||||
!memoizedUsersTokens.find(
|
||||
(usersToken) => usersToken.address === token.address,
|
||||
!memoizedUsersTokens.find((usersToken) =>
|
||||
isEqualCaseInsensitive(usersToken.address, token.address),
|
||||
)
|
||||
) {
|
||||
fetchTokenBalance(token.address, selectedAccountAddress).then(
|
||||
@ -298,12 +302,12 @@ export default function BuildQuote({
|
||||
);
|
||||
|
||||
const hideDropdownItemIf = useCallback(
|
||||
(item) => item.address === fromTokenAddress,
|
||||
(item) => isEqualCaseInsensitive(item.address, fromTokenAddress),
|
||||
[fromTokenAddress],
|
||||
);
|
||||
|
||||
const tokensWithBalancesFromToken = tokensWithBalances.find(
|
||||
(token) => token.address === fromToken?.address,
|
||||
const tokensWithBalancesFromToken = tokensWithBalances.find((token) =>
|
||||
isEqualCaseInsensitive(token.address, fromToken?.address),
|
||||
);
|
||||
const previousTokensWithBalancesFromToken = usePrevious(
|
||||
tokensWithBalancesFromToken,
|
||||
@ -314,9 +318,10 @@ export default function BuildQuote({
|
||||
tokensWithBalancesFromToken?.address,
|
||||
chainId,
|
||||
);
|
||||
const addressesAreTheSame =
|
||||
tokensWithBalancesFromToken?.address ===
|
||||
previousTokensWithBalancesFromToken?.address;
|
||||
const addressesAreTheSame = isEqualCaseInsensitive(
|
||||
tokensWithBalancesFromToken?.address,
|
||||
previousTokensWithBalancesFromToken?.address,
|
||||
);
|
||||
const balanceHasChanged =
|
||||
tokensWithBalancesFromToken?.balance !==
|
||||
previousTokensWithBalancesFromToken?.balance;
|
||||
@ -490,7 +495,9 @@ export default function BuildQuote({
|
||||
!Object.keys(topAssets).length)
|
||||
}
|
||||
selectPlaceHolderText={t('swapSelect')}
|
||||
hideItemIf={(item) => item.address === selectedToToken?.address}
|
||||
hideItemIf={(item) =>
|
||||
isEqualCaseInsensitive(item.address, selectedToToken?.address)
|
||||
}
|
||||
listContainerClassName="build-quote__open-dropdown"
|
||||
autoFocus
|
||||
/>
|
||||
|
@ -50,7 +50,10 @@ import {
|
||||
} from '../../../selectors';
|
||||
import { getNativeCurrency, getTokens } from '../../../ducks/metamask/metamask';
|
||||
|
||||
import { toPrecisionWithoutTrailingZeros } from '../../../helpers/utils/util';
|
||||
import {
|
||||
toPrecisionWithoutTrailingZeros,
|
||||
isEqualCaseInsensitive,
|
||||
} from '../../../helpers/utils/util';
|
||||
|
||||
import {
|
||||
safeRefetchQuotes,
|
||||
@ -214,8 +217,8 @@ export default function ViewQuote() {
|
||||
const balanceToken =
|
||||
fetchParamsSourceToken === defaultSwapsToken.address
|
||||
? defaultSwapsToken
|
||||
: tokensWithBalances.find(
|
||||
({ address }) => address === fetchParamsSourceToken,
|
||||
: tokensWithBalances.find(({ address }) =>
|
||||
isEqualCaseInsensitive(address, fetchParamsSourceToken),
|
||||
);
|
||||
|
||||
const selectedFromToken = balanceToken || usedQuote.sourceTokenInfo;
|
||||
|
Loading…
Reference in New Issue
Block a user