You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
953 B
29 lines
953 B
4 years ago
|
import React from 'react';
|
||
|
import { useSelector } from 'react-redux';
|
||
|
import { Redirect, useParams } from 'react-router-dom';
|
||
|
import { getTokens } from '../../ducks/metamask/metamask';
|
||
|
import { DEFAULT_ROUTE } from '../../helpers/constants/routes';
|
||
5 years ago
|
|
||
4 years ago
|
import NativeAsset from './components/native-asset';
|
||
|
import TokenAsset from './components/token-asset';
|
||
5 years ago
|
|
||
|
const Asset = () => {
|
||
4 years ago
|
const nativeCurrency = useSelector((state) => state.metamask.nativeCurrency);
|
||
|
const tokens = useSelector(getTokens);
|
||
|
const { asset } = useParams();
|
||
5 years ago
|
|
||
4 years ago
|
const token = tokens.find(({ address }) => address === asset);
|
||
5 years ago
|
|
||
4 years ago
|
let content;
|
||
5 years ago
|
if (token) {
|
||
4 years ago
|
content = <TokenAsset token={token} />;
|
||
5 years ago
|
} else if (asset === nativeCurrency) {
|
||
4 years ago
|
content = <NativeAsset nativeCurrency={nativeCurrency} />;
|
||
5 years ago
|
} else {
|
||
4 years ago
|
content = <Redirect to={{ pathname: DEFAULT_ROUTE }} />;
|
||
5 years ago
|
}
|
||
4 years ago
|
return <div className="main-container asset__container">{content}</div>;
|
||
|
};
|
||
5 years ago
|
|
||
4 years ago
|
export default Asset;
|