Skip to content

Commit

Permalink
Adapt TokenTrader for single NFT
Browse files Browse the repository at this point in the history
  • Loading branch information
macterra committed Oct 25, 2023
1 parent 9282ce8 commit e97073c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion frontend/src/NftView.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const NftView = ({ navigate }) => {
<Tab key="history" value="history" label={'History'} />
</Tabs>
{tab === 'edition' && <EditionView nft={nft} />}
{tab === 'trade' && <TokenTrader metadata={nft.token} setRefreshKey={setRefreshKey} />}
{tab === 'trade' && <TokenTrader metadata={nft.token} xid={nft.xid} setRefreshKey={setRefreshKey} />}
{tab === 'pfp' && <PfpEditor metadata={nft.token} setTab={setTab} />}
{tab === 'history' && <TokenHistory metadata={nft.token} xid={nft.xid} />}
</div>
Expand Down
30 changes: 22 additions & 8 deletions frontend/src/TokenTrader.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import axios from 'axios';
import InvoiceView from './InvoiceView';

const TokenTrader = ({ metadata, setRefreshKey }) => {
const TokenTrader = ({ metadata, xid, setRefreshKey }) => {
const [nfts, setNfts] = useState(0);
const [exchangeRate, setExchangeRate] = useState(null);
const [modalOpen, setModalOpen] = useState(false);
Expand All @@ -32,11 +32,19 @@ const TokenTrader = ({ metadata, setRefreshKey }) => {

const nfts = [];

for (const xid of metadata.token.nfts) {
if (xid) {
// single NFT specified from NftView
const response = await fetch(`/api/v1/asset/${xid}`);
const nft = await response.json();
nfts.push(nft);
}
else {
for (const xid of metadata.token.nfts) {
const response = await fetch(`/api/v1/asset/${xid}`);
const nft = await response.json();
nfts.push(nft);
}
}

setNfts(nfts);
} catch (error) {
Expand Down Expand Up @@ -94,7 +102,7 @@ const TokenTrader = ({ metadata, setRefreshKey }) => {

return (
<TableRow>
<TableCell>{nft.asset.title}</TableCell>
<TableCell><a href={`/nft/${nft.xid}`}>{nft.asset.title}</a></TableCell>
<TableCell align="right">{usdPrice}</TableCell>
{nft.userIsOwner ?
(
Expand Down Expand Up @@ -217,12 +225,18 @@ const TokenTrader = ({ metadata, setRefreshKey }) => {
<TableBody>
<TableRow>
<TableCell>Title:</TableCell>
<TableCell>{metadata.asset.title}</TableCell>
</TableRow>
<TableRow>
<TableCell>Editions:</TableCell>
<TableCell>{metadata.token.editions > 1 ? metadata.token.editions : "1 of 1"}</TableCell>
{xid ? (
<TableCell>{metadata.asset.title} ({nfts[0].asset.title})</TableCell>
) : (
<TableCell>{metadata.asset.title}</TableCell>
)}
</TableRow>
{!xid &&
<TableRow>
<TableCell>Editions:</TableCell>
<TableCell>{metadata.token.editions > 1 ? metadata.token.editions : "1 of 1"}</TableCell>
</TableRow>
}
<TableRow>
<TableCell>Exchange rate:</TableCell>
<TableCell>{exchangeRate} USD/BTC</TableCell>
Expand Down

0 comments on commit e97073c

Please sign in to comment.