fix: spdv-963 - Expired admin drive upgrading handling (#230)
* fix: spdv-963 * refactor: spdv-963
This commit is contained in:
@@ -3,11 +3,12 @@ import { DriveInfo, estimateDriveListMetadataSize } from '@solarpunkltd/file-man
|
|||||||
import { ReactElement, useCallback, useContext, useEffect, useMemo, useState } from 'react'
|
import { ReactElement, useCallback, useContext, useEffect, useMemo, useState } from 'react'
|
||||||
|
|
||||||
import { Context as FMContext } from '../../../../providers/FileManager'
|
import { Context as FMContext } from '../../../../providers/FileManager'
|
||||||
|
import { Context as SettingsContext } from '../../../../providers/Settings'
|
||||||
import { getHumanReadableFileSize } from '../../../../utils/file'
|
import { getHumanReadableFileSize } from '../../../../utils/file'
|
||||||
import { FILE_MANAGER_EVENTS, POLLING_TIMEOUT_MS } from '../../constants/common'
|
import { FILE_MANAGER_EVENTS, POLLING_TIMEOUT_MS } from '../../constants/common'
|
||||||
import { TOOLTIPS } from '../../constants/tooltips'
|
import { TOOLTIPS } from '../../constants/tooltips'
|
||||||
import { useStampPolling } from '../../hooks/useStampPolling'
|
import { useStampPolling } from '../../hooks/useStampPolling'
|
||||||
import { calculateStampCapacityMetrics } from '../../utils/bee'
|
import { calculateStampCapacityMetrics, validateStampStillExists } from '../../utils/bee'
|
||||||
import { ConfirmModal } from '../ConfirmModal/ConfirmModal'
|
import { ConfirmModal } from '../ConfirmModal/ConfirmModal'
|
||||||
import { ProgressBar } from '../ProgressBar/ProgressBar'
|
import { ProgressBar } from '../ProgressBar/ProgressBar'
|
||||||
import { Tooltip } from '../Tooltip/Tooltip'
|
import { Tooltip } from '../Tooltip/Tooltip'
|
||||||
@@ -32,6 +33,7 @@ export function AdminStatusBar({
|
|||||||
setErrorMessage,
|
setErrorMessage,
|
||||||
}: AdminStatusBarProps): ReactElement {
|
}: AdminStatusBarProps): ReactElement {
|
||||||
const { drives, setShowError, refreshStamp } = useContext(FMContext)
|
const { drives, setShowError, refreshStamp } = useContext(FMContext)
|
||||||
|
const { beeApi } = useContext(SettingsContext)
|
||||||
|
|
||||||
const [isUpgradeDriveModalOpen, setIsUpgradeDriveModalOpen] = useState(false)
|
const [isUpgradeDriveModalOpen, setIsUpgradeDriveModalOpen] = useState(false)
|
||||||
const [isUpgradeTimeoutModalOpen, setIsUpgradeTimeoutModalOpen] = useState(false)
|
const [isUpgradeTimeoutModalOpen, setIsUpgradeTimeoutModalOpen] = useState(false)
|
||||||
@@ -236,7 +238,20 @@ export function AdminStatusBar({
|
|||||||
|
|
||||||
<div
|
<div
|
||||||
className="fm-admin-status-bar-upgrade-button"
|
className="fm-admin-status-bar-upgrade-button"
|
||||||
onClick={() => !isBusy && actualStamp && adminDrive && setIsUpgradeDriveModalOpen(true)}
|
onClick={async () => {
|
||||||
|
if (!isBusy && actualStamp && adminDrive && beeApi) {
|
||||||
|
const isStampValid = await validateStampStillExists(beeApi, actualStamp.batchID)
|
||||||
|
|
||||||
|
if (!isStampValid) {
|
||||||
|
setErrorMessage?.('The admin drive has expired. Please clear the browser cache and reload the page.')
|
||||||
|
setShowError(true)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsUpgradeDriveModalOpen(true)
|
||||||
|
}
|
||||||
|
}}
|
||||||
aria-disabled={isBusy ? 'true' : 'false'}
|
aria-disabled={isBusy ? 'true' : 'false'}
|
||||||
>
|
>
|
||||||
{isBusy ? 'Working…' : 'Manage'}
|
{isBusy ? 'Working…' : 'Manage'}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import { getHumanReadableFileSize } from '../../../../utils/file'
|
|||||||
import { FILE_MANAGER_EVENTS, POLLING_TIMEOUT_MS } from '../../constants/common'
|
import { FILE_MANAGER_EVENTS, POLLING_TIMEOUT_MS } from '../../constants/common'
|
||||||
import { desiredLifetimeOptions } from '../../constants/stamps'
|
import { desiredLifetimeOptions } from '../../constants/stamps'
|
||||||
import { useStampPolling } from '../../hooks/useStampPolling'
|
import { useStampPolling } from '../../hooks/useStampPolling'
|
||||||
|
import { validateStampStillExists } from '../../utils/bee'
|
||||||
import { fromBytesConversion, getExpiryDateByLifetime, truncateNameMiddle } from '../../utils/common'
|
import { fromBytesConversion, getExpiryDateByLifetime, truncateNameMiddle } from '../../utils/common'
|
||||||
import { Button } from '../Button/Button'
|
import { Button } from '../Button/Button'
|
||||||
import { CustomDropdown } from '../CustomDropdown/CustomDropdown'
|
import { CustomDropdown } from '../CustomDropdown/CustomDropdown'
|
||||||
@@ -334,6 +335,16 @@ export function UpgradeDriveModal({
|
|||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
if (!beeApi || !walletBalance) return
|
if (!beeApi || !walletBalance) return
|
||||||
|
|
||||||
|
const isStampValid = await validateStampStillExists(beeApi, stamp.batchID)
|
||||||
|
|
||||||
|
if (!isStampValid) {
|
||||||
|
setErrorMessage?.('The admin drive has expired. Please clear the browser cache and reload the page.')
|
||||||
|
setShowError(true)
|
||||||
|
onCancelClick()
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setIsSubmitting(true)
|
setIsSubmitting(true)
|
||||||
window.dispatchEvent(
|
window.dispatchEvent(
|
||||||
|
|||||||
Reference in New Issue
Block a user