Skip to content

Commit

Permalink
[Explorer] Clicking on the Object Type should go to the Address/Modul…
Browse files Browse the repository at this point in the history
…e associated with the Type string not the last transaction (#4521)

* switches ID of package and module to being extracted from the type string rather than from the last tx

* improves genesis handling
  • Loading branch information
apburnie authored Sep 8, 2022
1 parent 7093357 commit 5d346fd
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 64 deletions.
68 changes: 24 additions & 44 deletions explorer/client/src/pages/object-result/ObjectResult.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions explorer/client/src/pages/object-result/ObjectResultType.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ export type DataType = {
ethAddress?: string;
ethTokenId?: string;
publisherAddress?: string;
module?: string;
package?: string;
contract_id?: { bytes: string };
data: {
contents: {
Expand Down
36 changes: 18 additions & 18 deletions explorer/client/src/pages/object-result/views/TokenView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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 (
<div>
Expand All @@ -76,22 +84,14 @@ function TokenView({ data }: { data: DataType }) {
<tbody>
<tr>
<td>Type</td>
{viewedData.package && viewedData.module ? (
<td>
<Link
to={href}
className={styles.objecttypelink}
>
{trimStdLibPrefix(
viewedData.objType
)}
</Link>
</td>
) : (
<td>
<td>
<Link
to={genhref(viewedData.objType)}
className={styles.objecttypelink}
>
{trimStdLibPrefix(viewedData.objType)}
</td>
)}
</Link>
</td>
</tr>
<tr>
<td>Object ID</td>
Expand Down

0 comments on commit 5d346fd

Please sign in to comment.