|
| 1 | +import { OfferAssets, OfferRecord } from '@/bindings'; |
| 2 | +import { nftUri } from '@/lib/nftUri'; |
| 3 | +import { toDecimal } from '@/lib/utils'; |
| 4 | +import { useWalletState } from '@/state'; |
| 5 | +import BigNumber from 'bignumber.js'; |
| 6 | + |
| 7 | +export interface OfferSummaryCardProps { |
| 8 | + record: OfferRecord; |
| 9 | + content: React.ReactNode; |
| 10 | +} |
| 11 | + |
| 12 | +export function OfferSummaryCard({ record, content }: OfferSummaryCardProps) { |
| 13 | + return ( |
| 14 | + <div className='block p-4 rounded-sm bg-neutral-100 dark:bg-neutral-900'> |
| 15 | + <div className='flex justify-between'> |
| 16 | + <div className='grid grid-cols-1 md:grid-cols-3 gap-4'> |
| 17 | + <div className='flex flex-col gap-1'> |
| 18 | + <div> |
| 19 | + {record.status === 'active' |
| 20 | + ? 'Pending' |
| 21 | + : record.status === 'completed' |
| 22 | + ? 'Taken' |
| 23 | + : record.status === 'cancelled' |
| 24 | + ? 'Cancelled' |
| 25 | + : 'Expired'} |
| 26 | + </div> |
| 27 | + <div className='text-muted-foreground text-sm'> |
| 28 | + {record.creation_date} |
| 29 | + </div> |
| 30 | + </div> |
| 31 | + |
| 32 | + <AssetPreview label='Offered' assets={record.summary.maker} /> |
| 33 | + <AssetPreview label='Requested' assets={record.summary.taker} /> |
| 34 | + </div> |
| 35 | + |
| 36 | + {content} |
| 37 | + </div> |
| 38 | + </div> |
| 39 | + ); |
| 40 | +} |
| 41 | + |
| 42 | +interface AssetPreviewProps { |
| 43 | + label: string; |
| 44 | + assets: OfferAssets; |
| 45 | +} |
| 46 | + |
| 47 | +function AssetPreview({ label, assets }: AssetPreviewProps) { |
| 48 | + const walletState = useWalletState(); |
| 49 | + |
| 50 | + return ( |
| 51 | + <div className='flex flex-col gap-1 w-[125px] lg:w-[200px] xl:w-[300px]'> |
| 52 | + <div>{label}</div> |
| 53 | + {BigNumber(assets.xch.amount) |
| 54 | + .plus(assets.xch.royalty) |
| 55 | + .isGreaterThan(0) && ( |
| 56 | + <div className='flex items-center gap-2'> |
| 57 | + <img src='https://icons.dexie.space/xch.webp' className='w-8 h-8' /> |
| 58 | + |
| 59 | + <div className='text-sm text-muted-foreground truncate'> |
| 60 | + {toDecimal( |
| 61 | + BigNumber(assets.xch.amount).plus(assets.xch.royalty).toString(), |
| 62 | + walletState.sync.unit.decimals, |
| 63 | + )}{' '} |
| 64 | + {walletState.sync.unit.ticker} |
| 65 | + </div> |
| 66 | + </div> |
| 67 | + )} |
| 68 | + {Object.entries(assets.cats).map(([_assetId, cat]) => ( |
| 69 | + <div className='flex items-center gap-2'> |
| 70 | + <img src={cat.icon_url!} className='w-8 h-8' /> |
| 71 | + |
| 72 | + <div className='text-sm text-muted-foreground truncate'> |
| 73 | + {toDecimal(BigNumber(cat.amount).plus(cat.royalty).toString(), 3)}{' '} |
| 74 | + {cat.name ?? cat.ticker ?? 'Unknown'} |
| 75 | + </div> |
| 76 | + </div> |
| 77 | + ))} |
| 78 | + {Object.entries(assets.nfts).map(([_nftId, nft]) => ( |
| 79 | + <div className='flex items-center gap-2'> |
| 80 | + <img |
| 81 | + src={nftUri(nft.image_mime_type, nft.image_data)} |
| 82 | + className='w-8 h-8' |
| 83 | + /> |
| 84 | + |
| 85 | + <div className='text-sm text-muted-foreground truncate'> |
| 86 | + {nft.name ?? 'Unknown'} |
| 87 | + </div> |
| 88 | + </div> |
| 89 | + ))} |
| 90 | + </div> |
| 91 | + ); |
| 92 | +} |
0 commit comments