Skip to content

Commit

Permalink
refactor: remove redundant static param
Browse files Browse the repository at this point in the history
  • Loading branch information
bucurdavid committed Nov 11, 2024
1 parent c6efc7e commit d4e641b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 33 deletions.
39 changes: 7 additions & 32 deletions src/datanft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ export class DataNft implements DataNftType {
}[] = [];

static networkConfiguration: Config;
static apiConfiguration: string;
static env: string;

/**
Expand Down Expand Up @@ -108,34 +107,10 @@ export class DataNft implements DataNftType {
}
this.env = env;
this.networkConfiguration = networkConfiguration[env as EnvironmentsEnum];
this.apiConfiguration = apiConfiguration[env as EnvironmentsEnum];

console.log(
'SDK debug: setNetworkConfig this.apiConfiguration B4 =',
this.apiConfiguration
);
console.log(
'SDK debug: setNetworkConfig this.networkConfiguration B4 =',
this.networkConfiguration
);

if (useSpecificApiEndpoint && useSpecificApiEndpoint.trim() !== '') {
this.apiConfiguration = useSpecificApiEndpoint.trim();
this.networkConfiguration.networkProvider = useSpecificApiEndpoint.trim();
}

console.log(
'SDK debug: setNetworkConfig useSpecificApiEndpoint A8 =',
useSpecificApiEndpoint
);
console.log(
'SDK debug: setNetworkConfig this.apiConfiguration A8 =',
this.apiConfiguration
);
console.log(
'SDK debug: setNetworkConfig this.networkConfiguration A8 =',
this.networkConfiguration
);
}

/**
Expand All @@ -156,7 +131,9 @@ export class DataNft implements DataNftType {
token.nonce
);

const response = await fetch(`${this.apiConfiguration}/nfts/${identifier}`);
const response = await fetch(
`${this.networkConfiguration.networkProvider}/nfts/${identifier}`
);

checkStatus(response);

Expand Down Expand Up @@ -199,10 +176,8 @@ export class DataNft implements DataNftType {
return [];
}

console.log('SDK debug: createManyFromApi api =', this.apiConfiguration);

const fetchUrl = `${
this.apiConfiguration
this.networkConfiguration.networkProvider
}/nfts?identifiers=${identifiers.join(',')}&withSupply=true&size=${
identifiers.length
}`;
Expand Down Expand Up @@ -304,7 +279,7 @@ export class DataNft implements DataNftType {
dataNftTokenIdentifier[this.env as EnvironmentsEnum];

const res = await fetch(
`${this.apiConfiguration}/accounts/${address}/nfts?size=10000&collections=${identifiersMap}&withSupply=true`
`${this.networkConfiguration.networkProvider}/accounts/${address}/nfts?size=10000&collections=${identifiersMap}&withSupply=true`
);

checkStatus(res);
Expand All @@ -325,7 +300,7 @@ export class DataNft implements DataNftType {
const identifier = createTokenIdentifier(this.tokenIdentifier, this.nonce);

const response = await fetch(
`${DataNft.apiConfiguration}/nfts/${identifier}/accounts`
`${DataNft.networkConfiguration.networkProvider}/nfts/${identifier}/accounts`
);

checkStatus(response);
Expand Down Expand Up @@ -711,7 +686,7 @@ export class DataNft implements DataNftType {
}

private static ensureNetworkConfigSet() {
if (!this.env || !this.apiConfiguration) {
if (!this.env || !this.networkConfiguration) {
throw new ErrNetworkConfig();
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/datanft.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe('Data NFT test', () => {
for (const item of dataNfts) {
expect(item).toBeInstanceOf(Object as unknown as DataNft);
}
});
}, 10000);

test('#create many data NFTs different token identifiers', async () => {
DataNft.setNetworkConfig('devnet');
Expand Down

0 comments on commit d4e641b

Please sign in to comment.