mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-29 23:58:06 +01:00
3732c5f71e
ESLint rules have been added to enforce our JSDoc conventions. These rules were introduced by updating `@metamask/eslint-config` to v9. Some of the rules have been disabled because the effort to fix all lint errors was too high. It might be easiest to enable these rules one directory at a time, or one rule at a time. Most of the changes in this PR were a result of running `yarn lint:fix`. There were a handful of manual changes that seemed obvious and simple to make. Anything beyond that and the rule was left disabled.
42 lines
1.4 KiB
JavaScript
42 lines
1.4 KiB
JavaScript
import { useSelector } from 'react-redux';
|
|
import { useRouteMatch } from 'react-router-dom';
|
|
import { getTokens } from '../ducks/metamask/metamask';
|
|
import { getCurrentChainId } from '../selectors';
|
|
import { ASSET_ROUTE } from '../helpers/constants/routes';
|
|
import { isEqualCaseInsensitive } from '../helpers/utils/util';
|
|
import {
|
|
SWAPS_CHAINID_DEFAULT_TOKEN_MAP,
|
|
ETH_SWAPS_TOKEN_OBJECT,
|
|
} from '../../shared/constants/swaps';
|
|
|
|
/**
|
|
* Returns a token object for the asset that is currently being viewed.
|
|
* Will return the default token object for the current chain when the
|
|
* user is viewing either the primary, unfiltered, activity list or the
|
|
* default token asset page.
|
|
*
|
|
* @returns {import('./useTokenDisplayValue').Token}
|
|
*/
|
|
export function useCurrentAsset() {
|
|
// To determine which primary currency to display for swaps transactions we need to be aware
|
|
// of which asset, if any, we are viewing at present
|
|
const match = useRouteMatch({
|
|
path: `${ASSET_ROUTE}/:asset`,
|
|
exact: true,
|
|
strict: true,
|
|
});
|
|
const tokenAddress = match?.params?.asset;
|
|
const knownTokens = useSelector(getTokens);
|
|
const token =
|
|
tokenAddress &&
|
|
knownTokens.find(({ address }) =>
|
|
isEqualCaseInsensitive(address, tokenAddress),
|
|
);
|
|
const chainId = useSelector(getCurrentChainId);
|
|
|
|
return (
|
|
token ??
|
|
(SWAPS_CHAINID_DEFAULT_TOKEN_MAP[chainId] || ETH_SWAPS_TOKEN_OBJECT)
|
|
);
|
|
}
|