fix: remove expired stamps (#463)
* fix: increase waitUntilStampUsable timeout * fix: wait for stamp to exist after buying
This commit is contained in:
@@ -9,7 +9,13 @@ import { SwarmTextInput } from '../../components/SwarmTextInput'
|
|||||||
import { Context as BeeContext } from '../../providers/Bee'
|
import { Context as BeeContext } from '../../providers/Bee'
|
||||||
import { Context as SettingsContext } from '../../providers/Settings'
|
import { Context as SettingsContext } from '../../providers/Settings'
|
||||||
import { Context as StampsContext } from '../../providers/Stamps'
|
import { Context as StampsContext } from '../../providers/Stamps'
|
||||||
import { calculateStampPrice, convertAmountToSeconds, convertDepthToBytes, secondsToTimeString } from '../../utils'
|
import {
|
||||||
|
calculateStampPrice,
|
||||||
|
convertAmountToSeconds,
|
||||||
|
convertDepthToBytes,
|
||||||
|
secondsToTimeString,
|
||||||
|
waitUntilStampExists,
|
||||||
|
} from '../../utils'
|
||||||
import { getHumanReadableFileSize } from '../../utils/file'
|
import { getHumanReadableFileSize } from '../../utils/file'
|
||||||
|
|
||||||
interface FormValues {
|
interface FormValues {
|
||||||
@@ -97,7 +103,8 @@ export function PostageStampCreation({ onFinished }: Props): ReactElement {
|
|||||||
const amount = BigInt(values.amount)
|
const amount = BigInt(values.amount)
|
||||||
const depth = Number.parseInt(values.depth)
|
const depth = Number.parseInt(values.depth)
|
||||||
const options = values.label ? { label: values.label } : undefined
|
const options = values.label ? { label: values.label } : undefined
|
||||||
await beeDebugApi.createPostageBatch(amount.toString(), depth, options)
|
const batchId = await beeDebugApi.createPostageBatch(amount.toString(), depth, options)
|
||||||
|
await waitUntilStampExists(batchId, beeDebugApi)
|
||||||
actions.resetForm()
|
actions.resetForm()
|
||||||
await refresh()
|
await refresh()
|
||||||
onFinished()
|
onFinished()
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ export function Provider({ children }: Props): ReactElement {
|
|||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
const stamps = await beeDebugApi.getAllPostageBatch()
|
const stamps = await beeDebugApi.getAllPostageBatch()
|
||||||
|
|
||||||
setStamps(stamps.map(enrichStamp))
|
setStamps(stamps.filter(x => x.exists).map(enrichStamp))
|
||||||
setLastUpdate(Date.now())
|
setLastUpdate(Date.now())
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setError(e as Error)
|
setError(e as Error)
|
||||||
|
|||||||
+16
-7
@@ -1,8 +1,8 @@
|
|||||||
import { BigNumber } from 'bignumber.js'
|
|
||||||
import { Token } from '../models/Token'
|
|
||||||
import { decodeCid } from '@ethersphere/swarm-cid'
|
|
||||||
import { BZZ_LINK_DOMAIN } from '../constants'
|
|
||||||
import { BatchId, BeeDebug, PostageBatch } from '@ethersphere/bee-js'
|
import { BatchId, BeeDebug, PostageBatch } from '@ethersphere/bee-js'
|
||||||
|
import { decodeCid } from '@ethersphere/swarm-cid'
|
||||||
|
import { BigNumber } from 'bignumber.js'
|
||||||
|
import { BZZ_LINK_DOMAIN } from '../constants'
|
||||||
|
import { Token } from '../models/Token'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test if value is an integer
|
* Test if value is an integer
|
||||||
@@ -229,16 +229,25 @@ export function shortenText(text: string, length = 20, separator = '[…]'): str
|
|||||||
}
|
}
|
||||||
|
|
||||||
const DEFAULT_POLLING_FREQUENCY = 1_000
|
const DEFAULT_POLLING_FREQUENCY = 1_000
|
||||||
const DEFAULT_STAMP_USABLE_TIMEOUT = 120_000
|
const DEFAULT_STAMP_USABLE_TIMEOUT = 240_000
|
||||||
|
|
||||||
interface Options {
|
interface Options {
|
||||||
pollingFrequency?: number
|
pollingFrequency?: number
|
||||||
timeout?: number
|
timeout?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function waitUntilStampUsable(
|
export function waitUntilStampUsable(batchId: BatchId, beeDebug: BeeDebug, options?: Options): Promise<PostageBatch> {
|
||||||
|
return waitForStamp(batchId, beeDebug, 'usable', options)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function waitUntilStampExists(batchId: BatchId, beeDebug: BeeDebug, options?: Options): Promise<PostageBatch> {
|
||||||
|
return waitForStamp(batchId, beeDebug, 'exists', options)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function waitForStamp(
|
||||||
batchId: BatchId,
|
batchId: BatchId,
|
||||||
beeDebug: BeeDebug,
|
beeDebug: BeeDebug,
|
||||||
|
field: 'exists' | 'usable',
|
||||||
options?: Options,
|
options?: Options,
|
||||||
): Promise<PostageBatch> {
|
): Promise<PostageBatch> {
|
||||||
const timeout = options?.timeout || DEFAULT_STAMP_USABLE_TIMEOUT
|
const timeout = options?.timeout || DEFAULT_STAMP_USABLE_TIMEOUT
|
||||||
@@ -247,7 +256,7 @@ export async function waitUntilStampUsable(
|
|||||||
for (let i = 0; i < timeout; i += pollingFrequency) {
|
for (let i = 0; i < timeout; i += pollingFrequency) {
|
||||||
const stamp = await beeDebug.getPostageBatch(batchId)
|
const stamp = await beeDebug.getPostageBatch(batchId)
|
||||||
|
|
||||||
if (stamp.usable) return stamp
|
if (stamp[field]) return stamp
|
||||||
await sleepMs(pollingFrequency)
|
await sleepMs(pollingFrequency)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user