forked from MystenLabs/sui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[explorer] Rebuild transactions for address and object (MystenLabs#9852)
## Description On object and address pages, the transaction table used a deprecated method and required calling multiGetTransactions to populate. This caused it to fail for big objects / transactions. Rewriting onto native queryTransactions. For now, this has the limitation of not being able to paginate, because we need to interleave two result sets. But once the API is updated to support this filter we can pretty easily change that. ## Test Plan Ran locally.
- Loading branch information
1 parent
d6f9aee
commit b1c8042
Showing
11 changed files
with
87 additions
and
225 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
apps/explorer/src/components/transactions/TransactionsForAddress.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { useRpcClient } from '@mysten/core'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
import { genTableDataFromTxData } from './TxCardUtils'; | ||
|
||
import { Banner } from '~/ui/Banner'; | ||
import { LoadingSpinner } from '~/ui/LoadingSpinner'; | ||
import { TableCard } from '~/ui/TableCard'; | ||
|
||
interface Props { | ||
address: string; | ||
type: 'object' | 'address'; | ||
} | ||
|
||
export function TransactionsForAddress({ address, type }: Props) { | ||
const rpc = useRpcClient(); | ||
|
||
const { data, isLoading, isError } = useQuery( | ||
['transactions-for-address', address, type], | ||
async () => { | ||
const filters = | ||
type === 'object' | ||
? [{ InputObject: address }, { ChangedObject: address }] | ||
: [{ ToAddress: address }, { FromAddress: address }]; | ||
|
||
const results = await Promise.all( | ||
filters.map((filter) => | ||
rpc.queryTransactions({ | ||
filter, | ||
order: 'descending', | ||
limit: 100, | ||
options: { | ||
showEffects: true, | ||
showBalanceChanges: true, | ||
showInput: true, | ||
}, | ||
}) | ||
) | ||
); | ||
|
||
return [...results[0].data, ...results[1].data].sort( | ||
(a, b) => (b.timestampMs ?? 0) - (a.timestampMs ?? 0) | ||
); | ||
} | ||
); | ||
|
||
if (isLoading) { | ||
return ( | ||
<div> | ||
<LoadingSpinner /> | ||
</div> | ||
); | ||
} | ||
|
||
if (isError) { | ||
return ( | ||
<Banner variant="error" fullWidth> | ||
Transactions could not be extracted on the following specified | ||
address: {address} | ||
</Banner> | ||
); | ||
} | ||
|
||
const tableData = genTableDataFromTxData(data); | ||
|
||
return ( | ||
<div data-testid="tx"> | ||
<TableCard data={tableData.data} columns={tableData.columns} /> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.