Skip to content

Commit

Permalink
[explorer] Display Transactions for Object ID (MystenLabs#2485)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Li <[email protected]>
  • Loading branch information
apburnie and 666lcz authored Jun 16, 2022
1 parent e4f8c53 commit a388f68
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 83 deletions.
17 changes: 13 additions & 4 deletions explorer/client/src/__tests__/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,15 +403,24 @@ describe('End-to-end Tests', () => {
});
});
describe('Transactions for ID', () => {
it('are displayed deduplicated from and to', async () => {
const txResults =
'TxIdTxTypeStatusAddressesDa4vHc9IwbvOYblE8LnrVsqXwryt2Kmms+xnJ7Zx5E4=Transfer\u2714From:senderAddressTo:receiv...dressGHTP9gcFmF5KTspnz3KxXjvSH8Bx0jv68KFhdqfpdK8=Transfer\u2716From:senderAddressTo:receiv...dressXHTP9gcFmF5KTspnz3KxXjvSH8Bx0jv68KFhdqfpdK8=Transfer\u2714From:senderAddressTo:receiv...dress';

it('are displayed deduplicated from and to address', async () => {
const address = 'ownsAllAddress';
await page.goto(`${BASE_URL}/addresses/${address}`);
const fromResults = await cssInteract(page)
.with('#tx')
.get.textContent();
expect(fromResults.replace(/\s/g, '')).toBe(
'TxIdTxTypeStatusAddressesDa4vHc9IwbvOYblE8LnrVsqXwryt2Kmms+xnJ7Zx5E4=Transfer\u2714From:senderAddressTo:receiv...dressGHTP9gcFmF5KTspnz3KxXjvSH8Bx0jv68KFhdqfpdK8=Transfer\u2716From:senderAddressTo:receiv...dressXHTP9gcFmF5KTspnz3KxXjvSH8Bx0jv68KFhdqfpdK8=Transfer\u2714From:senderAddressTo:receiv...dress'
);
expect(fromResults.replace(/\s/g, '')).toBe(txResults);
});
it('are displayed deduplicated for input and mutated object', async () => {
const address = 'CollectionObject';
await page.goto(`${BASE_URL}/addresses/${address}`);
const fromResults = await cssInteract(page)
.with('#tx')
.get.textContent();
expect(fromResults.replace(/\s/g, '')).toBe(txResults);
});
});
});
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
.txresults {
@apply font-mono ml-[1vw] w-[100%];
}

.txheader {
@apply hidden bg-offblack text-offwhite py-2;
@apply hidden bg-offblack text-offwhite py-2 md:grid md:grid-cols-12;
}

.txheader,
.txrow {
@apply md:flex;
@apply md:grid md:grid-cols-12;
}

.txheader > div,
.txrow > div {
@apply md:ml-[2vw];
@apply break-all mx-[0.5vw];
}

.txid {
@apply md:w-[35vw];
@apply col-span-5;
}

.txtype {
@apply md:w-[10vw];
.txadd {
@apply col-span-3;
}

.txtype,
.txstatus {
@apply md:w-[5vw];
@apply col-span-2;
}

.txadd a {
Expand Down
120 changes: 63 additions & 57 deletions explorer/client/src/components/transactions-for-id/TxForID.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,76 +37,82 @@ type TxnData = {
To?: string;
};

type categoryType = 'address' | 'object';

const getTx = async (
id: string,
network: string,
category: 'address'
): Promise<GetTxnDigestsResponse> => rpc(network).getTransactionsForAddress(id);
category: categoryType
): Promise<GetTxnDigestsResponse> =>
category === 'address'
? rpc(network).getTransactionsForAddress(id)
: rpc(network).getTransactionsForObject(id);

function TxForIDView({ showData }: { showData: TxnData[] | undefined }) {
if (!showData || showData.length === 0) return <></>;

return (
<>
<div>
<div>Transactions</div>
<div id="tx">
<div className={styles.txheader}>
<div className={styles.txid}>TxId</div>
<div className={styles.txtype}>TxType</div>
<div className={styles.txstatus}>Status</div>
<div className={styles.txadd}>Addresses</div>
</div>
<div id="tx" className={styles.txresults}>
<div className={styles.txheader}>
<div className={styles.txid}>TxId</div>
<div className={styles.txtype}>TxType</div>
<div className={styles.txstatus}>Status</div>
<div className={styles.txadd}>Addresses</div>
</div>

{showData.map((x, index) => (
<div key={`txid-${index}`} className={styles.txrow}>
<div className={styles.txid}>
<Longtext
text={x.txId}
category="transactions"
isLink={true}
/>
</div>
<div className={styles.txtype}>{x.kind}</div>
<div
className={cl(
styles.txstatus,
styles[x.status.toLowerCase()]
)}
{showData.map((x, index) => (
<div key={`txid-${index}`} className={styles.txrow}>
<div className={styles.txid}>
<Longtext
text={x.txId}
category="transactions"
isLink={true}
/>
</div>
<div className={styles.txtype}>{x.kind}</div>
<div
className={cl(
styles.txstatus,
styles[x.status.toLowerCase()]
)}
>
{x.status === 'success' ? '\u2714' : '\u2716'}
</div>
<div className={styles.txadd}>
<div>
From:
<Link
className={styles.txlink}
to={'addresses/' + x.From}
>
{x.status === 'success' ? '\u2714' : '\u2716'}
</div>
<div className={styles.txadd}>
<div>
From:
<Link
className={styles.txlink}
to={'addresses/' + x.From}
>
{truncate(x.From, 14, '...')}
</Link>
</div>
{x.To && (
<div>
To :
<Link
className={styles.txlink}
to={'addresses/' + x.To}
>
{truncate(x.To, 14, '...')}
</Link>
</div>
)}
</div>
{truncate(x.From, 14, '...')}
</Link>
</div>
))}
{x.To && (
<div>
To :
<Link
className={styles.txlink}
to={'addresses/' + x.To}
>
{truncate(x.To, 14, '...')}
</Link>
</div>
)}
</div>
</div>
</div>
</>
))}
</div>
);
}

function TxForIDStatic({ id, category }: { id: string; category: 'address' }) {
function TxForIDStatic({
id,
category,
}: {
id: string;
category: categoryType;
}) {
const data = deduplicate(
findTxfromID(id)?.data as [number, string][] | undefined
)
Expand All @@ -116,7 +122,7 @@ function TxForIDStatic({ id, category }: { id: string; category: 'address' }) {
return <TxForIDView showData={data} />;
}

function TxForIDAPI({ id, category }: { id: string; category: 'address' }) {
function TxForIDAPI({ id, category }: { id: string; category: categoryType }) {
const [showData, setData] =
useState<{ data?: TxnData[]; loadState: string }>(DATATYPE_DEFAULT);
const [network] = useContext(NetworkContext);
Expand Down Expand Up @@ -173,7 +179,7 @@ export default function TxForID({
category,
}: {
id: string;
category: 'address';
category: categoryType;
}) {
return IS_STATIC_ENV ? (
<TxForIDStatic id={id} category={category} />
Expand Down
5 changes: 4 additions & 1 deletion explorer/client/src/pages/address-result/AddressResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ function AddressResult() {
{<OwnedObjects id={addressID} byAddress={true} />}
</div>
</div>
<TxForID id={addressID} category="address" />
<div>
<div>Transactions</div>
<TxForID id={addressID} category="address" />
</div>
</div>
);
} else {
Expand Down
19 changes: 17 additions & 2 deletions explorer/client/src/pages/object-result/ObjectLoaded.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useEffect, useState, useCallback } from 'react';
import DisplayBox from '../../components/displaybox/DisplayBox';
import Longtext from '../../components/longtext/Longtext';
import OwnedObjects from '../../components/ownedobjects/OwnedObjects';
import TxForID from '../../components/transactions-for-id/TxForID';
import theme from '../../styles/theme.module.css';
import { type AddressOwner } from '../../utils/api/DefaultRpcClient';
import { parseImageURL } from '../../utils/objectUtils';
Expand All @@ -22,12 +23,19 @@ function ObjectLoaded({ data }: { data: DataType }) {
const [showDescription, setShowDescription] = useState(true);
const [showProperties, setShowProperties] = useState(false);
const [showConnectedEntities, setShowConnectedEntities] = useState(false);
const [showTx, setShowTx] = useState(true);

useEffect(() => {
setShowDescription(true);
setShowProperties(true);
setShowConnectedEntities(true);
}, [setShowDescription, setShowProperties, setShowConnectedEntities]);
setShowTx(true);
}, [
setShowDescription,
setShowProperties,
setShowConnectedEntities,
setShowTx,
]);

const clickSetShowDescription = useCallback(
() => setShowDescription(!showDescription),
Expand All @@ -41,6 +49,7 @@ function ObjectLoaded({ data }: { data: DataType }) {
() => setShowConnectedEntities(!showConnectedEntities),
[showConnectedEntities]
);
const clickSetShowTx = useCallback(() => setShowTx(!showTx), [showTx]);
const prepLabel = (label: string) => label.split('_').join(' ');
const checkIsPropertyType = (value: any) =>
['number', 'string'].includes(typeof value);
Expand Down Expand Up @@ -243,7 +252,6 @@ function ObjectLoaded({ data }: { data: DataType }) {
</div>
</div>
)}

<div>
<div>Version</div>
<div>{data.version}</div>
Expand Down Expand Up @@ -380,6 +388,13 @@ function ObjectLoaded({ data }: { data: DataType }) {
data.objType !== 'Move Package' && (
<OwnedObjects id={data.id} byAddress={false} />
)}
<h2
className={styles.clickableheader}
onClick={clickSetShowTx}
>
Transactions {showTx ? '' : '+'}
</h2>
{showTx && <TxForID id={data.id} category="object" />}
</div>
</div>
</>
Expand Down
12 changes: 12 additions & 0 deletions explorer/client/src/utils/static/tx_for_id.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@
[3, "GHTP9gcFmF5KTspnz3KxXjvSH8Bx0jv68KFhdqfpdK8="],
[4, "XHTP9gcFmF5KTspnz3KxXjvSH8Bx0jv68KFhdqfpdK8="]
]
},
{
"id": "CollectionObject",
"data": [
[0, "Da4vHc9IwbvOYblE8LnrVsqXwryt2Kmms+xnJ7Zx5E4="],
[1, "Da4vHc9IwbvOYblE8LnrVsqXwryt2Kmms+xnJ7Zx5E4="],
[0, "GHTP9gcFmF5KTspnz3KxXjvSH8Bx0jv68KFhdqfpdK8="],
[1, "GHTP9gcFmF5KTspnz3KxXjvSH8Bx0jv68KFhdqfpdK8="],
[2, "Da4vHc9IwbvOYblE8LnrVsqXwryt2Kmms+xnJ7Zx5E4="],
[3, "GHTP9gcFmF5KTspnz3KxXjvSH8Bx0jv68KFhdqfpdK8="],
[4, "XHTP9gcFmF5KTspnz3KxXjvSH8Bx0jv68KFhdqfpdK8="]
]
}
]
}
Loading

0 comments on commit a388f68

Please sign in to comment.