@orbit-software/sdk 1.40.0 → 1.42.0

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.
@@ -0,0 +1 @@
1
+ export declare const BuyShopItems: () => import("react/jsx-runtime").JSX.Element | null;
package/dist/esm/sdk.d.ts CHANGED
@@ -88,6 +88,11 @@ interface TMANetworkInterstitialResponse {
88
88
  id: string;
89
89
  reward: boolean;
90
90
  }
91
+ interface BalanceResponse {
92
+ balance: number;
93
+ balance_gems: number;
94
+ balance_coins: number;
95
+ }
91
96
  export type AdType = "REWARD" | "INTERSTITIAL";
92
97
  export interface RequestAdOptions {
93
98
  onStart?: () => void;
@@ -100,7 +105,7 @@ export interface CryptoSteamSDK {
100
105
  requestAd: (options?: RequestAdOptions) => Promise<true>;
101
106
  requestRewardAd: (options?: RequestAdOptions) => Promise<boolean>;
102
107
  getProfile: () => Promise<CryptoSteamSDKProfile>;
103
- getBalance: () => Promise<number>;
108
+ getBalance: () => Promise<BalanceResponse>;
104
109
  trackGameTimeTick: () => void;
105
110
  getVersion: () => string;
106
111
  initializeOverlay: (config?: OverlayConfig) => void;
package/dist/esm/sdk.mjs CHANGED
@@ -1854,7 +1854,7 @@ function promisify(e) {
1854
1854
  };
1855
1855
  }
1856
1856
  promisify.argumentNames = "__ES6-PROMISIFY--CUSTOM-ARGUMENTS__", promisify.Promise = void 0;
1857
- const version = "1.40.0";
1857
+ const version = "1.42.0";
1858
1858
  var jsxRuntime = { exports: {} }, reactJsxRuntime_development = {}, hasRequiredReactJsxRuntime_development;
1859
1859
  function requireReactJsxRuntime_development() {
1860
1860
  if (hasRequiredReactJsxRuntime_development) return reactJsxRuntime_development;
@@ -12328,7 +12328,7 @@ function useStore$1(e, T = identity) {
12328
12328
  const createImpl = (e) => {
12329
12329
  const T = createStore$1(e), C = (J) => useStore$1(T, J);
12330
12330
  return Object.assign(C, T), C;
12331
- }, create$2 = (e) => createImpl(e), waitForSDK = () => new Promise((e) => {
12331
+ }, create$2 = (e) => e ? createImpl(e) : createImpl, waitForSDK = () => new Promise((e) => {
12332
12332
  if (window.CryptoSteamSDK) {
12333
12333
  e();
12334
12334
  return;
@@ -26532,7 +26532,7 @@ const tgs = 1, v$1 = "5.5.2", fr = 60, ip = 0, op = 179, w$1 = 512, h$1 = 512, n
26532
26532
  box_open,
26533
26533
  common
26534
26534
  };
26535
- var define_process_env_default$3 = { NODE_ENV: '"production"', version: '"1.40.0"' };
26535
+ var define_process_env_default$3 = { NODE_ENV: '"production"', version: '"1.42.0"' };
26536
26536
  const resources = {
26537
26537
  en: {
26538
26538
  translation: en$1
@@ -27819,7 +27819,7 @@ function createThunkMiddleware(e) {
27819
27819
  }
27820
27820
  var thunk = createThunkMiddleware();
27821
27821
  thunk.withExtraArgument = createThunkMiddleware;
27822
- var define_process_env_default$2 = { NODE_ENV: '"production"', version: '"1.40.0"' }, __extends = /* @__PURE__ */ function() {
27822
+ var define_process_env_default$2 = { NODE_ENV: '"production"', version: '"1.42.0"' }, __extends = /* @__PURE__ */ function() {
27823
27823
  var e = function(T, C) {
27824
27824
  return e = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(J, V) {
27825
27825
  J.__proto__ = V;
@@ -31132,6 +31132,14 @@ const PrizeCarousel = ({
31132
31132
  )
31133
31133
  }
31134
31134
  );
31135
+ }, useBuyShopModalStore = create$2((e) => ({
31136
+ isOpen: !1,
31137
+ open: () => e({ isOpen: !0 }),
31138
+ close: () => e({ isOpen: !1 }),
31139
+ onOpenChange: (T) => e({ isOpen: T })
31140
+ })), BuyShopItems = () => {
31141
+ const { isOpen: e, onOpenChange: T } = useBuyShopModalStore(), { profile: C } = useProfileStore();
31142
+ return C ? /* @__PURE__ */ jsxRuntimeExports.jsx(ClosableModal, { isOpen: e, onOpenChange: T, children: /* @__PURE__ */ jsxRuntimeExports.jsx(BuyMenu, { user: C }) }, "buy_menu") : null;
31135
31143
  };
31136
31144
  function createOverlay(e) {
31137
31145
  let T = document.getElementById("overlay-root");
@@ -31174,6 +31182,7 @@ const OverlayManager = ({ options: e }) => {
31174
31182
  }
31175
31183
  ),
31176
31184
  /* @__PURE__ */ jsxRuntimeExports.jsx(Inventory, {}),
31185
+ /* @__PURE__ */ jsxRuntimeExports.jsx(BuyShopItems, {}),
31177
31186
  /* @__PURE__ */ jsxRuntimeExports.jsx(BoxOpeningModal, {})
31178
31187
  ] }) }) }) }) }) });
31179
31188
  };
@@ -31197,7 +31206,7 @@ function delay(e, { signal: T } = {}) {
31197
31206
  T == null || T.addEventListener("abort", K, { once: !0 });
31198
31207
  });
31199
31208
  }
31200
- var define_process_env_default$1 = { NODE_ENV: '"production"', version: '"1.40.0"' }, win;
31209
+ var define_process_env_default$1 = { NODE_ENV: '"production"', version: '"1.42.0"' }, win;
31201
31210
  if (typeof window > "u") {
31202
31211
  var loc = {
31203
31212
  hostname: ""
@@ -44369,7 +44378,7 @@ const getGlobalObj = () => {
44369
44378
  return self;
44370
44379
  throw new Error("No global object found");
44371
44380
  };
44372
- var define_process_env_default = { NODE_ENV: '"production"', version: '"1.40.0"' };
44381
+ var define_process_env_default = { NODE_ENV: '"production"', version: '"1.42.0"' };
44373
44382
  const CloudStorageGetItem = promisify(WebApp.CloudStorage.getItem), CloudStorageSetItem = promisify(WebApp.CloudStorage.setItem), CloudStorageRemoveItem = promisify(WebApp.CloudStorage.removeItem), BASE_URL = "https://app.portalapp.games/sdk", G_MEASUREMENT_ID = "G-4RMXVE2K75";
44374
44383
  let configCache = null;
44375
44384
  const CACHE_DURATION_MS = 5 * 60 * 1e3;
@@ -44481,7 +44490,9 @@ const CryptoSteamSDK = {
44481
44490
  }, document.head.appendChild(V), console.log("Monetag: script appended to head.");
44482
44491
  });
44483
44492
  } else
44484
- console.error("Monetag: no script tag found in monetag configuration.");
44493
+ console.error(
44494
+ "Monetag: no script tag found in monetag configuration."
44495
+ );
44485
44496
  } catch (C) {
44486
44497
  console.error("Monetag: failed to initialize.", C);
44487
44498
  }
@@ -44494,15 +44505,21 @@ const CryptoSteamSDK = {
44494
44505
  console.log("Adsgram: script loaded successfully.");
44495
44506
  const K = Date.now(), $ = setInterval(() => {
44496
44507
  if (window.Adsgram && typeof window.Adsgram.init == "function")
44497
- if (clearInterval($), console.log("Adsgram: window.Adsgram found, initializing..."), adsgramAdController = window.Adsgram.init({ blockId: T.adsgram }), adsgramAdController)
44508
+ if (clearInterval($), console.log("Adsgram: window.Adsgram found, initializing..."), adsgramAdController = window.Adsgram.init({
44509
+ blockId: T.adsgram
44510
+ }), adsgramAdController)
44498
44511
  console.log("Adsgram: initialized successfully."), J();
44499
44512
  else {
44500
- const ee = new Error("Adsgram: init returned null or undefined.");
44513
+ const ee = new Error(
44514
+ "Adsgram: init returned null or undefined."
44515
+ );
44501
44516
  console.error(ee), V(ee);
44502
44517
  }
44503
44518
  else if (Date.now() - K > 5e3) {
44504
44519
  clearInterval($);
44505
- const ee = new Error("Adsgram: window.Adsgram did not appear within 5 seconds.");
44520
+ const ee = new Error(
44521
+ "Adsgram: window.Adsgram did not appear within 5 seconds."
44522
+ );
44506
44523
  console.error(ee), V(ee);
44507
44524
  }
44508
44525
  }, 100);
@@ -44594,7 +44611,7 @@ const CryptoSteamSDK = {
44594
44611
  "profile",
44595
44612
  "GET"
44596
44613
  ),
44597
- getBalance: async () => (await makeRequest("balance", "GET")).balance,
44614
+ getBalance: async () => await makeRequest("balance", "GET"),
44598
44615
  trackGameTimeTick: () => {
44599
44616
  makeRequest("ping", "POST");
44600
44617
  },
@@ -44612,33 +44629,45 @@ const CryptoSteamSDK = {
44612
44629
  "shop/purchases",
44613
44630
  "GET"
44614
44631
  ),
44615
- buyShopItem: async (e) => await makeRequest(`shop/items/${e}/buy`, "POST"),
44616
- openPurchaseConfirmModal: async (e, T) => new Promise((C, J) => {
44617
- const V = document.createElement("div");
44618
- V.style.position = "fixed", V.style.top = "0", V.style.left = "0", V.style.width = "100%", V.style.height = "100%", V.style.backgroundColor = "transparent", V.style.zIndex = "9999";
44619
- const K = document.createElement("iframe");
44620
- if (K.style.position = "fixed", T) {
44621
- let oe = T.x + (T.width - 210) / 2, ie = T.y - 108 - 20;
44622
- ie < 8 && (ie = T.y + T.height + 20), oe + 210 > window.innerWidth - 8 && (oe = window.innerWidth - 8 - 210), oe < 8 && (oe = 8), (ie + 108 > window.innerHeight - 8 || ie < 8) && (ie = (window.innerHeight - 108) / 2, oe = (window.innerWidth - 210) / 2), K.style.left = `${oe}px`, K.style.top = `${ie}px`;
44623
- } else
44624
- K.style.left = "50%", K.style.top = "50%", K.style.transform = "translate(-50%, -50%)";
44625
- K.style.boxShadow = "0px 0px 2px 1px rgba(0, 0, 0, 0.22), 0px 32px 64px rgba(0, 0, 0, 0.34)", K.style.borderRadius = "24px", K.style.border = "none", K.style.zIndex = "10000", K.referrerPolicy = "origin", K.style.width = "210px", K.style.height = "108px", K.style.backgroundColor = "white";
44626
- const $ = new URLSearchParams();
44627
- $.set("itemId", e.id.toString()), $.set("price", e.price.toString()), $.set("__tg_x_auth", TelegramWebApp.initData);
44628
- const ee = {
44629
- confirm: {
44630
- pay: instance.t("confirmIframe.pay"),
44631
- cancel: instance.t("confirmIframe.cancel")
44632
+ buyShopItem: async (e) => {
44633
+ const T = await CryptoSteamSDK.getBalance(), J = (await CryptoSteamSDK.getShopItems()).find((V) => V.id === e);
44634
+ if (J || console.warn(`Not found shop item with id ${e}`), J && T.balance_gems >= J.price)
44635
+ return await makeRequest(`shop/items/${e}/buy`, "POST");
44636
+ useBuyShopModalStore.getState().open();
44637
+ },
44638
+ openPurchaseConfirmModal: async (e, T) => {
44639
+ const C = await CryptoSteamSDK.getBalance();
44640
+ return new Promise((J, V) => {
44641
+ if (C.balance_gems < e.price) {
44642
+ useBuyShopModalStore.getState().open(), V(new Error("insufficient funds"));
44643
+ return;
44632
44644
  }
44633
- };
44634
- $.set("translations", JSON.stringify(ee)), K.src = `${BASE_URL}/shop/payment_iframe?${$.toString()}`;
44635
- const te = (re) => {
44636
- re.data.type === "confirm" ? (window.removeEventListener("message", te), document.body.removeChild(V), document.body.removeChild(K), C({ status: "success" })) : re.data.type === "cancel" ? (window.removeEventListener("message", te), document.body.removeChild(V), document.body.removeChild(K), C({ status: "error" })) : re.data.type === "error" && (window.removeEventListener("message", te), document.body.removeChild(V), document.body.removeChild(K), J(new Error(re.data.message)));
44637
- };
44638
- window.addEventListener("message", te), V.onclick = () => {
44639
- window.removeEventListener("message", te), document.body.removeChild(V), document.body.removeChild(K), C({ status: "error" });
44640
- }, document.body.appendChild(V), document.body.appendChild(K);
44641
- }),
44645
+ const K = document.createElement("div");
44646
+ K.style.position = "fixed", K.style.top = "0", K.style.left = "0", K.style.width = "100%", K.style.height = "100%", K.style.backgroundColor = "transparent", K.style.zIndex = "9999";
44647
+ const $ = document.createElement("iframe");
44648
+ if ($.style.position = "fixed", T) {
44649
+ let ie = T.x + (T.width - 210) / 2, le = T.y - 108 - 20;
44650
+ le < 8 && (le = T.y + T.height + 20), ie + 210 > window.innerWidth - 8 && (ie = window.innerWidth - 8 - 210), ie < 8 && (ie = 8), (le + 108 > window.innerHeight - 8 || le < 8) && (le = (window.innerHeight - 108) / 2, ie = (window.innerWidth - 210) / 2), $.style.left = `${ie}px`, $.style.top = `${le}px`;
44651
+ } else
44652
+ $.style.left = "50%", $.style.top = "50%", $.style.transform = "translate(-50%, -50%)";
44653
+ $.style.boxShadow = "0px 0px 2px 1px rgba(0, 0, 0, 0.22), 0px 32px 64px rgba(0, 0, 0, 0.34)", $.style.borderRadius = "24px", $.style.border = "none", $.style.zIndex = "10000", $.referrerPolicy = "origin", $.style.width = "210px", $.style.height = "108px", $.style.backgroundColor = "white";
44654
+ const ee = new URLSearchParams();
44655
+ ee.set("itemId", e.id.toString()), ee.set("price", e.price.toString()), ee.set("__tg_x_auth", TelegramWebApp.initData);
44656
+ const te = {
44657
+ confirm: {
44658
+ pay: instance.t("confirmIframe.pay"),
44659
+ cancel: instance.t("confirmIframe.cancel")
44660
+ }
44661
+ };
44662
+ ee.set("translations", JSON.stringify(te)), $.src = `${BASE_URL}/shop/payment_iframe?${ee.toString()}`;
44663
+ const re = (ne) => {
44664
+ ne.data.type === "confirm" ? (window.removeEventListener("message", re), document.body.removeChild(K), document.body.removeChild($), J({ status: "success" })) : ne.data.type === "cancel" ? (window.removeEventListener("message", re), document.body.removeChild(K), document.body.removeChild($), J({ status: "error" })) : ne.data.type === "error" && (window.removeEventListener("message", re), document.body.removeChild(K), document.body.removeChild($), V(new Error(ne.data.message)));
44665
+ };
44666
+ window.addEventListener("message", re), K.onclick = () => {
44667
+ window.removeEventListener("message", re), document.body.removeChild(K), document.body.removeChild($), J({ status: "error" });
44668
+ }, document.body.appendChild(K), document.body.appendChild($);
44669
+ });
44670
+ },
44642
44671
  createInvoice: async (e, T, C, J) => await makeRequest("invoices", "POST", {
44643
44672
  title: e,
44644
44673
  description: T,
@@ -44719,16 +44748,21 @@ async function showMonetagAdWithTimeout(e) {
44719
44748
  window.addEventListener("message", ee);
44720
44749
  const te = `
44721
44750
  <script>
44751
+ function safePostMessage(msg) {
44752
+ if (window.parent && typeof window.parent.postMessage === 'function') {
44753
+ window.parent.postMessage(msg, '*');
44754
+ }
44755
+ }
44722
44756
  try {
44723
44757
  window.parent['${monetagShowAdFnName}']({ ymid: '${e}' })
44724
44758
  .then(() => {
44725
- window.parent.postMessage({ type: 'monetag_ad_success' }, '*');
44759
+ safePostMessage({ type: 'monetag_ad_success' });
44726
44760
  })
44727
44761
  .catch((e) => {
44728
- window.parent.postMessage({ type: 'monetag_ad_error', error: e.toString() }, '*');
44762
+ safePostMessage({ type: 'monetag_ad_error', error: e.toString() });
44729
44763
  });
44730
44764
  } catch (e) {
44731
- window.parent.postMessage({ type: 'monetag_ad_error', error: e.toString() }, '*');
44765
+ safePostMessage({ type: 'monetag_ad_error', error: e.toString() });
44732
44766
  }
44733
44767
  <\/script>
44734
44768
  `;