Skip to content

Commit

Permalink
Merge pull request #121 from Itheum/d-damian
Browse files Browse the repository at this point in the history
D damian
  • Loading branch information
bucurdavid authored Mar 28, 2024
2 parents fbaba85 + 4b55d98 commit d65beea
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@itheum/sdk-mx-data-nft",
"version": "3.0.0-alpha.3",
"version": "3.0.0-alpha.5",
"description": "SDK for Itheum's Data NFT Technology on MultiversX Blockchain",
"main": "out/index.js",
"types": "out/index.d.js",
Expand Down
29 changes: 25 additions & 4 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
ErrFetch,
ErrInvalidTokenIdentifier,
ErrMissingTrait,
ErrMissingValueForTrait
ErrMissingValueForTrait,
ErrParseNft
} from '../errors';
import {
Bond,
Expand Down Expand Up @@ -149,7 +150,26 @@ export function parseRefund(value: any): Refund {
}

export function parseDataNft(value: NftType): DataNft {
return new DataNft({
let attributes;
try {
attributes = DataNft.decodeAttributes(value.attributes); // normal attributes
} catch (error: any) {
try {
attributes = {
dataPreview: value.metadata?.itheum_data_preview_url ?? '',
dataStream: value.metadata?.itheum_data_stream_url ?? '',
dataMarshal: value.metadata?.itheum_data_marshal_url ?? '',
creator: value.metadata?.itheum_creator ?? '',
creationTime: new Date(value.timestamp * 1000),
description: value.metadata?.description ?? '',
isDataNFTPH: true,
title: value.name
};
} catch (error: any) {
throw new ErrParseNft(error.message);
}
}
const returnValue = {
tokenIdentifier: value.identifier,
nftImgUrl: value.url ?? '',
tokenName: value.name,
Expand All @@ -163,8 +183,9 @@ export function parseDataNft(value: NftType): DataNft {
collection: value.collection,
balance: value.balance ? Number(value.balance) : 0,
owner: value.owner ? value.owner : '',
...DataNft.decodeAttributes(value.attributes)
});
...attributes
};
return new DataNft(returnValue);
}

export async function checkTraitsUrl(traitsUrl: string) {
Expand Down
1 change: 1 addition & 0 deletions src/datanft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class DataNft implements DataNftType {
readonly owner: string = ''; // works if tokenIdentifier is an NFT
readonly overrideDataMarshal: string = '';
readonly overrideDataMarshalChainId: string = '';
readonly isDataNFTPH: boolean = false;

static networkConfiguration: Config;
static apiConfiguration: string;
Expand Down
6 changes: 6 additions & 0 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ export class ErrDecodeAttributes extends Error {
}
}

export class ErrParseNft extends Error {
public constructor(message?: string) {
super(`Failed to parse NFT: ${message}`);
}
}

export class ErrAttributeNotSet extends Error {
public constructor(attribute: string) {
super(`Attribute "${attribute}" is not set`);
Expand Down
4 changes: 4 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export interface NftType {
fileType?: string;
fileUri?: string;
fileName?: string;
itheum_data_preview_url?: string;
itheum_data_stream_url?: string;
itheum_data_marshal_url?: string;
itheum_creator?: string;
};
media?: {
url: string;
Expand Down
6 changes: 3 additions & 3 deletions tests/bond.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ describe('Bond test', () => {
expect(bond).toMatchObject<Bond>;
const sameBond: Bond[] = await bondContract.viewBonds(
[tokenIdentifier],
[76]
[172]
);
expect(sameBond).toMatchObject<Bond[]>;
const sameBond2: Bond[] = await bondContract.viewBonds([
createTokenIdentifier(tokenIdentifier, 76)
createTokenIdentifier(tokenIdentifier, 172)
]);
expect(sameBond2).toMatchObject<Bond[]>;
expect(sameBond).toStrictEqual(sameBond2);
Expand All @@ -65,7 +65,7 @@ describe('Bond test', () => {
expect(compensation).toMatchObject<Compensation>;

const compensations: Compensation[] = await bondContract.viewCompensations([
{ tokenIdentifier: tokenIdentifier, nonce: 76 }
{ tokenIdentifier: tokenIdentifier, nonce: 172 }
]);
expect(compensations).toMatchObject<Compensation[]>;
expect(compensations[0]).toStrictEqual(compensation);
Expand Down

0 comments on commit d65beea

Please sign in to comment.