diff --git a/explorer/client/src/components/ownedobjects/OwnedObjects.tsx b/explorer/client/src/components/ownedobjects/OwnedObjects.tsx index 50d3f1aa0da6a..006250eac7afc 100644 --- a/explorer/client/src/components/ownedobjects/OwnedObjects.tsx +++ b/explorer/client/src/components/ownedobjects/OwnedObjects.tsx @@ -3,20 +3,26 @@ import React, { useCallback, useEffect, useState } from 'react'; import { useNavigate } from 'react-router-dom'; +import { getObjectExistsResponse } from 'sui.js'; -import { DefaultRpcClient as rpc } from '../../utils/api/SuiRpcClient'; +import { DefaultRpcClient as rpc } from '../../utils/api/DefaultRpcClient'; import { parseImageURL } from '../../utils/objectUtils'; import { navigateWithUnknown } from '../../utils/searchUtil'; -import { findDataFromID } from '../../utils/static/searchUtil'; -import { trimStdLibPrefix, processDisplayValue } from '../../utils/stringUtils'; +import { + findDataFromID, + findOwnedObjectsfromID, +} from '../../utils/static/searchUtil'; +import { processDisplayValue, trimStdLibPrefix } from '../../utils/stringUtils'; import DisplayBox from '../displaybox/DisplayBox'; +import type { ObjectRef } from 'sui.js'; + import styles from './OwnedObjects.module.css'; type resultType = { id: string; Type: string; - Version: string; + Version?: string; display?: string; }[]; @@ -24,8 +30,6 @@ const DATATYPE_DEFAULT: resultType = [ { id: '', Type: '', - Version: '', - display: '', }, ]; @@ -51,14 +55,22 @@ function OwnedObjectAPI({ objects }: { objects: string[] }) { Promise.all(objects.map((objID) => rpc.getObjectInfo(objID))).then( (results) => { setResults( - results.map(({ id, objType, version, data }) => ({ - id: id, - Type: objType, - Version: version, - display: parseImageURL(data) - ? processDisplayValue(parseImageURL(data)) - : undefined, - })) + results + .filter(({ status }) => status === 'Exists') + .map( + (resp) => { + const info = getObjectExistsResponse(resp)!; + const url = parseImageURL(info.object); + return { + id: info.objectRef.objectId, + Type: info.object.contents.type, + display: url + ? processDisplayValue(url) + : undefined, + }; + } + //TO DO - add back display and version + ) ); setIsLoaded(true); } @@ -139,7 +151,38 @@ function OwnedObjectView({ results }: { results: resultType }) { ); } -function OwnedObject({ objects }: { objects: string[] }) { +function GetObjectsStatic({ id }: { id: string }) { + const objects = findOwnedObjectsfromID(id); + + if (objects !== undefined) { + return ( + objectId)} + /> + ); + } + + return
; +} + +function GetObjectsAPI({ id }: { id: string }) { + const [objects, setObjects] = useState([]); + useEffect(() => { + rpc.getOwnedObjectRefs(id).then((objects) => setObjects(objects)); + }, [id]); + return ( + objectId)} /> + ); +} +function OwnedObject({ id }: { id: string }) { + if (process.env.REACT_APP_DATA === 'static') { + return ; + } else { + return ; + } +} + +function OwnedObjectSection({ objects }: { objects: string[] }) { const [pageIndex, setPageIndex] = useState(0); const ITEMS_PER_PAGE = 12; diff --git a/explorer/client/src/pages/address-result/AddressResult.tsx b/explorer/client/src/pages/address-result/AddressResult.tsx index 2055f054c67f0..9f28a9fa66fec 100644 --- a/explorer/client/src/pages/address-result/AddressResult.tsx +++ b/explorer/client/src/pages/address-result/AddressResult.tsx @@ -1,14 +1,12 @@ // Copyright (c) 2022, Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -import { useEffect, useState } from 'react'; -import { useLocation, useParams } from 'react-router-dom'; +import { useParams } from 'react-router-dom'; import ErrorResult from '../../components/error-result/ErrorResult'; import Longtext from '../../components/longtext/Longtext'; import OwnedObjects from '../../components/ownedobjects/OwnedObjects'; import theme from '../../styles/theme.module.css'; -import { DefaultRpcClient as rpc } from '../../utils/api/SuiRpcClient'; type DataType = { id: string; @@ -24,124 +22,30 @@ function instanceOfDataType(object: any): object is DataType { return object !== undefined && ['id', 'objects'].every((x) => x in object); } -function instanceOfResponseType(input: any): input is ResponseType { - return input && input.length > 0 && input[0].objectId; -} +function AddressResult() { + const { id: addressID } = useParams(); -function Loaded({ data }: { data: DataType }) { - return ( -
-
-
Address ID
-
- -
-
-
-
Owned Objects
+ if (addressID !== undefined) { + return ( +
- { - objectId - )} +
Address ID
+
+ - } +
+
+
+
Owned Objects
+
{}
-
- ); -} - -function Pending() { - return
Please wait for results to load
; -} - -function Fail({ id }: { id: string | undefined }) { - return ( - - ); -} - -function AddressResultStatic({ addressID }: { addressID: string | undefined }) { - const { findDataFromID } = require('../../utils/static/searchUtil'); - const data = findDataFromID(addressID, undefined); - - if (instanceOfDataType(data) && instanceOfResponseType(data.objects)) { - return ; - } else { - return ; - } -} - -function AddressResultAPI({ addressID }: { addressID: string | undefined }) { - const defaultData = (addressID: string | undefined) => ({ - id: addressID, - objects: [{}], - loadState: 'pending', - }); - const [data, setData] = useState(defaultData(addressID)); - - useEffect(() => { - if (addressID === undefined) return; - - rpc.getAddressObjects(addressID as string) - .then((json) => { - setData({ - id: addressID, - objects: json, - loadState: 'loaded', - }); - }) - .catch((error) => { - console.log(error); - setData({ ...defaultData(addressID), loadState: 'fail' }); - }); - }, [addressID]); - - if ( - instanceOfDataType(data) && - instanceOfResponseType(data.objects) && - data.loadState === 'loaded' - ) { - return ; - } - - if (data.loadState === 'pending') { - return ; - } - - return ; -} - -function AddressResult() { - const { id: addressID } = useParams(); - const { state } = useLocation(); - - if (instanceOfResponseType(state)) { - const stringid = addressID === undefined ? '' : addressID; - return ( - ); - } - - if (process.env.REACT_APP_DATA !== 'static') { - return ; } else { - return ; + return ; } } diff --git a/explorer/client/src/pages/object-result/ObjectLoaded.tsx b/explorer/client/src/pages/object-result/ObjectLoaded.tsx index b105e92106c41..0f4e5057cb2e8 100644 --- a/explorer/client/src/pages/object-result/ObjectLoaded.tsx +++ b/explorer/client/src/pages/object-result/ObjectLoaded.tsx @@ -364,7 +364,7 @@ function ObjectLoaded({ data }: { data: DataType }) { key={`ConnectedEntity-${index1}`} >
{prepLabel(key)}
- +
) )} diff --git a/explorer/client/src/utils/api/searchUtil.ts b/explorer/client/src/utils/api/searchUtil.ts index f478fc0d545ef..11c9c2458bd55 100644 --- a/explorer/client/src/utils/api/searchUtil.ts +++ b/explorer/client/src/utils/api/searchUtil.ts @@ -2,14 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 import { DefaultRpcClient as rpc } from './DefaultRpcClient'; -import { DefaultRpcClient as legacyAPI } from './SuiRpcClient'; export const navigateWithUnknown = async ( input: string, navigate: Function ) => { - // TODO - replace multi-request search with backend function when ready - const addrPromise = legacyAPI.getAddressObjects(input).then((data) => { + const addrPromise = rpc.getOwnedObjectRefs(input).then((data) => { if (data.length <= 0) throw new Error('No objects for Address'); return { @@ -17,7 +15,6 @@ export const navigateWithUnknown = async ( data: data, }; }); - const objInfoPromise = rpc.getObjectInfo(input).then((data) => ({ category: 'objects', data: data, diff --git a/explorer/client/src/utils/static/owned_object.json b/explorer/client/src/utils/static/owned_object.json new file mode 100644 index 0000000000000..3227ddee6edc1 --- /dev/null +++ b/explorer/client/src/utils/static/owned_object.json @@ -0,0 +1,139 @@ +{ + "data": [ + { + "id": "ownsAllAddress", + "objects": [ + { + "objectId": "playerOne" + }, + { + "objectId": "7bc832ec31709638cd8d9323e90edf332gff4389" + }, + { + "objectId": "7bc832ec31709638cd8d9323e90edf332gff4389" + }, + { + "objectId": "ComponentObject" + }, + { + "objectId": "7bc832ec31709638cd8d9323e90edf332gff4389" + }, + { + "objectId": "7bc832ec31709638cd8d9323e90edf332gff4389" + }, + { + "objectId": "ComponentObject" + }, + { + "objectId": "ComponentObject" + }, + { + "objectId": "ComponentObject" + }, + { + "objectId": "ComponentObject" + }, + { + "objectId": "ComponentObject" + }, + { + "objectId": "ComponentObject" + }, + { + "objectId": "7bc832ec31709638cd8d9323e90edf332gff4389" + }, + { + "objectId": "playerTwo" + }, + { + "objectId": "CollectionObject" + }, + { + "objectId": "CollectionObject" + }, + { + "objectId": "CollectionObject" + }, + { + "objectId": "CollectionObject" + }, + { + "objectId": "CollectionObject" + }, + { + "objectId": "CollectionObject" + }, + { + "objectId": "CollectionObject" + }, + { + "objectId": "CollectionObject" + }, + { + "objectId": "7bc832ec31709638cd8d9323e90edf332gff4389" + }, + { + "objectId": "CollectionObject" + }, + { + "objectId": "standaloneObject" + }, + { + "objectId": "CollectionObject" + }, + { + "objectId": "CollectionObject" + } + ] + }, + { + "id": "CollectionObject", + "objects": [ + { + "objectId": "ComponentObject", + "version": 1 + } + ] + }, + { + "id": "playerTwo", + "objects": [ + { + "objectId": "standaloneObject", + "version": 1 + } + ] + }, + { + "id": "ObjectThatOwns", + "objects": [ + { + "objectId": "ChildObjectWImage", + "version": 1 + }, + { + "objectId": "ChildObjectWBrokenImage", + "version": 1 + } + ] + }, + + { + "id": "receiverAddress", + "objects": [ + { + "objectId": "playerOne", + "version": 6 + }, + { + "objectId": "playerTwo", + "version": 5 + } + ] + }, + { + "id": "senderAddress", + "objects": [] + } + ] +} diff --git a/explorer/client/src/utils/static/searchUtil.ts b/explorer/client/src/utils/static/searchUtil.ts index e86e27fa01df7..79fd49f18b3cd 100644 --- a/explorer/client/src/utils/static/searchUtil.ts +++ b/explorer/client/src/utils/static/searchUtil.ts @@ -1,7 +1,8 @@ // Copyright (c) 2022, Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -import mockTransactionData from './mock_data.json'; +import mockObjectData from './mock_data.json'; +import mockOwnedObjectData from './owned_object.json'; const navigateWithUnknown = async (input: string, navigate: Function) => { const data = findDataFromID(input, false); @@ -21,6 +22,9 @@ const navigateWithUnknown = async (input: string, navigate: Function) => { const findDataFromID = (targetID: string | undefined, state: any) => state?.category !== undefined ? state - : mockTransactionData.data.find(({ id }) => id === targetID); + : mockObjectData.data.find(({ id }) => id === targetID); -export { findDataFromID, navigateWithUnknown }; +const findOwnedObjectsfromID = (targetID: string | undefined) => + mockOwnedObjectData?.data?.find(({ id }) => id === targetID)?.objects; + +export { findDataFromID, navigateWithUnknown, findOwnedObjectsfromID };