Skip to content

Commit

Permalink
feat: update postage stamp creation screen (#641)
Browse files Browse the repository at this point in the history
* style: UI changes for postage stamp

* feat: New postage stamp standard page

---------

Co-authored-by: Seres Roland <[email protected]>
  • Loading branch information
rolandlor and Seres Roland authored Dec 4, 2023
1 parent 20a051b commit 4f9abc6
Show file tree
Hide file tree
Showing 12 changed files with 392 additions and 87 deletions.
46 changes: 23 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"url": "https://github.com/ethersphere/bee-dashboard.git"
},
"dependencies": {
"@ethersphere/bee-js": "^6.2.0",
"@ethersphere/bee-js": "^6.6.0",
"@ethersphere/swarm-cid": "^0.1.0",
"@material-ui/core": "4.12.3",
"@material-ui/icons": "4.11.2",
Expand Down
2 changes: 1 addition & 1 deletion src/pages/account/stamps/AccountStamps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function AccountStamps(): ReactElement {
if (status.all === CheckState.ERROR) return <TroubleshootConnectionCard />

function navigateToNewStamp() {
navigate(ROUTES.ACCOUNT_STAMPS_NEW)
navigate(ROUTES.ACCOUNT_STAMPS_NEW_STANDARD)
}

return (
Expand Down
4 changes: 2 additions & 2 deletions src/pages/files/Upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { detectIndexHtml, getAssetNameFromFiles, packageFile } from '../../utils
import { persistIdentity, updateFeed } from '../../utils/identity'
import { HISTORY_KEYS, putHistory } from '../../utils/local-storage'
import { FeedPasswordDialog } from '../feeds/FeedPasswordDialog'
import { PostageStampCreation } from '../stamps/PostageStampCreation'
import { PostageStampAdvancedCreation } from '../stamps/PostageStampAdvancedCreation'
import { PostageStampSelector } from '../stamps/PostageStampSelector'
import { AssetPreview } from './AssetPreview'
import { StampPreview } from './StampPreview'
Expand Down Expand Up @@ -186,7 +186,7 @@ export function Upload(): ReactElement {
{hasAnyStamps && stampMode === 'SELECT' ? (
<PostageStampSelector onSelect={stamp => setStamp(stamp)} defaultValue={stamp?.batchID} />
) : (
<PostageStampCreation onFinished={() => setStampMode('SELECT')} />
<PostageStampAdvancedCreation onFinished={() => setStampMode('SELECT')} />
)}
</Box>
<Box mb={4}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ReactElement } from 'react'
import { useNavigate } from 'react-router'
import { HistoryHeader } from '../../components/HistoryHeader'
import { ROUTES } from '../../routes'
import { PostageStampCreation } from './PostageStampCreation'
import { PostageStampAdvancedCreation } from './PostageStampAdvancedCreation'

export function CreatePostageStampPage(): ReactElement {
const navigate = useNavigate()
Expand All @@ -13,8 +13,8 @@ export function CreatePostageStampPage(): ReactElement {

return (
<div>
<HistoryHeader>Buy new postage stamp</HistoryHeader>
<PostageStampCreation onFinished={onFinished} />
<HistoryHeader>Buy new postage stamp batch</HistoryHeader>
<PostageStampAdvancedCreation onFinished={onFinished} />
</div>
)
}
20 changes: 20 additions & 0 deletions src/pages/stamps/CreatePostageStampStandardPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ReactElement } from 'react'
import { useNavigate } from 'react-router'
import { HistoryHeader } from '../../components/HistoryHeader'
import { ROUTES } from '../../routes'
import { PostageStampStandardCreation } from './PostageStampStandardCreation'

export function CreatePostageStampBasicPage(): ReactElement {
const navigate = useNavigate()

function onFinished() {
navigate(ROUTES.ACCOUNT_STAMPS)
}

return (
<div>
<HistoryHeader>Buy new postage stamp batch</HistoryHeader>
<PostageStampStandardCreation onFinished={onFinished} />
</div>
)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PostageBatchOptions } from '@ethersphere/bee-js'
import { Box, Grid, Typography } from '@material-ui/core'
import { createStyles, makeStyles, Theme } from '@material-ui/core/styles'
import BigNumber from 'bignumber.js'
import { useSnackbar } from 'notistack'
import { ReactElement, useContext, useState } from 'react'
Expand All @@ -18,12 +19,32 @@ import {
waitUntilStampExists,
} from '../../utils'
import { getHumanReadableFileSize } from '../../utils/file'
import { Link } from 'react-router-dom'
import { ROUTES } from '../../routes'

interface Props {
onFinished: () => void
}

export function PostageStampCreation({ onFinished }: Props): ReactElement {
const useStyles = makeStyles((theme: Theme) =>
createStyles({
link: {
color: '#dd7700',
textDecoration: 'underline',
'&:hover': {
textDecoration: 'none',

// https://github.com/mui-org/material-ui/issues/22543
'@media (hover: none)': {
textDecoration: 'none',
},
},
},
}),
)

export function PostageStampAdvancedCreation({ onFinished }: Props): ReactElement {
const classes = useStyles()
const { chainState } = useContext(BeeContext)
const { refresh } = useContext(StampsContext)
const { beeDebugApi } = useContext(SettingsContext)
Expand Down Expand Up @@ -153,22 +174,25 @@ export function PostageStampCreation({ onFinished }: Props): ReactElement {

return (
<>
<Box mb={4}>
<Typography>
To upload data to Swarm network, you will need to purchase a postage stamp. If you&apos;re not familiar with
this, please read{' '}
<a
href="https://medium.com/ethereum-swarm/how-to-upload-data-to-the-swarm-network-c0766c3ae381"
target="_blank"
rel="noreferrer"
>
this guide
</a>
.
</Typography>
<Box mb={1}>
<Typography variant="h2">Batch name</Typography>
</Box>
<Box mb={2}>
<SwarmTextInput name="label" label="Label" optional onChange={event => setLabelInput(event.target.value)} />
</Box>
<Box mb={2}>
<SwarmSelect
label="Immutable"
defaultValue="No"
onChange={event => setImmutable(event.target.value === 'Yes')}
options={[
{ value: 'Yes', label: 'Yes' },
{ value: 'No', label: 'No' },
]}
/>
</Box>
<Box mb={2}>
<SwarmTextInput name="depth" label="Depth" onChange={event => validateDepthInput(event.target.value)} />
<SwarmTextInput name="depth" label="Batch depth" onChange={event => validateDepthInput(event.target.value)} />
<Box mt={0.25} sx={{ bgcolor: '#f6f6f6' }} p={2}>
<Grid container justifyContent="space-between">
<Typography>Corresponding file size</Typography>
Expand All @@ -185,38 +209,14 @@ export function PostageStampCreation({ onFinished }: Props): ReactElement {
<Typography>{!amountError && amountInput ? getTtl(Number.parseInt(amountInput, 10)) : '-'}</Typography>
</Grid>
</Box>
{amountError && <Typography>{amountError}</Typography>}
</Box>
<Box mb={2}>
<SwarmTextInput name="label" label="Label" optional onChange={event => setLabelInput(event.target.value)} />
</Box>
<Box mb={2}>
<SwarmSelect
label="Immutable"
defaultValue="No"
onChange={event => setImmutable(event.target.value === 'Yes')}
options={[
{ value: 'Yes', label: 'Yes' },
{ value: 'No', label: 'No' },
]}
/>
<Box mt={0.25} sx={{ bgcolor: '#f6f6f6' }} p={2}>
<Grid container justifyContent="space-between">
{immutable && (
<Typography>
Once an immutable stamp is maxed out, it disallows further content uploads, thereby safeguarding your
previously uploaded content from unintentional overwriting.
</Typography>
)}
{!immutable && (
<Typography>
When a mutable stamp reaches full capacity, it still permits new content uploads. However, this comes
with the caveat of overwriting previously uploaded content associated with the same stamp.
</Typography>
)}
</Grid>
<Box display="flex" justifyContent={'right'} mt={0.5}>
<Typography style={{ fontSize: '10px', color: 'rgba(0, 0, 0, 0.26)' }}>
Current price of 24000 per block
</Typography>
</Box>
{amountError && <Typography>{amountError}</Typography>}
</Box>

<Box mb={4} sx={{ bgcolor: '#fcf2e8' }} p={2}>
<Grid container justifyContent="space-between">
<Typography>Indicative Price</Typography>
Expand All @@ -227,14 +227,24 @@ export function PostageStampCreation({ onFinished }: Props): ReactElement {
</Typography>
</Grid>
</Box>
<SwarmButton
disabled={submitting || Boolean(depthError) || Boolean(amountError) || !depthInput || !amountInput}
onClick={submit}
iconType={Check}
loading={submitting}
>
Buy New Stamp
</SwarmButton>

<Grid container justifyContent="space-between" alignItems="center">
<Grid item>
<SwarmButton
disabled={submitting || Boolean(depthError) || Boolean(amountError) || !depthInput || !amountInput}
onClick={submit}
iconType={Check}
loading={submitting}
>
Buy New Stamp
</SwarmButton>
</Grid>
<Grid item>
<Link to={ROUTES.ACCOUNT_STAMPS_NEW_STANDARD} className={classes.link}>
Standard mode
</Link>
</Grid>
</Grid>
</>
)
}
Loading

0 comments on commit 4f9abc6

Please sign in to comment.