Skip to content

Commit

Permalink
feat: list and delist
Browse files Browse the repository at this point in the history
  • Loading branch information
ybgbob committed Nov 16, 2023
1 parent 7932849 commit 19af955
Show file tree
Hide file tree
Showing 12 changed files with 370 additions and 168 deletions.
4 changes: 3 additions & 1 deletion src/components/modal/DelistModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const DelistModal = (props: any) => {

const { object_name, create_at, bucket_name, groupId } = delistData;

const name = object_name || bucket_name;
const name = bucket_name;
const type = object_name ? 'Data' : 'Collection';

const { num } = useCollectionItems(name, false);
Expand Down Expand Up @@ -137,6 +137,8 @@ export const DelistModal = (props: any) => {
result: tmp,
});
setLoading(false);

modalData.modalState?.callBack();
}}
disabled={!BSC_FEE_SUFF || loading}
isLoading={loading}
Expand Down
1 change: 1 addition & 0 deletions src/components/modal/ListModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ export const ListModal = (props: ListModalProps) => {
modalData.modalDispatch({
type: 'OPEN_LIST_PROCESS',
listData,
callBack: modalData.modalState.callBack,
});
}}
disabled={!available}
Expand Down
6 changes: 5 additions & 1 deletion src/components/modal/ListProcess.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const ListProcess = (props: ListProcessProps) => {
setTitle(hasRole ? 'Finalize on BSC' : 'Approve on BSC');
setStatus(1);
}
}, [stateModal.modalState.initListStatus]);
}, [hasRole, stateModal.modalState.initListStatus]);

const reset = useCallback(() => {
setStep(0);
Expand Down Expand Up @@ -241,7 +241,11 @@ export const ListProcess = (props: ListProcessProps) => {
{status == 2 && (
<Button
onClick={() => {
console.log(stateModal.modalState.callBack);
stateModal.modalState?.callBack();

reset();

stateModal.modalDispatch({ type: 'RESET' });
handleOpen(false);
}}
Expand Down
97 changes: 97 additions & 0 deletions src/components/resource/collection/ActionButtonGroup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { Box } from '@totejs/uikit';
import { FILE_ITEM } from '../../../hooks/useGetObjectList';
import { useAccount } from 'wagmi';
import { useMemo } from 'react';
import { useModal } from '../../../hooks/useModal';
import {
useGetBucketByName,
useGetGroupByName,
useGetObject,
} from '../../../hooks/useGetBucketOrObj';
import { generateGroupName } from '../../../utils';

interface Props {
fileInfo: FILE_ITEM;
uploadFn: () => void;
}

export const ActionButtonGroup = (props: Props) => {
const { fileInfo, uploadFn } = props;
const { name, type, data, isListed, isPurchasedByMe } = fileInfo;
const { BucketName, ObjectName } = data;
const { address } = useAccount();
const modalData = useModal();

const { data: bucketData } = useGetBucketByName(BucketName);
const { data: objectData } = useGetObject(BucketName, ObjectName);

const { data: groupData } = useGetGroupByName(
generateGroupName(BucketName, ObjectName),
data.Owner,
);

return (
<Box>
{/* only owner can delist */}
{isListed && data.Owner === address && (
<Box
onClick={() => {
if (!objectData || !groupData) return;

console.log(
'generateGroupName(BucketName, ObjectName)',
generateGroupName(BucketName, ObjectName),
);

modalData.modalDispatch({
type: 'OPEN_DELIST',
delistData: {
groupId: groupData.groupInfo.id,
bucket_name: BucketName,
object_name: ObjectName,
create_at: objectData.objectInfo.createAt.low,
owner: objectData.objectInfo.owner,
},
callBack: () => {
uploadFn();
},
});
}}
>
delist
</Box>
)}

{/* only owner can list */}
{!isListed && data.Owner === address && (
<Box
onClick={() => {
if (!bucketData || !objectData) return;

const initInfo = {
bucket_name: BucketName,
object_name: objectData.objectInfo.objectName,
create_at: objectData.objectInfo.createAt.low,
payload_size: objectData.objectInfo.payloadSize,
};
modalData.modalDispatch({
type: 'OPEN_LIST',
initInfo,
callBack: () => {
uploadFn();
},
});
}}
>
list
</Box>
)}

{/* only buyer can download */}
{isPurchasedByMe && <Box>download</Box>}

{/* haven't bought can buy excepy owner */}
{!isPurchasedByMe && data.Owner !== address && <Box>Buy</Box>}
</Box>
);
};
Loading

0 comments on commit 19af955

Please sign in to comment.