Skip to content

Commit

Permalink
Merge pull request #371 from node-real/feat/created-on-chain-deletable
Browse files Browse the repository at this point in the history
feat(dcellar-web-ui): created on chain status deletable
  • Loading branch information
aiden-cao authored Apr 11, 2024
2 parents 5835eaa + ac52489 commit 9fe6922
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 44 deletions.
12 changes: 12 additions & 0 deletions apps/dcellar-web-ui/CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
{
"name": "dcellar-web-ui",
"entries": [
{
"version": "0.5.0",
"tag": "dcellar-web-ui_v0.5.0",
"date": "Thu, 11 Apr 2024 02:29:47 GMT",
"comments": {
"minor": [
{
"comment": "make created on chain status object deletable"
}
]
}
},
{
"version": "0.4.0",
"tag": "dcellar-web-ui_v0.4.0",
Expand Down
9 changes: 8 additions & 1 deletion apps/dcellar-web-ui/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Change Log - dcellar-web-ui

This log was last generated on Mon, 25 Mar 2024 04:02:13 GMT and should not be manually modified.
This log was last generated on Thu, 11 Apr 2024 02:29:47 GMT and should not be manually modified.

## 0.5.0
Thu, 11 Apr 2024 02:29:47 GMT

### Minor changes

- make created on chain status object deletable

## 0.4.0
Mon, 25 Mar 2024 04:02:13 GMT
Expand Down
2 changes: 1 addition & 1 deletion apps/dcellar-web-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dcellar-web-ui",
"version": "0.4.0",
"version": "0.5.0",
"private": false,
"scripts": {
"dev": "node ./scripts/dev.js -p 3200",
Expand Down
27 changes: 9 additions & 18 deletions apps/dcellar-web-ui/src/components/common/DCTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ import {
SimplePaginationProps,
} from '@/components/common/DCTable/SimplePagination';
import { useAppSelector } from '@/store';
import { UploadObject, selectUploadQueue } from '@/store/slices/global';
import { formatBytes } from '@/utils/formatter';
import styled from '@emotion/styled';
import { Badge, Box, Flex, Pagination, PaginationProps, Text, keyframes } from '@node-real/uikit';
import { Badge, Box, Flex, keyframes, Pagination, PaginationProps, Text } from '@node-real/uikit';
import { ConfigProvider, Table, TableProps } from 'antd';
import { ConfigProviderProps } from 'antd/es/config-provider';
import { find } from 'lodash-es';
import { memo } from 'react';
import { useUploadProcessObjects } from '@/hooks/useUploadProcessObjects';

export type AlignType = 'left' | 'right' | 'center';

Expand Down Expand Up @@ -165,21 +164,13 @@ export const UploadProgress = (props: { progress: number }) => {

export const UploadStatus = ({ object, size }: { object: string; size: number }) => {
const loginAccount = useAppSelector((root) => root.persist.loginAccount);
const queue = useAppSelector(selectUploadQueue(loginAccount));

const file = find<UploadObject>(queue, (q) => {
const objectInList = [
q.bucketName,
...q.prefixFolders,
q.waitObject.relativePath || '',
q.waitObject.name,
]
.filter((item) => !!item)
.join('/');
return objectInList === object;
});

if (!file) return <Badge colorScheme="warning">Created on Chain</Badge>;
const { processUploadObjects, processUploadObjectRecord } = useUploadProcessObjects(loginAccount);

const processing = processUploadObjects.includes(object);

if (!processing) return <Badge colorScheme="warning">Created on Chain</Badge>;

const file = processUploadObjectRecord[object];

if (file.status === 'UPLOAD') return <UploadProgress progress={file.progress} />;

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
30 changes: 30 additions & 0 deletions apps/dcellar-web-ui/src/hooks/useUploadProcessObjects.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { useAppSelector } from '@/store';
import { selectUploadQueue, UploadObject } from '@/store/slices/global';
import { useMemo } from 'react';

export const useUploadProcessObjects = (loginAccount: string) => {
const queue = useAppSelector(selectUploadQueue(loginAccount));

return useMemo(() => {
const processUploadObjectRecord: Record<string, UploadObject> = {};
const processUploadObjects = queue
.filter((q) => q.status !== 'ERROR')
.map((q) => {
const key = [
q.bucketName,
...q.prefixFolders,
q.waitObject.relativePath || '',
q.waitObject.name,
]
.filter((item) => !!item)
.join('/');
processUploadObjectRecord[key] = q;
return key;
});

return {
processUploadObjects,
processUploadObjectRecord,
};
}, [queue]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ import {
setupAccountRecords,
} from '@/store/slices/accounts';
import { TBucket } from '@/store/slices/bucket';
import { selectGnfdGasFeesConfig, setSignatureAction } from '@/store/slices/global';
import {
selectGnfdGasFeesConfig,
selectUploadQueue,
setSignatureAction,
} from '@/store/slices/global';
import { setDeletedObject, setObjectSelectedKeys } from '@/store/slices/object';
import { BN } from '@/utils/math';
import { getStoreNetflowRate } from '@/utils/payment';
Expand All @@ -37,6 +41,7 @@ import { parseEther } from 'ethers/lib/utils.js';
import { round } from 'lodash-es';
import { memo, useMemo, useState } from 'react';
import { useAccount } from 'wagmi';
import { useUploadProcessObjects } from '@/hooks/useUploadProcessObjects';

interface BatchDeleteObjectOperationProps {
selectBucket: TBucket;
Expand Down Expand Up @@ -70,6 +75,7 @@ export const BatchDeleteObjectOperation = memo<BatchDeleteObjectOperationProps>(
const { loading: loadingSettlementFee, settlementFee } = useSettlementFee(
bucket?.PaymentAddress,
);
const { processUploadObjects } = useUploadProcessObjects(loginAccount);

const deleteObjects = objectSelectedKeys.map((key) => {
return objectRecords[currentBucketName + '/' + key];
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,10 @@ export const BatchDeleteObjectOperation = memo<BatchDeleteObjectOperationProps>(
connector: connector!,
privateKey,
};
const [txRes, error] = await (ObjectStatus === 1

const processing = processUploadObjects.includes(`${currentBucketName}/${objectName}`);

const [txRes, error] = await (ObjectStatus === 1 || (ObjectStatus !== 1 && !processing)
? deleteObject(payload)
: cancelCreateObject(payload));
if (error && error !== E_OBJECT_NOT_EXISTS) {
Expand Down
38 changes: 20 additions & 18 deletions apps/dcellar-web-ui/src/modules/object/components/ObjectList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ import { Box, Flex } from '@node-real/uikit';
import { useAsyncEffect, useUpdateEffect } from 'ahooks';
import { ColumnProps } from 'antd/es/table';
import dayjs from 'dayjs';
import { find, uniq, without, xor } from 'lodash-es';
import { uniq, without, xor } from 'lodash-es';
import { memo, useCallback } from 'react';
import { OBJECT_ERROR_TYPES, ObjectErrorType } from '../ObjectError';
import Link from 'next/link';
// import { ManageObjectTagsDrawer } from './ManageObjectTagsDrawer';
import { useUploadProcessObjects } from '@/hooks/useUploadProcessObjects';

export type ObjectActionValueType =
| 'marketplace'
Expand Down Expand Up @@ -123,6 +123,7 @@ export const ObjectList = memo<ObjectListProps>(function ObjectList({ shareMode
const loading = useAppSelector(selectPathLoading);
const objectList = useAppSelector(selectObjectList);
const uploadQueue = useAppSelector(selectUploadQueue(loginAccount));
const { processUploadObjects, processUploadObjectRecord } = useUploadProcessObjects(loginAccount);

const { setOpenAuthModal } = useOffChainAuth();
const bucket = bucketRecords[currentBucketName];
Expand Down Expand Up @@ -345,20 +346,17 @@ export const ObjectList = memo<ObjectListProps>(function ObjectList({ shareMode
pruneActions = removeAction(pruneActions, ['cancel']);
} else {
// It is not allowed to cancel when the chain is sealed, but the SP is not synchronized.
const file = find<UploadObject>(
uploadQueue,
(q) =>
[...q.prefixFolders, q.waitObject.name].join('/') === record.objectName &&
q.status !== 'ERROR',
);
const object = `${record.bucketName}/${record.objectName}`;
const processing = processUploadObjects.includes(object);
const file = processUploadObjectRecord[object];
// if is uploading, can not cancel;
if (file && ['SIGN', 'SIGNED', 'UPLOAD'].includes(file.status)) {
if (processing && ['SIGN', 'SIGNED', 'UPLOAD'].includes(file.status)) {
pruneActions = pickAction(pruneActions, ['detail']);
} else if (file && ['SEAL'].includes(file.status)) {
pruneActions = removeAction(pruneActions, ['cancel', 'share']);
} else if (processing && ['SEAL', 'SEALING'].includes(file.status)) {
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 +400,16 @@ 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 object = `${record.bucketName}/${record.objectName}`;
const processing = processUploadObjects.includes(object);

return {
// folder or processing
disabled: record.folder || (record.objectStatus !== 1 && processing), // Column configuration not to be checked
name: record.name,
};
},
};

const errorHandler = (type: string) => {
Expand Down Expand Up @@ -464,8 +468,6 @@ export const ObjectList = memo<ObjectListProps>(function ObjectList({ shareMode
address: loginAccount,
};

// const operator = primarySpInfo.operatorAddress;
// const { seedString } = await dispatch(getSpOffChainData(loginAccount, operator));
const [success, opsError] = await downloadObject(params, seedString);
if (opsError) return errorHandler(opsError);
dispatch(setupBucketQuota(currentBucketName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,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 9fe6922

Please sign in to comment.