@ab-org/predicate-market-sdk 2.2.0-beta.5 → 2.2.0-beta.8

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.
@@ -1,5 +1,5 @@
1
- import { getSDKConfig } from './chunk-BWKDIOBB.js';
2
- import './chunk-CGP7TSLF.js';
1
+ import { getSDKConfig } from './chunk-E3UPFA4K.js';
2
+ import './chunk-R2D3SM4S.js';
3
3
  import './chunk-UPMVYXZ6.js';
4
4
  import { sessionStore, createDefaultInjectedWalletRegistry, WalletConnector } from '@ab-org/sdk-core';
5
5
  import { CubistSocialProvider } from '@ab-org/sdk-core/social/provider';
@@ -10,10 +10,10 @@ var v = getEnv("RELAY_ORIGIN");
10
10
  function L(e) {
11
11
  return getEnv(e) || "";
12
12
  }
13
- var f = ({ url: e, name: g, width: r, height: t }) => {
13
+ var f = ({ url: e, name: l, width: r, height: t }) => {
14
14
  let i = (window.innerHeight - (t || 400)) / 2 + window.screenY, a = (window.innerWidth - (r || 400)) / 2 + window.screenX;
15
15
  try {
16
- let s = window.open(e, g, `dialog=yes,top=${i}px,left=${a},width=${r !== void 0 ? r : 400}px,height=${t !== void 0 ? t : 600}px`);
16
+ let s = window.open(e, l, `dialog=yes,top=${i}px,left=${a},width=${r !== void 0 ? r : 400}px,height=${t !== void 0 ? t : 600}px`);
17
17
  return s || null;
18
18
  } catch (s) {
19
19
  return console.error("Failed to open window:", s), null;
@@ -25,8 +25,8 @@ function $(e) {
25
25
  if (/^https?:\/\//.test(e)) return e.replace(/\/$/, "");
26
26
  throw new Error(`Unsupported CubeSigner env: ${e}`);
27
27
  }
28
- var O = async (e, g, r) => {
29
- let t = await fetch(`${$(g)}/v0/org/${encodeURIComponent(r)}/oidc/email-otp`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ email: e }) });
28
+ var O = async (e, l, r) => {
29
+ let t = await fetch(`${$(l)}/v0/org/${encodeURIComponent(r)}/oidc/email-otp`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ email: e }) });
30
30
  if (!t.ok) {
31
31
  let a = await t.text().catch(() => "");
32
32
  throw new Error(a ? `Email login failed (${t.status}): ${a}` : `Email login failed (${t.status})`);
@@ -35,25 +35,25 @@ var O = async (e, g, r) => {
35
35
  if (!i.partial_token) throw new Error("Email login response missing partial_token");
36
36
  return i.partial_token;
37
37
  };
38
- var Y = ({ stage: e, xClientId: g, googleClientId: r }) => {
39
- let t = v;
40
- if (window.location.hostname === "localhost" && (t = window.location.origin), !t) throw new Error("Invalid stage");
38
+ var Y = ({ stage: e, xClientId: l, googleClientId: r }) => {
39
+ let t = window.location.origin || v;
40
+ if (!t) throw new Error("Invalid stage");
41
41
  let i = `${t}/relay/x`, a = `${t}/relay/google`, s = S[e], E = C;
42
42
  if (!E) throw new Error("Invalid cube stage");
43
- let y = (o, l = 12e4) => new Promise((c, n) => {
43
+ let y = (o, g = 12e4) => new Promise((c, n) => {
44
44
  if (!o) {
45
45
  n(new Error("Failed to open popup"));
46
46
  return;
47
47
  }
48
48
  let m = setTimeout(() => {
49
49
  o.close(), n(new Error("Login timeout"));
50
- }, l), d = async (p) => {
50
+ }, g), d = async (p) => {
51
51
  if (p.origin !== t || p.data.action !== "login") return;
52
52
  let { data: I } = p.data;
53
53
  try {
54
- let { oidcToken: u = "", error: h } = I || {};
55
- if (h) {
56
- clearTimeout(m), window.removeEventListener("message", d), o.close(), n(new Error(String(h)));
54
+ let { oidcToken: u = "", error: b } = I || {};
55
+ if (b) {
56
+ clearTimeout(m), window.removeEventListener("message", d), o.close(), n(new Error(String(b)));
57
57
  return;
58
58
  }
59
59
  u && (clearTimeout(m), window.removeEventListener("message", d), o.close(), c(u));
@@ -67,10 +67,10 @@ var Y = ({ stage: e, xClientId: g, googleClientId: r }) => {
67
67
  }, 400);
68
68
  });
69
69
  return { loginByGoogle: async () => {
70
- let l = { target: window.location.origin, stage: e, eventId: Date.now().toString(), action: "login", clientId: r }, c = `${a}?${new URLSearchParams(l).toString()}`, n = f({ url: c, name: "Google login" });
70
+ let g = { target: window.location.origin, stage: e, eventId: Date.now().toString(), action: "login", clientId: r }, c = `${a}?${new URLSearchParams(g).toString()}`, n = f({ url: c, name: "Google login" });
71
71
  return await y(n);
72
72
  }, loginByX: async () => {
73
- let l = { target: window.location.origin, stage: e, eventId: Date.now().toString(), action: "login", clientId: g }, c = `${i}?${new URLSearchParams(l).toString()}`, n = f({ url: c, name: "X login" });
73
+ let g = { target: window.location.origin, stage: e, eventId: Date.now().toString(), action: "login", clientId: l }, c = `${i}?${new URLSearchParams(g).toString()}`, n = f({ url: c, name: "X login" });
74
74
  return await y(n);
75
75
  }, loginByEmail: async (o) => {
76
76
  if (!R(o)) throw new Error("Invalid email");
@@ -78,4 +78,4 @@ var Y = ({ stage: e, xClientId: g, googleClientId: r }) => {
78
78
  } };
79
79
  };
80
80
 
81
- export { w as CubeEnvs, C as CubeOrgId, S as CubeStages, x as EmailCodeLifeTime, Y as OidcAuth, _ as RelayMessageTypes, v as RelayOrigin, O as emailLogin, L as getPredicateCubeRegisterPath };
81
+ export { C, L, O, S, Y, _, v, w, x };
@@ -1,6 +1,6 @@
1
- import { getChainInfo, getFundingTokenAddress, DEFAULT_FUNDING_CHAIN_ID } from './chunk-NTFBZNCV.js';
2
- import { getChains, createOrder } from './chunk-HNL3SLGU.js';
3
- import { getEnv } from './chunk-CGP7TSLF.js';
1
+ import { getChainInfo, getFundingTokenAddress, DEFAULT_FUNDING_CHAIN_ID } from './chunk-6AZQBNMY.js';
2
+ import { getChains, createOrder } from './chunk-E65LLR2W.js';
3
+ import { getEnv } from './chunk-R2D3SM4S.js';
4
4
  import { sessionStore, createSessionCapabilityPolicy } from '@ab-org/sdk-core';
5
5
  import { formatUnits } from 'viem';
6
6
 
@@ -246,9 +246,11 @@ async function fetchFundingTokenBalance(walletAddress, options) {
246
246
  const FUNDING_TOKEN_SYMBOL = getEnv("FUNDING_TOKEN_SYMBOL");
247
247
  const displaySymbol = options?.displaySymbol ?? (FUNDING_TOKEN_SYMBOL || "Funding");
248
248
  const raw = await fetchErc20Balance(rpcUrl, tokenAddress, walletAddress);
249
+ const fullPrecision = formatUnits2(raw, decimals);
249
250
  return {
250
251
  raw,
251
252
  formatted: formatBalanceDisplay(raw, decimals),
253
+ fullPrecision,
252
254
  symbol: displaySymbol
253
255
  };
254
256
  }
@@ -1,4 +1,4 @@
1
- import { getEnv } from './chunk-CGP7TSLF.js';
1
+ import { getEnv } from './chunk-R2D3SM4S.js';
2
2
 
3
3
  // src/constants/chains.ts
4
4
  var TENDERLY_BSC_3131 = {
@@ -1,8 +1,9 @@
1
1
  import { getExplorerUrl } from './chunk-XB2DFS2W.js';
2
- import { getChains, registerPlatform, quote, getWithdrawOrder } from './chunk-HNL3SLGU.js';
3
- import { getEnv } from './chunk-CGP7TSLF.js';
2
+ import { getChains, registerPlatform, quote, getWithdrawOrder } from './chunk-E65LLR2W.js';
3
+ import { getEnv } from './chunk-R2D3SM4S.js';
4
4
  import { clientIds, stage } from './chunk-SV3NR2LW.js';
5
5
  import { getSDKConfig } from './chunk-UPMVYXZ6.js';
6
+ import { Y } from './chunk-26R46ZBM.js';
6
7
  import { cache_exports } from './chunk-YX56ZGDB.js';
7
8
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
8
9
  import { useEffect, useState, useRef, useMemo, useCallback } from 'react';
@@ -225,7 +226,7 @@ async function loadWalletAccount() {
225
226
  return import('./account-6PGNCFOX.js');
226
227
  }
227
228
  async function loadOidcAuth() {
228
- return import('./dist-Q2PDXT2F.js');
229
+ return import('./dist-C3ENWBQI.js');
229
230
  }
230
231
  var SignInModalFrame = ({ id, title, onClose, footer, children }) => {
231
232
  const isMobile = useIsMobileViewport();
@@ -303,14 +304,10 @@ var useSignInModalController = ({ wallets, initialVisibleCount, onGoogleLogin: _
303
304
  const showExpandToggle = resolvedWallets.length > initialVisibleCount;
304
305
  const visibleWallets = expanded ? resolvedWallets : resolvedWallets.slice(0, initialVisibleCount);
305
306
  const isBusy = !!loadingProvider || !!loadingWalletId;
306
- async function loadOidcAuth2() {
307
- return import('./dist-Q2PDXT2F.js');
308
- }
309
307
  const handleSocialClick = async (providerId) => {
310
308
  setLoadingProvider(providerId);
311
309
  const cfg = getSDKConfig();
312
- const { OidcAuth } = await loadOidcAuth2();
313
- const { loginByX, loginByGoogle } = OidcAuth({
310
+ const { loginByX, loginByGoogle } = Y({
314
311
  stage,
315
312
  xClientId: cfg.twitterClientId ?? clientIds.x ?? "",
316
313
  googleClientId: cfg.googleClientId ?? clientIds.google ?? ""
@@ -479,7 +476,8 @@ var SignInModal = ({ title = "Welcome to PredicateMarket", socialProviders, wall
479
476
  capabilities: CUBIST_CAPABILITIES,
480
477
  sessionData: cubeSignerSession.sessionData,
481
478
  chainContext: createChainContext(chain),
482
- capabilityPolicy
479
+ capabilityPolicy,
480
+ userInfo: cubeSignerSession.userInfo
483
481
  };
484
482
  persistSocialAdapterId();
485
483
  sessionStore.setSession(session);
@@ -1634,9 +1632,6 @@ var DepositModal = ({
1634
1632
  onShowToast("Transfer confirmed");
1635
1633
  }
1636
1634
  }, [txHash, chain, onShowToast]);
1637
- if (!session) {
1638
- return /* @__PURE__ */ jsx(LoginRequiredOverlay, { title: "Deposit", onSignIn, onClose });
1639
- }
1640
1635
  const goToEntry = () => {
1641
1636
  setView("entry");
1642
1637
  onBack?.();
@@ -1651,6 +1646,9 @@ var DepositModal = ({
1651
1646
  const t = setTimeout(() => setCopySuccessMessage(null), 2e3);
1652
1647
  return () => clearTimeout(t);
1653
1648
  }, [copySuccessMessage]);
1649
+ if (!session) {
1650
+ return /* @__PURE__ */ jsx(LoginRequiredOverlay, { title: "Deposit", onSignIn, onClose });
1651
+ }
1654
1652
  return /* @__PURE__ */ jsxs(
1655
1653
  ModalFrame2,
1656
1654
  {
@@ -2246,9 +2244,12 @@ function chainsToTokenOptions2(chains) {
2246
2244
  function chainsToChainOptionsForToken2(chains, tokenSymbol) {
2247
2245
  return chains.filter((c) => c.tokens.some((t) => t.symbol === tokenSymbol)).map((c) => ({ id: c.chain_id, label: c.network, subtitle: c.chain_id }));
2248
2246
  }
2249
- function getTokenAddressForChain2(chains, chainId, tokenSymbol) {
2247
+ function getTokenMetaForChain(chains, chainId, tokenSymbol) {
2250
2248
  const chain = chains.find((c) => c.chain_id === chainId);
2251
- return chain?.tokens.find((t) => t.symbol === tokenSymbol)?.address;
2249
+ return chain?.tokens.find((t) => t.symbol === tokenSymbol);
2250
+ }
2251
+ function getTokenAddressForChain2(chains, chainId, tokenSymbol) {
2252
+ return getTokenMetaForChain(chains, chainId, tokenSymbol)?.address;
2252
2253
  }
2253
2254
  function parseBalanceNumber(balance) {
2254
2255
  const match = balance.trim().match(/^(\d*\.?\d*)/);
@@ -2266,17 +2267,45 @@ function formatBalanceTo2Decimals(balance) {
2266
2267
  const formatted = n.toFixed(2);
2267
2268
  return formatted + suffix;
2268
2269
  }
2269
- function weiToEtherDisplay(wei) {
2270
- const s = (wei || "0").trim().replace(/^0+/, "") || "0";
2270
+ function formatBaseUnitAmount(value, decimals = 18) {
2271
+ const trimmed = (value || "0").trim();
2272
+ if (!/^\d+$/.test(trimmed)) return value;
2273
+ const s = trimmed.replace(/^0+/, "") || "0";
2271
2274
  if (s === "0") return "0";
2272
- const padded = s.padStart(19, "0");
2273
- const intPart = padded.slice(0, Math.max(0, padded.length - 18));
2274
- const decPart = padded.slice(-18).replace(/0+$/, "");
2275
- const combined = decPart ? `${intPart}.${decPart}` : intPart;
2276
- const num = Number(combined);
2277
- if (Number.isNaN(num)) return wei;
2278
- const fixed = num.toFixed(6).replace(/\.?0+$/, "");
2279
- return fixed;
2275
+ if (decimals <= 0) return s;
2276
+ const padded = s.padStart(decimals + 1, "0");
2277
+ const splitIndex = padded.length - decimals;
2278
+ const intPart = padded.slice(0, splitIndex).replace(/^0+(?=\d)/, "") || "0";
2279
+ const decPart = padded.slice(splitIndex).replace(/0+$/, "");
2280
+ const visibleDecimals = decPart.slice(0, 6).replace(/0+$/, "");
2281
+ return visibleDecimals ? `${intPart}.${visibleDecimals}` : intPart;
2282
+ }
2283
+ function formatDecimalAmount(value, maxDecimals = 6) {
2284
+ if (!Number.isFinite(value)) return "";
2285
+ if (value === 0) return "0";
2286
+ return value.toFixed(maxDecimals).replace(/\.?0+$/, "");
2287
+ }
2288
+ function multiplyDecimalStringsToBaseUnits(left, right, decimals) {
2289
+ const normalize = (input) => {
2290
+ const trimmed = input.trim();
2291
+ const match = trimmed.match(/^(\d+)(?:\.(\d+))?$/);
2292
+ if (!match) return null;
2293
+ const intPart = match[1] ?? "0";
2294
+ const fracPart = match[2] ?? "";
2295
+ return {
2296
+ digits: BigInt(`${intPart}${fracPart}`),
2297
+ scale: fracPart.length
2298
+ };
2299
+ };
2300
+ const a = normalize(left);
2301
+ const b = normalize(right);
2302
+ if (!a || !b || decimals < 0) return void 0;
2303
+ const product = a.digits * b.digits;
2304
+ const totalScale = a.scale + b.scale;
2305
+ if (decimals >= totalScale) {
2306
+ return (product * 10n ** BigInt(decimals - totalScale)).toString();
2307
+ }
2308
+ return (product / 10n ** BigInt(totalScale - decimals)).toString();
2280
2309
  }
2281
2310
  function findScrollableAncestor(node) {
2282
2311
  let current = node?.parentElement ?? null;
@@ -2296,6 +2325,7 @@ var WithdrawModal = ({
2296
2325
  chain,
2297
2326
  amount = "",
2298
2327
  balance,
2328
+ balanceMax,
2299
2329
  status = "idle",
2300
2330
  receiveAmount: receiveAmountProp,
2301
2331
  txHash,
@@ -2344,6 +2374,14 @@ var WithdrawModal = ({
2344
2374
  if (!apiChains?.length || !token || !chain) return void 0;
2345
2375
  return getTokenAddressForChain2(apiChains, chain, token);
2346
2376
  }, [apiChains, token, chain]);
2377
+ const destinationTokenDecimals = useMemo(() => {
2378
+ if (!token) return apiQuote?.token_decimals ?? 18;
2379
+ const targetChainId = withdrawOrder?.target_chain_id ?? chain;
2380
+ if (apiChains?.length && targetChainId) {
2381
+ return getTokenMetaForChain(apiChains, targetChainId, token)?.decimals ?? apiQuote?.token_decimals ?? 18;
2382
+ }
2383
+ return apiQuote?.token_decimals ?? 18;
2384
+ }, [apiChains, apiQuote?.token_decimals, chain, token, withdrawOrder?.target_chain_id]);
2347
2385
  const [directActive, setDirectActive] = useState(false);
2348
2386
  useEffect(() => {
2349
2387
  setDirectActive(withdrawMode === "direct" && Boolean(withdrawDirectResult));
@@ -2382,7 +2420,7 @@ var WithdrawModal = ({
2382
2420
  direction: "withdraw",
2383
2421
  chain_id: chain,
2384
2422
  token_address: tokenAddress,
2385
- dst_token_amount: amountWei
2423
+ token_amount: amountWei
2386
2424
  }).then((q) => setApiQuote(q ?? null)).catch(() => {
2387
2425
  setApiQuote({
2388
2426
  token_address: tokenAddress,
@@ -2391,6 +2429,7 @@ var WithdrawModal = ({
2391
2429
  rate: "1",
2392
2430
  chain_id: Number(chain) || 56,
2393
2431
  token_amount: amountWei,
2432
+ dst_token_amount: amountWei,
2394
2433
  expires_at: new Date(Date.now() + 6e4).toISOString()
2395
2434
  });
2396
2435
  }).finally(() => setLoadingQuote(false));
@@ -2433,6 +2472,15 @@ var WithdrawModal = ({
2433
2472
  if (!orderId && directActive) {
2434
2473
  const now = (/* @__PURE__ */ new Date()).toISOString();
2435
2474
  const inferredAmountWei = (() => {
2475
+ if (apiQuote?.dst_token_amount) return apiQuote.dst_token_amount;
2476
+ if (amount && apiQuote?.rate) {
2477
+ const quotedAmountWei = multiplyDecimalStringsToBaseUnits(
2478
+ amount,
2479
+ apiQuote.rate,
2480
+ apiQuote.token_decimals ?? 18
2481
+ );
2482
+ if (quotedAmountWei) return quotedAmountWei;
2483
+ }
2436
2484
  if (withdrawDirectResult?.dst_token_amount) return withdrawDirectResult.dst_token_amount;
2437
2485
  const n = Number(amount || "0");
2438
2486
  return String(n > 0 ? BigInt(Math.floor(n * 1e18)) : 0n);
@@ -2456,7 +2504,7 @@ var WithdrawModal = ({
2456
2504
  return;
2457
2505
  }
2458
2506
  setWithdrawOrder(null);
2459
- }, [orderId, directActive, withdrawDirectResult, amount, feeDisplay, chain, address, txHash, fundingChainId, onShowToast, mockWithdrawOrderState]);
2507
+ }, [orderId, directActive, withdrawDirectResult, amount, apiQuote, feeDisplay, chain, address, txHash, fundingChainId, onShowToast, mockWithdrawOrderState]);
2460
2508
  const completedKeyRef = useRef(null);
2461
2509
  const successToastKeyRef = useRef(null);
2462
2510
  useEffect(() => {
@@ -2485,11 +2533,33 @@ var WithdrawModal = ({
2485
2533
  if (!Number.isNaN(n)) return n.toFixed(2);
2486
2534
  return receiveAmountProp;
2487
2535
  }
2488
- if (!apiQuote?.token_amount || !apiQuote?.token_symbol) return void 0;
2489
- const amount2 = Number(apiQuote.token_amount);
2490
- const formatted = Number.isNaN(amount2) ? apiQuote.token_amount : amount2.toFixed(2);
2491
- return `\u2248 ${formatted} (wei) ${apiQuote.token_symbol}`;
2536
+ const rawAmount = apiQuote?.dst_token_amount ?? apiQuote?.token_amount;
2537
+ if (!rawAmount || !apiQuote?.token_symbol) return void 0;
2538
+ const formatted = formatBaseUnitAmount(rawAmount, apiQuote.token_decimals ?? 18);
2539
+ return `\u2248 ${formatted} ${apiQuote.token_symbol}`;
2492
2540
  }, [receiveAmountProp, apiQuote]);
2541
+ const displayReceiveAmount = useMemo(() => {
2542
+ if (receiveAmount) return receiveAmount;
2543
+ if (!amount || !apiQuote?.token_symbol || !apiQuote?.rate) return void 0;
2544
+ const fundingAmount = Number(amount);
2545
+ const rate = Number(apiQuote.rate);
2546
+ if (!Number.isFinite(fundingAmount) || fundingAmount <= 0 || !Number.isFinite(rate) || rate <= 0) {
2547
+ return void 0;
2548
+ }
2549
+ return `\u2248 ${formatDecimalAmount(fundingAmount * rate)} ${apiQuote.token_symbol}`;
2550
+ }, [amount, apiQuote?.rate, apiQuote?.token_symbol, receiveAmount]);
2551
+ const successAmountDisplay = useMemo(() => {
2552
+ if (displayReceiveAmount) {
2553
+ return displayReceiveAmount.replace(/^≈\s*/, "");
2554
+ }
2555
+ if (!withdrawOrder?.dst_token_amount) return void 0;
2556
+ return `${formatBaseUnitAmount(withdrawOrder.dst_token_amount, destinationTokenDecimals)} ${tokenSymbol}`;
2557
+ }, [
2558
+ destinationTokenDecimals,
2559
+ displayReceiveAmount,
2560
+ tokenSymbol,
2561
+ withdrawOrder?.dst_token_amount
2562
+ ]);
2493
2563
  const quoteExpired = useMemo(() => {
2494
2564
  if (!apiQuote?.expires_at) return false;
2495
2565
  try {
@@ -2509,7 +2579,7 @@ var WithdrawModal = ({
2509
2579
  direction: "withdraw",
2510
2580
  chain_id: chain,
2511
2581
  token_address: tokenAddress,
2512
- dst_token_amount: amountWei
2582
+ token_amount: amountWei
2513
2583
  }).then((q) => setApiQuote(q ?? null)).catch(() => {
2514
2584
  setApiQuote({
2515
2585
  token_address: tokenAddress,
@@ -2518,6 +2588,7 @@ var WithdrawModal = ({
2518
2588
  rate: "1",
2519
2589
  chain_id: Number(chain) || 56,
2520
2590
  token_amount: amountWei,
2591
+ dst_token_amount: amountWei,
2521
2592
  expires_at: new Date(Date.now() + 6e4).toISOString()
2522
2593
  });
2523
2594
  }).finally(() => setLoadingQuote(false));
@@ -2525,7 +2596,7 @@ var WithdrawModal = ({
2525
2596
  const handleAmountChange = useCallback(
2526
2597
  (e) => {
2527
2598
  const raw = e.target.value;
2528
- const maxNum = balance ? parseBalanceNumber(balance) : null;
2599
+ const maxNum = parseBalanceNumber(balanceMax ?? balance ?? "");
2529
2600
  if (maxNum != null && raw !== "" && raw !== ".") {
2530
2601
  const num = Number(raw);
2531
2602
  if (!Number.isNaN(num) && num > maxNum) {
@@ -2768,11 +2839,7 @@ var WithdrawModal = ({
2768
2839
  children: [
2769
2840
  /* @__PURE__ */ jsxs("div", { className: "absdk-predicate-withdraw-modal__summary-row absdk-predicate-withdraw-modal__summary-row--amount", style: { display: "flex", justifyContent: "space-between", alignItems: "center", padding: isMobile ? "6px 0" : "8px 0", height: isMobile ? 29 : 36 }, children: [
2770
2841
  /* @__PURE__ */ jsx("span", { className: "absdk-predicate-withdraw-modal__summary-label", style: { fontSize: 14, lineHeight: 1.4, color: colors2.textSecondary }, children: "Amount" }),
2771
- /* @__PURE__ */ jsxs("span", { className: "absdk-predicate-withdraw-modal__summary-value", style: { fontSize: 14, lineHeight: 1.4, color: colors2.textPrimary }, children: [
2772
- weiToEtherDisplay(withdrawOrder.dst_token_amount),
2773
- " ",
2774
- tokenSymbol
2775
- ] })
2842
+ /* @__PURE__ */ jsx("span", { className: "absdk-predicate-withdraw-modal__summary-value", style: { fontSize: 14, lineHeight: 1.4, color: colors2.textPrimary }, children: successAmountDisplay ?? "\u2014" })
2776
2843
  ] }),
2777
2844
  /* @__PURE__ */ jsxs("div", { className: "absdk-predicate-withdraw-modal__summary-row absdk-predicate-withdraw-modal__summary-row--fee", style: { display: "flex", justifyContent: "space-between", alignItems: "center", padding: isMobile ? "6px 0" : "8px 0", height: isMobile ? 29 : 36 }, children: [
2778
2845
  /* @__PURE__ */ jsx("span", { className: "absdk-predicate-withdraw-modal__summary-label", style: { fontSize: 14, lineHeight: 1.4, color: colors2.textSecondary }, children: "Fee" }),
@@ -3127,10 +3194,10 @@ var WithdrawModal = ({
3127
3194
  ]
3128
3195
  }
3129
3196
  ),
3130
- !orderSucceeded && /* @__PURE__ */ jsxs("span", { className: "absdk-predicate-withdraw-modal__receive-amount", style: { fontSize: 14, lineHeight: 1.4, color: colors2.textPrimary, opacity: !trackingWithdraw && amount && Number(amount) > 0 ? 1 : 0 }, children: [
3197
+ !orderSucceeded && /* @__PURE__ */ jsxs("span", { className: "absdk-predicate-withdraw-modal__receive-amount", style: { fontSize: 14, lineHeight: 1.4, color: colors2.textPrimary, opacity: !trackingWithdraw && displayReceiveAmount ? 1 : 0 }, children: [
3131
3198
  /* @__PURE__ */ jsx("span", { className: "absdk-predicate-withdraw-modal__receive-amount-label", children: "You will receive :" }),
3132
3199
  " ",
3133
- /* @__PURE__ */ jsx("span", { className: "absdk-predicate-withdraw-modal__receive-amount-value", children: receiveAmount })
3200
+ /* @__PURE__ */ jsx("span", { className: "absdk-predicate-withdraw-modal__receive-amount-value", children: displayReceiveAmount })
3134
3201
  ] })
3135
3202
  ] }) })
3136
3203
  ]
@@ -1,8 +1,7 @@
1
- import { getOptionalEnv, setMerchantBaseUrl } from './chunk-CGP7TSLF.js';
1
+ import { getOptionalEnv, setMerchantBaseUrl } from './chunk-R2D3SM4S.js';
2
2
  import { getSDKConfig, initSDK } from './chunk-UPMVYXZ6.js';
3
- import { sessionStore } from '@ab-org/sdk-core';
4
- import { refreshCubeSignerSessionData } from '@ab-org/sdk-core/social/auth';
5
3
  import axios from 'axios';
4
+ import { sessionStore } from '@ab-org/sdk-core';
6
5
 
7
6
  // src/auth/bundledConfig.ts
8
7
  function getBundledAuthConfig() {
@@ -10,6 +9,7 @@ function getBundledAuthConfig() {
10
9
  const cubeEnv = getOptionalEnv("CUBE_SIGNER_ENV");
11
10
  const cubeOrgId = getOptionalEnv("CUBE_SIGNER_ORG_ID");
12
11
  const cubeLifetimes = getOptionalEnv("CUBE_SIGNER_LIFETIMES");
12
+ const lifetime = cubeLifetimes ? parseInt(cubeLifetimes) : 604800;
13
13
  return {
14
14
  googleClientId: getOptionalEnv("GOOGLE_CLIENT_ID"),
15
15
  twitterClientId: getOptionalEnv("X_CLIENT_ID"),
@@ -18,9 +18,10 @@ function getBundledAuthConfig() {
18
18
  env: cubeEnv,
19
19
  orgId: cubeOrgId,
20
20
  lifetimes: cubeLifetimes == void 0 ? void 0 : {
21
- session: parseInt(cubeLifetimes),
22
- auth: parseInt(cubeLifetimes),
23
- refresh: parseInt(cubeLifetimes) * 2
21
+ session: lifetime,
22
+ auth: Math.min(86400, lifetime),
23
+ refresh: lifetime,
24
+ grace: 30
24
25
  }
25
26
  } : void 0
26
27
  };
@@ -89,62 +90,35 @@ async function defaultRegisterUser(oidcToken) {
89
90
  throw new Error(`User register failed: ${body?.message || body?.error || body.code}`);
90
91
  }
91
92
  }
92
-
93
- // src/auth/config.ts
94
93
  function getFixedAuthConfig() {
95
94
  const bundled = getBundledAuthConfig();
96
95
  return bundled;
97
96
  }
98
- var CUBE_KEEPALIVE_INTERVAL_MS = 5 * 60 * 1e3;
99
- function getCubistKeepAliveIntervalMs() {
100
- const rawValue = getOptionalEnv("CUBE_KEEPALIVE_INTERVAL_MS");
101
- if (!rawValue) return CUBE_KEEPALIVE_INTERVAL_MS;
102
- const parsed = Number.parseInt(rawValue, 10);
103
- return Number.isFinite(parsed) && parsed > 0 ? parsed : CUBE_KEEPALIVE_INTERVAL_MS;
104
- }
105
- var cubistKeepAliveTimer = null;
106
- var cubistKeepAlivePending = null;
107
97
  function isCubistSession(session) {
108
- if (!session?.sessionData) return false;
109
- return session.walletType === "social" || session.authSource === "google" || session.authSource === "twitter";
98
+ return Boolean(
99
+ session && session.sessionData && (session.walletType === "social" || session.authSource === "google" || session.authSource === "twitter")
100
+ );
110
101
  }
111
- function isAuthorizationError(error) {
112
- return error instanceof Error && /\(401\)|\(403\)/.test(error.message);
102
+ function notifyCubistSessionExpired(session) {
103
+ cubistSessionExpiredCallback?.(session);
113
104
  }
114
- async function refreshActiveCubistSession() {
115
- const session = sessionStore.getState().session;
116
- if (!isCubistSession(session)) return;
117
- try {
118
- const refreshedSessionData = await refreshCubeSignerSessionData(session.sessionData);
119
- const latestSession = sessionStore.getState().session;
120
- if (!latestSession || latestSession.sessionId !== session.sessionId) return;
121
- sessionStore.setSession({
122
- ...latestSession,
123
- sessionData: refreshedSessionData
124
- });
125
- } catch (error) {
126
- if (isAuthorizationError(error)) {
127
- sessionStore.clearSession();
128
- }
129
- }
105
+ var cubistSessionExpiredListenerCleanup = null;
106
+ var cubistSessionExpiredCallback;
107
+ function ensureCubistSessionExpiredListener() {
108
+ if (cubistSessionExpiredListenerCleanup) return;
109
+ cubistSessionExpiredListenerCleanup = sessionStore.on("session:expired", (session) => {
110
+ if (!isCubistSession(session)) return;
111
+ notifyCubistSessionExpired(session);
112
+ });
130
113
  }
131
114
  function scheduleAutoReconnect() {
132
115
  if (typeof window === "undefined") return;
133
- void import('./autoReconnect-STOYP7SX.js').then(({ tryAutoReconnect }) => tryAutoReconnect()).catch(() => {
116
+ void import('./autoReconnect-GHZLB233.js').then(({ tryAutoReconnect }) => tryAutoReconnect()).catch(() => {
134
117
  });
135
118
  }
136
- function scheduleCubistKeepAlive() {
137
- if (typeof window === "undefined") return;
138
- if (cubistKeepAliveTimer !== null) return;
139
- const keepAliveIntervalMs = getCubistKeepAliveIntervalMs();
140
- cubistKeepAliveTimer = window.setInterval(() => {
141
- cubistKeepAlivePending ?? (cubistKeepAlivePending = refreshActiveCubistSession().finally(() => {
142
- cubistKeepAlivePending = null;
143
- }));
144
- }, keepAliveIntervalMs);
145
- }
146
119
  function initSDK2(config = {}) {
147
- const { merchantBaseUrl, registerUser, ...rest } = config;
120
+ const { merchantBaseUrl, registerUser, onSessionExpired, ...rest } = config;
121
+ cubistSessionExpiredCallback = onSessionExpired;
148
122
  const fixed = getFixedAuthConfig();
149
123
  const prev = getSDKConfig();
150
124
  const merged = {
@@ -179,8 +153,10 @@ function initSDK2(config = {}) {
179
153
  setMerchantBaseUrl(merchantBaseUrl);
180
154
  }
181
155
  initSDK(merged);
156
+ ensureCubistSessionExpiredListener();
157
+ sessionStore.flushPendingExpiry();
158
+ sessionStore.startExpiryTimer();
182
159
  scheduleAutoReconnect();
183
- scheduleCubistKeepAlive();
184
160
  }
185
161
  function getSDKConfig2() {
186
162
  return getSDKConfig();
@@ -1,4 +1,4 @@
1
- import { setMerchantBaseUrl, getMerchantBaseUrl } from './chunk-CGP7TSLF.js';
1
+ import { setMerchantBaseUrl, getMerchantBaseUrl } from './chunk-R2D3SM4S.js';
2
2
  import axios from 'axios';
3
3
 
4
4
  var merchantApiConfig = {};
@@ -1,6 +1,6 @@
1
1
  // src/core.ts
2
2
  function tryAutoReconnect() {
3
- return import('./autoReconnect-STOYP7SX.js').then(({ tryAutoReconnect: reconnect }) => reconnect());
3
+ return import('./autoReconnect-GHZLB233.js').then(({ tryAutoReconnect: reconnect }) => reconnect());
4
4
  }
5
5
 
6
6
  export { tryAutoReconnect };
@@ -34,6 +34,8 @@ function readProcessEnvStatic(key) {
34
34
  process.env.NEXT_PUBLIC_CUBE_KEEPALIVE_INTERVAL_MS,
35
35
  process.env.CUBE_KEEPALIVE_INTERVAL_MS
36
36
  );
37
+ case "FUNDING_CHAIN_ID":
38
+ return pick(process.env.NEXT_PUBLIC_FUNDING_CHAIN_ID, process.env.FUNDING_CHAIN_ID) || "3131";
37
39
  case "FUNDING_TOKEN_SYMBOL":
38
40
  return pick(process.env.NEXT_PUBLIC_FUNDING_TOKEN_SYMBOL, process.env.FUNDING_TOKEN_SYMBOL) || "USDT";
39
41
  default:
package/dist/core.d.ts CHANGED
@@ -26,6 +26,7 @@ declare function getFixedAuthConfig(): Partial<SDKConfig>;
26
26
  interface PredicateSDKConfig extends Partial<SDKConfig> {
27
27
  merchantBaseUrl?: string;
28
28
  registerUser?: (oidcToken: string) => Promise<void>;
29
+ onSessionExpired?: (session: WalletSession) => void;
29
30
  }
30
31
  declare function initSDK(config?: PredicateSDKConfig): void;
31
32
  declare function getSDKConfig(): Readonly<SDKConfig>;
package/dist/core.js CHANGED
@@ -1,6 +1,6 @@
1
- export { tryAutoReconnect } from './chunk-63AEVWHE.js';
2
- export { ClientIds, DEFAULT_FUNDING_CHAIN_ID, DEFAULT_FUNDING_TOKEN_ADDRESS, getChainInfo, getFundingTokenAddress } from './chunk-NTFBZNCV.js';
1
+ export { tryAutoReconnect } from './chunk-GIPWCNYS.js';
2
+ export { ClientIds, DEFAULT_FUNDING_CHAIN_ID, DEFAULT_FUNDING_TOKEN_ADDRESS, getChainInfo, getFundingTokenAddress } from './chunk-6AZQBNMY.js';
3
3
  export { getExplorerUrl } from './chunk-XB2DFS2W.js';
4
- export { getFixedAuthConfig, getSDKConfig, initSDK } from './chunk-BWKDIOBB.js';
5
- export { getEnv } from './chunk-CGP7TSLF.js';
4
+ export { getFixedAuthConfig, getSDKConfig, initSDK } from './chunk-E3UPFA4K.js';
5
+ export { getEnv } from './chunk-R2D3SM4S.js';
6
6
  import './chunk-UPMVYXZ6.js';
@@ -0,0 +1,2 @@
1
+ export { w as CubeEnvs, C as CubeOrgId, S as CubeStages, x as EmailCodeLifeTime, Y as OidcAuth, _ as RelayMessageTypes, v as RelayOrigin, O as emailLogin, L as getPredicateCubeRegisterPath } from './chunk-26R46ZBM.js';
2
+ import './chunk-YX56ZGDB.js';
package/dist/index.js CHANGED
@@ -1,12 +1,13 @@
1
1
  export { notifyTwitterCallback } from './chunk-ZS6FNG2D.js';
2
- export { tryAutoReconnect } from './chunk-63AEVWHE.js';
3
- export { createDepositController, createFundingWithdrawExecutor, createMarketDataProvider, createPredicateMarketPolicyAdapter, createWithdrawController, fetchErc20Balance, fetchFundingTokenBalance, findTokenDataFromChains, isUsdtWithdrawDirect, parseUnits } from './chunk-UMSH3Z43.js';
4
- export { ClientIds, DEFAULT_FUNDING_CHAIN_ID, DEFAULT_FUNDING_TOKEN_ADDRESS, getChainInfo, getFundingTokenAddress } from './chunk-NTFBZNCV.js';
5
- export { DepositDetailsPanel, DepositModal, DropdownField, SignInModal, Toast, WalletAccount, WalletSelectionModal, WithdrawModal, clearSocialAccountInstance } from './chunk-GQV3VLAX.js';
2
+ export { tryAutoReconnect } from './chunk-GIPWCNYS.js';
3
+ export { createDepositController, createFundingWithdrawExecutor, createMarketDataProvider, createPredicateMarketPolicyAdapter, createWithdrawController, fetchErc20Balance, fetchFundingTokenBalance, findTokenDataFromChains, isUsdtWithdrawDirect, parseUnits } from './chunk-4XO4Z5TC.js';
4
+ export { ClientIds, DEFAULT_FUNDING_CHAIN_ID, DEFAULT_FUNDING_TOKEN_ADDRESS, getChainInfo, getFundingTokenAddress } from './chunk-6AZQBNMY.js';
5
+ export { DepositDetailsPanel, DepositModal, DropdownField, SignInModal, Toast, WalletAccount, WalletSelectionModal, WithdrawModal, clearSocialAccountInstance } from './chunk-BLUBNFON.js';
6
6
  export { getExplorerUrl } from './chunk-XB2DFS2W.js';
7
- export { configureMerchantApi, createOrder, getChains, getDepositOrder, getMerchantApiClient, getWithdrawOrder, quote, registerPlatform } from './chunk-HNL3SLGU.js';
8
- export { getFixedAuthConfig, getSDKConfig, initSDK } from './chunk-BWKDIOBB.js';
9
- export { getEnv } from './chunk-CGP7TSLF.js';
7
+ export { configureMerchantApi, createOrder, getChains, getDepositOrder, getMerchantApiClient, getWithdrawOrder, quote, registerPlatform } from './chunk-E65LLR2W.js';
8
+ export { getFixedAuthConfig, getSDKConfig, initSDK } from './chunk-E3UPFA4K.js';
9
+ export { getEnv } from './chunk-R2D3SM4S.js';
10
10
  import './chunk-SV3NR2LW.js';
11
11
  import './chunk-UPMVYXZ6.js';
12
+ import './chunk-26R46ZBM.js';
12
13
  import './chunk-YX56ZGDB.js';
@@ -77,6 +77,7 @@ declare function createMarketDataProvider(): MarketDataProvider;
77
77
  interface Erc20BalanceResult {
78
78
  raw: bigint;
79
79
  formatted: string;
80
+ fullPrecision: string;
80
81
  symbol: string;
81
82
  }
82
83
  /**
package/dist/merchant.js CHANGED
@@ -1,4 +1,4 @@
1
- export { createDepositController, createFundingWithdrawExecutor, createMarketDataProvider, createPredicateMarketPolicyAdapter, createWithdrawController, fetchErc20Balance, fetchFundingTokenBalance, findTokenDataFromChains, isUsdtWithdrawDirect, parseUnits } from './chunk-UMSH3Z43.js';
2
- import './chunk-NTFBZNCV.js';
3
- export { configureMerchantApi, createOrder, getChains, getDepositOrder, getMerchantApiClient, getWithdrawOrder, quote, registerPlatform } from './chunk-HNL3SLGU.js';
4
- import './chunk-CGP7TSLF.js';
1
+ export { createDepositController, createFundingWithdrawExecutor, createMarketDataProvider, createPredicateMarketPolicyAdapter, createWithdrawController, fetchErc20Balance, fetchFundingTokenBalance, findTokenDataFromChains, isUsdtWithdrawDirect, parseUnits } from './chunk-4XO4Z5TC.js';
2
+ import './chunk-6AZQBNMY.js';
3
+ export { configureMerchantApi, createOrder, getChains, getDepositOrder, getMerchantApiClient, getWithdrawOrder, quote, registerPlatform } from './chunk-E65LLR2W.js';
4
+ import './chunk-R2D3SM4S.js';
package/dist/react.d.ts CHANGED
@@ -137,6 +137,7 @@ interface WithdrawModalProps {
137
137
  chain?: string;
138
138
  amount?: string;
139
139
  balance?: string;
140
+ balanceMax?: string;
140
141
  status?: WithdrawUiStatus;
141
142
  receiveAmount?: string;
142
143
  txHash?: string;
@@ -182,7 +183,7 @@ interface WithdrawModalProps {
182
183
  onSignIn?: () => void;
183
184
  onClose?: () => void;
184
185
  }
185
- declare const WithdrawModal: ({ address, token, tokenSymbol, chain, amount, balance, status, receiveAmount: receiveAmountProp, txHash, tokenOptions: tokenOptionsProp, chainOptions: chainOptionsProp, useMerchantApi, orderId, withdrawMode, withdrawDirectResult, feeDisplay, fundingChainId, onShowToast, onAddressChange, onTokenSelect, onChainSelect, onAmountChange, onMaxClick, onSubmit, onWithdrawCompleted, onStartAnotherWithdrawal, onSignIn, onClose, }: WithdrawModalProps) => react_jsx_runtime.JSX.Element;
186
+ declare const WithdrawModal: ({ address, token, tokenSymbol, chain, amount, balance, balanceMax, status, receiveAmount: receiveAmountProp, txHash, tokenOptions: tokenOptionsProp, chainOptions: chainOptionsProp, useMerchantApi, orderId, withdrawMode, withdrawDirectResult, feeDisplay, fundingChainId, onShowToast, onAddressChange, onTokenSelect, onChainSelect, onAmountChange, onMaxClick, onSubmit, onWithdrawCompleted, onStartAnotherWithdrawal, onSignIn, onClose, }: WithdrawModalProps) => react_jsx_runtime.JSX.Element;
186
187
 
187
188
  interface DepositDetailsPanelProps {
188
189
  address: string;
package/dist/react.js CHANGED
@@ -1,7 +1,8 @@
1
- export { DepositDetailsPanel, DepositModal, DropdownField, SignInModal, Toast, WalletAccount, WalletSelectionModal, WithdrawModal, clearSocialAccountInstance } from './chunk-GQV3VLAX.js';
1
+ export { DepositDetailsPanel, DepositModal, DropdownField, SignInModal, Toast, WalletAccount, WalletSelectionModal, WithdrawModal, clearSocialAccountInstance } from './chunk-BLUBNFON.js';
2
2
  import './chunk-XB2DFS2W.js';
3
- import './chunk-HNL3SLGU.js';
4
- import './chunk-CGP7TSLF.js';
3
+ import './chunk-E65LLR2W.js';
4
+ import './chunk-R2D3SM4S.js';
5
5
  import './chunk-SV3NR2LW.js';
6
6
  import './chunk-UPMVYXZ6.js';
7
+ import './chunk-26R46ZBM.js';
7
8
  import './chunk-YX56ZGDB.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ab-org/predicate-market-sdk",
3
- "version": "2.2.0-beta.5",
3
+ "version": "2.2.0-beta.8",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist/**/*",
@@ -39,7 +39,7 @@
39
39
  "axios": "^1.13.6",
40
40
  "qrcode-generator": "^2.0.4",
41
41
  "viem": "2.21.54",
42
- "@ab-org/sdk-core": "0.3.0-beta.3"
42
+ "@ab-org/sdk-core": "0.3.0-beta.6"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "react": ">=18"
@@ -48,10 +48,10 @@
48
48
  "@types/react": "^18.2.66",
49
49
  "typescript": "^5.5.4",
50
50
  "tsup": "^8.5.1",
51
- "@ab-org/chains-service": "0.0.8",
52
51
  "@ab-org/oidc-auth": "0.0.16",
52
+ "@ab-org/chains-service": "0.0.8",
53
53
  "@ab-org/sign-in-sdk": "0.1.0",
54
- "@ab-org/wallet-utils": "0.0.7"
54
+ "@ab-org/wallet-utils": "0.1.0-beta.1"
55
55
  },
56
56
  "scripts": {
57
57
  "build": "pnpm exec tsup",