Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ssamkkim committed Feb 27, 2024
1 parent 6d1aad1 commit f346976
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 19 deletions.
7 changes: 4 additions & 3 deletions src/lib/components/transaction.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -229,7 +230,7 @@
].label}
</p>
</h3>
{:else if !action?.actionType?.includes("NFT")}
{:else if !action?.actionType?.includes("NFT") || action?.actionType === TransactionType.COMPRESSED_NFT_MINT}
<div class="flex">
{#if action?.actionType?.includes("SENT") && action.to}
<p
Expand Down Expand Up @@ -327,7 +328,7 @@
<div
class="absolute -left-3 top-1/2 h-0.5 w-3 -translate-y-1/2 rounded-full bg-secondary"
/>
{#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}
<h3
class="text-bold text-success"
>
Expand Down
71 changes: 55 additions & 16 deletions src/lib/xray/lib/parser/parsers/nft.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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 {
Expand Down

0 comments on commit f346976

Please sign in to comment.