Skip to content

Commit

Permalink
feat(dcellar-web-ui): created on chain status deletable
Browse files Browse the repository at this point in the history
  • Loading branch information
aiden-cao committed Apr 7, 2024
1 parent 9c32d33 commit 5ecd925
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Badge colorScheme="warning">Created on Chain</Badge>;
Expand Down
4 changes: 2 additions & 2 deletions apps/dcellar-web-ui/src/facade/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const getAccountBalance = async ({
export type CreateTmpAccountParams = {
address: string;
bucketName: string;
amount: number;
amount: ReturnType<typeof parseEther>;
connector: Connector<any, any>;
actionType?: 'delete' | 'create';
};
Expand Down Expand Up @@ -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),
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';

Expand All @@ -60,6 +65,7 @@ export const BatchDeleteObjectOperation = memo<BatchDeleteObjectOperationProps>(
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);
Expand Down Expand Up @@ -126,10 +132,12 @@ export const BatchDeleteObjectOperation = memo<BatchDeleteObjectOperationProps>(
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',
});
Expand All @@ -149,7 +157,20 @@ export const BatchDeleteObjectOperation = memo<BatchDeleteObjectOperationProps>(
connector: connector!,
privateKey,
};
const [txRes, error] = await (ObjectStatus === 1

const file = find<UploadObject>(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) {
Expand Down
33 changes: 24 additions & 9 deletions apps/dcellar-web-ui/src/modules/object/components/ObjectList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -348,17 +347,18 @@ export const ObjectList = memo<ObjectListProps>(function ObjectList({ shareMode
const file = find<UploadObject>(
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']);
}
}

Expand Down Expand Up @@ -402,10 +402,25 @@ export const ObjectList = memo<ObjectListProps>(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<UploadObject>(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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ export const UploadObjectsOperation = memo<UploadObjectsOperationProps>(
const [tempAccount, error] = await createTempAccount({
address: loginAccount,
bucketName: currentBucketName,
amount: parseEther(String(safeAmount)).toNumber(),
amount: parseEther(String(safeAmount)),
connector: connector!,
});
if (!tempAccount) {
Expand Down

0 comments on commit 5ecd925

Please sign in to comment.