2021-06-29 22:08:31 +02:00
|
|
|
import React, { useEffect } from 'react';
|
2021-02-04 19:15:23 +01:00
|
|
|
import { useSelector } from 'react-redux';
|
|
|
|
import { Redirect, useParams } from 'react-router-dom';
|
2022-03-07 19:54:36 +01:00
|
|
|
import { isEqualCaseInsensitive } from '../../../shared/modules/string-utils';
|
2023-02-16 20:23:29 +01:00
|
|
|
import NftDetails from '../../components/app/nft-details/nft-details';
|
|
|
|
import { getNfts, getTokens } from '../../ducks/metamask/metamask';
|
2021-02-04 19:15:23 +01:00
|
|
|
import { DEFAULT_ROUTE } from '../../helpers/constants/routes';
|
2020-06-01 19:54:32 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
import NativeAsset from './components/native-asset';
|
|
|
|
import TokenAsset from './components/token-asset';
|
2020-06-01 19:54:32 +02:00
|
|
|
|
|
|
|
const Asset = () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const nativeCurrency = useSelector((state) => state.metamask.nativeCurrency);
|
|
|
|
const tokens = useSelector(getTokens);
|
2023-02-16 20:23:29 +01:00
|
|
|
const nfts = useSelector(getNfts);
|
2021-12-14 00:41:10 +01:00
|
|
|
const { asset, id } = useParams();
|
2020-06-01 19:54:32 +02:00
|
|
|
|
2021-09-10 19:37:19 +02:00
|
|
|
const token = tokens.find(({ address }) =>
|
|
|
|
isEqualCaseInsensitive(address, asset),
|
|
|
|
);
|
2020-06-01 19:54:32 +02:00
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
const nft = nfts.find(
|
2021-12-14 00:41:10 +01:00
|
|
|
({ address, tokenId }) =>
|
2022-01-19 19:42:41 +01:00
|
|
|
isEqualCaseInsensitive(address, asset) && id === tokenId.toString(),
|
2021-12-14 00:41:10 +01:00
|
|
|
);
|
|
|
|
|
2021-06-29 22:08:31 +02:00
|
|
|
useEffect(() => {
|
|
|
|
const el = document.querySelector('.app');
|
|
|
|
el.scroll(0, 0);
|
|
|
|
}, []);
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let content;
|
2023-02-16 20:23:29 +01:00
|
|
|
if (nft) {
|
|
|
|
content = <NftDetails nft={nft} />;
|
2021-12-14 00:41:10 +01:00
|
|
|
} else if (token) {
|
2021-02-04 19:15:23 +01:00
|
|
|
content = <TokenAsset token={token} />;
|
2020-06-01 19:54:32 +02:00
|
|
|
} else if (asset === nativeCurrency) {
|
2021-02-04 19:15:23 +01:00
|
|
|
content = <NativeAsset nativeCurrency={nativeCurrency} />;
|
2020-06-01 19:54:32 +02:00
|
|
|
} else {
|
2021-02-04 19:15:23 +01:00
|
|
|
content = <Redirect to={{ pathname: DEFAULT_ROUTE }} />;
|
2020-06-01 19:54:32 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
return <div className="main-container asset__container">{content}</div>;
|
|
|
|
};
|
2020-06-01 19:54:32 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
export default Asset;
|