1- import { PostageBatchOptions } from '@ethersphere/bee-js'
2- import { Box , Grid , Typography , createStyles , makeStyles } from '@material-ui/core'
1+ import { PostageBatchOptions , Utils } from '@ethersphere/bee-js'
2+ import { Box , Grid , IconButton , Typography , createStyles , makeStyles } from '@material-ui/core'
33import BigNumber from 'bignumber.js'
44import { useSnackbar } from 'notistack'
55import { ReactElement , useContext , useState } from 'react'
66import { Link } from 'react-router-dom'
77import Check from 'remixicon-react/CheckLineIcon'
8+ import Info from 'remixicon-react/InformationLineIcon'
89import { SwarmButton } from '../../components/SwarmButton'
910import { SwarmSelect } from '../../components/SwarmSelect'
1011import { SwarmTextInput } from '../../components/SwarmTextInput'
1112import { Context as BeeContext } from '../../providers/Bee'
1213import { Context as SettingsContext } from '../../providers/Settings'
1314import { Context as StampsContext } from '../../providers/Stamps'
1415import { ROUTES } from '../../routes'
15- import {
16- calculateStampPrice ,
17- convertAmountToSeconds ,
18- convertDepthToBytes ,
19- secondsToTimeString ,
20- waitUntilStampExists ,
21- } from '../../utils'
16+ import { calculateStampPrice , convertAmountToSeconds , secondsToTimeString , waitUntilStampExists } from '../../utils'
2217import { getHumanReadableFileSize } from '../../utils/file'
2318
2419interface Props {
@@ -39,6 +34,14 @@ const useStyles = makeStyles(() =>
3934 } ,
4035 } ,
4136 } ,
37+ stampVolumeWrapper : {
38+ width : 'fit-content' ,
39+ '& button' : {
40+ marginLeft : 4 ,
41+ width : 24 ,
42+ padding : 2 ,
43+ } ,
44+ } ,
4245 } ) ,
4346)
4447
@@ -58,14 +61,6 @@ export function PostageStampAdvancedCreation({ onFinished }: Props): ReactElemen
5861
5962 const { enqueueSnackbar } = useSnackbar ( )
6063
61- function getFileSize ( depth : number ) : string {
62- if ( isNaN ( depth ) || depth < 17 || depth > 255 ) {
63- return '-'
64- }
65-
66- return `~${ getHumanReadableFileSize ( convertDepthToBytes ( depth ) ) } `
67- }
68-
6964 function getTtl ( amount : number ) : string {
7065 const isCurrentPriceAvailable = chainState && chainState . currentPrice
7166
@@ -171,6 +166,36 @@ export function PostageStampAdvancedCreation({ onFinished }: Props): ReactElemen
171166 setDepthInput ( validDepthInput )
172167 }
173168
169+ function renderStampVolumesInfo ( ) {
170+ const depth = parseInt ( depthInput , 10 )
171+
172+ if ( depthError || isNaN ( depth ) || depth < 17 || depth > 255 ) {
173+ return '-'
174+ }
175+
176+ const theoreticalMaximumVolume = getHumanReadableFileSize ( Utils . getStampMaximumCapacityBytes ( depth ) )
177+ const effectiveVolume = getHumanReadableFileSize ( Utils . getStampEffectiveBytes ( depth ) )
178+
179+ return (
180+ < Grid item container alignItems = "center" className = { classes . stampVolumeWrapper } >
181+ < Typography >
182+ Theoretical: ~{ theoreticalMaximumVolume } / Effective: ~{ effectiveVolume }
183+ </ Typography >
184+ < IconButton
185+ onClick = { ( ) =>
186+ window . open (
187+ 'https://docs.ethswarm.org/docs/learn/technology/contracts/postage-stamp/#effective-utilisation-table' ,
188+ '_blank' ,
189+ 'noopener,noreferrer' ,
190+ )
191+ }
192+ >
193+ < Info />
194+ </ IconButton >
195+ </ Grid >
196+ )
197+ }
198+
174199 return (
175200 < >
176201 < Box mb = { 4 } >
@@ -190,9 +215,9 @@ export function PostageStampAdvancedCreation({ onFinished }: Props): ReactElemen
190215 < Box mb = { 2 } >
191216 < SwarmTextInput name = "depth" label = "Depth" onChange = { event => validateDepthInput ( event . target . value ) } />
192217 < Box mt = { 0.25 } sx = { { bgcolor : '#f6f6f6' } } p = { 2 } >
193- < Grid container justifyContent = "space-between" >
218+ < Grid container justifyContent = "space-between" alignItems = "center" >
194219 < Typography > Corresponding file size</ Typography >
195- < Typography > { ! depthError && depthInput ? getFileSize ( parseInt ( depthInput , 10 ) ) : '-' } </ Typography >
220+ { renderStampVolumesInfo ( ) }
196221 </ Grid >
197222 </ Box >
198223 { depthError && < Typography > { depthError } </ Typography > }
0 commit comments