fix: spdv-973
This commit is contained in:
@@ -121,6 +121,10 @@ export function FileItem({
|
|||||||
isMountedRef.current = true
|
isMountedRef.current = true
|
||||||
|
|
||||||
const getStamps = async () => {
|
const getStamps = async () => {
|
||||||
|
if (!beeApi) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const stamps = await getUsableStamps(beeApi)
|
const stamps = await getUsableStamps(beeApi)
|
||||||
const driveStamp = stamps.find(s =>
|
const driveStamp = stamps.find(s =>
|
||||||
drives.some(d => d.batchId.toString() === s.batchID.toString() && d.id === fileInfo.driveId),
|
drives.some(d => d.batchId.toString() === s.batchID.toString() && d.id === fileInfo.driveId),
|
||||||
|
|||||||
@@ -172,6 +172,10 @@ export function InitialModal({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const getStamps = async () => {
|
const getStamps = async () => {
|
||||||
|
if (!beeApi) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const stamps = await getUsableStamps(beeApi)
|
const stamps = await getUsableStamps(beeApi)
|
||||||
|
|
||||||
safeSetState(isMountedRef, setUsableStamps)([...stamps])
|
safeSetState(isMountedRef, setUsableStamps)([...stamps])
|
||||||
|
|||||||
@@ -38,6 +38,10 @@ export function NotificationBar({ setErrorMessage }: NotificationBarProps): Reac
|
|||||||
let isMounted = true
|
let isMounted = true
|
||||||
|
|
||||||
const getStamps = async () => {
|
const getStamps = async () => {
|
||||||
|
if (!beeApi) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const allStamps = await getUsableStamps(beeApi)
|
const allStamps = await getUsableStamps(beeApi)
|
||||||
const expiringStamps: PostageBatch[] = []
|
const expiringStamps: PostageBatch[] = []
|
||||||
const expiringDrives: DriveInfo[] = []
|
const expiringDrives: DriveInfo[] = []
|
||||||
|
|||||||
@@ -59,6 +59,10 @@ export function Sidebar({ setErrorMessage, loading }: SidebarProps): ReactElemen
|
|||||||
let isMounted = true
|
let isMounted = true
|
||||||
|
|
||||||
const getStamps = async () => {
|
const getStamps = async () => {
|
||||||
|
if (!beeApi) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const stamps = await getUsableStamps(beeApi)
|
const stamps = await getUsableStamps(beeApi)
|
||||||
|
|
||||||
if (isMounted) {
|
if (isMounted) {
|
||||||
|
|||||||
@@ -55,6 +55,10 @@ export function useBulkActions({ listToRender, trackDownload, setErrorMessage }:
|
|||||||
isMountedRef.current = true
|
isMountedRef.current = true
|
||||||
|
|
||||||
const getStamps = async () => {
|
const getStamps = async () => {
|
||||||
|
if (!beeApi) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const stamps = await getUsableStamps(beeApi)
|
const stamps = await getUsableStamps(beeApi)
|
||||||
const stampList = stamps.filter(s => drives.some(d => d.batchId.toString() === s.batchID.toString()))
|
const stampList = stamps.filter(s => drives.some(d => d.batchId.toString() === s.batchID.toString()))
|
||||||
|
|
||||||
|
|||||||
@@ -11,11 +11,7 @@ import React from 'react'
|
|||||||
import { getHumanReadableFileSize } from '../../../utils/file'
|
import { getHumanReadableFileSize } from '../../../utils/file'
|
||||||
import { ActionTag } from '../constants/transfers'
|
import { ActionTag } from '../constants/transfers'
|
||||||
|
|
||||||
export const getUsableStamps = async (bee: Bee | null): Promise<PostageBatch[]> => {
|
export const getUsableStamps = async (bee: Bee): Promise<PostageBatch[]> => {
|
||||||
if (!bee) {
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return (await bee.getPostageBatches())
|
return (await bee.getPostageBatches())
|
||||||
.filter(s => s.usable)
|
.filter(s => s.usable)
|
||||||
|
|||||||
@@ -86,8 +86,9 @@ const findDrives = (
|
|||||||
|
|
||||||
export function Provider({ children }: Props) {
|
export function Provider({ children }: Props) {
|
||||||
const initInProgressRef = useRef(false)
|
const initInProgressRef = useRef(false)
|
||||||
|
const beeInstanceRef = useRef<Bee | null>(null)
|
||||||
|
|
||||||
const { apiUrl, beeApi } = useContext(SettingsContext)
|
const { apiUrl } = useContext(SettingsContext)
|
||||||
|
|
||||||
const [fm, setFm] = useState<FileManagerBase | null>(null)
|
const [fm, setFm] = useState<FileManagerBase | null>(null)
|
||||||
const [shallReset, setShallReset] = useState<boolean>(false)
|
const [shallReset, setShallReset] = useState<boolean>(false)
|
||||||
@@ -128,9 +129,12 @@ export function Provider({ children }: Props) {
|
|||||||
setFiles([...manager.fileInfoList])
|
setFiles([...manager.fileInfoList])
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const syncDrives = useCallback(
|
const syncDrives = useCallback(async (manager: FileManagerBase, di?: DriveInfo, remove?: boolean): Promise<void> => {
|
||||||
async (manager: FileManagerBase, di?: DriveInfo, remove?: boolean): Promise<void> => {
|
if (!beeInstanceRef.current) {
|
||||||
const usableStamps = await getUsableStamps(beeApi)
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const usableStamps = await getUsableStamps(beeInstanceRef.current)
|
||||||
|
|
||||||
if (di) {
|
if (di) {
|
||||||
const isNotExpired = usableStamps.some(s => s.batchID.toString() === di.batchId.toString())
|
const isNotExpired = usableStamps.some(s => s.batchID.toString() === di.batchId.toString())
|
||||||
@@ -188,9 +192,7 @@ export function Provider({ children }: Props) {
|
|||||||
setAdminDrive(tmpAdminDrive)
|
setAdminDrive(tmpAdminDrive)
|
||||||
setDrives(userDrives)
|
setDrives(userDrives)
|
||||||
setExpiredDrives(expiredDrives)
|
setExpiredDrives(expiredDrives)
|
||||||
},
|
}, [])
|
||||||
[beeApi],
|
|
||||||
)
|
|
||||||
|
|
||||||
const syncDrivesPublic = useCallback(async () => {
|
const syncDrivesPublic = useCallback(async () => {
|
||||||
if (fm) {
|
if (fm) {
|
||||||
@@ -198,9 +200,12 @@ export function Provider({ children }: Props) {
|
|||||||
}
|
}
|
||||||
}, [fm, syncDrives])
|
}, [fm, syncDrives])
|
||||||
|
|
||||||
const refreshStamp = useCallback(
|
const refreshStamp = useCallback(async (batchId: string): Promise<PostageBatch | undefined> => {
|
||||||
async (batchId: string): Promise<PostageBatch | undefined> => {
|
if (!beeInstanceRef.current) {
|
||||||
const usableStamps = await getUsableStamps(beeApi)
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const usableStamps = await getUsableStamps(beeInstanceRef.current)
|
||||||
const refreshedStamp = usableStamps.find(s => s.batchID.toString() === batchId)
|
const refreshedStamp = usableStamps.find(s => s.batchID.toString() === batchId)
|
||||||
|
|
||||||
setCurrentStamp(prev => {
|
setCurrentStamp(prev => {
|
||||||
@@ -212,9 +217,7 @@ export function Provider({ children }: Props) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
return refreshedStamp
|
return refreshedStamp
|
||||||
},
|
}, [])
|
||||||
[beeApi],
|
|
||||||
)
|
|
||||||
|
|
||||||
const init = useCallback(async (): Promise<FileManagerBase | null> => {
|
const init = useCallback(async (): Promise<FileManagerBase | null> => {
|
||||||
const pk = getSignerPk()
|
const pk = getSignerPk()
|
||||||
@@ -231,8 +234,11 @@ export function Provider({ children }: Props) {
|
|||||||
setCurrentDrive(undefined)
|
setCurrentDrive(undefined)
|
||||||
setCurrentStamp(undefined)
|
setCurrentStamp(undefined)
|
||||||
|
|
||||||
const bee = new Bee(apiUrl, { signer: pk })
|
if (!beeInstanceRef.current) {
|
||||||
const manager = new FileManagerBase(bee)
|
beeInstanceRef.current = new Bee(apiUrl, { signer: pk })
|
||||||
|
}
|
||||||
|
|
||||||
|
const manager = new FileManagerBase(beeInstanceRef.current)
|
||||||
|
|
||||||
const handleInitialized = (success: boolean) => {
|
const handleInitialized = (success: boolean) => {
|
||||||
setInitializationError(!success)
|
setInitializationError(!success)
|
||||||
@@ -316,28 +322,28 @@ export function Provider({ children }: Props) {
|
|||||||
|
|
||||||
const manager = await init()
|
const manager = await init()
|
||||||
|
|
||||||
if (prevDriveId && manager) {
|
if (prevDriveId && manager && beeInstanceRef.current) {
|
||||||
const refreshedDrive = manager.driveList.find(d => d.id.toString() === prevDriveId)
|
const refreshedDrive = manager.driveList.find(d => d.id.toString() === prevDriveId)
|
||||||
setCurrentDrive(refreshedDrive)
|
setCurrentDrive(refreshedDrive)
|
||||||
|
|
||||||
const uStamps: PostageBatch[] = await getUsableStamps(beeApi)
|
const uStamps: PostageBatch[] = await getUsableStamps(beeInstanceRef.current)
|
||||||
const isValidCurrentStamp = uStamps.find(s => s.batchID.toString() === prevStamp?.batchID.toString())
|
const isValidCurrentStamp = uStamps.find(s => s.batchID.toString() === prevStamp?.batchID.toString())
|
||||||
|
|
||||||
setCurrentStamp(isValidCurrentStamp)
|
setCurrentStamp(isValidCurrentStamp)
|
||||||
}
|
}
|
||||||
}, [currentDrive?.id, currentStamp, init, beeApi])
|
}, [currentDrive?.id, currentStamp, init])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const pk = getSignerPk()
|
if (!apiUrl || initInProgressRef.current) {
|
||||||
|
return
|
||||||
if (!pk || fm || initInProgressRef.current) return
|
}
|
||||||
|
|
||||||
const initFromLocalState = async () => {
|
const initFromLocalState = async () => {
|
||||||
await init()
|
await init()
|
||||||
}
|
}
|
||||||
|
|
||||||
initFromLocalState()
|
initFromLocalState()
|
||||||
}, [fm, init])
|
}, [apiUrl, init])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (fm && drives.length === 0 && !adminDrive) {
|
if (fm && drives.length === 0 && !adminDrive) {
|
||||||
|
|||||||
Reference in New Issue
Block a user