From 5ecd9252bf58b25f31d8b5f57790b10f61f9d2ab Mon Sep 17 00:00:00 2001 From: aidencao Date: Sun, 7 Apr 2024 17:14:48 +0800 Subject: [PATCH] feat(dcellar-web-ui): created on chain status deletable --- .../src/components/common/DCTable/index.tsx | 2 +- apps/dcellar-web-ui/src/facade/account.ts | 4 +-- .../components/BatchDeleteObjectOperation.tsx | 29 +++++++++++++--- .../modules/object/components/ObjectList.tsx | 33 ++++++++++++++----- .../modules/upload/UploadObjectsOperation.tsx | 2 +- 5 files changed, 53 insertions(+), 17 deletions(-) diff --git a/apps/dcellar-web-ui/src/components/common/DCTable/index.tsx b/apps/dcellar-web-ui/src/components/common/DCTable/index.tsx index 3b45e534..203837f3 100644 --- a/apps/dcellar-web-ui/src/components/common/DCTable/index.tsx +++ b/apps/dcellar-web-ui/src/components/common/DCTable/index.tsx @@ -176,7 +176,7 @@ export const UploadStatus = ({ object, size }: { object: string; size: number }) ] .filter((item) => !!item) .join('/'); - return objectInList === object; + return objectInList === object && q.status !== 'ERROR'; }); if (!file) return Created on Chain; diff --git a/apps/dcellar-web-ui/src/facade/account.ts b/apps/dcellar-web-ui/src/facade/account.ts index 128bf779..a4a961ab 100644 --- a/apps/dcellar-web-ui/src/facade/account.ts +++ b/apps/dcellar-web-ui/src/facade/account.ts @@ -41,7 +41,7 @@ export const getAccountBalance = async ({ export type CreateTmpAccountParams = { address: string; bucketName: string; - amount: number; + amount: ReturnType; connector: Connector; actionType?: 'delete' | 'create'; }; @@ -74,7 +74,7 @@ export const createTempAccount = async ({ granter: address, grantee: wallet.address, allowedMessages: grantAllowedMessage, - amount: parseEther(amount <= 0 ? '0.1' : String(amount)).toString(), + amount: parseEther(amount.lte(0) ? '0.1' : String(amount)).toString(), denom: 'BNB', expirationTime: toTimestamp(expirationDate), }) diff --git a/apps/dcellar-web-ui/src/modules/object/components/BatchDeleteObjectOperation.tsx b/apps/dcellar-web-ui/src/modules/object/components/BatchDeleteObjectOperation.tsx index 38a8dfa4..bcacc3c1 100644 --- a/apps/dcellar-web-ui/src/modules/object/components/BatchDeleteObjectOperation.tsx +++ b/apps/dcellar-web-ui/src/modules/object/components/BatchDeleteObjectOperation.tsx @@ -19,7 +19,12 @@ import { setupAccountRecords, } from '@/store/slices/accounts'; import { TBucket } from '@/store/slices/bucket'; -import { selectGnfdGasFeesConfig, setSignatureAction } from '@/store/slices/global'; +import { + selectGnfdGasFeesConfig, + selectUploadQueue, + setSignatureAction, + UploadObject, +} from '@/store/slices/global'; import { setDeletedObject, setObjectSelectedKeys } from '@/store/slices/object'; import { BN } from '@/utils/math'; import { getStoreNetflowRate } from '@/utils/payment'; @@ -34,7 +39,7 @@ import { ColoredWaitingIcon } from '@node-real/icons'; import { Flex, ModalBody, ModalFooter, ModalHeader, Text, toast } from '@node-real/uikit'; import { useAsyncEffect } from 'ahooks'; import { parseEther } from 'ethers/lib/utils.js'; -import { round } from 'lodash-es'; +import { find, round } from 'lodash-es'; import { memo, useMemo, useState } from 'react'; import { useAccount } from 'wagmi'; @@ -60,6 +65,7 @@ export const BatchDeleteObjectOperation = memo( const bankBalance = useAppSelector((root) => root.accounts.bankOrWalletBalance); const gnfdGasFeesConfig = useAppSelector(selectGnfdGasFeesConfig); + const uploadQueue = useAppSelector(selectUploadQueue(loginAccount)); const { crudTimestamp } = useAppSelector(selectAccount(bucket?.PaymentAddress)); const availableBalance = useAppSelector(selectAvailableBalance(bucket?.PaymentAddress)); const [loading, setLoading] = useState(false); @@ -126,10 +132,12 @@ export const BatchDeleteObjectOperation = memo( desc: WALLET_CONFIRM, }), ); + const [tempAccount, err] = await createTempAccount({ address: loginAccount, bucketName: currentBucketName, - amount: parseEther(round(Number(availableBalance), 6).toString()).toNumber(), + // fix toNumber overflow fault + amount: parseEther(round(Number(availableBalance), 6).toString()), connector: connector!, actionType: 'delete', }); @@ -149,7 +157,20 @@ export const BatchDeleteObjectOperation = memo( connector: connector!, privateKey, }; - const [txRes, error] = await (ObjectStatus === 1 + + const file = find(uploadQueue, (q) => { + const objectInList = [ + ...q.prefixFolders, + q.waitObject.relativePath || '', + q.waitObject.name, + ] + .filter((item) => !!item) + .join('/'); + + return objectInList === objectName && q.status !== 'ERROR'; + }); + + const [txRes, error] = await (ObjectStatus === 1 || (ObjectStatus !== 1 && !file) ? deleteObject(payload) : cancelCreateObject(payload)); if (error && error !== E_OBJECT_NOT_EXISTS) { diff --git a/apps/dcellar-web-ui/src/modules/object/components/ObjectList.tsx b/apps/dcellar-web-ui/src/modules/object/components/ObjectList.tsx index 0ca4c4ec..1becbc93 100644 --- a/apps/dcellar-web-ui/src/modules/object/components/ObjectList.tsx +++ b/apps/dcellar-web-ui/src/modules/object/components/ObjectList.tsx @@ -59,7 +59,6 @@ import { memo, useCallback } from 'react'; import { OBJECT_ERROR_TYPES, ObjectErrorType } from '../ObjectError'; import Link from 'next/link'; - export type ObjectActionValueType = | 'marketplace' | 'detail' @@ -348,17 +347,18 @@ export const ObjectList = memo(function ObjectList({ shareMode const file = find( uploadQueue, (q) => - [...q.prefixFolders, q.waitObject.name].join('/') === record.objectName && - q.status !== 'ERROR', + [...q.prefixFolders, q.waitObject.relativePath || '', q.waitObject.name] + .filter((item) => !!item) + .join('/') === record.objectName && q.status !== 'ERROR', ); // if is uploading, can not cancel; if (file && ['SIGN', 'SIGNED', 'UPLOAD'].includes(file.status)) { pruneActions = pickAction(pruneActions, ['detail']); } else if (file && ['SEAL', 'SEALING'].includes(file.status)) { - pruneActions = removeAction(pruneActions, ['cancel', 'share']); + pruneActions = removeAction(pruneActions, ['cancel', 'share', 'delete']); } else { // if not sealed, only support 'cancel' 'detail' - pruneActions = pickAction(pruneActions, ['cancel', 'detail']); + pruneActions = pickAction(pruneActions, ['detail', 'delete']); } } @@ -402,10 +402,25 @@ export const ObjectList = memo(function ObjectList({ shareMode selectedRowKeys: objectSelectedKeys, onSelect: onSelectChange, onSelectAll: onSelectAllChange, - getCheckboxProps: (record: ObjectEntity) => ({ - disabled: record.folder || record.objectStatus !== 1, // Column configuration not to be checked - name: record.name, - }), + getCheckboxProps: (record: ObjectEntity) => { + const file = find(uploadQueue, (q) => { + const objectInList = [ + ...q.prefixFolders, + q.waitObject.relativePath || '', + q.waitObject.name, + ] + .filter((item) => !!item) + .join('/'); + + return objectInList === record.objectName && q.status !== 'ERROR'; + }); + + return { + // folder or upload failed + disabled: record.folder || (record.objectStatus !== 1 && !!file), // Column configuration not to be checked + name: record.name, + }; + }, }; const errorHandler = (type: string) => { diff --git a/apps/dcellar-web-ui/src/modules/upload/UploadObjectsOperation.tsx b/apps/dcellar-web-ui/src/modules/upload/UploadObjectsOperation.tsx index b2df1b48..0f4d3512 100644 --- a/apps/dcellar-web-ui/src/modules/upload/UploadObjectsOperation.tsx +++ b/apps/dcellar-web-ui/src/modules/upload/UploadObjectsOperation.tsx @@ -358,7 +358,7 @@ export const UploadObjectsOperation = memo( const [tempAccount, error] = await createTempAccount({ address: loginAccount, bucketName: currentBucketName, - amount: parseEther(String(safeAmount)).toNumber(), + amount: parseEther(String(safeAmount)), connector: connector!, }); if (!tempAccount) {