From f346976a2b758e90cf927cc7a2cf0435a1adbbef Mon Sep 17 00:00:00 2001 From: scammo Date: Tue, 27 Feb 2024 01:32:26 -0800 Subject: [PATCH] fix --- src/lib/components/transaction.svelte | 7 +-- src/lib/xray/lib/parser/parsers/nft.ts | 71 ++++++++++++++++++++------ 2 files changed, 59 insertions(+), 19 deletions(-) diff --git a/src/lib/components/transaction.svelte b/src/lib/components/transaction.svelte index 2accb2ed..eaed62e7 100644 --- a/src/lib/components/transaction.svelte +++ b/src/lib/components/transaction.svelte @@ -3,14 +3,15 @@ import { ProtonCustomActionLabelTypes } from "$lib/xray"; - import { fade, fly } from "svelte/transition"; import { transactionActionsMetadata } from "$lib/types"; + import { fade, fly } from "svelte/transition"; import formatDate from "$lib/util/format-date"; export let transaction: ProtonTransaction; import Icon from "$lib/components/icon.svelte"; + import { TransactionType } from "helius-sdk"; import IntersectionObserver from "svelte-intersection-observer"; import shortenString from "../util/shorten-string"; import TokenProvider from "./providers/token-provider.svelte"; @@ -229,7 +230,7 @@ ].label}

- {:else if !action?.actionType?.includes("NFT")} + {:else if !action?.actionType?.includes("NFT") || action?.actionType === TransactionType.COMPRESSED_NFT_MINT}
{#if action?.actionType?.includes("SENT") && action.to}

- {#if action?.actionType?.includes("RECEIVED") || action?.actionType?.includes("NFT_SELL") || action?.actionType?.includes("AIRDROP")} + {#if action?.actionType?.includes("RECEIVED") || action?.actionType?.includes("NFT_SELL") || action?.actionType?.includes("AIRDROP") || action?.actionType === TransactionType.COMPRESSED_NFT_MINT}

diff --git a/src/lib/xray/lib/parser/parsers/nft.ts b/src/lib/xray/lib/parser/parsers/nft.ts index c29175de..a61e7dc0 100644 --- a/src/lib/xray/lib/parser/parsers/nft.ts +++ b/src/lib/xray/lib/parser/parsers/nft.ts @@ -1,9 +1,10 @@ import { LAMPORTS_PER_SOL } from "@solana/web3.js"; -import type { - EnrichedTransaction, - NFTEvent, +import { TransactionType, + type CompressedNftEvent, + type EnrichedTransaction, + type NFTEvent, } from "helius-sdk"; import { SOL, unknownProtonTransaction } from "../types"; @@ -382,9 +383,20 @@ export const parseNftMint: ProtonParser = (transaction, address) => { }); }; +function returnCompressedNftEventArray(value: CompressedNftEvent | null) { + if (Array.isArray(value)) { + return value; + } else if (value) { + return [value]; + } else { + return []; + } +} + export const parseCompressedNftMint: ProtonParser = (transaction, address) => { - // @ts-ignore - const nftEvent = transaction.events.compressed; + const nftEvent = returnCompressedNftEventArray( + transaction.events.compressed + ); const { signature, timestamp, accountData, type, source } = transaction; const fee = transaction.fee / LAMPORTS_PER_SOL; @@ -444,8 +456,9 @@ export const parseCompressedNftTransfer: ProtonParser = ( transaction, address ) => { - // @ts-ignore - const nftEvent = transaction.events.compressed; + const nftEvent = returnCompressedNftEventArray( + transaction.events.compressed + ); const { signature, timestamp, accountData, type, source } = transaction; const fee = transaction.fee / LAMPORTS_PER_SOL; @@ -504,8 +517,14 @@ export const parseCompressedNftTransfer: ProtonParser = ( }; export const parseCompressedNftBurn: ProtonParser = (transaction, address) => { - // @ts-ignore - const nftEvent = transaction.events.compressed; + const nftEvent = returnCompressedNftEventArray( + transaction.events.compressed + ); + // const nftEvent = Array.isArray(transaction.events.compressed) + // ? transaction.events.compressed + // : transaction.events.compressed + // ? [transaction.events.compressed] + // : []; const { signature, timestamp, accountData, type, source } = transaction; const fee = transaction.fee / LAMPORTS_PER_SOL; @@ -522,13 +541,33 @@ export const parseCompressedNftBurn: ProtonParser = (transaction, address) => { for (let i = 0; i < nftEvent.length; i++) { const nftEventAction = nftEvent[i]; - actions.push({ - actionType: "BURN_NFT", - amount: 1, - from: nftEventAction.oldLeafOwner, - sent: nftEventAction.assetId, - to: "", - }); + if (nftEventAction.type === TransactionType.COMPRESSED_NFT_BURN) { + actions.push({ + actionType: "BURN_NFT", + amount: 1, + from: nftEventAction.oldLeafOwner, + sent: nftEventAction.assetId, + to: "", + }); + } else if ( + nftEventAction.type === TransactionType.COMPRESSED_NFT_MINT + ) { + actions.push({ + actionType: "COMPRESSED_NFT_MINT", + amount: 1, + from: "", + sent: nftEventAction.assetId, + to: nftEventAction.newLeafOwner, + }); + } else { + actions.push({ + actionType: "COMPRESSED_NFT_TRANSFER", + amount: 1, + from: nftEventAction.oldLeafOwner, + sent: nftEventAction.assetId, + to: nftEventAction.newLeafOwner, + }); + } } return {