Skip to content

Commit

Permalink
Merge pull request tqtezos#117 from tqtezos/alex-kooper/asset-details
Browse files Browse the repository at this point in the history
Adding asset details page base
  • Loading branch information
obstropolos authored Dec 29, 2020
2 parents 23f0b36 + 2392995 commit 1b6315a
Show file tree
Hide file tree
Showing 13 changed files with 349 additions and 78 deletions.
25 changes: 20 additions & 5 deletions client/src/components/App/App.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React, { FC } from 'react';
import { Switch, Route, useLocation } from 'wouter';
import { Fade as Reveal} from "react-awesome-reveal";
import { Fade as Reveal } from 'react-awesome-reveal';

import './App.css';
import GlobalContextProvider from './globalContext'
import GlobalContextProvider from './globalContext';

import SplashPage from '../SplashPage';
import CreateNonFungiblePage from '../CreateNonFungiblePage';
import AssetsPage from '../AssetsPage';
import AssetDetailsPage from '../AssetDetailsPage';

const App: FC = () => {
const [location] = useLocation();
Expand All @@ -16,9 +17,23 @@ const App: FC = () => {
<GlobalContextProvider>
<Reveal key={location} duration={1500}>
<Switch>
<Route path="/"><SplashPage /></Route>
<Route path="/create-non-fungible"><CreateNonFungiblePage /></Route>
<Route path="/assets"><AssetsPage /></Route>
<Route path="/">
<SplashPage />
</Route>
<Route path="/create-non-fungible">
<CreateNonFungiblePage />
</Route>
<Route path="/assets">
<AssetsPage />
</Route>
<Route path="/asset-details/:contractAddress/:tokenId">
{({ contractAddress, tokenId }) => (
<AssetDetailsPage
contractAddress={contractAddress}
tokenId={parseInt(tokenId)}
/>
)}
</Route>
</Switch>
</Reveal>
</GlobalContextProvider>
Expand Down
23 changes: 23 additions & 0 deletions client/src/components/AssetDetailsPage/Actions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/** @jsx jsx */
import { FC } from 'react';
import { jsx } from '@emotion/core';
import { Space, Button } from 'antd';

import { ParamName } from './Typography';

const Actions: FC = () => (
<Space size="middle" direction="vertical">
<div>
<ParamName>STATUS: </ParamName>
<ParamName css={{ fontWeight: 'bold', color: 'red' }}>
NOT FOR SALE
</ParamName>
</div>

<Button type="primary" shape="round" size="large" css={{ width: '10em' }}>
List For Sale
</Button>
</Space>
);

export default Actions;
50 changes: 50 additions & 0 deletions client/src/components/AssetDetailsPage/AssetDescription.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/** @jsx jsx */
import url from 'url';
import { FC, Fragment } from 'react';
import { jsx } from '@emotion/core';

import { Description, ParamName, ParamValue } from './Typography';
import { NonFungibleToken } from '../../generated/graphql_schema';
import { Skeleton } from 'antd';
import config from '../../config';

const AssetDescription: FC<{ nft?: NonFungibleToken }> = ({ nft }) => (
<Fragment>
{!nft ? (
<Skeleton title={false} paragraph={{ rows: 3 }} />
) : (
<Fragment>
<Description>{nft.extras.description}</Description>

<div>
<ParamName>Type: </ParamName>
<ParamValue>Digital Art</ParamValue>
</div>

<div>
<ParamName>Collection: </ParamName>
<ParamValue>{nft.contractInfo.name}</ParamValue>
</div>

<div>
<ParamName>Owner: </ParamName>

<ParamValue>
<img
src={url.resolve(config.tzktAvatarUrl, nft.owner)}
css={{ width: '2.5em' }}
alt=""
/>
{nft.owner}
</ParamValue>
</div>

<div css={{ marginTop: '4em' }}>
<ParamName>History: </ParamName>
</div>
</Fragment>
)}
</Fragment>
);

export default AssetDescription;
37 changes: 37 additions & 0 deletions client/src/components/AssetDetailsPage/Typography.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import styled from '@emotion/styled';

export const Name = styled.div({
fontFamily: 'sans-serif',
fontSize: '45px',
lineHeight: '60px',
letterSpacing: '0.75px',
color: 'black'
});

export const Description = styled.p({
fontFamily: 'sans-serif',
fontWeight: 300,
fontSize: '20px',
lineHeight: '30px',
letterSpacing: '0.75px',
color: 'black'
});

export const ParamName = styled.span({
fontFamily: 'sans-serif',
fontWeight: 300,
fontSize: '20px',
lineHeight: '30px',
letterSpacing: '0.75px',
color: 'black'
});

export const ParamValue = styled.span({
fontFamily: 'sans-serif',
fontStyle: 'italic',
fontWeight: 300,
fontSize: '20px',
lineHeight: '30px',
letterSpacing: '0.75px',
color: 'black'
});
128 changes: 128 additions & 0 deletions client/src/components/AssetDetailsPage/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/** @jsx jsx */
import { FC, Fragment } from 'react';
import { jsx } from '@emotion/core';
import { Row, Col, Spin, Skeleton, Alert as AntdAlert } from 'antd';
import { Flip, AttentionSeeker } from 'react-awesome-reveal';

import Page from '../Page';
import { BackButtonRow } from '../common/PageTitle';
import { Name } from './Typography';
import AssetDescription from './AssetDescription';
import Actions from './Actions';
import { useNftsQuery } from '../common/useNftsQuery';
import { NonFungibleToken } from '../../generated/graphql_schema';
import { urlFromCid } from '../../api/ipfsUploader';
import { useWalletAddress } from '../App/globalContext';
import NotConnectedAlert from '../common/NotConnectedAlert';

const Image: FC<{ nft?: NonFungibleToken }> = ({ nft }) => {
return (
<Fragment>
{!nft ? (
<Skeleton.Image
css={{
display: 'flex',
flex: 1,
width: '70%',
padding: '1em',
border: 'solid 1px'
}}
/>
) : (
<div css={{ width: '70%', padding: '1em', border: 'solid 1px' }}>
<Flip key={nft.extras.ipfs_cid}>
<img
css={{ width: '100%' }}
src={urlFromCid(nft.extras.ipfs_cid)}
alt=""
/>
</Flip>
</div>
)}
</Fragment>
);
};

const AssetDetails: FC<{ nft?: NonFungibleToken }> = ({ nft }) => (
<Row>
<Col offset={3} span={18}>
<Row>
<Col offset={12} span={12}>
{nft ? <Name>{nft.name}</Name> : <Skeleton paragraph={false} />}
</Col>
</Row>
<Row>
<Col span={12}>
<Image nft={nft} />
</Col>
<Col span={12}>
<AssetDescription nft={nft} />
</Col>
</Row>
<Row>
<Col offset={12} span={12}>
<Actions />
</Col>
</Row>
</Col>
</Row>
);

const Alert: FC<{ message: string; description: string }> = ({
message,
description
}) => (
<AttentionSeeker effect="headShake">
<AntdAlert
css={{ marginTop: '3em', marginBottom: '3em', width: '50em' }}
type="error"
message={message}
description={description}
showIcon
/>
</AttentionSeeker>
);
interface Props {
contractAddress: string;
tokenId: number;
}

export const PageBody: FC<Props> = ({ contractAddress, tokenId }) => {
const walletAddress = useWalletAddress();
const { data, error, loading } = useNftsQuery(contractAddress);
const nft = data?.nfts.find(t => t.tokenId === tokenId);

if (!walletAddress)
return (
<NotConnectedAlert
message="Cannot show asset details!"
description="To see your asset details please connect to your wallet first."
/>
);

if (error)
return <Alert message="GraphQL Error!" description={error.toString()} />;

if (data && !nft)
return (
<Alert
message="GraphQL Error!"
description={`Cannot find token ${tokenId} in contract ${contractAddress}`}
/>
);

return (
<Spin spinning={loading} size="large">
<AssetDetails nft={nft} />
</Spin>
);
};

const AssetDetailsPage: FC<Props> = ({ contractAddress, tokenId }) => (
<Page>
<BackButtonRow onClick={() => window.history.back()} />
<PageBody contractAddress={contractAddress} tokenId={tokenId} />
</Page>
);

export default AssetDetailsPage;
5 changes: 3 additions & 2 deletions client/src/components/AssetsPage/AssetCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { urlFromCid } from '../../api/ipfsUploader';
import AssetTransfer from './AssetTransfer';
import { useContracts } from '../App/globalContext';
import useSettings from '../common/useSettings';
import { useLocation } from 'wouter';

const { Paragraph, Text, Link } = Typography;

Expand Down Expand Up @@ -65,6 +66,7 @@ const AssetCard: FC<Props> = ({ token, onChange }) => {
const [transferVisible, setTransferVisible] = useState(false);
const contracts = useContracts();
const { settings } = useSettings();
const [, setLocation] = useLocation();

const handleTransfer = () => {
if (!contracts) {
Expand Down Expand Up @@ -182,8 +184,7 @@ const AssetCard: FC<Props> = ({ token, onChange }) => {
<Col span={12} css={{ display: 'flex', alignItems: 'center' }}>
<Link
css={{ margin: 'auto' }}
href={`${settings?.bcdGuiUrl}/${settings?.bcdNetwork}/${token.contractInfo.address}`}
target="_blank"
onClick={() => setLocation(`/asset-details/${token.contractInfo.address}/${token.tokenId}`)}
>
DETAILS
</Link>
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/AssetsPage/Assets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { jsx } from '@emotion/core';
import { Row, Col, Spin } from 'antd';
import { Zoom } from 'react-awesome-reveal';

import { useNftsQuery } from './useNftsQuery';
import { useNftsQuery } from '../common/useNftsQuery';
import AssetCard from './AssetCard';
import ContractsFilter from './ContractsFilter';
import ContractsTitle from './ContractsTitle';
Expand Down
35 changes: 14 additions & 21 deletions client/src/components/AssetsPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,13 @@
import { FC } from 'react';
import { jsx } from '@emotion/core';
import { useLocation } from 'wouter';
import { Alert, Row, Col } from 'antd';
import { AttentionSeeker } from 'react-awesome-reveal';
import { Row, Col } from 'antd';

import { useWalletAddress } from '../App/globalContext';
import WalletConnector from '../WalletConnector';
import Page from '../Page';
import PageTitle from '../common/PageTitle';
import Assets from './Assets';

const NotConnectedAlert: FC = () => (
<Row>
<Col offset={3} span={18}>
<AttentionSeeker effect="headShake">
<Alert
css={{ marginTop: '3em', marginBottom: '3em', width: '50em' }}
type="error"
message="Cannot show assets!"
description="To see your assets please connect to your wallet first."
showIcon
/>
</AttentionSeeker>
<WalletConnector />
</Col>
</Row>
);
import NotConnectedAlert from '../common/NotConnectedAlert';

const AssetsPage: FC = () => {
const [, setLocation] = useLocation();
Expand All @@ -41,7 +23,18 @@ const AssetsPage: FC = () => {
setLocation('/');
}}
/>
{walletAddress ? <Assets /> : <NotConnectedAlert />}
{walletAddress ? (
<Assets />
) : (
<Row>
<Col offset={3} span={18}>
<NotConnectedAlert
message="Cannot show assets!"
description="To see your assets please connect to your wallet first."
/>
</Col>
</Row>
)}
</Page>
);
};
Expand Down
Loading

0 comments on commit 1b6315a

Please sign in to comment.