Skip to content

Commit

Permalink
add token thumbnail to mech invetory
Browse files Browse the repository at this point in the history
  • Loading branch information
samepant committed Jan 29, 2024
1 parent d76944f commit 30b62b9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
14 changes: 14 additions & 0 deletions frontend/src/components/NFTItem/NFTItem.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@
}

.assetList {
display: flex;
flex-direction: column;
gap: 10px;
width: 100%;
}

Expand All @@ -145,6 +148,17 @@
font-size: 12px;
}

.assetName {
display: flex;
gap: 10px;
align-items: center;
}
.assetName img {
width: 20px;
height: 20px;
border-radius: 50%;
}

.asset .value {
display: flex;
gap: 10px;
Expand Down
33 changes: 22 additions & 11 deletions frontend/src/components/NFTItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ const NFTItem: React.FC<Props> = ({ nft, chainId }) => {
chainId,
})

const mechBalances = data ? [data.native, ...data.erc20s] : []
const mechNativeBalance = data ? data.native : null
const mechErc20Balances = data ? data.erc20s : []
const { deployed } = useDeployMech(getNFTContext(nft), chainId)
const metadata = JSON.parse(nft.metadata || "{}")
const name = nft.name || metadata?.name || "..."
Expand Down Expand Up @@ -98,20 +99,30 @@ const NFTItem: React.FC<Props> = ({ nft, chainId }) => {
</ul>
</div>
<label>Inventory</label>
<div
className={clsx(
classes.assetsContainer,
mechBalances.length === 0 && classes.empty
)}
>
<div className={clsx(classes.assetsContainer)}>
{mechBalancesError && <p>Failed to load assets</p>}
{mechBalancesLoading && <Loading />}

{mechBalances.length === 0 && <p>No assets found</p>}
<ul className={classes.assetList}>
{mechBalances.map((balance, index) => (
{!mechBalancesLoading && !mechBalancesError && mechNativeBalance && (
<li className={classes.asset}>
<div>{mechNativeBalance.name}</div>
<div className={classes.value}>
<p>
{formatUnits(
BigInt(mechNativeBalance.balance),
mechNativeBalance.decimals || 0
)}
</p>
<p>{mechNativeBalance.symbol}</p>
</div>
</li>
)}
{mechErc20Balances.map((balance, index) => (
<li key={index} className={classes.asset}>
<div>{balance.name}</div>
<div className={classes.assetName}>
<img src={balance.logo} alt={`logo for ${balance.name}`} />
<div>{balance.name}</div>
</div>
<div className={classes.value}>
<p>
{formatUnits(BigInt(balance.balance), balance.decimals || 0)}
Expand Down

1 comment on commit 30b62b9

@vercel
Copy link

@vercel vercel bot commented on 30b62b9 Jan 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.