@palliora.org/chainsdk 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -756,16 +756,19 @@ function assert(condition, message) {
756
756
  }
757
757
 
758
758
  // src/config.ts
759
+
759
760
  var env = typeof process !== "undefined" && process.env ? process.env : {};
760
761
  var PALLIORA_WS = env.PALLIORA_WS || "wss://manas-rpc.palliora.org";
761
762
  var PALLIORA_RPC_URL = env.PALLIORA_RPC_URL || "wss://manas-rpc.palliora.org";
762
763
  var DEBUG = env.DEBUG === "true" || false;
763
764
  var TX_WAIT_FINALIZATION = env.TX_WAIT_FINALIZATION === "true" || false;
765
+ var provider = new (0, _api2.WsProvider)(PALLIORA_WS, 1e4);
764
766
  function configure(opts) {
765
767
  if (opts.pallioraWs !== void 0) PALLIORA_WS = exports.PALLIORA_WS = opts.pallioraWs;
766
768
  if (opts.pallioraRpcUrl !== void 0) PALLIORA_RPC_URL = exports.PALLIORA_RPC_URL = opts.pallioraRpcUrl;
767
769
  if (opts.debug !== void 0) DEBUG = exports.DEBUG = opts.debug;
768
770
  if (opts.txWaitFinalization !== void 0) TX_WAIT_FINALIZATION = exports.TX_WAIT_FINALIZATION = opts.txWaitFinalization;
771
+ provider = exports.provider = new (0, _api2.WsProvider)(PALLIORA_WS, 1e4);
769
772
  }
770
773
 
771
774
  // src/utils/helper.ts
@@ -868,19 +871,23 @@ var tokenToBigint = toAtomicPaliAmount;
868
871
  // src/chain/singleton.ts
869
872
 
870
873
 
871
- // src/chain/wsProvider.ts
872
-
873
- var provider = new (0, _api2.WsProvider)(PALLIORA_WS, 1e4);
874
-
875
- // src/chain/singleton.ts
876
-
877
874
  var api = null;
875
+ var apiUrl = null;
878
876
  var keyring = null;
879
877
  var encKeyring = null;
880
878
  var apiListenersAttached = false;
881
879
  var apiTeardownInProgress = false;
882
880
  async function getApi(cb) {
883
881
  if (!provider) return;
882
+ if (api && PALLIORA_WS !== apiUrl) {
883
+ const staleApi = api;
884
+ api = null;
885
+ apiUrl = null;
886
+ apiListenersAttached = false;
887
+ apiTeardownInProgress = false;
888
+ await staleApi.disconnect().catch(() => {
889
+ });
890
+ }
884
891
  if (!api) {
885
892
  api = await _api2.ApiPromise.create({
886
893
  provider,
@@ -888,6 +895,7 @@ async function getApi(cb) {
888
895
  types: API_TYPES,
889
896
  signedExtensions: API_EXTENSIONS
890
897
  });
898
+ apiUrl = PALLIORA_WS;
891
899
  }
892
900
  const isNode = typeof process !== "undefined" && typeof process.exit === "function";
893
901
  const isTest = typeof process !== "undefined" && _optionalChain([process, 'access', _37 => _37.env, 'optionalAccess', _38 => _38.NODE_ENV]) === "test";