1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

Invalid transction link fix (#1035)

* get nft updates fix

* fix

* use nft update type

* message case fixed

* update message fix

Co-authored-by: ClaudiaHolhos <claudia@oceanprotocol.com>
This commit is contained in:
claudiaHash 2022-01-31 15:15:52 +02:00 committed by GitHub
parent 8293e9ad5f
commit 4b6be6da0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,13 +10,17 @@ import styles from './EditHistory.module.css'
const getReceipts = gql` const getReceipts = gql`
query ReceiptData($address: ID!) { query ReceiptData($address: ID!) {
nftUpdates( nftUpdates(
where: { id: $address } where: { nft: $address }
orderBy: timestamp orderBy: timestamp
orderDirection: desc orderDirection: desc
) { ) {
id id
nft {
address
}
tx tx
timestamp timestamp
type
} }
} }
` `
@ -24,6 +28,20 @@ const getReceipts = gql`
export default function EditHistory(): ReactElement { export default function EditHistory(): ReactElement {
const { ddo } = useAsset() const { ddo } = useAsset()
function getUpdateType(type: string): string {
switch (type) {
case 'METADATA_CREATED':
return 'published'
case 'METADATA_UPDATED':
return 'updated'
case 'STATE_UPDATED':
return 'state updated'
case 'TOKENURI_UPDATED':
return 'NFT metadata updated'
default:
return ''
}
}
// //
// 1. Construct subgraph query based on DDO. // 1. Construct subgraph query based on DDO.
// Need to wait for it to avoid infinite rerender loop with useQuery. // Need to wait for it to avoid infinite rerender loop with useQuery.
@ -39,7 +57,7 @@ export default function EditHistory(): ReactElement {
const [result] = useQuery({ const [result] = useQuery({
query: getReceipts, query: getReceipts,
variables: { address: ddo?.services[0].datatokenAddress.toLowerCase() }, variables: { address: ddo?.nft.address.toLowerCase() },
context: queryContext, context: queryContext,
pause: !ddo || !queryContext pause: !ddo || !queryContext
}) })
@ -49,18 +67,10 @@ export default function EditHistory(): ReactElement {
// 2. Construct display data based on fetched data. // 2. Construct display data based on fetched data.
// //
const [receipts, setReceipts] = useState<ReceiptData[]>() const [receipts, setReceipts] = useState<ReceiptData[]>()
const [creationTx, setCreationTx] = useState<string>()
useEffect(() => { useEffect(() => {
if (!data || data.nftUpdates.length === 0) return if (!data || data.nftUpdates.length === 0) return
const receiptCollection = data.nftUpdates
const receiptCollectionLength = data.nftUpdates.length
const creationData = data.nftUpdates[receiptCollectionLength - 1]
setCreationTx(creationData.tx)
const receiptCollection = [...data.nftUpdates]
receiptCollection.splice(-1, 1)
setReceipts(receiptCollection) setReceipts(receiptCollection)
}, [data]) }, [data])
@ -71,15 +81,11 @@ export default function EditHistory(): ReactElement {
{receipts?.map((receipt) => ( {receipts?.map((receipt) => (
<li key={receipt.id} className={styles.item}> <li key={receipt.id} className={styles.item}>
<ExplorerLink networkId={ddo?.chainId} path={`/tx/${receipt.tx}`}> <ExplorerLink networkId={ddo?.chainId} path={`/tx/${receipt.tx}`}>
edited <Time date={`${receipt.timestamp}`} relative isUnix /> {getUpdateType(receipt.type)}{' '}
<Time date={`${receipt.timestamp}`} relative isUnix />
</ExplorerLink> </ExplorerLink>
</li> </li>
))} ))}
<li className={styles.item}>
<ExplorerLink networkId={ddo?.chainId} path={`/tx/${creationTx}`}>
published <Time date={ddo?.metadata?.created} relative />
</ExplorerLink>
</li>
</ul> </ul>
</> </>
) )