diff --git a/explorer/client/src/pages/object-result/ObjectResult.tsx b/explorer/client/src/pages/object-result/ObjectResult.tsx index c87a3aea876c6..367c09f53fc64 100644 --- a/explorer/client/src/pages/object-result/ObjectResult.tsx +++ b/explorer/client/src/pages/object-result/ObjectResult.tsx @@ -1,12 +1,7 @@ // Copyright (c) 2022, Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -import { - getObjectId, - getTransactions, - getTransactionSender, - getMoveCallTransaction, -} from '@mysten/sui.js'; +import { getTransactionSender } from '@mysten/sui.js'; import * as Sentry from '@sentry/react'; import React, { useEffect, useState, useContext } from 'react'; import { useLocation, useParams } from 'react-router-dom'; @@ -47,53 +42,38 @@ const Fail = ({ objID }: { objID: string | undefined }): JSX.Element => { ); }; -// Get the data for the object ID and either: -// address that publishes a Package or -// module and package associated with token +// Get the data for the object ID and address that publishes a Package: function getObjectDataWithPackageAddress(objID: string, network: string) { return rpc(network) .getObject(objID as string) .then((objState) => { const resp: DataType = translate(objState) as DataType; - if (resp.data.tx_digest) { + + const GENESIS_TX_DIGEST = + 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA='; + + if ( + resp.data.tx_digest && + resp.data.tx_digest === GENESIS_TX_DIGEST + ) { + return { + ...resp, + publisherAddress: 'Genesis', + }; + } + + if (resp.objType === 'Move Package' && resp.data.tx_digest) { return rpc(network) .getTransactionWithEffects(resp.data.tx_digest) - .then((txEff) => { - if (resp.objType === 'Move Package') { - // If Package, then extract publisher address - return { - ...resp, - publisherAddress: getTransactionSender( - txEff.certificate - ), - }; - } else { - // If Token, then extract the module and package - const movecall = getMoveCallTransaction( - getTransactions(txEff.certificate)[0] - ); - if (!movecall) return resp; - return { - ...resp, - module: movecall.module, - package: getObjectId(movecall.package), - }; - } - }) + .then((txEff) => ({ + ...resp, + publisherAddress: getTransactionSender( + txEff.certificate + ), + })) .catch((err) => { console.log(err); - // TODO: Not sure if I should show Genesis as Package Publisher or ignore it - - if (resp.objType === 'Move Package') { - return { - ...(resp.owner === 'Immutable' - ? { publisherAddress: 'Genesis' } - : {}), - ...resp, - }; - } else { - return resp; - } + return resp; }); } return resp; diff --git a/explorer/client/src/pages/object-result/ObjectResultType.tsx b/explorer/client/src/pages/object-result/ObjectResultType.tsx index f05525a55594a..1fe48af2ee677 100644 --- a/explorer/client/src/pages/object-result/ObjectResultType.tsx +++ b/explorer/client/src/pages/object-result/ObjectResultType.tsx @@ -25,8 +25,6 @@ export type DataType = { ethAddress?: string; ethTokenId?: string; publisherAddress?: string; - module?: string; - package?: string; contract_id?: { bytes: string }; data: { contents: { diff --git a/explorer/client/src/pages/object-result/views/TokenView.tsx b/explorer/client/src/pages/object-result/views/TokenView.tsx index a688fccc0f19b..248da3d70e33e 100644 --- a/explorer/client/src/pages/object-result/views/TokenView.tsx +++ b/explorer/client/src/pages/object-result/views/TokenView.tsx @@ -16,14 +16,18 @@ import { checkIsPropertyType, extractName, } from '../../../utils/objectUtils'; -import { trimStdLibPrefix, genFileTypeMsg } from '../../../utils/stringUtils'; +import { + trimStdLibPrefix, + genFileTypeMsg, + normalizeSuiAddress, +} from '../../../utils/stringUtils'; import { type DataType } from '../ObjectResultType'; import styles from './ObjectView.module.css'; function TokenView({ data }: { data: DataType }) { const viewedData = { ...data, - objType: trimStdLibPrefix(data.objType), + objType: data.objType, tx_digest: data.data.tx_digest, owner: getOwnerStr(data.owner), url: parseImageURL(data.data.contents), @@ -65,7 +69,11 @@ function TokenView({ data }: { data: DataType }) { setImageFullScreen(true); }, []); - const href = `/objects/${viewedData.package}?module=${viewedData.module}`; + const genhref = (objType: string) => { + const metadataarr = objType.split('::'); + const address = normalizeSuiAddress(metadataarr[0]); + return `/objects/${address}?module=${metadataarr[1]}`; + }; return (
@@ -76,22 +84,14 @@ function TokenView({ data }: { data: DataType }) { Type - {viewedData.package && viewedData.module ? ( - - - {trimStdLibPrefix( - viewedData.objType - )} - - - ) : ( - + + {trimStdLibPrefix(viewedData.objType)} - - )} + + Object ID