Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

type attr on DataNft object #140

Merged
merged 8 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-alpha.3",
"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
};
}
}
Loading