diff --git a/package.json b/package.json index 4d3c030..ba203d6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@itheum/sdk-mx-data-nft", - "version": "3.8.0-alpha.3", + "version": "3.8.0-alpha.4", "description": "SDK for Itheum's Data NFT Technology on MultiversX Blockchain", "main": "out/index.js", "types": "out/index.d.js", diff --git a/src/common/utils.ts b/src/common/utils.ts index e62d1c7..c43905e 100644 --- a/src/common/utils.ts +++ b/src/common/utils.ts @@ -616,7 +616,7 @@ export function getDataFromClientSessionCache(cacheKey: string) { return false; } else { // did it expire? is so, delete it from the cache - if (cacheObject.addedOn - Date.now() > cacheObject.expireAfter) { + if (Date.now() - cacheObject.addedOn > cacheObject.expireAfter) { console.log('getDataFromClientSessionCache: expired'); delete sessionCache[cacheKey]; // remove it from cache as its expired return false; diff --git a/src/config.ts b/src/config.ts index e732939..4c4cc61 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,12 +1,3 @@ -/* -Host apps like the data dex or explorer, when the MVX dappProvider in initialized (very early in the page) -it calls a utility method that loads the best RPC to use in the ITH_GLOBAL_MVX_RPC_API_SESSION global variable -so we aim to use that if available so this SDK uses the same RPC as the host to talk to the MVX chain -*/ -declare const window: { - ITH_GLOBAL_MVX_RPC_API_SESSION: string; -} & Window; - export enum EnvironmentsEnum { devnet = 'devnet', testnet = 'testnet', @@ -21,28 +12,17 @@ export interface Config { // note that in all rpc check methods below we check if window === 'undefined' as this is need for tests to pass const devnetNetworkConfig: Config = { chainID: 'D', - networkProvider: - typeof window === 'undefined' - ? 'https://devnet-api.multiversx.com' - : window.ITH_GLOBAL_MVX_RPC_API_SESSION || - 'https://devnet-api.multiversx.com' + networkProvider: 'https://devnet-api.multiversx.com' }; const mainnetNetworkConfig: Config = { chainID: '1', - networkProvider: - typeof window === 'undefined' - ? 'https://api.multiversx.com' - : window.ITH_GLOBAL_MVX_RPC_API_SESSION || 'https://api.multiversx.com' + networkProvider: 'https://api.multiversx.com' }; const testnetNetworkConfig: Config = { chainID: 'T', - networkProvider: - typeof window === 'undefined' - ? 'https://testnet-api.multiversx.com' - : window.ITH_GLOBAL_MVX_RPC_API_SESSION || - 'https://testnet-api.multiversx.com' + networkProvider: 'https://testnet-api.multiversx.com' }; export const itheumTokenIdentifier: { [key in EnvironmentsEnum]: string } = { @@ -85,20 +65,9 @@ export const livelinessStakeContractAddress: { }; export const apiConfiguration: { [key in EnvironmentsEnum]: string } = { - devnet: - typeof window === 'undefined' - ? 'https://devnet-api.multiversx.com' - : window.ITH_GLOBAL_MVX_RPC_API_SESSION || - 'https://devnet-api.multiversx.com', - mainnet: - typeof window === 'undefined' - ? 'https://api.multiversx.com' - : window.ITH_GLOBAL_MVX_RPC_API_SESSION || 'https://api.multiversx.com', - testnet: - typeof window === 'undefined' - ? 'https://testnet-api.multiversx.com' - : window.ITH_GLOBAL_MVX_RPC_API_SESSION || - 'https://testnet-api.multiversx.com' + devnet: 'https://devnet-api.multiversx.com', + mainnet: 'https://api.multiversx.com', + testnet: 'https://testnet-api.multiversx.com' }; export const networkConfiguration: { [key in EnvironmentsEnum]: Config } = { diff --git a/src/datanft.ts b/src/datanft.ts index 37acc54..6b7ed61 100644 --- a/src/datanft.ts +++ b/src/datanft.ts @@ -98,8 +98,9 @@ export class DataNft implements DataNftType { /** * Sets the network configuration for the DataNft class. * @param env 'devnet' | 'mainnet' | 'testnet' + * @param useSpecificApiEndpoint optional param to use a specific RPC API endpoint for the env, if not given, defaults to config default value. Value need to start with https:// */ - static setNetworkConfig(env: string) { + static setNetworkConfig(env: string, useSpecificApiEndpoint?: string) { if (!(env in EnvironmentsEnum)) { throw new ErrNetworkConfig( `Invalid environment: ${env}, Expected: 'devnet' | 'mainnet' | 'testnet'` @@ -108,6 +109,14 @@ export class DataNft implements DataNftType { this.env = env; this.networkConfiguration = networkConfiguration[env as EnvironmentsEnum]; this.apiConfiguration = apiConfiguration[env as EnvironmentsEnum]; + + if ( + useSpecificApiEndpoint && + useSpecificApiEndpoint.trim().includes('https://') + ) { + this.apiConfiguration = useSpecificApiEndpoint.trim(); + this.networkConfiguration.networkProvider = useSpecificApiEndpoint.trim(); + } } /** diff --git a/tests/environment.test.ts b/tests/environment.test.ts index 320bf71..40de54b 100644 --- a/tests/environment.test.ts +++ b/tests/environment.test.ts @@ -1,7 +1,3 @@ -declare const window: { - ITH_GLOBAL_MVX_RPC_API_SESSION: string; -} & Window; - import { ApiNetworkProvider } from '@multiversx/sdk-core/out'; import { DataNftMarket, SftMinter } from '../src/index';