@ab-org/predicate-market-sdk 2.2.0-beta.5 → 2.2.0-beta.6
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/{chunk-GQV3VLAX.js → chunk-IVPLOLGZ.js} +96 -27
- package/dist/index.js +1 -1
- package/dist/react.js +1 -1
- package/package.json +2 -2
|
@@ -479,7 +479,8 @@ var SignInModal = ({ title = "Welcome to PredicateMarket", socialProviders, wall
|
|
|
479
479
|
capabilities: CUBIST_CAPABILITIES,
|
|
480
480
|
sessionData: cubeSignerSession.sessionData,
|
|
481
481
|
chainContext: createChainContext(chain),
|
|
482
|
-
capabilityPolicy
|
|
482
|
+
capabilityPolicy,
|
|
483
|
+
userInfo: cubeSignerSession.userInfo
|
|
483
484
|
};
|
|
484
485
|
persistSocialAdapterId();
|
|
485
486
|
sessionStore.setSession(session);
|
|
@@ -2246,9 +2247,12 @@ function chainsToTokenOptions2(chains) {
|
|
|
2246
2247
|
function chainsToChainOptionsForToken2(chains, tokenSymbol) {
|
|
2247
2248
|
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
2249
|
}
|
|
2249
|
-
function
|
|
2250
|
+
function getTokenMetaForChain(chains, chainId, tokenSymbol) {
|
|
2250
2251
|
const chain = chains.find((c) => c.chain_id === chainId);
|
|
2251
|
-
return chain?.tokens.find((t) => t.symbol === tokenSymbol)
|
|
2252
|
+
return chain?.tokens.find((t) => t.symbol === tokenSymbol);
|
|
2253
|
+
}
|
|
2254
|
+
function getTokenAddressForChain2(chains, chainId, tokenSymbol) {
|
|
2255
|
+
return getTokenMetaForChain(chains, chainId, tokenSymbol)?.address;
|
|
2252
2256
|
}
|
|
2253
2257
|
function parseBalanceNumber(balance) {
|
|
2254
2258
|
const match = balance.trim().match(/^(\d*\.?\d*)/);
|
|
@@ -2266,17 +2270,45 @@ function formatBalanceTo2Decimals(balance) {
|
|
|
2266
2270
|
const formatted = n.toFixed(2);
|
|
2267
2271
|
return formatted + suffix;
|
|
2268
2272
|
}
|
|
2269
|
-
function
|
|
2270
|
-
const
|
|
2273
|
+
function formatBaseUnitAmount(value, decimals = 18) {
|
|
2274
|
+
const trimmed = (value || "0").trim();
|
|
2275
|
+
if (!/^\d+$/.test(trimmed)) return value;
|
|
2276
|
+
const s = trimmed.replace(/^0+/, "") || "0";
|
|
2271
2277
|
if (s === "0") return "0";
|
|
2272
|
-
|
|
2273
|
-
const
|
|
2274
|
-
const
|
|
2275
|
-
const
|
|
2276
|
-
const
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2278
|
+
if (decimals <= 0) return s;
|
|
2279
|
+
const padded = s.padStart(decimals + 1, "0");
|
|
2280
|
+
const splitIndex = padded.length - decimals;
|
|
2281
|
+
const intPart = padded.slice(0, splitIndex).replace(/^0+(?=\d)/, "") || "0";
|
|
2282
|
+
const decPart = padded.slice(splitIndex).replace(/0+$/, "");
|
|
2283
|
+
const visibleDecimals = decPart.slice(0, 6).replace(/0+$/, "");
|
|
2284
|
+
return visibleDecimals ? `${intPart}.${visibleDecimals}` : intPart;
|
|
2285
|
+
}
|
|
2286
|
+
function formatDecimalAmount(value, maxDecimals = 6) {
|
|
2287
|
+
if (!Number.isFinite(value)) return "";
|
|
2288
|
+
if (value === 0) return "0";
|
|
2289
|
+
return value.toFixed(maxDecimals).replace(/\.?0+$/, "");
|
|
2290
|
+
}
|
|
2291
|
+
function multiplyDecimalStringsToBaseUnits(left, right, decimals) {
|
|
2292
|
+
const normalize = (input) => {
|
|
2293
|
+
const trimmed = input.trim();
|
|
2294
|
+
const match = trimmed.match(/^(\d+)(?:\.(\d+))?$/);
|
|
2295
|
+
if (!match) return null;
|
|
2296
|
+
const intPart = match[1] ?? "0";
|
|
2297
|
+
const fracPart = match[2] ?? "";
|
|
2298
|
+
return {
|
|
2299
|
+
digits: BigInt(`${intPart}${fracPart}`),
|
|
2300
|
+
scale: fracPart.length
|
|
2301
|
+
};
|
|
2302
|
+
};
|
|
2303
|
+
const a = normalize(left);
|
|
2304
|
+
const b = normalize(right);
|
|
2305
|
+
if (!a || !b || decimals < 0) return void 0;
|
|
2306
|
+
const product = a.digits * b.digits;
|
|
2307
|
+
const totalScale = a.scale + b.scale;
|
|
2308
|
+
if (decimals >= totalScale) {
|
|
2309
|
+
return (product * 10n ** BigInt(decimals - totalScale)).toString();
|
|
2310
|
+
}
|
|
2311
|
+
return (product / 10n ** BigInt(totalScale - decimals)).toString();
|
|
2280
2312
|
}
|
|
2281
2313
|
function findScrollableAncestor(node) {
|
|
2282
2314
|
let current = node?.parentElement ?? null;
|
|
@@ -2344,6 +2376,14 @@ var WithdrawModal = ({
|
|
|
2344
2376
|
if (!apiChains?.length || !token || !chain) return void 0;
|
|
2345
2377
|
return getTokenAddressForChain2(apiChains, chain, token);
|
|
2346
2378
|
}, [apiChains, token, chain]);
|
|
2379
|
+
const destinationTokenDecimals = useMemo(() => {
|
|
2380
|
+
if (!token) return apiQuote?.token_decimals ?? 18;
|
|
2381
|
+
const targetChainId = withdrawOrder?.target_chain_id ?? chain;
|
|
2382
|
+
if (apiChains?.length && targetChainId) {
|
|
2383
|
+
return getTokenMetaForChain(apiChains, targetChainId, token)?.decimals ?? apiQuote?.token_decimals ?? 18;
|
|
2384
|
+
}
|
|
2385
|
+
return apiQuote?.token_decimals ?? 18;
|
|
2386
|
+
}, [apiChains, apiQuote?.token_decimals, chain, token, withdrawOrder?.target_chain_id]);
|
|
2347
2387
|
const [directActive, setDirectActive] = useState(false);
|
|
2348
2388
|
useEffect(() => {
|
|
2349
2389
|
setDirectActive(withdrawMode === "direct" && Boolean(withdrawDirectResult));
|
|
@@ -2382,7 +2422,7 @@ var WithdrawModal = ({
|
|
|
2382
2422
|
direction: "withdraw",
|
|
2383
2423
|
chain_id: chain,
|
|
2384
2424
|
token_address: tokenAddress,
|
|
2385
|
-
|
|
2425
|
+
token_amount: amountWei
|
|
2386
2426
|
}).then((q) => setApiQuote(q ?? null)).catch(() => {
|
|
2387
2427
|
setApiQuote({
|
|
2388
2428
|
token_address: tokenAddress,
|
|
@@ -2391,6 +2431,7 @@ var WithdrawModal = ({
|
|
|
2391
2431
|
rate: "1",
|
|
2392
2432
|
chain_id: Number(chain) || 56,
|
|
2393
2433
|
token_amount: amountWei,
|
|
2434
|
+
dst_token_amount: amountWei,
|
|
2394
2435
|
expires_at: new Date(Date.now() + 6e4).toISOString()
|
|
2395
2436
|
});
|
|
2396
2437
|
}).finally(() => setLoadingQuote(false));
|
|
@@ -2433,6 +2474,15 @@ var WithdrawModal = ({
|
|
|
2433
2474
|
if (!orderId && directActive) {
|
|
2434
2475
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
2435
2476
|
const inferredAmountWei = (() => {
|
|
2477
|
+
if (apiQuote?.dst_token_amount) return apiQuote.dst_token_amount;
|
|
2478
|
+
if (amount && apiQuote?.rate) {
|
|
2479
|
+
const quotedAmountWei = multiplyDecimalStringsToBaseUnits(
|
|
2480
|
+
amount,
|
|
2481
|
+
apiQuote.rate,
|
|
2482
|
+
apiQuote.token_decimals ?? 18
|
|
2483
|
+
);
|
|
2484
|
+
if (quotedAmountWei) return quotedAmountWei;
|
|
2485
|
+
}
|
|
2436
2486
|
if (withdrawDirectResult?.dst_token_amount) return withdrawDirectResult.dst_token_amount;
|
|
2437
2487
|
const n = Number(amount || "0");
|
|
2438
2488
|
return String(n > 0 ? BigInt(Math.floor(n * 1e18)) : 0n);
|
|
@@ -2456,7 +2506,7 @@ var WithdrawModal = ({
|
|
|
2456
2506
|
return;
|
|
2457
2507
|
}
|
|
2458
2508
|
setWithdrawOrder(null);
|
|
2459
|
-
}, [orderId, directActive, withdrawDirectResult, amount, feeDisplay, chain, address, txHash, fundingChainId, onShowToast, mockWithdrawOrderState]);
|
|
2509
|
+
}, [orderId, directActive, withdrawDirectResult, amount, apiQuote, feeDisplay, chain, address, txHash, fundingChainId, onShowToast, mockWithdrawOrderState]);
|
|
2460
2510
|
const completedKeyRef = useRef(null);
|
|
2461
2511
|
const successToastKeyRef = useRef(null);
|
|
2462
2512
|
useEffect(() => {
|
|
@@ -2485,11 +2535,33 @@ var WithdrawModal = ({
|
|
|
2485
2535
|
if (!Number.isNaN(n)) return n.toFixed(2);
|
|
2486
2536
|
return receiveAmountProp;
|
|
2487
2537
|
}
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
const formatted =
|
|
2491
|
-
return `\u2248 ${formatted}
|
|
2538
|
+
const rawAmount = apiQuote?.dst_token_amount ?? apiQuote?.token_amount;
|
|
2539
|
+
if (!rawAmount || !apiQuote?.token_symbol) return void 0;
|
|
2540
|
+
const formatted = formatBaseUnitAmount(rawAmount, apiQuote.token_decimals ?? 18);
|
|
2541
|
+
return `\u2248 ${formatted} ${apiQuote.token_symbol}`;
|
|
2492
2542
|
}, [receiveAmountProp, apiQuote]);
|
|
2543
|
+
const displayReceiveAmount = useMemo(() => {
|
|
2544
|
+
if (receiveAmount) return receiveAmount;
|
|
2545
|
+
if (!amount || !apiQuote?.token_symbol || !apiQuote?.rate) return void 0;
|
|
2546
|
+
const fundingAmount = Number(amount);
|
|
2547
|
+
const rate = Number(apiQuote.rate);
|
|
2548
|
+
if (!Number.isFinite(fundingAmount) || fundingAmount <= 0 || !Number.isFinite(rate) || rate <= 0) {
|
|
2549
|
+
return void 0;
|
|
2550
|
+
}
|
|
2551
|
+
return `\u2248 ${formatDecimalAmount(fundingAmount * rate)} ${apiQuote.token_symbol}`;
|
|
2552
|
+
}, [amount, apiQuote?.rate, apiQuote?.token_symbol, receiveAmount]);
|
|
2553
|
+
const successAmountDisplay = useMemo(() => {
|
|
2554
|
+
if (displayReceiveAmount) {
|
|
2555
|
+
return displayReceiveAmount.replace(/^≈\s*/, "");
|
|
2556
|
+
}
|
|
2557
|
+
if (!withdrawOrder?.dst_token_amount) return void 0;
|
|
2558
|
+
return `${formatBaseUnitAmount(withdrawOrder.dst_token_amount, destinationTokenDecimals)} ${tokenSymbol}`;
|
|
2559
|
+
}, [
|
|
2560
|
+
destinationTokenDecimals,
|
|
2561
|
+
displayReceiveAmount,
|
|
2562
|
+
tokenSymbol,
|
|
2563
|
+
withdrawOrder?.dst_token_amount
|
|
2564
|
+
]);
|
|
2493
2565
|
const quoteExpired = useMemo(() => {
|
|
2494
2566
|
if (!apiQuote?.expires_at) return false;
|
|
2495
2567
|
try {
|
|
@@ -2509,7 +2581,7 @@ var WithdrawModal = ({
|
|
|
2509
2581
|
direction: "withdraw",
|
|
2510
2582
|
chain_id: chain,
|
|
2511
2583
|
token_address: tokenAddress,
|
|
2512
|
-
|
|
2584
|
+
token_amount: amountWei
|
|
2513
2585
|
}).then((q) => setApiQuote(q ?? null)).catch(() => {
|
|
2514
2586
|
setApiQuote({
|
|
2515
2587
|
token_address: tokenAddress,
|
|
@@ -2518,6 +2590,7 @@ var WithdrawModal = ({
|
|
|
2518
2590
|
rate: "1",
|
|
2519
2591
|
chain_id: Number(chain) || 56,
|
|
2520
2592
|
token_amount: amountWei,
|
|
2593
|
+
dst_token_amount: amountWei,
|
|
2521
2594
|
expires_at: new Date(Date.now() + 6e4).toISOString()
|
|
2522
2595
|
});
|
|
2523
2596
|
}).finally(() => setLoadingQuote(false));
|
|
@@ -2768,11 +2841,7 @@ var WithdrawModal = ({
|
|
|
2768
2841
|
children: [
|
|
2769
2842
|
/* @__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
2843
|
/* @__PURE__ */ jsx("span", { className: "absdk-predicate-withdraw-modal__summary-label", style: { fontSize: 14, lineHeight: 1.4, color: colors2.textSecondary }, children: "Amount" }),
|
|
2771
|
-
/* @__PURE__ */
|
|
2772
|
-
weiToEtherDisplay(withdrawOrder.dst_token_amount),
|
|
2773
|
-
" ",
|
|
2774
|
-
tokenSymbol
|
|
2775
|
-
] })
|
|
2844
|
+
/* @__PURE__ */ jsx("span", { className: "absdk-predicate-withdraw-modal__summary-value", style: { fontSize: 14, lineHeight: 1.4, color: colors2.textPrimary }, children: successAmountDisplay ?? "\u2014" })
|
|
2776
2845
|
] }),
|
|
2777
2846
|
/* @__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
2847
|
/* @__PURE__ */ jsx("span", { className: "absdk-predicate-withdraw-modal__summary-label", style: { fontSize: 14, lineHeight: 1.4, color: colors2.textSecondary }, children: "Fee" }),
|
|
@@ -3127,10 +3196,10 @@ var WithdrawModal = ({
|
|
|
3127
3196
|
]
|
|
3128
3197
|
}
|
|
3129
3198
|
),
|
|
3130
|
-
!orderSucceeded && /* @__PURE__ */ jsxs("span", { className: "absdk-predicate-withdraw-modal__receive-amount", style: { fontSize: 14, lineHeight: 1.4, color: colors2.textPrimary, opacity: !trackingWithdraw &&
|
|
3199
|
+
!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
3200
|
/* @__PURE__ */ jsx("span", { className: "absdk-predicate-withdraw-modal__receive-amount-label", children: "You will receive :" }),
|
|
3132
3201
|
" ",
|
|
3133
|
-
/* @__PURE__ */ jsx("span", { className: "absdk-predicate-withdraw-modal__receive-amount-value", children:
|
|
3202
|
+
/* @__PURE__ */ jsx("span", { className: "absdk-predicate-withdraw-modal__receive-amount-value", children: displayReceiveAmount })
|
|
3134
3203
|
] })
|
|
3135
3204
|
] }) })
|
|
3136
3205
|
]
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ export { notifyTwitterCallback } from './chunk-ZS6FNG2D.js';
|
|
|
2
2
|
export { tryAutoReconnect } from './chunk-63AEVWHE.js';
|
|
3
3
|
export { createDepositController, createFundingWithdrawExecutor, createMarketDataProvider, createPredicateMarketPolicyAdapter, createWithdrawController, fetchErc20Balance, fetchFundingTokenBalance, findTokenDataFromChains, isUsdtWithdrawDirect, parseUnits } from './chunk-UMSH3Z43.js';
|
|
4
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-
|
|
5
|
+
export { DepositDetailsPanel, DepositModal, DropdownField, SignInModal, Toast, WalletAccount, WalletSelectionModal, WithdrawModal, clearSocialAccountInstance } from './chunk-IVPLOLGZ.js';
|
|
6
6
|
export { getExplorerUrl } from './chunk-XB2DFS2W.js';
|
|
7
7
|
export { configureMerchantApi, createOrder, getChains, getDepositOrder, getMerchantApiClient, getWithdrawOrder, quote, registerPlatform } from './chunk-HNL3SLGU.js';
|
|
8
8
|
export { getFixedAuthConfig, getSDKConfig, initSDK } from './chunk-BWKDIOBB.js';
|
package/dist/react.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { DepositDetailsPanel, DepositModal, DropdownField, SignInModal, Toast, WalletAccount, WalletSelectionModal, WithdrawModal, clearSocialAccountInstance } from './chunk-
|
|
1
|
+
export { DepositDetailsPanel, DepositModal, DropdownField, SignInModal, Toast, WalletAccount, WalletSelectionModal, WithdrawModal, clearSocialAccountInstance } from './chunk-IVPLOLGZ.js';
|
|
2
2
|
import './chunk-XB2DFS2W.js';
|
|
3
3
|
import './chunk-HNL3SLGU.js';
|
|
4
4
|
import './chunk-CGP7TSLF.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.
|
|
3
|
+
"version": "2.2.0-beta.6",
|
|
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.
|
|
42
|
+
"@ab-org/sdk-core": "0.3.0-beta.4"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"react": ">=18"
|