diff --git a/package-lock.json b/package-lock.json index 04532c95..f0d3dd1b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,19 +1,19 @@ { "name": "@upcoming/bee-dashboard", - "version": "0.1.0", + "version": "0.3.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@upcoming/bee-dashboard", - "version": "0.1.0", + "version": "0.3.0", "license": "BSD-3-Clause", "dependencies": { "@fairdatasociety/fdp-storage": "^0.19.0", "@material-ui/core": "4.12.3", "@material-ui/icons": "4.11.2", "@material-ui/lab": "4.0.0-alpha.57", - "@upcoming/bee-js": "^0.8.1", + "@upcoming/bee-js": "^0.10.0", "axios": "^0.28.1", "bignumber.js": "^9.1.2", "buffer": "^6.0.3", @@ -5452,9 +5452,9 @@ } }, "node_modules/@upcoming/bee-js": { - "version": "0.8.1", - "resolved": "https://registry.npmjs.org/@upcoming/bee-js/-/bee-js-0.8.1.tgz", - "integrity": "sha512-BSX5H2+DDrkom7NHMFL6mmNjpic7jH+6o+Haf+QfnKGAh+pRpoplIKBfQMcjrumAiW8ZXzvsUkwrwYuUpxQoNA==", + "version": "0.10.0", + "resolved": "https://registry.npmjs.org/@upcoming/bee-js/-/bee-js-0.10.0.tgz", + "integrity": "sha512-twvNtTM3xVHL8+YSMbgsjqELfSi0hPYjir9ieVh5IuvgBM0EXDnYE0dLw0oFE4EyZf/o8p8zav7va6Ouxlp6IA==", "license": "BSD-3-Clause", "dependencies": { "axios": "^0.28.1", @@ -24429,9 +24429,9 @@ } }, "@upcoming/bee-js": { - "version": "0.8.1", - "resolved": "https://registry.npmjs.org/@upcoming/bee-js/-/bee-js-0.8.1.tgz", - "integrity": "sha512-BSX5H2+DDrkom7NHMFL6mmNjpic7jH+6o+Haf+QfnKGAh+pRpoplIKBfQMcjrumAiW8ZXzvsUkwrwYuUpxQoNA==", + "version": "0.10.0", + "resolved": "https://registry.npmjs.org/@upcoming/bee-js/-/bee-js-0.10.0.tgz", + "integrity": "sha512-twvNtTM3xVHL8+YSMbgsjqELfSi0hPYjir9ieVh5IuvgBM0EXDnYE0dLw0oFE4EyZf/o8p8zav7va6Ouxlp6IA==", "requires": { "axios": "^0.28.1", "cafe-utility": "^27.12.1", diff --git a/package.json b/package.json index 5daec4ed..371868e5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@upcoming/bee-dashboard", - "version": "0.1.0", + "version": "0.3.0", "description": "An app which helps users to setup their Bee node and do actions like cash out cheques", "keywords": [ "bee", @@ -30,7 +30,7 @@ "@material-ui/core": "4.12.3", "@material-ui/icons": "4.11.2", "@material-ui/lab": "4.0.0-alpha.57", - "@upcoming/bee-js": "^0.8.1", + "@upcoming/bee-js": "^0.10.0", "axios": "^0.28.1", "bignumber.js": "^9.1.2", "buffer": "^6.0.3", diff --git a/src/pages/stamps/PostageStampAdvancedCreation.tsx b/src/pages/stamps/PostageStampAdvancedCreation.tsx index 3fa5036b..b63571be 100644 --- a/src/pages/stamps/PostageStampAdvancedCreation.tsx +++ b/src/pages/stamps/PostageStampAdvancedCreation.tsx @@ -13,7 +13,7 @@ import { Context as BeeContext } from '../../providers/Bee' import { Context as SettingsContext } from '../../providers/Settings' import { Context as StampsContext } from '../../providers/Stamps' import { ROUTES } from '../../routes' -import { secondsToTimeString, waitUntilStampExists } from '../../utils' +import { secondsToTimeString } from '../../utils' import { getHumanReadableFileSize } from '../../utils/file' interface Props { @@ -71,7 +71,7 @@ export function PostageStampAdvancedCreation({ onFinished }: Props): ReactElemen const pricePerBlock = chainState.currentPrice return `${secondsToTimeString( - Utils.getStampTtlSeconds(amount, pricePerBlock), + Utils.getStampDuration(amount, pricePerBlock).toSeconds(), )} (with price of ${pricePerBlock} PLUR per block)` } @@ -107,8 +107,7 @@ export function PostageStampAdvancedCreation({ onFinished }: Props): ReactElemen immutableFlag: immutable, } - const batchId = await beeApi.createPostageBatch(amount.toString(), depth, options) - await waitUntilStampExists(batchId, beeApi) + await beeApi.createPostageBatch(amount.toString(), depth, options) await refresh() onFinished() } catch (e) { @@ -173,7 +172,7 @@ export function PostageStampAdvancedCreation({ onFinished }: Props): ReactElemen return '-' } - const theoreticalMaximumVolume = getHumanReadableFileSize(Utils.getStampMaximumCapacityBytes(depth)) + const theoreticalMaximumVolume = getHumanReadableFileSize(Utils.getStampTheoreticalBytes(depth)) const effectiveVolume = getHumanReadableFileSize(Utils.getStampEffectiveBytes(depth)) return ( diff --git a/src/pages/stamps/PostageStampStandardCreation.tsx b/src/pages/stamps/PostageStampStandardCreation.tsx index 939e6fa4..a52d75bc 100644 --- a/src/pages/stamps/PostageStampStandardCreation.tsx +++ b/src/pages/stamps/PostageStampStandardCreation.tsx @@ -1,6 +1,6 @@ import { Box, Button, Grid, Slider, Typography } from '@material-ui/core' import { Theme, createStyles, makeStyles } from '@material-ui/core/styles' -import { PostageBatchOptions, Utils } from '@upcoming/bee-js' +import { Duration, PostageBatchOptions, Utils } from '@upcoming/bee-js' import { useSnackbar } from 'notistack' import { ReactElement, useContext, useState } from 'react' import { Link } from 'react-router-dom' @@ -10,7 +10,7 @@ import { SwarmTextInput } from '../../components/SwarmTextInput' import { Context as SettingsContext } from '../../providers/Settings' import { Context as StampsContext } from '../../providers/Stamps' import { ROUTES } from '../../routes' -import { secondsToTimeString, waitUntilStampExists } from '../../utils' +import { secondsToTimeString } from '../../utils' interface Props { onFinished: () => void @@ -46,8 +46,8 @@ export function PostageStampStandardCreation({ onFinished }: Props): ReactElemen const { refresh } = useContext(StampsContext) const { beeApi } = useContext(SettingsContext) - const [depthInput, setDepthInput] = useState(Utils.getDepthForCapacity(4)) - const [amountInput, setAmountInput] = useState(Utils.getAmountForTtl(30)) + const [depthInput, setDepthInput] = useState(Utils.getDepthForSize(4)) + const [amountInput, setAmountInput] = useState(Utils.getAmountForDuration(Duration.fromDays(30), 26500)) const [labelInput, setLabelInput] = useState('') const [submitting, setSubmitting] = useState(false) const [buttonValue, setButtonValue] = useState(4) @@ -56,7 +56,7 @@ export function PostageStampStandardCreation({ onFinished }: Props): ReactElemen if (typeof newValue !== 'number') { return } - const amountValue = Utils.getAmountForTtl(newValue) + const amountValue = Utils.getAmountForDuration(Duration.fromDays(newValue), 26500) setAmountInput(amountValue) } @@ -66,7 +66,7 @@ export function PostageStampStandardCreation({ onFinished }: Props): ReactElemen const pricePerBlock = 24000 return `${secondsToTimeString( - Utils.getStampTtlSeconds(amount, pricePerBlock), + Utils.getStampDuration(amount, pricePerBlock).toSeconds(), )} (with price of ${pricePerBlock} PLUR per block)` } @@ -96,8 +96,7 @@ export function PostageStampStandardCreation({ onFinished }: Props): ReactElemen immutableFlag: true, } - const batchId = await beeApi.createPostageBatch(amount.toString(), depth, options) - await waitUntilStampExists(batchId, beeApi) + await beeApi.createPostageBatch(amount.toString(), depth, options) await refresh() onFinished() } catch (e) { @@ -109,7 +108,7 @@ export function PostageStampStandardCreation({ onFinished }: Props): ReactElemen function handleBatchSize(gigabytes: number) { setButtonValue(gigabytes) - const capacity = Utils.getDepthForCapacity(gigabytes) + const capacity = Utils.getDepthForSize(gigabytes) setDepthInput(capacity) } diff --git a/src/pages/stamps/StampsTable.tsx b/src/pages/stamps/StampsTable.tsx index 3485796d..63044595 100644 --- a/src/pages/stamps/StampsTable.tsx +++ b/src/pages/stamps/StampsTable.tsx @@ -40,13 +40,9 @@ function StampsTable({ postageStamps }: Props): ReactElement | null { )}`} /> - + - diff --git a/src/providers/Stamps.tsx b/src/providers/Stamps.tsx index 5ea2232f..54b2654e 100644 --- a/src/providers/Stamps.tsx +++ b/src/providers/Stamps.tsx @@ -68,7 +68,7 @@ export function Provider({ children }: Props): ReactElement { setIsLoading(true) const stamps = await beeApi.getAllPostageBatch() - setStamps(stamps.filter(x => x.exists).map(enrichStamp)) + setStamps(stamps.map(enrichStamp)) setLastUpdate(Date.now()) setError(null) } catch (e) { diff --git a/src/utils/index.ts b/src/utils/index.ts index 6f9af497..cf66b5d8 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -212,19 +212,10 @@ interface Options { } export function waitUntilStampUsable(batchId: BatchId | string, bee: Bee, options?: Options): Promise { - return waitForStamp(batchId, bee, 'usable', options) + return waitForStamp(batchId, bee, options) } -export function waitUntilStampExists(batchId: BatchId | string, bee: Bee, options?: Options): Promise { - return waitForStamp(batchId, bee, 'exists', options) -} - -async function waitForStamp( - batchId: BatchId | string, - bee: Bee, - field: 'exists' | 'usable', - options?: Options, -): Promise { +async function waitForStamp(batchId: BatchId | string, bee: Bee, options?: Options): Promise { const timeout = options?.timeout || DEFAULT_STAMP_USABLE_TIMEOUT const pollingFrequency = options?.pollingFrequency || DEFAULT_POLLING_FREQUENCY @@ -232,7 +223,9 @@ async function waitForStamp( try { const stamp = await bee.getPostageBatch(batchId) - if (stamp[field]) return stamp + if (stamp.usable) { + return stamp + } } catch { // ignore }