From a0b463bc340482c3fa19f55d8ddc530beffa5d57 Mon Sep 17 00:00:00 2001 From: devinxl Date: Wed, 20 Mar 2024 15:25:50 +0800 Subject: [PATCH 1/3] feat(dcellar-web-ui): support new off-chain authentication and remove getApproval flow --- apps/dcellar-web-ui/package.json | 4 +- .../GlobalObjectUploadManager.tsx | 27 ++++----- .../off-chain-auth/OffChainAuthContext.tsx | 1 - apps/dcellar-web-ui/src/facade/bucket.ts | 20 +++---- .../components/CreateBucketOperation.tsx | 55 +++++++------------ .../components/CreateFolderOperation.tsx | 37 +++++++------ .../modules/object/components/ObjectList.tsx | 2 - .../dcellar-web-ui/src/modules/object/type.ts | 7 --- .../modules/object/utils/genCreateObjectTx.ts | 11 ---- .../object/utils/generatePubObjectOptions.ts | 13 ++--- .../modules/object/utils/getCreateObjectTx.ts | 7 +++ .../modules/upload/UploadObjectsOperation.tsx | 45 ++++++++------- .../src/store/slices/persist.ts | 8 +-- apps/dcellar-web-ui/src/store/slices/sp.ts | 2 +- common/config/rush/pnpm-lock.yaml | 34 +++++++----- 15 files changed, 124 insertions(+), 149 deletions(-) delete mode 100644 apps/dcellar-web-ui/src/modules/object/type.ts delete mode 100644 apps/dcellar-web-ui/src/modules/object/utils/genCreateObjectTx.ts create mode 100644 apps/dcellar-web-ui/src/modules/object/utils/getCreateObjectTx.ts diff --git a/apps/dcellar-web-ui/package.json b/apps/dcellar-web-ui/package.json index d3fa57d1..9672f237 100644 --- a/apps/dcellar-web-ui/package.json +++ b/apps/dcellar-web-ui/package.json @@ -18,8 +18,8 @@ "antd": "5.11.0", "ahooks": "3.7.7", "hash-wasm": "4.10.0", - "@bnb-chain/greenfield-js-sdk": "1.2.0", - "@bnb-chain/greenfield-cosmos-types": "0.4.0-alpha.30", + "@bnb-chain/greenfield-js-sdk": "1.3.0-alpha.2", + "@bnb-chain/greenfield-cosmos-types": "0.4.0-alpha.31", "@emotion/react": "^11.10.5", "@emotion/styled": "^11.10.5", "@next/bundle-analyzer": "^13.1.6", diff --git a/apps/dcellar-web-ui/src/components/layout/GlobalManagements/GlobalObjectUploadManager.tsx b/apps/dcellar-web-ui/src/components/layout/GlobalManagements/GlobalObjectUploadManager.tsx index 24326823..ae845be0 100644 --- a/apps/dcellar-web-ui/src/components/layout/GlobalManagements/GlobalObjectUploadManager.tsx +++ b/apps/dcellar-web-ui/src/components/layout/GlobalManagements/GlobalObjectUploadManager.tsx @@ -23,7 +23,7 @@ import { useOffChainAuth } from '@/context/off-chain-auth/useOffChainAuth'; import { resolve } from '@/facade/common'; import { broadcastFault, commonFault, createTxFault, simulateFault } from '@/facade/error'; import { getObjectMeta } from '@/facade/object'; -import { genCreateObjectTx } from '@/modules/object/utils/genCreateObjectTx'; +import { getCreateObjectTx } from '@/modules/object/utils/getCreateObjectTx'; import { TMakePutObjectHeaders, makePutObjectHeaders, @@ -31,9 +31,10 @@ import { import { setupAccountRecords } from '@/store/slices/accounts'; import { setupSpMeta } from '@/store/slices/sp'; import { parseErrorXml, sleep } from '@/utils/common'; -import { AuthType, CreateObjectApprovalRequest } from '@bnb-chain/greenfield-js-sdk'; +import { AuthType, Long, RedundancyType, bytesFromBase64 } from '@bnb-chain/greenfield-js-sdk'; import axios from 'axios'; import { isEmpty } from 'lodash-es'; +import { MsgCreateObject } from '@bnb-chain/greenfield-cosmos-types/greenfield/storage/tx'; interface GlobalTasksProps {} @@ -122,7 +123,6 @@ export const GlobalObjectUploadManager = memo( if (authModal) return; dispatch(updateUploadProgress({ account: loginAccount, id: task.id, progress })); }, - headers: { Authorization: headers.get('Authorization'), 'content-type': headers.get('content-type'), @@ -132,6 +132,7 @@ export const GlobalObjectUploadManager = memo( 'x-gnfd-expiry-timestamp': headers.get('x-gnfd-expiry-timestamp'), 'x-gnfd-txn-hash': headers.get('x-gnfd-txn-hash'), 'x-gnfd-user-address': headers.get('x-gnfd-user-address'), + 'X-Gnfd-App-Reg-Public-Key': headers.get('X-Gnfd-App-Reg-Public-Key'), }, }) .then(async () => { @@ -206,20 +207,20 @@ export const GlobalObjectUploadManager = memo( const finalName = [...task.prefixFolders, task.waitObject.relativePath, task.waitObject.name] .filter((item) => !!item) .join('/'); - const createObjectPayload: CreateObjectApprovalRequest = { + const msgCreateObject: MsgCreateObject = { + creator: tempAccount.address, bucketName: task.bucketName, objectName: finalName, - creator: tempAccount.address, visibility: reverseVisibilityType[task.visibility], - fileType: task.waitObject.type || 'application/octet-stream', - contentLength: task.waitObject.size, - expectCheckSums: task.checksum, - duration: 5000, + contentType: task.waitObject.type || 'application/octet-stream', + payloadSize: Long.fromInt(task.waitObject.size), + expectChecksums: task.checksum.map((x) => bytesFromBase64(x)), + redundancyType: RedundancyType.REDUNDANCY_EC_TYPE, }; - const [createObjectTx, _createError] = await genCreateObjectTx(createObjectPayload, { - type: 'ECDSA', - privateKey: tempAccount.privateKey, - }).then(resolve, createTxFault); + const [createObjectTx, _createError] = await getCreateObjectTx(msgCreateObject).then( + resolve, + createTxFault, + ); if (_createError) { console.error('createError', _createError); return dispatch( diff --git a/apps/dcellar-web-ui/src/context/off-chain-auth/OffChainAuthContext.tsx b/apps/dcellar-web-ui/src/context/off-chain-auth/OffChainAuthContext.tsx index 402876d2..2a06127b 100644 --- a/apps/dcellar-web-ui/src/context/off-chain-auth/OffChainAuthContext.tsx +++ b/apps/dcellar-web-ui/src/context/off-chain-auth/OffChainAuthContext.tsx @@ -56,7 +56,6 @@ export const OffChainAuthProvider: React.FC = ({ children }) => { try { const domain = getDomain(); - // If no sps selected, use all sps for welcome auth const pruneSps = (isEmpty(authSps.current) ? allSpList : authSps.current).map( (item: any) => ({ address: item.operatorAddress, diff --git a/apps/dcellar-web-ui/src/facade/bucket.ts b/apps/dcellar-web-ui/src/facade/bucket.ts index a30dd8b4..c842552b 100644 --- a/apps/dcellar-web-ui/src/facade/bucket.ts +++ b/apps/dcellar-web-ui/src/facade/bucket.ts @@ -17,11 +17,13 @@ import { QueryHeadBucketResponse, QueryQuoteUpdateTimeResponse, } from '@bnb-chain/greenfield-cosmos-types/greenfield/storage/query'; -import { MsgUpdateBucketInfo } from '@bnb-chain/greenfield-cosmos-types/greenfield/storage/tx'; +import { + MsgCreateBucket, + MsgUpdateBucketInfo, +} from '@bnb-chain/greenfield-cosmos-types/greenfield/storage/tx'; import { ResourceTags_Tag } from '@bnb-chain/greenfield-cosmos-types/greenfield/storage/types'; import { AuthType, - CreateBucketApprovalRequest, GRNToString, GetBucketMetaResponse, GetUserBucketsResponse, @@ -263,12 +265,11 @@ export const getBucketQuotaUpdateTime = async (bucketName: string) => { }; export const getCreateBucketTx = async ( - params: CreateBucketApprovalRequest, - authType: AuthType, + msgCreateBucket: MsgCreateBucket, ): Promise<[TxResponse, null] | ErrorResponse> => { const client = await getClient(); const [createBucketTx, error1] = await client.bucket - .createBucket(params, authType) + .createBucket(msgCreateBucket) .then(resolve, createTxFault); if (!createBucketTx) return [null, error1]; @@ -277,12 +278,11 @@ export const getCreateBucketTx = async ( }; export const simulateCreateBucket = async ( - params: CreateBucketApprovalRequest, - authType: AuthType, + params: MsgCreateBucket, ): Promise<[ISimulateGasFee, null, TxResponse] | ErrorResponse> => { const client = await getClient(); const [createBucketTx, error1] = await client.bucket - .createBucket(params, authType) + .createBucket(params) .then(resolve, createTxFault); if (!createBucketTx) return [null, error1]; @@ -299,11 +299,11 @@ export const simulateCreateBucket = async ( }; export const createBucket = async ( - params: CreateBucketApprovalRequest, + params: MsgCreateBucket, authType: AuthType, connector: Connector, ): BroadcastResponse => { - const [simulateInfo, error, createBucketTx] = await simulateCreateBucket(params, authType); + const [simulateInfo, error, createBucketTx] = await simulateCreateBucket(params); if (!simulateInfo) return [null, error]; const payload = { diff --git a/apps/dcellar-web-ui/src/modules/bucket/components/CreateBucketOperation.tsx b/apps/dcellar-web-ui/src/modules/bucket/components/CreateBucketOperation.tsx index bea1189a..f5040614 100644 --- a/apps/dcellar-web-ui/src/modules/bucket/components/CreateBucketOperation.tsx +++ b/apps/dcellar-web-ui/src/modules/bucket/components/CreateBucketOperation.tsx @@ -39,7 +39,6 @@ import { useSettlementFee } from '@/hooks/useSettlementFee'; import { PaymentAccountSelector } from '@/modules/bucket/components/PaymentAccountSelector'; import { TotalFees } from '@/modules/object/components/TotalFees'; import { BUTTON_GOT_IT, WALLET_CONFIRM } from '@/modules/object/constant'; -import { ChainVisibilityEnum } from '@/modules/object/type'; import { PaymentInsufficientBalance } from '@/modules/object/utils'; import { MIN_AMOUNT } from '@/modules/wallet/constants'; import { useAppDispatch, useAppSelector } from '@/store'; @@ -56,19 +55,20 @@ import { setSignatureAction, setupStoreFeeParams, } from '@/store/slices/global'; -import { getSpOffChainData } from '@/store/slices/persist'; import { SpEntity } from '@/store/slices/sp'; import { reportEvent } from '@/utils/gtag'; import { BN } from '@/utils/math'; import { getQuotaNetflowRate } from '@/utils/payment'; import { - CreateBucketApprovalRequest, MsgCreateBucketTypeUrl, MsgSetTagTypeUrl, TxResponse, + VisibilityType, + Long, } from '@bnb-chain/greenfield-js-sdk'; import { useAsyncEffect, useUnmount } from 'ahooks'; import { SPSelector } from './SPSelector'; +import { MsgCreateBucket } from '@bnb-chain/greenfield-cosmos-types/greenfield/storage/tx'; type ValidateNameAndGas = { isValidating: boolean; @@ -231,23 +231,18 @@ export const CreateBucketOperation = memo(function C const bucketName = value; setValidateNameAndGas({ ...validateNameAndGas, isValidating: true }); const sp = selectedSpRef.current; - const { seedString } = await dispatch(getSpOffChainData(loginAccount, sp.operatorAddress)); - const createBucketPayload: CreateBucketApprovalRequest = { - bucketName, + const msgCreateBucket: MsgCreateBucket = { creator: loginAccount, - visibility: ChainVisibilityEnum.VISIBILITY_TYPE_PUBLIC_READ, - chargedReadQuota: String(chargeQuota * G_BYTES), - spInfo: { - primarySpAddress: sp.operatorAddress, - }, + bucketName, + // done TODO visibility check done + visibility: VisibilityType.VISIBILITY_TYPE_PUBLIC_READ, paymentAddress: loginAccount, + primarySpAddress: sp.operatorAddress, + + //done TODO chargedReadQuota check + chargedReadQuota: Long.fromNumber(chargeQuota * G_BYTES), }; - const [simulateInfo, error] = await simulateCreateBucket(createBucketPayload, { - type: 'EDDSA', - domain: window.location.origin, - seed: seedString, - address: loginAccount, - }); + const [simulateInfo, error] = await simulateCreateBucket(msgCreateBucket); if (!simulateInfo) { if (curNonce !== nonceRef.current) return; @@ -315,29 +310,19 @@ export const CreateBucketOperation = memo(function C dispatch( setSignatureAction({ icon: Animates.object, title: 'Creating Bucket', desc: WALLET_CONFIRM }), ); - const { seedString } = await dispatch( - getSpOffChainData(loginAccount, selectedSpRef.current.operatorAddress), - ); const bucketName = data.bucketName; const selectedPaAddress = selectedPaRef.current.address; - const createBucketPayload: CreateBucketApprovalRequest = { - bucketName, + const msgCreateBucket: MsgCreateBucket = { creator: loginAccount, + bucketName, paymentAddress: selectedPaAddress, - visibility: ChainVisibilityEnum.VISIBILITY_TYPE_PUBLIC_READ, - chargedReadQuota: String(chargeQuota * G_BYTES), - spInfo: { - primarySpAddress: selectedSpRef.current.operatorAddress, - }, + visibility: VisibilityType.VISIBILITY_TYPE_PUBLIC_READ, + chargedReadQuota: Long.fromNumber(chargeQuota * G_BYTES), + primarySpAddress: selectedSpRef.current.operatorAddress, }; const txs: TxResponse[] = []; - const [bucketTx, error1] = await getCreateBucketTx(createBucketPayload, { - type: 'EDDSA', - domain: window.location.origin, - seed: seedString, - address: loginAccount, - }); + const [bucketTx, error1] = await getCreateBucketTx(msgCreateBucket); if (!bucketTx) return errorHandler(error1); txs.push(bucketTx); @@ -361,9 +346,9 @@ export const CreateBucketOperation = memo(function C if (txRes?.code !== 0) return errorHandler((txRes as any).message || txRes?.rawLog); await pollingGetBucket({ - address: createBucketPayload.creator, + address: msgCreateBucket.creator, endpoint: globalSP.endpoint, - bucketName: createBucketPayload.bucketName, + bucketName: msgCreateBucket.bucketName, }); dispatch(setSignatureAction({})); diff --git a/apps/dcellar-web-ui/src/modules/object/components/CreateFolderOperation.tsx b/apps/dcellar-web-ui/src/modules/object/components/CreateFolderOperation.tsx index c8af3f6c..048501d0 100644 --- a/apps/dcellar-web-ui/src/modules/object/components/CreateFolderOperation.tsx +++ b/apps/dcellar-web-ui/src/modules/object/components/CreateFolderOperation.tsx @@ -28,7 +28,7 @@ import { WALLET_CONFIRM, } from '@/modules/object/constant'; import { PaymentInsufficientBalance } from '@/modules/object/utils'; -import { genCreateObjectTx } from '@/modules/object/utils/genCreateObjectTx'; +import { getCreateObjectTx } from '@/modules/object/utils/getCreateObjectTx'; import { useAppDispatch, useAppSelector } from '@/store'; import { AccountInfo, setupAccountRecords } from '@/store/slices/accounts'; import { TBucket } from '@/store/slices/bucket'; @@ -39,16 +39,18 @@ import { setupStoreFeeParams, } from '@/store/slices/global'; import { setObjectEditTagsData, setObjectOperation } from '@/store/slices/object'; -import { getSpOffChainData } from '@/store/slices/persist'; import { SpEntity } from '@/store/slices/sp'; import { BN } from '@/utils/math'; import { getStoreNetflowRate } from '@/utils/payment'; import { removeTrailingSlash } from '@/utils/string'; import { - CreateObjectApprovalRequest, MsgCreateObjectTypeUrl, MsgSetTagTypeUrl, TxResponse, + Long, + RedundancyType, + bytesFromBase64, + VisibilityType, } from '@bnb-chain/greenfield-js-sdk'; import { Box, @@ -68,6 +70,7 @@ import { isEmpty } from 'lodash-es'; import { ChangeEvent, memo, useCallback, useEffect, useMemo, useState } from 'react'; import { useAccount } from 'wagmi'; import { TotalFees } from './TotalFees'; +import { MsgCreateObject } from '@bnb-chain/greenfield-cosmos-types/greenfield/storage/tx'; interface CreateFolderOperationProps { selectBucket: TBucket; @@ -298,29 +301,27 @@ export const CreateFolderOperation = memo(function C const simulateCreateFolderTx = async ( fullFolderName: string, - visibility: any = 'VISIBILITY_TYPE_INHERIT', + visibility: VisibilityType = VisibilityType.VISIBILITY_TYPE_INHERIT, ): Promise => { // const fullPath = getPath(folderName, folders); const file = new File([], fullFolderName, { type: 'text/plain' }); - const { seedString } = await dispatch( - getSpOffChainData(loginAccount, primarySp.operatorAddress), - ); const hashResult = await checksumWorkerApi?.generateCheckSumV2(file); - const createObjectPayload: CreateObjectApprovalRequest = { + const expectCheckSums = hashResult?.expectCheckSums || []; + const msgCreateObject: MsgCreateObject = { + creator: loginAccount, bucketName: currentBucketName, objectName: fullFolderName, - creator: loginAccount, visibility, - fileType: file.type, - contentLength: file.size, - expectCheckSums: hashResult?.expectCheckSums || [], + contentType: file.type, + payloadSize: Long.fromInt(file.size), + expectChecksums: expectCheckSums.map((x) => bytesFromBase64(x)), + redundancyType: RedundancyType.REDUNDANCY_EC_TYPE, }; - const [createObjectTx, createError] = await genCreateObjectTx(createObjectPayload, { - type: 'EDDSA', - domain: window.location.origin, - seed: seedString, - address: loginAccount, - }).then(resolve, createTxFault); + + const [createObjectTx, createError] = await getCreateObjectTx(msgCreateObject).then( + resolve, + createTxFault, + ); if (!createObjectTx) { return [null, createError]; 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 d64e193b..434d488c 100644 --- a/apps/dcellar-web-ui/src/modules/object/components/ObjectList.tsx +++ b/apps/dcellar-web-ui/src/modules/object/components/ObjectList.tsx @@ -450,8 +450,6 @@ export const ObjectList = memo(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)); diff --git a/apps/dcellar-web-ui/src/modules/object/type.ts b/apps/dcellar-web-ui/src/modules/object/type.ts deleted file mode 100644 index cce5901c..00000000 --- a/apps/dcellar-web-ui/src/modules/object/type.ts +++ /dev/null @@ -1,7 +0,0 @@ -export enum ChainVisibilityEnum { - VISIBILITY_TYPE_UNSPECIFIED = 'VISIBILITY_TYPE_UNSPECIFIED', - VISIBILITY_TYPE_PUBLIC_READ = 'VISIBILITY_TYPE_PUBLIC_READ', - VISIBILITY_TYPE_PRIVATE = 'VISIBILITY_TYPE_PRIVATE', - VISIBILITY_TYPE_INHERIT = 'VISIBILITY_TYPE_INHERIT', - UNRECOGNIZED = 'UNRECOGNIZED', -} diff --git a/apps/dcellar-web-ui/src/modules/object/utils/genCreateObjectTx.ts b/apps/dcellar-web-ui/src/modules/object/utils/genCreateObjectTx.ts deleted file mode 100644 index e52d1e7d..00000000 --- a/apps/dcellar-web-ui/src/modules/object/utils/genCreateObjectTx.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { AuthType, CreateObjectApprovalRequest } from '@bnb-chain/greenfield-js-sdk'; - -import { getClient } from '@/facade'; - -export const genCreateObjectTx = async ( - configParam: CreateObjectApprovalRequest, - authType: AuthType, -) => { - const client = await getClient(); - return client.object.createObject(configParam, authType); -}; diff --git a/apps/dcellar-web-ui/src/modules/object/utils/generatePubObjectOptions.ts b/apps/dcellar-web-ui/src/modules/object/utils/generatePubObjectOptions.ts index 5784a9e1..a2132968 100644 --- a/apps/dcellar-web-ui/src/modules/object/utils/generatePubObjectOptions.ts +++ b/apps/dcellar-web-ui/src/modules/object/utils/generatePubObjectOptions.ts @@ -3,8 +3,8 @@ import { METHOD_PUT, PutObjectRequest, SpMetaInfo, - isValidBucketName, - isValidObjectName, + verifyBucketName, + verifyObjectName, } from '@bnb-chain/greenfield-js-sdk'; import { getClient } from '@/facade'; @@ -18,12 +18,9 @@ export const makePutObjectHeaders = async ( ) => { const client = await getClient(); const { bucketName, objectName, txnHash, body, endpoint } = configParam; - if (!isValidBucketName(bucketName)) { - throw new Error('Error bucket name'); - } - if (!isValidObjectName(objectName)) { - throw new Error('Error object name'); - } + verifyBucketName(bucketName); + verifyObjectName(objectName); + if (!txnHash) { throw new Error('Transaction hash is empty, please check.'); } diff --git a/apps/dcellar-web-ui/src/modules/object/utils/getCreateObjectTx.ts b/apps/dcellar-web-ui/src/modules/object/utils/getCreateObjectTx.ts new file mode 100644 index 00000000..dd2f0b7e --- /dev/null +++ b/apps/dcellar-web-ui/src/modules/object/utils/getCreateObjectTx.ts @@ -0,0 +1,7 @@ +import { getClient } from '@/facade'; +import { MsgCreateObject } from '@bnb-chain/greenfield-cosmos-types/greenfield/storage/tx'; + +export const getCreateObjectTx = async (msgCreateObject: MsgCreateObject) => { + const client = await getClient(); + return client.object.createObject(msgCreateObject); +}; diff --git a/apps/dcellar-web-ui/src/modules/upload/UploadObjectsOperation.tsx b/apps/dcellar-web-ui/src/modules/upload/UploadObjectsOperation.tsx index 92f5fc7d..5cb81277 100644 --- a/apps/dcellar-web-ui/src/modules/upload/UploadObjectsOperation.tsx +++ b/apps/dcellar-web-ui/src/modules/upload/UploadObjectsOperation.tsx @@ -1,5 +1,7 @@ -import { VisibilityType } from '@bnb-chain/greenfield-cosmos-types/greenfield/storage/common'; -import { CreateObjectApprovalRequest } from '@bnb-chain/greenfield-js-sdk'; +import { + RedundancyType, + VisibilityType, +} from '@bnb-chain/greenfield-cosmos-types/greenfield/storage/common'; import styled from '@emotion/styled'; import { Box, @@ -30,7 +32,7 @@ import { ListItem } from './ListItem'; import { useUploadTab } from './useUploadTab'; import { useChecksumApi } from '../checksum'; import { OBJECT_ERROR_TYPES, ObjectErrorType } from '../object/ObjectError'; -import { genCreateObjectTx } from '../object/utils/genCreateObjectTx'; +import { getCreateObjectTx } from '../object/utils/getCreateObjectTx'; import { Animates } from '@/components/AnimatePng'; import { DCButton } from '@/components/common/DCButton'; @@ -74,7 +76,6 @@ import { SINGLE_OBJECT_MAX_SIZE, TEditUploadContent, } from '@/store/slices/object'; -import { getSpOffChainData } from '@/store/slices/persist'; import { SpEntity } from '@/store/slices/sp'; import { isUTF8 } from '@/utils/coder'; import { @@ -87,6 +88,8 @@ import { formatBytes } from '@/utils/formatter'; import { getTimestamp } from '@/utils/time'; import { setTempAccountRecords } from '@/store/slices/accounts'; import { createTempAccount } from '@/facade/account'; +import { MsgCreateObject } from '@bnb-chain/greenfield-cosmos-types/greenfield/storage/tx'; +import { Long, bytesFromBase64 } from '@bnb-chain/greenfield-js-sdk'; const defaultScroll = { top: 0 }; const defaultActionParams = {} as TEditUploadContent; @@ -267,27 +270,31 @@ export const UploadObjectsOperation = memo( const expectCheckSums = res?.expectCheckSums || []; console.log('hashing time', performance.now() - a); // 2. getApproval & sign - const { seedString } = await dispatch( - getSpOffChainData(loginAccount, primarySp.operatorAddress), - ); const finalName = [...pathSegments, waitObject.relativePath, waitObject.name] .filter((item) => !!item) .join('/'); - const createObjectPayload: CreateObjectApprovalRequest = { + console.log( + 'reverseVisibilityType[visibility]', + reverseVisibilityType[visibility], + VisibilityType[visibility], + visibility, + ); + const test1 = VisibilityType[visibility]; + console.log('a', test1); + const msgCreateObject: MsgCreateObject = { + creator: loginAccount, bucketName: currentBucketName, objectName: finalName, - creator: loginAccount, - visibility: reverseVisibilityType[visibility], - fileType: waitObject.type || 'application/octet-stream', - contentLength: waitObject.size, - expectCheckSums, + payloadSize: Long.fromInt(waitObject.size), + visibility, + contentType: waitObject.type || 'application/octet-stream', + expectChecksums: expectCheckSums.map((x) => bytesFromBase64(x)), + redundancyType: RedundancyType.REDUNDANCY_EC_TYPE, }; - const [createObjectTx, _createError] = await genCreateObjectTx(createObjectPayload, { - type: 'EDDSA', - seed: seedString, - domain: window.location.origin, - address: loginAccount, - }).then(resolve, createTxFault); + const [createObjectTx, _createError] = await getCreateObjectTx(msgCreateObject).then( + resolve, + createTxFault, + ); if (!createObjectTx) { // TODO refactor diff --git a/apps/dcellar-web-ui/src/store/slices/persist.ts b/apps/dcellar-web-ui/src/store/slices/persist.ts index 0b5c9999..3e2b7a17 100644 --- a/apps/dcellar-web-ui/src/store/slices/persist.ts +++ b/apps/dcellar-web-ui/src/store/slices/persist.ts @@ -10,7 +10,6 @@ type OffChain = IReturnOffChainAuthKeyPairAndUpload; export type SorterType = [string, 'descend' | 'ascend']; export const getDefaultAccountConfig = (): PersistedAccountConfig => ({ - seedString: '', directDownload: false, directView: false, offchain: [] as Array, @@ -20,7 +19,6 @@ export const getDefaultAccountConfig = (): PersistedAccountConfig => ({ export const defaultAccountConfig = getDefaultAccountConfig(); export type PersistedAccountConfig = { - seedString: string; directDownload: boolean; directView: boolean; offchain: OffChain[]; @@ -165,6 +163,7 @@ export const setupOffchain = spAddresses: o.spAddresses.filter((s) => !sps.includes(s)), })) .filter((o) => o.spAddresses.length && o.expirationTime > curTime); + // filter livable sps if (needUpdate) { const unAvailableSps = allSpList @@ -198,11 +197,6 @@ export const checkOffChainDataAvailable = return offchain.some((o) => o.expirationTime > curTime); }; -export const checkSpOffChainDataAvailable = - (address: string, sp: string) => async (dispatch: AppDispatch) => { - return !!(await dispatch(getSpOffChainData(address, sp))).seedString; - }; - export const checkSpOffChainMayExpired = (address: string) => async (dispatch: AppDispatch, getState: GetState) => { const { accountRecords, unAvailableSps } = getState().persist; diff --git a/apps/dcellar-web-ui/src/store/slices/sp.ts b/apps/dcellar-web-ui/src/store/slices/sp.ts index 710bed92..d30392d7 100644 --- a/apps/dcellar-web-ui/src/store/slices/sp.ts +++ b/apps/dcellar-web-ui/src/store/slices/sp.ts @@ -187,7 +187,7 @@ export const setupSpLatency = (endpoints: string[], address: string) => async () group.map(async (endpoint) => { await Promise.race([ window - .fetch(`${endpoint}/auth/request_nonce`, { + .fetch(`${endpoint}/status`, { headers: new Headers({ 'X-Gnfd-User-Address': address, 'X-Gnfd-App-Domain': getDomain(), diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index b7d1bcab..0f53f351 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -7,8 +7,8 @@ importers: ../../apps/dcellar-web-ui: specifiers: - '@bnb-chain/greenfield-cosmos-types': 0.4.0-alpha.30 - '@bnb-chain/greenfield-js-sdk': 1.2.0 + '@bnb-chain/greenfield-cosmos-types': 0.4.0-alpha.31 + '@bnb-chain/greenfield-js-sdk': 1.3.0-alpha.2 '@commitlint/cli': ^17.4.3 '@commitlint/config-conventional': ^17.4.3 '@emotion/react': ^11.10.5 @@ -72,8 +72,8 @@ importers: viem: ~1.19.11 wagmi: ~1.4.10 dependencies: - '@bnb-chain/greenfield-cosmos-types': 0.4.0-alpha.30 - '@bnb-chain/greenfield-js-sdk': 1.2.0 + '@bnb-chain/greenfield-cosmos-types': 0.4.0-alpha.31 + '@bnb-chain/greenfield-js-sdk': 1.3.0-alpha.2 '@emotion/react': 11.11.3_mj3jo2baq3jslihcop7oivercy '@emotion/styled': 11.11.0_44o7ug6fvmx5wru7ifqtcwoy2i '@next/bundle-analyzer': 13.5.6 @@ -1486,18 +1486,17 @@ packages: '@babel/helper-validator-identifier': 7.22.20 to-fast-properties: 2.0.0 - /@bnb-chain/greenfield-cosmos-types/0.4.0-alpha.30: - resolution: {integrity: sha512-nYThWPZHfq/bDMEu+Sw9cMMqgTk4NEg+PH9GkvN2OMgpo8QuCDy3Eh4C1g6lJy0BFv+ilethoPmKjSeEwa1m8g==} + /@bnb-chain/greenfield-cosmos-types/0.4.0-alpha.31: + resolution: {integrity: sha512-EPKQyQC/oe4/2p1Pn0FCECl7RyIvsXKs8bOmQHaylZweS6rZkXj5yov9oD1dVoHglV/tbQ/6EjdPg3wXUR+rww==} dependencies: long: 4.0.0 protobufjs: 6.11.4 dev: false - /@bnb-chain/greenfield-js-sdk/1.2.0: - resolution: {integrity: sha512-xYYK+4WXGiqX7MBNqRij2zo/3HI3mMwtuUOQS3qOoWkHG6oWUAKeBPxUNKz6RuPigZYAckAH0XcrJT0kjJIB+g==} + /@bnb-chain/greenfield-js-sdk/1.3.0-alpha.2: + resolution: {integrity: sha512-MC3H4WENC8lsxeyoqklocWWyYlUcWel54tt5FeAT5WpF05EHn6Rt4HKRWat6JnybtZdsvR9TNHAs/qAMZaLA/g==} dependencies: - '@bnb-chain/greenfield-cosmos-types': 0.4.0-alpha.30 - '@bnb-chain/greenfield-zk-crypto': 1.0.0 + '@bnb-chain/greenfield-cosmos-types': 0.4.0-alpha.31 '@cosmjs/proto-signing': 0.32.2 '@cosmjs/stargate': 0.32.2 '@cosmjs/tendermint-rpc': 0.32.2 @@ -1507,7 +1506,8 @@ packages: '@ethersproject/strings': 5.7.0 '@ethersproject/units': 5.7.0 '@metamask/eth-sig-util': 5.1.0 - cross-fetch: 3.1.8 + '@noble/curves': 1.3.0 + cross-fetch: 4.0.0 dayjs: 1.11.10 ethereum-cryptography: 2.1.3 fast-xml-parser: 4.2.7 @@ -1526,10 +1526,6 @@ packages: - utf-8-validate dev: false - /@bnb-chain/greenfield-zk-crypto/1.0.0: - resolution: {integrity: sha512-QlHNIleujENh02oPidtLFVNMArVpSQDdV9omOUTLjKA1j2/rrd4OKfMLh1gpeVKl53vw50ReGkbm2VlBXTZRbQ==} - dev: false - /@coinbase/wallet-sdk/3.7.2: resolution: {integrity: sha512-lIGvXMsgpsQWci/XOMQIJ2nIZ8JUy/L+bvC0wkRaYarr0YylwpXrJ2gRM3hCXPS477pkyO7N/kSiAoRgEXUdJQ==} engines: {node: '>= 10.0.0'} @@ -5496,6 +5492,14 @@ packages: - encoding dev: false + /cross-fetch/4.0.0: + resolution: {integrity: sha512-e4a5N8lVvuLgAWgnCrLr2PP0YyDOTHa9H/Rj54dirp61qXnNq46m82bRhNqIA5VccJtWBvPTFRV3TtvHUKPB1g==} + dependencies: + node-fetch: 2.7.0 + transitivePeerDependencies: + - encoding + dev: false + /cross-spawn/7.0.3: resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==} engines: {node: '>= 8'} From 491ebea86f43443792c71951155e3b9e2dfe07f3 Mon Sep 17 00:00:00 2001 From: devinxl Date: Wed, 20 Mar 2024 15:31:22 +0800 Subject: [PATCH 2/3] chore(dcellar-web-ui): remove redundant comments --- .../src/modules/bucket/components/CreateBucketOperation.tsx | 2 -- .../extract-translation/src/transformer/Extractor.js | 1 - 2 files changed, 3 deletions(-) diff --git a/apps/dcellar-web-ui/src/modules/bucket/components/CreateBucketOperation.tsx b/apps/dcellar-web-ui/src/modules/bucket/components/CreateBucketOperation.tsx index f5040614..6be3a19d 100644 --- a/apps/dcellar-web-ui/src/modules/bucket/components/CreateBucketOperation.tsx +++ b/apps/dcellar-web-ui/src/modules/bucket/components/CreateBucketOperation.tsx @@ -234,12 +234,10 @@ export const CreateBucketOperation = memo(function C const msgCreateBucket: MsgCreateBucket = { creator: loginAccount, bucketName, - // done TODO visibility check done visibility: VisibilityType.VISIBILITY_TYPE_PUBLIC_READ, paymentAddress: loginAccount, primarySpAddress: sp.operatorAddress, - //done TODO chargedReadQuota check chargedReadQuota: Long.fromNumber(chargeQuota * G_BYTES), }; const [simulateInfo, error] = await simulateCreateBucket(msgCreateBucket); diff --git a/common/autoinstallers/extract-translation/src/transformer/Extractor.js b/common/autoinstallers/extract-translation/src/transformer/Extractor.js index 94a23793..dc302ee3 100644 --- a/common/autoinstallers/extract-translation/src/transformer/Extractor.js +++ b/common/autoinstallers/extract-translation/src/transformer/Extractor.js @@ -18,7 +18,6 @@ class Extractor { this.localeFilePath = path.join(getCwd(), localeDir, `${devLang}.json`); } - // TODO Semantics _getNewLabelKey() { while (true) { const randomId = getRandomId(); From f759c7451fb80672504c451540bdfeb508c73d56 Mon Sep 17 00:00:00 2001 From: devinxl Date: Fri, 22 Mar 2024 15:36:45 +0800 Subject: [PATCH 3/3] fix(dcellar-web-ui): resolve visiblity issue during batch upload --- .../GlobalObjectUploadManager.tsx | 11 ++++++++--- apps/dcellar-web-ui/src/constants/legacy.ts | 3 --- .../modules/upload/UploadObjectsOperation.tsx | 16 +++++++--------- apps/dcellar-web-ui/src/utils/object/index.ts | 11 ----------- .../commitlint/src/commitlint.config.js | 18 ------------------ 5 files changed, 15 insertions(+), 44 deletions(-) diff --git a/apps/dcellar-web-ui/src/components/layout/GlobalManagements/GlobalObjectUploadManager.tsx b/apps/dcellar-web-ui/src/components/layout/GlobalManagements/GlobalObjectUploadManager.tsx index ae845be0..9ebee420 100644 --- a/apps/dcellar-web-ui/src/components/layout/GlobalManagements/GlobalObjectUploadManager.tsx +++ b/apps/dcellar-web-ui/src/components/layout/GlobalManagements/GlobalObjectUploadManager.tsx @@ -18,7 +18,6 @@ import { getSpOffChainData } from '@/store/slices/persist'; import { useAsyncEffect } from 'ahooks'; import { memo, useEffect, useMemo, useState } from 'react'; -import { reverseVisibilityType } from '@/constants/legacy'; import { useOffChainAuth } from '@/context/off-chain-auth/useOffChainAuth'; import { resolve } from '@/facade/common'; import { broadcastFault, commonFault, createTxFault, simulateFault } from '@/facade/error'; @@ -31,7 +30,13 @@ import { import { setupAccountRecords } from '@/store/slices/accounts'; import { setupSpMeta } from '@/store/slices/sp'; import { parseErrorXml, sleep } from '@/utils/common'; -import { AuthType, Long, RedundancyType, bytesFromBase64 } from '@bnb-chain/greenfield-js-sdk'; +import { + AuthType, + Long, + RedundancyType, + VisibilityType, + bytesFromBase64, +} from '@bnb-chain/greenfield-js-sdk'; import axios from 'axios'; import { isEmpty } from 'lodash-es'; import { MsgCreateObject } from '@bnb-chain/greenfield-cosmos-types/greenfield/storage/tx'; @@ -211,7 +216,7 @@ export const GlobalObjectUploadManager = memo( creator: tempAccount.address, bucketName: task.bucketName, objectName: finalName, - visibility: reverseVisibilityType[task.visibility], + visibility: task.visibility, contentType: task.waitObject.type || 'application/octet-stream', payloadSize: Long.fromInt(task.waitObject.size), expectChecksums: task.checksum.map((x) => bytesFromBase64(x)), diff --git a/apps/dcellar-web-ui/src/constants/legacy.ts b/apps/dcellar-web-ui/src/constants/legacy.ts index b408e62d..ba85bdc4 100644 --- a/apps/dcellar-web-ui/src/constants/legacy.ts +++ b/apps/dcellar-web-ui/src/constants/legacy.ts @@ -1,5 +1,4 @@ import { assetPrefix } from '@/base/env'; -import { convertVisibility } from '@/utils/object'; export const getLoginLocalStorageKey = (prefix = '') => `${prefix}_GREENFIELD_LOGIN_STORAGE`; @@ -7,8 +6,6 @@ export const USER_REJECT_STATUS_NUM = 4001; export const REQUEST_PENDING_NUM = -32002; -export const reverseVisibilityType = convertVisibility(); - export const GNFD_TESTNET = 5600; export const GNFD_MAINNET = 1017; diff --git a/apps/dcellar-web-ui/src/modules/upload/UploadObjectsOperation.tsx b/apps/dcellar-web-ui/src/modules/upload/UploadObjectsOperation.tsx index 5cb81277..972df6fd 100644 --- a/apps/dcellar-web-ui/src/modules/upload/UploadObjectsOperation.tsx +++ b/apps/dcellar-web-ui/src/modules/upload/UploadObjectsOperation.tsx @@ -39,7 +39,6 @@ import { DCButton } from '@/components/common/DCButton'; import { DotLoading } from '@/components/common/DotLoading'; import { getValidTags } from '@/components/common/ManageTags'; import { IconFont } from '@/components/IconFont'; -import { reverseVisibilityType } from '@/constants/legacy'; import { broadcastTx, resolve } from '@/facade/common'; import { E_FILE_IS_EMPTY, @@ -273,14 +272,7 @@ export const UploadObjectsOperation = memo( const finalName = [...pathSegments, waitObject.relativePath, waitObject.name] .filter((item) => !!item) .join('/'); - console.log( - 'reverseVisibilityType[visibility]', - reverseVisibilityType[visibility], - VisibilityType[visibility], - visibility, - ); const test1 = VisibilityType[visibility]; - console.log('a', test1); const msgCreateObject: MsgCreateObject = { creator: loginAccount, bucketName: currentBucketName, @@ -291,6 +283,7 @@ export const UploadObjectsOperation = memo( expectChecksums: expectCheckSums.map((x) => bytesFromBase64(x)), redundancyType: RedundancyType.REDUNDANCY_EC_TYPE, }; + console.log('msgCreateObject-single', msgCreateObject); const [createObjectTx, _createError] = await getCreateObjectTx(msgCreateObject).then( resolve, createTxFault, @@ -319,7 +312,12 @@ export const UploadObjectsOperation = memo( connector: connector!, }); if (!txRes || error) { - dispatch(setupWaitTaskErrorMsg({ id: waitObject.id, errorMsg: error ?? '' })); + dispatch( + setupWaitTaskErrorMsg({ + id: waitObject.id, + errorMsg: error ?? 'Something went wrong.', + }), + ); closeModal(); return; } diff --git a/apps/dcellar-web-ui/src/utils/object/index.ts b/apps/dcellar-web-ui/src/utils/object/index.ts index 69f9ceca..413e0bf1 100644 --- a/apps/dcellar-web-ui/src/utils/object/index.ts +++ b/apps/dcellar-web-ui/src/utils/object/index.ts @@ -9,17 +9,6 @@ export type TReverseVisibilityType = { const StringIsNumber = (value: string) => !isNaN(Number(value)); -export const convertVisibility = () => { - const reverseVisibilityType: any = {} as TReverseVisibilityType; - Object.keys(VisibilityType) - .filter(StringIsNumber) - .forEach((item: any) => { - reverseVisibilityType[item] = VisibilityType[item]; - }); - - return reverseVisibilityType; -}; - export const formatLockFee = (lockFee: string | undefined) => { return String(Number(lockFee || '') / Math.pow(10, 18)); }; diff --git a/common/autoinstallers/commitlint/src/commitlint.config.js b/common/autoinstallers/commitlint/src/commitlint.config.js index 4adda06b..015b4e79 100644 --- a/common/autoinstallers/commitlint/src/commitlint.config.js +++ b/common/autoinstallers/commitlint/src/commitlint.config.js @@ -4,23 +4,5 @@ module.exports = { extends: ["@commitlint/config-conventional"], rules: { "scope-enum": [2, "always", allPkgs], - "subject-empty": [2, "never"], - "type-case": [2, "always", "lower-case"], - "type-empty": [2, "never"], - "type-enum": [ - 2, - "always", - [ - "chore", - "docs", - "feat", - "fix", - "perf", - "refactor", - "revert", - "style", - "test", - ], - ], }, };