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';
|
2021-12-14 00:41:10 +01:00
|
|
|
import CollectibleDetails from '../../components/app/collectible-details/collectible-details';
|
|
|
|
import { getCollectibles, getTokens } from '../../ducks/metamask/metamask';
|
2021-02-04 19:15:23 +01:00
|
|
|
import { DEFAULT_ROUTE } from '../../helpers/constants/routes';
|
2021-09-10 19:37:19 +02:00
|
|
|
import { isEqualCaseInsensitive } from '../../helpers/utils/util';
|
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);
|
2021-12-14 00:41:10 +01:00
|
|
|
const collectibles = useSelector(getCollectibles);
|
|
|
|
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
|
|
|
|
2021-12-14 00:41:10 +01:00
|
|
|
const collectible = collectibles.find(
|
|
|
|
({ 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;
|
2021-12-14 00:41:10 +01:00
|
|
|
if (collectible) {
|
|
|
|
content = <CollectibleDetails collectible={collectible} />;
|
|
|
|
} 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;
|