Skip to content

Commit

Permalink
Merge branch 'feat/pa-create' into feat/buy-quota
Browse files Browse the repository at this point in the history
  • Loading branch information
aiden-cao committed Aug 29, 2023
2 parents aaf6d3e + 48442cf commit 9680966
Show file tree
Hide file tree
Showing 31 changed files with 177 additions and 2,033 deletions.
2 changes: 1 addition & 1 deletion apps/dcellar-web-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"ahooks": "3.7.7",
"hash-wasm": "4.9.0",
"@babel/core": "^7.20.12",
"@bnb-chain/greenfield-js-sdk": "0.2.4-alpha.23",
"@bnb-chain/greenfield-js-sdk": "0.2.4-alpha.24",
"@bnb-chain/greenfield-cosmos-types": "0.4.0-alpha.22",
"@emotion/react": "^11.10.5",
"@emotion/styled": "^11.10.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ import { updateBucketInfo } from '@/facade/bucket';
import { useAccount } from 'wagmi';
import { MsgUpdateBucketInfo } from '@bnb-chain/greenfield-cosmos-types/greenfield/storage/tx';
import Long from 'long';
import { VisibilityToChain } from '@/modules/file/utils/visibility';
import { VisibilityType } from '@bnb-chain/greenfield-cosmos-types/greenfield/storage/common';

interface ManageQuotaProps {
onClose: () => void;
Expand Down Expand Up @@ -147,9 +145,10 @@ export const ManageQuota = memo<ManageQuotaProps>(function ManageQuota({ onClose
// @ts-ignore
visibility: bucket.Visibility,
paymentAddress: bucket.PaymentAddress,
chargedReadQuota: { value: new Long(newChargedQuota * G_BYTES) },
chargedReadQuota: { value: Long.fromNumber(newChargedQuota * G_BYTES) },
};

console.log(payload);
const [txRes, txError] = await updateBucketInfo(payload, connector!);
setLoading(false);
if (!txRes || txRes.code !== 0) return errorHandler(txError || UNKNOWN_ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { LoadingAdaptor } from './LoadingAdaptor';
import { trimFloatZero } from '@/utils/trimFloatZero';
import { Tips } from '@/components/common/Tips';
import { getNumInDigits } from '@/utils/wallet';
import { selectBalance } from '@/store/slices/balance';

export const AccountDetail = ({ loading, title, accountDetail, lockFee }: any) => {
const bnbPrice = useAppSelector(selectBnbPrice);
Expand Down Expand Up @@ -90,7 +89,7 @@ export const AccountDetail = ({ loading, title, accountDetail, lockFee }: any) =
{trimFloatZero(
BigNumber(lockFee || 0)
.dp(CRYPTOCURRENCY_DISPLAY_PRECISION)
.toString(DECIMAL_NUMBER),
.toString(),
)}{' '}
BNB
</Text>
Expand Down
69 changes: 40 additions & 29 deletions apps/dcellar-web-ui/src/modules/bucket/components/DetailDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { useAppDispatch, useAppSelector } from '@/store';
import { BucketItem, setEditDetail, setEditQuota, setupBucketQuota } from '@/store/slices/bucket';
import { formatFullTime, getMillisecond } from '@/utils/time';
import { formatId } from '@/utils/string';
import { formatId, trimAddress } from '@/utils/string';
import { formatAddress } from '@/modules/buckets/utils/formatAddress';
import { GREENFIELD_CHAIN_EXPLORER_URL } from '@/base/env';
import { GAClick } from '@/components/common/GATracker';
Expand Down Expand Up @@ -55,9 +55,14 @@ export const DetailDrawer = memo<DetailDrawerProps>(function DetailDrawer() {
text: `${formatBytes(remainingQuota, true)} / ${formatBytes(freeQuota + readQuota)}`,
};
}, [quota]);
const { spInfo } = useAppSelector((root) => root.sp);
const { accountsInfo } = useAppSelector((root) => root.accounts);

const getContent = () => {
if (!isOpen) return;
if (!isOpen || !editDetail) return;
const CreateAt = getMillisecond(editDetail.CreateAt);
const spName = editDetail.PrimarySpAddress && spInfo[editDetail.PrimarySpAddress]?.moniker;
const payAccountName = bucket.PaymentAddress && accountsInfo[bucket.PaymentAddress]?.name;
const infos = [
{
canCopy: false,
Expand All @@ -66,33 +71,35 @@ export const DetailDrawer = memo<DetailDrawerProps>(function DetailDrawer() {
display: formatFullTime(CreateAt),
href: '',
},
{
canCopy: true,
label: 'Bucket ID',
value: formatId(Number(bucket.Id)),
display: formatAddress(formatId(Number(bucket.Id))),
copyGaClickName: 'dc.bucket.b_detail_pop.id_copy.click',
gaClickName: 'dc.bucket.b_detail_pop.id.click',
href: `${GREENFIELD_CHAIN_EXPLORER_URL}/bucket`,
},
{
canCopy: true,
label: 'Primary SP address',
name: spName,
value: editDetail?.PrimarySpAddress || '--',
display: editDetail?.PrimarySpAddress ? formatAddress(editDetail.PrimarySpAddress) : '--',
display: editDetail?.PrimarySpAddress ? trimAddress(editDetail.PrimarySpAddress) : '--',
copyGaClickName: 'dc.bucket.b_detail_pop.copy_spadd.click',
gaClickName: 'dc.bucket.b_detail_pop.spadd.click',
href: `${GREENFIELD_CHAIN_EXPLORER_URL}/account`,
},
{
canCopy: true,
label: 'Payment address',
name: payAccountName,
value: bucket.PaymentAddress,
display: formatAddress(bucket.PaymentAddress),
display: `${trimAddress(bucket.PaymentAddress)}`,
copyGaClickName: 'dc.bucket.b_detail_pop.copy_payment.click',
gaClickName: 'dc.bucket.b_detail_pop.payment.click',
href: `${GREENFIELD_CHAIN_EXPLORER_URL}/account`,
},
{
canCopy: true,
label: 'Bucket ID',
value: formatId(Number(bucket.Id)),
display: formatAddress(formatId(Number(bucket.Id))),
copyGaClickName: 'dc.bucket.b_detail_pop.id_copy.click',
gaClickName: 'dc.bucket.b_detail_pop.id.click',
href: `${GREENFIELD_CHAIN_EXPLORER_URL}/bucket`,
},
{
canCopy: true,
label: 'Create transaction hash',
Expand Down Expand Up @@ -136,22 +143,26 @@ export const DetailDrawer = memo<DetailDrawerProps>(function DetailDrawer() {
)}
{item.label !== 'Date Created' &&
(item.canCopy ? (
<GAClick name={item.gaClickName}>
<Link
target="_blank"
color="#1184EE"
cursor={'pointer'}
textDecoration={'underline'}
_hover={{
color: '#3C9AF1',
}}
href={`${item.href}/${item.value}`}
fontSize={'14px'}
fontWeight={500}
>
{item.display}
</Link>
</GAClick>
<>
{item.name ? `${item.name} |` : ''}
&nbsp;
<GAClick name={item.gaClickName}>
<Link
target="_blank"
color="#1184EE"
cursor={'pointer'}
textDecoration={'underline'}
_hover={{
color: '#3C9AF1',
}}
href={`${item.href}/${item.value}`}
fontSize={'14px'}
fontWeight={500}
>
{item.display}
</Link>
</GAClick>
</>
) : (
<Link
target="_blank"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ export const CreateBucket = ({ isOpen, onClose, refetch }: Props) => {
setOpenAuthModal();
return;
}
// TODO add payment account field
const createBucketPayload: IBaseGetCreateBucket = {
bucketName,
creator: address,
Expand Down Expand Up @@ -295,84 +294,81 @@ export const CreateBucket = ({ isOpen, onClose, refetch }: Props) => {
[checkGasFee, clearErrors, setError, setValue, validateNameRules],
);

const onSubmit = useCallback(
async (data: any) => {
try {
setStatus('operating');
const { seedString } = await dispatch(
getSpOffChainData(address, selectedSpRef.current.operatorAddress),
);
if (!seedString) {
onClose();
setOpenAuthModal();
return;
}
const bucketName = data.bucketName;
const selectedPaAddress = selectedPaRef.current.address;
const createBucketPayload: IBaseGetCreateBucket = {
bucketName,
creator: address,
paymentAddress: selectedPaAddress,
visibility: ChainVisibilityEnum.VISIBILITY_TYPE_PUBLIC_READ,
chargedReadQuota: String(chargeQuota * G_BYTES),
spInfo: {
primarySpAddress: selectedSpRef.current.operatorAddress,
},
};
const onSubmit = async (data: any) => {
try {
setStatus('operating');
const { seedString } = await dispatch(
getSpOffChainData(address, selectedSpRef.current.operatorAddress),
);
if (!seedString) {
onClose();
setOpenAuthModal();
return;
}
const bucketName = data.bucketName;
const selectedPaAddress = selectedPaRef.current.address;
const createBucketPayload: IBaseGetCreateBucket = {
bucketName,
creator: address,
paymentAddress: selectedPaAddress,
visibility: ChainVisibilityEnum.VISIBILITY_TYPE_PUBLIC_READ,
chargedReadQuota: String(chargeQuota * G_BYTES),
spInfo: {
primarySpAddress: selectedSpRef.current.operatorAddress,
},
};

const createBucketTx = await genCreateBucketTx(createBucketPayload, {
type: 'EDDSA',
domain: window.location.origin,
seed: seedString,
address,
});
const simulateInfo = await createBucketTx.simulate({
denom: 'BNB',
});
const txRes = await createBucketTx.broadcast({
denom: 'BNB',
gasLimit: Number(simulateInfo?.gasLimit),
gasPrice: simulateInfo?.gasPrice || '5000000000',
payer: createBucketPayload.creator,
granter: '',
signTypedDataCallback: async (addr: string, message: string) => {
const provider = await connector?.getProvider();
return await signTypedDataV4(provider, addr, message);
},
const createBucketTx = await genCreateBucketTx(createBucketPayload, {
type: 'EDDSA',
domain: window.location.origin,
seed: seedString,
address,
});
const simulateInfo = await createBucketTx.simulate({
denom: 'BNB',
});
const txRes = await createBucketTx.broadcast({
denom: 'BNB',
gasLimit: Number(simulateInfo?.gasLimit),
gasPrice: simulateInfo?.gasPrice || '5000000000',
payer: createBucketPayload.creator,
granter: '',
signTypedDataCallback: async (addr: string, message: string) => {
const provider = await connector?.getProvider();
return await signTypedDataV4(provider, addr, message);
},
});
// todo refactor
await pollingGetBucket({
address: createBucketPayload.creator,
endpoint: globalSP.endpoint,
bucketName: createBucketPayload.bucketName,
});

if (txRes.code === 0) {
onClose();
typeof refetch === 'function' && refetch();
toast.success({
description: `Bucket created successfully!`,
});
// todo refactor
await pollingGetBucket({
address: createBucketPayload.creator,
endpoint: globalSP.endpoint,
bucketName: createBucketPayload.bucketName,
setTimeout(() => {
setStatus('pending');
}, 200);
reportEvent({
name: 'dc.toast.bucket_create.success.show',
});

if (txRes.code === 0) {
onClose();
typeof refetch === 'function' && refetch();
toast.success({
description: `Bucket created successfully!`,
});
setTimeout(() => {
setStatus('pending');
}, 200);
reportEvent({
name: 'dc.toast.bucket_create.success.show',
});
} else {
throw txRes;
}
} catch (e: any) {
setStatus('failed');
// handle chain and storage error
const errorMsg = e?.message;
errorMsg && setSubmitErrorMsg(errorMsg);
// eslint-disable-next-line no-console
console.log('submit error', e);
} else {
throw txRes;
}
},
[address, connector, dispatch, globalSP?.endpoint, onClose, refetch, setOpenAuthModal],
);
} catch (e: any) {
setStatus('failed');
// handle chain and storage error
const errorMsg = e?.message;
errorMsg && setSubmitErrorMsg(errorMsg);
// eslint-disable-next-line no-console
console.log('submit error', e);
}
};

const disableCreateButton = () => {
return (
Expand Down
1 change: 0 additions & 1 deletion apps/dcellar-web-ui/src/modules/buckets/constants.ts

This file was deleted.

33 changes: 0 additions & 33 deletions apps/dcellar-web-ui/src/modules/buckets/type.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,4 @@
import { ChainVisibilityEnum } from "../file/type";

export type TNameFieldValue = {
bucketName: string;
};
export type TCreateBucketFromValues = TNameFieldValue;

export interface IApprovalCreateBucket {
BucketName: string;
creator: string;
visibility: ChainVisibilityEnum;
PrimarySpAddress: string;
primary_sp_approval: {
expired_height: string;
sig: string;
};
ChargedReadQuota: number;
RedundancyType: string;
}

export interface IRawSPInfo {
approvalAddress: string;
endpoint: string;
fundingAddress: string;
gcAddress: string;
operatorAddress: string;
sealAddress: string;
status: number;
totalDeposit: string;
description: {
details: string;
identity: string;
moniker: string;
securityContact: string;
website: string;
}
}
Loading

0 comments on commit 9680966

Please sign in to comment.