From 9746a53e4a34e699e23b961e47a0c046ef86f845 Mon Sep 17 00:00:00 2001 From: Stella Cannefax Date: Tue, 21 Jun 2022 10:30:16 -0500 Subject: [PATCH] Explorer demo cleanup (#2367) * remove special demo name handling * remove more number[] handling in explorer * lint changes * replace old AddressOwner code * lint changes * fix mock data for new object owner * lint changes * Update ObjectResultType.tsx * move isOwnerStr function * lint changes * add SingleOwner * lint changes * remove anyvec and old comment * add singleowner to TS sdk types * remove redundant typedef in getOwnerStr * lint changes * Update DefaultRpcClient.ts * Update index.guard.ts --- .../src/components/displaybox/DisplayBox.tsx | 6 +- .../components/ownedobjects/OwnedObjects.tsx | 4 +- .../src/pages/object-result/ObjectLoaded.tsx | 148 ++---------------- .../src/pages/object-result/ObjectResult.tsx | 2 +- .../pages/object-result/ObjectResultType.tsx | 17 +- .../client/src/utils/api/DefaultRpcClient.ts | 13 +- explorer/client/src/utils/objectUtils.ts | 15 +- .../client/src/utils/static/mock_data.json | 94 ++++++----- explorer/client/src/utils/stringUtils.ts | 14 +- sdk/typescript/src/index.guard.ts | 4 + sdk/typescript/src/types/common.ts | 1 + 11 files changed, 102 insertions(+), 216 deletions(-) diff --git a/explorer/client/src/components/displaybox/DisplayBox.tsx b/explorer/client/src/components/displaybox/DisplayBox.tsx index 2d4a615d9a9ed..c45222a000af2 100644 --- a/explorer/client/src/components/displaybox/DisplayBox.tsx +++ b/explorer/client/src/components/displaybox/DisplayBox.tsx @@ -3,11 +3,11 @@ import { useState, useCallback, useEffect } from 'react'; -import { processDisplayValue } from '../../utils/stringUtils'; +import { transformURL } from '../../utils/stringUtils'; import styles from './DisplayBox.module.css'; -function DisplayBox({ display }: { display: string | { bytes: number[] } }) { +function DisplayBox({ display }: { display: string }) { const [hasDisplayLoaded, setHasDisplayLoaded] = useState(false); const [hasFailedToLoad, setHasFailedToLoad] = useState(false); @@ -47,7 +47,7 @@ function DisplayBox({ display }: { display: string | { bytes: number[] } }) { className={styles.imagebox} style={imageStyle} alt="NFT" - src={processDisplayValue(display)} + src={transformURL(display)} onLoad={handleImageLoad} onError={handleImageFail} /> diff --git a/explorer/client/src/components/ownedobjects/OwnedObjects.tsx b/explorer/client/src/components/ownedobjects/OwnedObjects.tsx index 3783cabd32f4c..d849398628b02 100644 --- a/explorer/client/src/components/ownedobjects/OwnedObjects.tsx +++ b/explorer/client/src/components/ownedobjects/OwnedObjects.tsx @@ -23,7 +23,7 @@ import { } from '../../utils/static/searchUtil'; import { handleCoinType, - processDisplayValue, + transformURL, trimStdLibPrefix, } from '../../utils/stringUtils'; import DisplayBox from '../displaybox/DisplayBox'; @@ -137,7 +137,7 @@ function OwnedObjectAPI({ id, byAddress }: { id: string; byAddress: boolean }) { Type: objType, _isCoin: Coin.isCoin(resp), display: url - ? processDisplayValue(url) + ? transformURL(url) : undefined, balance: balanceValue, }; diff --git a/explorer/client/src/pages/object-result/ObjectLoaded.tsx b/explorer/client/src/pages/object-result/ObjectLoaded.tsx index fdb88c5154412..79f81d4cd1a61 100644 --- a/explorer/client/src/pages/object-result/ObjectLoaded.tsx +++ b/explorer/client/src/pages/object-result/ObjectLoaded.tsx @@ -9,12 +9,8 @@ import OwnedObjects from '../../components/ownedobjects/OwnedObjects'; import TxForID from '../../components/transactions-for-id/TxForID'; import codestyle from '../../styles/bytecode.module.css'; import theme from '../../styles/theme.module.css'; -import { type AddressOwner } from '../../utils/api/DefaultRpcClient'; -import { parseImageURL } from '../../utils/objectUtils'; -import { - asciiFromNumberBytes, - trimStdLibPrefix, -} from '../../utils/stringUtils'; +import { getOwnerStr, parseImageURL } from '../../utils/objectUtils'; +import { trimStdLibPrefix } from '../../utils/stringUtils'; import { type DataType } from './ObjectResultType'; import styles from './ObjectResult.module.css'; @@ -55,142 +51,25 @@ function ObjectLoaded({ data }: { data: DataType }) { const checkIsPropertyType = (value: any) => ['number', 'string'].includes(typeof value); - //TODO - a backend convention on how owned objects are labelled and how values are stored - //This would facilitate refactoring the below and stopping bugs when a variant is missed: - const addrOwnerPattern = /^AddressOwner\(k#/; - const endParensPattern = /\){1}$/; - - //TODO - improve move code handling: - // const isMoveVecType = (value: { vec?: [] }) => Array.isArray(value?.vec); - // TODO - merge / replace with other version of same thing const stdLibRe = /0x2::/; const prepObjTypeValue = (typeString: string) => typeString.replace(stdLibRe, ''); - const extractOwnerData = (owner: string | AddressOwner): string => { - switch (typeof owner) { - case 'string': - if (addrOwnerPattern.test(owner)) { - let ownerId = getAddressOwnerId(owner); - return ownerId ? ownerId : ''; - } - const singleOwnerPattern = /SingleOwner\(k#(.*)\)/; - const result = singleOwnerPattern.exec(owner); - return result ? result[1] : ''; - case 'object': - if ('AddressOwner' in owner) { - let ownerId = extractAddressOwner(owner.AddressOwner); - return ownerId ? ownerId : ''; - } - return ''; - default: - return ''; - } - }; - const getAddressOwnerId = (addrOwner: string): string | null => { - if ( - !addrOwnerPattern.test(addrOwner) || - !endParensPattern.test(addrOwner) - ) - return null; - - let str = addrOwner.replace(addrOwnerPattern, ''); - return str.replace(endParensPattern, ''); - }; - - const extractAddressOwner = (addrOwner: number[]): string | null => { - if (addrOwner.length !== 20) { - console.log('address owner byte length must be 20'); - return null; - } - - return asciiFromNumberBytes(addrOwner); - }; - type SuiIdBytes = { bytes: number[] }; - - function handleSpecialDemoNameArrays(data: { - name?: string; - player_name?: SuiIdBytes | string; - monster_name?: SuiIdBytes | string; - farm_name?: SuiIdBytes | string; - }): string { - let bytesObj: SuiIdBytes = { bytes: [] }; - - if ('player_name' in data) { - bytesObj = data.player_name as SuiIdBytes; - const ascii = asciiFromNumberBytes(bytesObj.bytes); - delete data.player_name; - return ascii; - } else if ('monster_name' in data) { - bytesObj = data.monster_name as SuiIdBytes; - const ascii = asciiFromNumberBytes(bytesObj.bytes); - delete data.monster_name; - return ascii; - } else if ('farm_name' in data) { - bytesObj = data.farm_name as SuiIdBytes; - const ascii = asciiFromNumberBytes(bytesObj.bytes); - delete data.farm_name; - return ascii; - } else if ('name' in data) { - return data['name'] as string; - } else { - bytesObj = { bytes: [] }; - } - - return asciiFromNumberBytes(bytesObj.bytes); - } - - function toHexString(byteArray: number[]): string { - return ( - '0x' + - Array.prototype.map - .call(byteArray, (byte) => { - return ('0' + (byte & 0xff).toString(16)).slice(-2); - }) - .join('') - ); - } - - function processName(name: string | undefined) { - // hardcode a friendly name for gas for now - const gasTokenTypeStr = 'Coin::Coin<0x2::GAS::GAS>'; - const gasTokenId = '0000000000000000000000000000000000000003'; - if (data.objType === gasTokenTypeStr && data.id === gasTokenId) - return 'GAS'; - - if (!name) { - return handleSpecialDemoNameArrays(data.data.contents); - } - } - - function processOwner(owner: any) { - if (typeof owner === 'object' && 'AddressOwner' in owner) { - return toHexString(owner.AddressOwner); - } - - return owner; - } - const viewedData = { ...data, objType: trimStdLibPrefix(data.objType), - name: processName(data.name), - tx_digest: - data.data.tx_digest && typeof data.data.tx_digest === 'object' - ? toHexString(data.data.tx_digest as number[]) - : data.data.tx_digest, - owner: processOwner(data.owner), + name: data.name, + tx_digest: data.data.tx_digest, + owner: getOwnerStr(data.owner), url: parseImageURL(data.data.contents), }; - //TO DO remove when have distinct name field under Description const nameKeyValue = Object.entries(viewedData.data?.contents) - .filter(([key, _]) => /name/i.test(key)) + .filter(([key, _]) => key === 'name') .map(([_, value]) => value); const properties = Object.entries(viewedData.data?.contents) - //TO DO: remove when have distinct 'name' field in Description - .filter(([key, _]) => !/name/i.test(key)) + .filter(([key, _]) => key !== 'name') .filter(([_, value]) => checkIsPropertyType(value)); const descriptionTitle = @@ -288,14 +167,17 @@ function ObjectLoaded({ data }: { data: DataType }) {
Owner
diff --git a/explorer/client/src/pages/object-result/ObjectResult.tsx b/explorer/client/src/pages/object-result/ObjectResult.tsx index 7ad7159c3272a..3b0e4eeed5dc5 100644 --- a/explorer/client/src/pages/object-result/ObjectResult.tsx +++ b/explorer/client/src/pages/object-result/ObjectResult.tsx @@ -19,7 +19,7 @@ import { const DATATYPE_DEFAULT: DataType = { id: '', category: '', - owner: '', + owner: 'Immutable', version: '', objType: '', data: { diff --git a/explorer/client/src/pages/object-result/ObjectResultType.tsx b/explorer/client/src/pages/object-result/ObjectResultType.tsx index 99b6967737c2c..f7dd6521efef9 100644 --- a/explorer/client/src/pages/object-result/ObjectResultType.tsx +++ b/explorer/client/src/pages/object-result/ObjectResultType.tsx @@ -10,7 +10,6 @@ import { getObjectPreviousTransactionDigest, } from '@mysten/sui.js'; -import { type AddressOwner } from '../../utils/api/DefaultRpcClient'; import { parseObjectType } from '../../utils/objectUtils'; import type { GetObjectDataResponse, ObjectOwner } from '@mysten/sui.js'; @@ -18,7 +17,7 @@ import type { GetObjectDataResponse, ObjectOwner } from '@mysten/sui.js'; export type DataType = { id: string; category?: string; - owner: string | AddressOwner; + owner: ObjectOwner | { SingleOwner: string }; version: string; readonly?: string; objType: string; @@ -52,7 +51,7 @@ export function translate(o: GetObjectDataResponse): DataType { id: getObjectId(o), version: getObjectVersion(o)!.toString(), objType: parseObjectType(o), - owner: parseOwner(getObjectOwner(o)!), + owner: getObjectOwner(o)!, data: { contents: getObjectFields(o) ?? getMovePackageContent(o)!, tx_digest: getObjectPreviousTransactionDigest(o), @@ -76,15 +75,3 @@ export function translate(o: GetObjectDataResponse): DataType { } } } - -function parseOwner(owner: ObjectOwner): string { - let result = ''; - if (typeof owner === 'string') { - result = owner; - } else if ('AddressOwner' in owner) { - result = owner['AddressOwner']; - } else { - result = owner['ObjectOwner']; - } - return `SingleOwner(k#${result})`; -} diff --git a/explorer/client/src/utils/api/DefaultRpcClient.ts b/explorer/client/src/utils/api/DefaultRpcClient.ts index ea8f2ae969919..188eea58de962 100644 --- a/explorer/client/src/utils/api/DefaultRpcClient.ts +++ b/explorer/client/src/utils/api/DefaultRpcClient.ts @@ -15,18 +15,11 @@ import { deduplicate } from '../searchUtil'; import { getEndpoint, Network } from './rpcSetting'; import type { - CertifiedTransaction, - TransactionEffectsResponse, GetTxnDigestsResponse, + TransactionEffectsResponse, + CertifiedTransaction, } from '@mysten/sui.js'; -// TODO: Remove these types with SDK types -export type AddressBytes = number[]; -export type AddressOwner = { AddressOwner: AddressBytes }; - -export type AnyVec = { vec: any[] }; -export type JsonBytes = { bytes: number[] }; - export { Network, getEndpoint }; export const DefaultRpcClient = (network: Network | string) => @@ -41,7 +34,7 @@ export const getDataOnTxDigests = ( .then((txEffs: TransactionEffectsResponse[]) => { return ( txEffs - .map((txEff, i) => { + .map((txEff) => { const [seq, digest] = transactions.filter( (transactionId) => transactionId[1] === diff --git a/explorer/client/src/utils/objectUtils.ts b/explorer/client/src/utils/objectUtils.ts index 015067b6b5c42..78ca65435d8f3 100644 --- a/explorer/client/src/utils/objectUtils.ts +++ b/explorer/client/src/utils/objectUtils.ts @@ -1,7 +1,11 @@ // Copyright (c) 2022, Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -import { getObjectType, getMoveObjectType } from '@mysten/sui.js'; +import { + getObjectType, + getMoveObjectType, + type ObjectOwner, +} from '@mysten/sui.js'; import type { GetObjectDataResponse } from '@mysten/sui.js'; @@ -26,3 +30,12 @@ export function parseObjectType(data: GetObjectDataResponse): string { } return 'unknown'; } + +export function getOwnerStr(owner: ObjectOwner | string): string { + if (typeof owner === 'object') { + if ('AddressOwner' in owner) return owner.AddressOwner; + if ('ObjectOwner' in owner) return owner.ObjectOwner; + if ('SingleOwner' in owner) return owner.SingleOwner; + } + return owner; +} diff --git a/explorer/client/src/utils/static/mock_data.json b/explorer/client/src/utils/static/mock_data.json index 56cbf013aab2d..457348db61e75 100644 --- a/explorer/client/src/utils/static/mock_data.json +++ b/explorer/client/src/utils/static/mock_data.json @@ -2,7 +2,7 @@ "data": [ { "id": "player1", - "owner": "SingleOwner(k#receiverAddress)", + "owner": { "SingleOwner": "receiverAddress" }, "category": "object", "version": "6", "readonly": "false", @@ -26,7 +26,7 @@ }, { "id": "player2", - "owner": "SingleOwner(k#receiverAddress)", + "owner": { "SingleOwner": "receiverAddress" }, "category": "object", "version": "5", "readonly": "false", @@ -58,7 +58,7 @@ }, { "id": "player0", - "owner": "SingleOwner(k#)", + "owner": { "SingleOwner": "" }, "category": "object", "version": "100", "readonly": "false", @@ -80,7 +80,7 @@ }, { "id": "player3", - "owner": "SingleOwner(k#)", + "owner": { "SingleOwner": "" }, "category": "object", "version": "100", "readonly": "false", @@ -102,7 +102,7 @@ }, { "id": "player4", - "owner": "SingleOwner(k#)", + "owner": { "SingleOwner": "" }, "category": "object", "version": "100", "readonly": "false", @@ -124,7 +124,7 @@ }, { "id": "player5", - "owner": "SingleOwner(k#)", + "owner": { "SingleOwner": "" }, "category": "object", "version": "100", "readonly": "false", @@ -146,7 +146,7 @@ }, { "id": "player6", - "owner": "SingleOwner(k#)", + "owner": { "SingleOwner": "" }, "category": "object", "version": "100", "readonly": "false", @@ -168,7 +168,7 @@ }, { "id": "player7", - "owner": "SingleOwner(k#)", + "owner": { "SingleOwner": "" }, "category": "object", "version": "100", "readonly": "false", @@ -190,7 +190,7 @@ }, { "id": "player8", - "owner": "SingleOwner(k#)", + "owner": { "SingleOwner": "" }, "category": "object", "version": "100", "readonly": "false", @@ -212,7 +212,7 @@ }, { "id": "player9", - "owner": "SingleOwner(k#)", + "owner": { "SingleOwner": "" }, "category": "object", "version": "100", "readonly": "false", @@ -234,7 +234,7 @@ }, { "id": "playerA1", - "owner": "SingleOwner(k#)", + "owner": { "SingleOwner": "" }, "category": "object", "version": "100", "readonly": "false", @@ -258,7 +258,7 @@ { "id": "Image1", "category": "object", - "owner": "SingleOwner(k#player2)", + "owner": { "SingleOwner": "player2" }, "version": "1", "readonly": "true", "objType": "0x2::Cosmetic::Plant", @@ -278,7 +278,7 @@ { "id": "Image2", "category": "object", - "owner": "SingleOwner(k#CollectionObject)", + "owner": { "SingleOwner": "CollectionObject" }, "version": "1", "readonly": "true", "objType": "0x2::Cosmetic::Plant", @@ -298,7 +298,7 @@ { "id": "Image3", "category": "object", - "owner": "SingleOwner(k#CollectionObject)", + "owner": { "SingleOwner": "CollectionObject" }, "version": "1", "readonly": "true", "objType": "0x2::Cosmetic::Plant", @@ -318,7 +318,7 @@ { "id": "Image4", "category": "object", - "owner": "SingleOwner(k#CollectionObject)", + "owner": { "SingleOwner": "CollectionObject" }, "version": "1", "readonly": "true", "objType": "0x2::Cosmetic::Plant", @@ -338,7 +338,7 @@ { "id": "Image5", "category": "object", - "owner": "SingleOwner(k#CollectionObject)", + "owner": { "SingleOwner": "CollectionObject" }, "version": "1", "readonly": "true", "objType": "0x2::Cosmetic::Plant", @@ -358,7 +358,7 @@ { "id": "Image6", "category": "object", - "owner": "SingleOwner(k#CollectionObject)", + "owner": { "SingleOwner": "CollectionObject" }, "version": "1", "readonly": "true", "objType": "0x2::Cosmetic::Plant", @@ -378,7 +378,7 @@ { "id": "Image7", "category": "object", - "owner": "SingleOwner(k#CollectionObject)", + "owner": { "SingleOwner": "CollectionObject" }, "version": "1", "readonly": "true", "objType": "0x2::Cosmetic::Plant", @@ -398,7 +398,7 @@ { "id": "Image8", "category": "object", - "owner": "SingleOwner(k#CollectionObject)", + "owner": { "SingleOwner": "CollectionObject" }, "version": "1", "readonly": "true", "objType": "0x2::Cosmetic::Plant", @@ -419,7 +419,7 @@ { "id": "standaloneObject", "category": "object", - "owner": "SingleOwner(k#player2)", + "owner": { "SingleOwner": "player2" }, "version": "87", "readonly": "true", "objType": "0x2::coin::Coin<0x2::USD::USD>", @@ -434,7 +434,7 @@ { "id": "standaloneObject2", "category": "object", - "owner": "SingleOwner(k#player2)", + "owner": { "SingleOwner": "player2" }, "version": "87", "readonly": "true", "objType": "0x2::coin::Coin<0x2::USD::USD>", @@ -448,7 +448,7 @@ { "id": "standaloneObjectSUI50", "category": "object", - "owner": "SingleOwner(k#player2)", + "owner": { "SingleOwner": "player2" }, "version": "87", "readonly": "true", "objType": "0x2::coin::Coin<0x2::sui::SUI>", @@ -462,7 +462,7 @@ { "id": "standaloneObjectSUI150", "category": "object", - "owner": "SingleOwner(k#player2)", + "owner": { "SingleOwner": "player2" }, "version": "87", "readonly": "true", "objType": "0x2::coin::Coin<0x2::sui::SUI>", @@ -481,7 +481,7 @@ { "id": "CollectionObject", "category": "object", - "owner": "SingleOwner(k#player2)", + "owner": { "SingleOwner": "player2" }, "version": "2", "readonly": "false", "objType": "0x2::MystenUniverse::Collection", @@ -503,7 +503,7 @@ { "id": "ComponentObject", "category": "object", - "owner": "SingleOwner(k#CollectionObject)", + "owner": { "SingleOwner": "CollectionObject" }, "version": "1", "readonly": "true", "objType": "0x2::Cosmetic::Plant", @@ -523,7 +523,7 @@ { "id": "ObjectThatOwns", "category": "object", - "owner": "SingleOwner(k#CollectionObject)", + "owner": { "SingleOwner": "CollectionObject" }, "version": "1", "readonly": "true", "objType": "0x2::Cosmetic::Plant", @@ -549,7 +549,7 @@ { "id": "ObjectWBrokenChild", "category": "object", - "owner": "SingleOwner(k#CollectionObject)", + "owner": { "SingleOwner": "CollectionObject" }, "version": "1", "readonly": "true", "objType": "0x2::Cosmetic::Plant", @@ -576,7 +576,7 @@ { "id": "ChildObjectWImage", "category": "object", - "owner": "SingleOwner(k#ObjectWBrokenChild)", + "owner": { "SingleOwner": "ObjectWBrokenChild" }, "version": "1", "readonly": "true", "objType": "0x2::Cosmetic::Plant", @@ -592,7 +592,7 @@ { "id": "ChildObjectWBrokenImage", "category": "object", - "owner": "SingleOwner(k#ObjectWBrokenChild)", + "owner": { "SingleOwner": "ObjectWBrokenChild" }, "version": "1", "readonly": "true", "objType": "0x2::Cosmetic::Plant", @@ -608,7 +608,9 @@ { "id": "7bc832ec31709638cd8d9323e90edf332gff4389", "category": "object", - "owner": "SingleOwner(k#0xa5e6dbcf33730ace6ec8b400ff4788c1f150ff7e)", + "owner": { + "SingleOwner": "0xa5e6dbcf33730ace6ec8b400ff4788c1f150ff7e" + }, "version": "1", "objType": "0x2::SuiDrop::NFT", "name": "Bored Ape Yacht Club #8937", @@ -671,7 +673,9 @@ }, { "id": "8cd943fd42810749de9e0434f01feg443hgg54v1", - "owner": "SingleOwner(k#0xb6f7ecdg44841bdf7fd9c511gg5899d2g261gg8f)", + "owner": { + "SingleOwner": "0xb6f7ecdg44841bdf7fd9c511gg5899d2g261gg8f" + }, "category": "object", "version": "5", "readonly": "false", @@ -694,7 +698,9 @@ }, { "id": "8cd943fd42810749de9e0434f01feg443hgg54v2", - "owner": "SingleOwner(k#0xb6f7ecdg44841bdf7fd9c511gg5899d2g261gg8f)", + "owner": { + "SingleOwner": "0xb6f7ecdg44841bdf7fd9c511gg5899d2g261gg8f" + }, "category": "object", "version": "6", "readonly": "false", @@ -725,7 +731,9 @@ }, { "id": "3a4e674ce2810749de9e0434f01feg443hgg54v2", - "owner": "SingleOwner(k#8cd943fd42810749de9e0434f01feg443hgg54v2)", + "owner": { + "SingleOwner": "8cd943fd42810749de9e0434f01feg443hgg54v2" + }, "category": "object", "version": "1", "readonly": "true", @@ -741,7 +749,9 @@ { "id": "9de054ge53921850ef0f1545g12gfh554ihh65v1", - "owner": "SingleOwner(k#0xb6f7ecdg44841bdf7fd9c511gg5899d2g261gg8f)", + "owner": { + "SingleOwner": "0xb6f7ecdg44841bdf7fd9c511gg5899d2g261gg8f" + }, "category": "object", "version": "4", "readonly": "false", @@ -764,7 +774,9 @@ }, { "id": "9de054ge53921850ef0f1545g12gfh554ihh65v2", - "owner": "SingleOwner(k#0xb6f7ecdg44841bdf7fd9c511gg5899d2g261gg8f)", + "owner": { + "SingleOwner": "0xb6f7ecdg44841bdf7fd9c511gg5899d2g261gg8f" + }, "category": "object", "version": "5", "readonly": "false", @@ -794,7 +806,9 @@ }, { "id": "f4a5535e53921850ef0f1545g12gfh554ihh65v2", - "owner": "SingleOwner(k#9de054ge53921850ef0f1545g12gfh554ihh65v2)", + "owner": { + "SingleOwner": "9de054ge53921850ef0f1545g12gfh554ihh65v2" + }, "category": "object", "version": "1", "readonly": "true", @@ -810,7 +824,9 @@ { "id": "0ef165hf64032961fg1g2656h23hgi665jii7690", - "owner": "SingleOwner(k#0xb6f7ecdg44841bdf7fd9c511gg5899d2g261gg8f)", + "owner": { + "SingleOwner": "0xb6f7ecdg44841bdf7fd9c511gg5899d2g261gg8f" + }, "category": "object", "version": "7", "readonly": "false", @@ -841,7 +857,9 @@ }, { "id": "f14e489364032961fg1g2656h23hgi665jii7690", - "owner": "SingleOwner(k#0ef165hf64032961fg1g2656h23hgi665jii7690)", + "owner": { + "SingleOwner": "0ef165hf64032961fg1g2656h23hgi665jii7690" + }, "category": "object", "version": "1", "readonly": "true", diff --git a/explorer/client/src/utils/stringUtils.ts b/explorer/client/src/utils/stringUtils.ts index 41dc94b87cf07..951c29a01423d 100644 --- a/explorer/client/src/utils/stringUtils.ts +++ b/explorer/client/src/utils/stringUtils.ts @@ -1,10 +1,6 @@ // Copyright (c) 2022, Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -export function asciiFromNumberBytes(bytes: number[]) { - return bytes.map((n) => String.fromCharCode(n)).join(''); -} - export function hexToAscii(hex: string) { if (!hex || typeof hex != 'string') return; hex = hex.replace(/^0x/, ''); @@ -24,15 +20,7 @@ export const handleCoinType = (str: string): string => ? 'SUI' : str.match(/^([a-zA-Z0-9:]*)<([a-zA-Z0-9:]*)>$/)?.[2] || str; -export const processDisplayValue = (display: { bytes: number[] } | string) => { - const url = - typeof display === 'object' && 'bytes' in display - ? asciiFromNumberBytes(display.bytes) - : display; - return typeof url === 'string' ? transformURL(url) : url; -}; - -function transformURL(url: string) { +export function transformURL(url: string) { const found = url.match(/^ipfs:\/\/(.*)/); if (!found) { return url; diff --git a/sdk/typescript/src/index.guard.ts b/sdk/typescript/src/index.guard.ts index 4993ac197344a..43a3afa782ffa 100644 --- a/sdk/typescript/src/index.guard.ts +++ b/sdk/typescript/src/index.guard.ts @@ -171,6 +171,10 @@ export function isObjectOwner(obj: any, _argumentName?: string): obj is ObjectOw typeof obj === "object" || typeof obj === "function") && isTransactionDigest(obj.ObjectOwner) as boolean || + (obj !== null && + typeof obj === "object" || + typeof obj === "function") && + isTransactionDigest(obj.SingleOwner) as boolean || obj === "Shared" || obj === "Immutable") ) diff --git a/sdk/typescript/src/types/common.ts b/sdk/typescript/src/types/common.ts index 906f79c3cbd5b..12871ac109dad 100644 --- a/sdk/typescript/src/types/common.ts +++ b/sdk/typescript/src/types/common.ts @@ -9,6 +9,7 @@ export type SuiAddress = string; export type ObjectOwner = | { AddressOwner: SuiAddress } | { ObjectOwner: SuiAddress } + | { SingleOwner: SuiAddress } | 'Shared' | 'Immutable';