Skip to content

Commit

Permalink
Merge pull request #141 from Itheum/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
bucurdavid authored Jun 11, 2024
2 parents 4d76bbb + b94e6f3 commit e103187
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 10 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.4.0",
"version": "3.5.0",
"description": "SDK for Itheum's Data NFT Technology on MultiversX Blockchain",
"main": "out/index.js",
"types": "out/index.d.js",
Expand Down
1 change: 1 addition & 0 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ export function parseDataNft(value: NftType): DataNft {
: value.type === NftEnumType.NonFungibleESDT
? 1
: 0,
type: value.type,
royalties: value.royalties !== null ? value.royalties / 100 : 0,
nonce: value.nonce,
collection: value.collection,
Expand Down
45 changes: 38 additions & 7 deletions src/datanft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ import {
ErrNetworkConfig,
ErrTooManyItems
} from './errors';
import { DataNftType, NftType, ViewDataReturnType } from './interfaces';
import {
DataNftType,
NftEnumType,
NftType,
ViewDataReturnType
} from './interfaces';
import BigNumber from 'bignumber.js';

export class DataNft implements DataNftType {
Expand All @@ -46,11 +51,13 @@ export class DataNft implements DataNftType {
readonly nonce: number = 0;
readonly collection: string = '';
readonly balance: BigNumber.Value = 0;
readonly type: NftEnumType = NftEnumType.SemiFungibleESDT;
readonly owner: string = ''; // works if tokenIdentifier is an NFT
readonly overrideDataMarshal: string = '';
readonly overrideDataMarshalChainId: string = '';
readonly isDataNFTPH: boolean = false;
readonly extraAssets: string[] = [];

readonly media: {
url: string;
originalUrl: string;
Expand Down Expand Up @@ -375,15 +382,35 @@ export class DataNft implements DataNftType {
}

try {
let chainId;

if (this.overrideDataMarshalChainId === '') {
chainId =
DataNft.networkConfiguration.chainID === 'D'
? 'ED'
: DataNft.networkConfiguration.chainID == '1'
? 'E1'
: '';
} else if (this.overrideDataMarshalChainId === 'D') {
chainId = 'ED';
} else if (this.overrideDataMarshalChainId === '1') {
chainId = 'E1';
} else {
chainId = this.overrideDataMarshalChainId;
}

let dataMarshal;
if (this.overrideDataMarshal === '') {
dataMarshal = this.dataMarshal;
} else {
dataMarshal = this.overrideDataMarshal;
}

let url = `${this.dataMarshal}/access?nonce=${p.signedMessage}&NFTId=${
this.collection
}-${numberToPaddedHex(this.nonce)}&signature=${
signResult.signature
}&chainId=${
DataNft.networkConfiguration.chainID == 'D'
? 'ED'
: DataNft.networkConfiguration.chainID
}&accessRequesterAddr=${signResult.addrInHex}`;
}&chainId=${chainId}&accessRequesterAddr=${signResult.addrInHex}`;

type FetchConfig = {
[key: string]: any;
Expand Down Expand Up @@ -522,9 +549,13 @@ export class DataNft implements DataNftType {
chainId =
DataNft.networkConfiguration.chainID === 'D'
? 'ED'
: DataNft.networkConfiguration.chainID;
: DataNft.networkConfiguration.chainID == '1'
? 'E1'
: '';
} else if (this.overrideDataMarshalChainId === 'D') {
chainId = 'ED';
} else if (this.overrideDataMarshalChainId === '1') {
chainId = 'E1';
} else {
chainId = this.overrideDataMarshalChainId;
}
Expand Down
1 change: 1 addition & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export interface NftType {
export interface DataNftType {
readonly tokenIdentifier: string;
readonly nftImgUrl: string;
readonly type: NftEnumType;
readonly dataPreview: string;
readonly dataStream: string;
readonly dataMarshal: string;
Expand Down
8 changes: 6 additions & 2 deletions src/sft-minter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ export class SftMinter extends Minter {
nftStorageToken?: string;
extraAssets?: string[];
}
): Promise<Transaction> {
): Promise<{ imageUrl: string; metadataUrl: string; tx: Transaction }> {
const { imageUrl, traitsUrl, nftStorageToken, extraAssets } = options ?? {};

const tokenNameValidator = new StringValidator()
Expand Down Expand Up @@ -434,6 +434,10 @@ export class SftMinter extends Minter {
chainID: this.chainID
});

return mintTx;
return {
imageUrl: imageOnIpfsUrl,
metadataUrl: metadataOnIpfsUrl,
tx: mintTx
};
}
}

0 comments on commit e103187

Please sign in to comment.