Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Commit

Permalink
Fixes NFT id (#1558)
Browse files Browse the repository at this point in the history
  • Loading branch information
gre authored Dec 3, 2021
1 parent 4f5a064 commit 4203d87
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/nft/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import eip55 from "eip55";
import BigNumber from "bignumber.js";
import { NFT, Operation } from "../types";
import { encodeNftId } from ".";

type Collection = NFT["collection"];

Expand All @@ -15,23 +16,22 @@ export const nftsFromOperations = (ops: Operation[]): NFT[] => {
// if ops are Operations get the prop nftOperations, else ops are considered nftOperations already
.flatMap((op) => (op?.nftOperations?.length ? op.nftOperations : op))
.reduce((acc: Record<string, NFT>, nftOp: Operation) => {
if (!nftOp?.contract) {
let { contract } = nftOp;
if (!contract) {
return acc;
}

// Creating a "token for a contract" unique key
const contract = eip55.encode(nftOp.contract!);
const nftKey = contract + nftOp.tokenId!;
const { tokenId, standard, id } = nftOp;
contract = eip55.encode(contract);
const { tokenId, standard, accountId } = nftOp;
if (!tokenId || !standard) return acc;
const id = encodeNftId(accountId, contract, tokenId || "");

const nft = (acc[nftKey] || {
const nft = (acc[id] || {
id,
tokenId: tokenId!,
tokenId,
amount: new BigNumber(0),
collection: {
contract,
standard: standard!,
},
collection: { contract, standard },
}) as NFT;

if (nftOp.type === "NFT_IN") {
Expand All @@ -40,7 +40,7 @@ export const nftsFromOperations = (ops: Operation[]): NFT[] => {
nft.amount = nft.amount.minus(nftOp.value);
}

acc[nftKey] = nft;
acc[id] = nft;

return acc;
}, {});
Expand Down

1 comment on commit 4203d87

@vercel
Copy link

@vercel vercel bot commented on 4203d87 Dec 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.