|
| 1 | +import type { DataLayerOfferSummary, SingletonSummaryRecord } from '@chia-network/api'; |
| 2 | +import { Color, CopyToClipboard, Flex, Truncate, truncateValue } from '@chia-network/core'; |
| 3 | +import { Trans } from '@lingui/macro'; |
| 4 | +import ArrowForwardIcon from '@mui/icons-material/ArrowForward'; |
| 5 | +import StorageIcon from '@mui/icons-material/Storage'; |
| 6 | +import VerifiedIcon from '@mui/icons-material/Verified'; |
| 7 | +import { |
| 8 | + Box, |
| 9 | + Chip, |
| 10 | + Divider, |
| 11 | + Table, |
| 12 | + TableBody, |
| 13 | + TableCell, |
| 14 | + TableContainer, |
| 15 | + TableHead, |
| 16 | + TableRow, |
| 17 | + Typography, |
| 18 | +} from '@mui/material'; |
| 19 | +import { useTheme } from '@mui/material/styles'; |
| 20 | +import React from 'react'; |
| 21 | + |
| 22 | +export type DataLayerOfferViewerProps = { |
| 23 | + summary: DataLayerOfferSummary; |
| 24 | +}; |
| 25 | + |
| 26 | +function StoreUpdateCard({ entry, index }: { entry: SingletonSummaryRecord; index: number }) { |
| 27 | + const theme = useTheme(); |
| 28 | + |
| 29 | + return ( |
| 30 | + <Box |
| 31 | + sx={{ |
| 32 | + borderRadius: 1, |
| 33 | + p: 3, |
| 34 | + backgroundColor: 'background.card', |
| 35 | + border: '1px solid', |
| 36 | + borderColor: theme.palette.mode === 'light' ? Color.Neutral[300] : Color.Neutral[600], |
| 37 | + }} |
| 38 | + > |
| 39 | + <Flex flexDirection="column" gap={2}> |
| 40 | + <Flex alignItems="center" gap={1}> |
| 41 | + <StorageIcon fontSize="small" color="primary" /> |
| 42 | + <Typography variant="subtitle2"> |
| 43 | + <Trans>Store {index + 1}</Trans> |
| 44 | + </Typography> |
| 45 | + </Flex> |
| 46 | + |
| 47 | + <Flex flexDirection="row" alignItems="center" gap={1}> |
| 48 | + <Typography variant="body2" color="textSecondary" sx={{ minWidth: 80 }}> |
| 49 | + <Trans>Store ID</Trans> |
| 50 | + </Typography> |
| 51 | + <Chip label={truncateValue(entry.launcherId, {})} size="small" variant="outlined" /> |
| 52 | + <CopyToClipboard value={entry.launcherId} /> |
| 53 | + </Flex> |
| 54 | + |
| 55 | + <Flex flexDirection="row" alignItems="center" gap={1}> |
| 56 | + <Typography variant="body2" color="textSecondary" sx={{ minWidth: 80 }}> |
| 57 | + <Trans>New Root</Trans> |
| 58 | + </Typography> |
| 59 | + <Flex alignItems="center" gap={0.5}> |
| 60 | + <ArrowForwardIcon fontSize="small" color="action" /> |
| 61 | + <Chip label={truncateValue(entry.newRoot, {})} size="small" color="primary" variant="outlined" /> |
| 62 | + <CopyToClipboard value={entry.newRoot} /> |
| 63 | + </Flex> |
| 64 | + </Flex> |
| 65 | + </Flex> |
| 66 | + </Box> |
| 67 | + ); |
| 68 | +} |
| 69 | + |
| 70 | +function RequiredProofsTable({ entries }: { entries: SingletonSummaryRecord[] }) { |
| 71 | + const allDeps = entries.flatMap((entry) => |
| 72 | + entry.dependencies.map((dep) => ({ |
| 73 | + sourceStoreId: entry.launcherId, |
| 74 | + dependsOnStoreId: dep.launcherId, |
| 75 | + valuesToProve: dep.valuesToProve, |
| 76 | + })), |
| 77 | + ); |
| 78 | + |
| 79 | + if (allDeps.length === 0) return null; |
| 80 | + |
| 81 | + return ( |
| 82 | + <Box> |
| 83 | + <Flex alignItems="center" gap={1} sx={{ mb: 1.5 }}> |
| 84 | + <VerifiedIcon fontSize="small" color="info" /> |
| 85 | + <Typography variant="subtitle2"> |
| 86 | + <Trans>Required Proofs</Trans> |
| 87 | + </Typography> |
| 88 | + </Flex> |
| 89 | + <Typography variant="body2" color="textSecondary" sx={{ mb: 2 }}> |
| 90 | + <Trans> |
| 91 | + The following values must be proven to exist in the specified stores before this offer can be accepted. |
| 92 | + </Trans> |
| 93 | + </Typography> |
| 94 | + <TableContainer> |
| 95 | + <Table size="small"> |
| 96 | + <TableHead> |
| 97 | + <TableRow> |
| 98 | + <TableCell> |
| 99 | + <Trans>For Store Update</Trans> |
| 100 | + </TableCell> |
| 101 | + <TableCell> |
| 102 | + <Trans>Requires Proof From Store</Trans> |
| 103 | + </TableCell> |
| 104 | + <TableCell> |
| 105 | + <Trans>Values to Prove</Trans> |
| 106 | + </TableCell> |
| 107 | + </TableRow> |
| 108 | + </TableHead> |
| 109 | + <TableBody> |
| 110 | + {allDeps.map((dep) => ( |
| 111 | + <TableRow key={`${dep.sourceStoreId}-${dep.dependsOnStoreId}`}> |
| 112 | + <TableCell> |
| 113 | + <Flex alignItems="center" gap={0.5}> |
| 114 | + <Truncate tooltip>{dep.sourceStoreId}</Truncate> |
| 115 | + <CopyToClipboard value={dep.sourceStoreId} /> |
| 116 | + </Flex> |
| 117 | + </TableCell> |
| 118 | + <TableCell> |
| 119 | + <Flex alignItems="center" gap={0.5}> |
| 120 | + <Truncate tooltip>{dep.dependsOnStoreId}</Truncate> |
| 121 | + <CopyToClipboard value={dep.dependsOnStoreId} /> |
| 122 | + </Flex> |
| 123 | + </TableCell> |
| 124 | + <TableCell> |
| 125 | + <Flex flexDirection="column" gap={0.5}> |
| 126 | + {dep.valuesToProve.map((v) => ( |
| 127 | + <Flex key={v} alignItems="center" gap={0.5}> |
| 128 | + <Truncate tooltip>{v}</Truncate> |
| 129 | + <CopyToClipboard value={v} /> |
| 130 | + </Flex> |
| 131 | + ))} |
| 132 | + </Flex> |
| 133 | + </TableCell> |
| 134 | + </TableRow> |
| 135 | + ))} |
| 136 | + </TableBody> |
| 137 | + </Table> |
| 138 | + </TableContainer> |
| 139 | + </Box> |
| 140 | + ); |
| 141 | +} |
| 142 | + |
| 143 | +export default function DataLayerOfferViewer(props: DataLayerOfferViewerProps) { |
| 144 | + const { summary } = props; |
| 145 | + |
| 146 | + return ( |
| 147 | + <Flex flexDirection="column" gap={3}> |
| 148 | + <Typography variant="h6"> |
| 149 | + <Trans>Data Layer Offer</Trans> |
| 150 | + </Typography> |
| 151 | + <Typography variant="body2" color="textSecondary"> |
| 152 | + <Trans> |
| 153 | + This offer proposes updates to Data Layer store roots. Accepting it will transition the listed stores to new |
| 154 | + roots. Dependencies specify values that must be proven to exist in other stores before acceptance. |
| 155 | + </Trans> |
| 156 | + </Typography> |
| 157 | + |
| 158 | + <Divider /> |
| 159 | + |
| 160 | + <Box> |
| 161 | + <Flex alignItems="center" gap={1} sx={{ mb: 1.5 }}> |
| 162 | + <StorageIcon fontSize="small" color="primary" /> |
| 163 | + <Typography variant="subtitle1"> |
| 164 | + <Trans>Offered Store Updates ({summary.offered.length})</Trans> |
| 165 | + </Typography> |
| 166 | + </Flex> |
| 167 | + <Typography variant="body2" color="textSecondary" sx={{ mb: 2 }}> |
| 168 | + <Trans>These stores will have their roots updated to the specified values.</Trans> |
| 169 | + </Typography> |
| 170 | + <Flex flexDirection="column" gap={2}> |
| 171 | + {summary.offered.map((entry, i) => ( |
| 172 | + <StoreUpdateCard key={entry.launcherId} entry={entry} index={i} /> |
| 173 | + ))} |
| 174 | + </Flex> |
| 175 | + </Box> |
| 176 | + |
| 177 | + <Divider /> |
| 178 | + |
| 179 | + <RequiredProofsTable entries={summary.offered} /> |
| 180 | + </Flex> |
| 181 | + ); |
| 182 | +} |
0 commit comments