@b3dotfun/sdk 0.1.65 → 0.1.66-alpha.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.
- package/dist/cjs/anyspend/react/components/AnySpend.d.ts +2 -0
- package/dist/cjs/anyspend/react/components/AnySpend.js +7 -16
- package/dist/cjs/anyspend/react/components/AnySpendCollectorClubPurchase.d.ts +6 -1
- package/dist/cjs/anyspend/react/components/AnySpendCollectorClubPurchase.js +151 -22
- package/dist/cjs/anyspend/react/components/AnySpendCustom.js +4 -50
- package/dist/cjs/anyspend/react/components/AnySpendCustomExactIn.d.ts +2 -0
- package/dist/cjs/anyspend/react/components/AnySpendCustomExactIn.js +4 -2
- package/dist/cjs/anyspend/react/components/AnySpendDeposit.d.ts +3 -1
- package/dist/cjs/anyspend/react/components/AnySpendDeposit.js +2 -2
- package/dist/cjs/anyspend/react/components/AnySpendWorkflowTrigger.d.ts +31 -0
- package/dist/cjs/anyspend/react/components/AnySpendWorkflowTrigger.js +14 -0
- package/dist/cjs/anyspend/react/components/QRDeposit.js +5 -13
- package/dist/cjs/anyspend/react/components/ccShopAbi.d.ts +113 -0
- package/dist/cjs/anyspend/react/components/ccShopAbi.js +63 -0
- package/dist/cjs/anyspend/react/components/common/CryptoPaySection.d.ts +1 -3
- package/dist/cjs/anyspend/react/components/common/CryptoPaySection.js +3 -3
- package/dist/cjs/anyspend/react/components/common/OrderTokenAmount.d.ts +1 -4
- package/dist/cjs/anyspend/react/components/common/OrderTokenAmount.js +3 -57
- package/dist/cjs/anyspend/react/components/common/PaySection.js +1 -1
- package/dist/cjs/anyspend/react/components/index.d.ts +2 -0
- package/dist/cjs/anyspend/react/components/index.js +3 -1
- package/dist/cjs/anyspend/react/hooks/index.d.ts +1 -0
- package/dist/cjs/anyspend/react/hooks/index.js +1 -0
- package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +1 -0
- package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOrder.d.ts +1 -0
- package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOrder.js +1 -0
- package/dist/cjs/anyspend/react/hooks/useOnOrderSuccess.d.ts +10 -0
- package/dist/cjs/anyspend/react/hooks/useOnOrderSuccess.js +27 -0
- package/dist/cjs/anyspend/services/anyspend.d.ts +2 -1
- package/dist/cjs/anyspend/services/anyspend.js +2 -1
- package/dist/cjs/anyspend/utils/chain.d.ts +1 -1
- package/dist/cjs/anyspend/utils/chain.js +72 -62
- package/dist/cjs/global-account/react/components/B3DynamicModal.js +4 -0
- package/dist/cjs/global-account/react/hooks/useUserQuery.js +10 -0
- package/dist/cjs/global-account/react/stores/useModalStore.d.ts +37 -1
- package/dist/cjs/global-account/react/stores/userStore.js +1 -0
- package/dist/esm/anyspend/react/components/AnySpend.d.ts +2 -0
- package/dist/esm/anyspend/react/components/AnySpend.js +7 -16
- package/dist/esm/anyspend/react/components/AnySpendCollectorClubPurchase.d.ts +6 -1
- package/dist/esm/anyspend/react/components/AnySpendCollectorClubPurchase.js +152 -23
- package/dist/esm/anyspend/react/components/AnySpendCustom.js +4 -17
- package/dist/esm/anyspend/react/components/AnySpendCustomExactIn.d.ts +2 -0
- package/dist/esm/anyspend/react/components/AnySpendCustomExactIn.js +4 -2
- package/dist/esm/anyspend/react/components/AnySpendDeposit.d.ts +3 -1
- package/dist/esm/anyspend/react/components/AnySpendDeposit.js +2 -2
- package/dist/esm/anyspend/react/components/AnySpendWorkflowTrigger.d.ts +31 -0
- package/dist/esm/anyspend/react/components/AnySpendWorkflowTrigger.js +11 -0
- package/dist/esm/anyspend/react/components/QRDeposit.js +6 -14
- package/dist/esm/anyspend/react/components/ccShopAbi.d.ts +113 -0
- package/dist/esm/anyspend/react/components/ccShopAbi.js +60 -0
- package/dist/esm/anyspend/react/components/common/CryptoPaySection.d.ts +1 -3
- package/dist/esm/anyspend/react/components/common/CryptoPaySection.js +3 -3
- package/dist/esm/anyspend/react/components/common/OrderTokenAmount.d.ts +1 -4
- package/dist/esm/anyspend/react/components/common/OrderTokenAmount.js +2 -56
- package/dist/esm/anyspend/react/components/common/PaySection.js +1 -1
- package/dist/esm/anyspend/react/components/index.d.ts +2 -0
- package/dist/esm/anyspend/react/components/index.js +1 -0
- package/dist/esm/anyspend/react/hooks/index.d.ts +1 -0
- package/dist/esm/anyspend/react/hooks/index.js +1 -0
- package/dist/esm/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +1 -0
- package/dist/esm/anyspend/react/hooks/useAnyspendCreateOrder.d.ts +1 -0
- package/dist/esm/anyspend/react/hooks/useAnyspendCreateOrder.js +1 -0
- package/dist/esm/anyspend/react/hooks/useOnOrderSuccess.d.ts +10 -0
- package/dist/esm/anyspend/react/hooks/useOnOrderSuccess.js +24 -0
- package/dist/esm/anyspend/services/anyspend.d.ts +2 -1
- package/dist/esm/anyspend/services/anyspend.js +2 -1
- package/dist/esm/anyspend/utils/chain.d.ts +1 -1
- package/dist/esm/anyspend/utils/chain.js +72 -62
- package/dist/esm/global-account/react/components/B3DynamicModal.js +4 -0
- package/dist/esm/global-account/react/hooks/useUserQuery.js +11 -1
- package/dist/esm/global-account/react/stores/useModalStore.d.ts +37 -1
- package/dist/esm/global-account/react/stores/userStore.js +1 -0
- package/dist/types/anyspend/react/components/AnySpend.d.ts +2 -0
- package/dist/types/anyspend/react/components/AnySpendCollectorClubPurchase.d.ts +6 -1
- package/dist/types/anyspend/react/components/AnySpendCustomExactIn.d.ts +2 -0
- package/dist/types/anyspend/react/components/AnySpendDeposit.d.ts +3 -1
- package/dist/types/anyspend/react/components/AnySpendWorkflowTrigger.d.ts +31 -0
- package/dist/types/anyspend/react/components/ccShopAbi.d.ts +113 -0
- package/dist/types/anyspend/react/components/common/CryptoPaySection.d.ts +1 -3
- package/dist/types/anyspend/react/components/common/OrderTokenAmount.d.ts +1 -4
- package/dist/types/anyspend/react/components/index.d.ts +2 -0
- package/dist/types/anyspend/react/hooks/index.d.ts +1 -0
- package/dist/types/anyspend/react/hooks/useAnyspendCreateOrder.d.ts +1 -0
- package/dist/types/anyspend/react/hooks/useOnOrderSuccess.d.ts +10 -0
- package/dist/types/anyspend/services/anyspend.d.ts +2 -1
- package/dist/types/anyspend/utils/chain.d.ts +1 -1
- package/dist/types/global-account/react/stores/useModalStore.d.ts +37 -1
- package/package.json +1 -1
- package/src/anyspend/README.md +14 -0
- package/src/anyspend/docs/checkout-sessions.md +228 -0
- package/src/anyspend/docs/components.md +26 -0
- package/src/anyspend/docs/examples.md +58 -0
- package/src/anyspend/docs/hooks.md +32 -0
- package/src/anyspend/llms.txt +185 -0
- package/src/anyspend/react/components/AnySpend.tsx +9 -17
- package/src/anyspend/react/components/AnySpendCollectorClubPurchase.tsx +206 -22
- package/src/anyspend/react/components/AnySpendCustom.tsx +3 -18
- package/src/anyspend/react/components/AnySpendCustomExactIn.tsx +5 -1
- package/src/anyspend/react/components/AnySpendDeposit.tsx +5 -0
- package/src/anyspend/react/components/AnySpendWorkflowTrigger.tsx +73 -0
- package/src/anyspend/react/components/QRDeposit.tsx +19 -15
- package/src/anyspend/react/components/ccShopAbi.ts +64 -0
- package/src/anyspend/react/components/common/CryptoPaySection.tsx +0 -5
- package/src/anyspend/react/components/common/OrderTokenAmount.tsx +1 -70
- package/src/anyspend/react/components/common/PaySection.tsx +0 -1
- package/src/anyspend/react/components/index.ts +2 -0
- package/src/anyspend/react/hooks/index.ts +1 -0
- package/src/anyspend/react/hooks/useAnyspendCreateOnrampOrder.ts +1 -0
- package/src/anyspend/react/hooks/useAnyspendCreateOrder.ts +2 -0
- package/src/anyspend/react/hooks/useOnOrderSuccess.ts +36 -0
- package/src/anyspend/services/anyspend.ts +3 -0
- package/src/anyspend/utils/chain.ts +81 -65
- package/src/global-account/react/components/B3DynamicModal.tsx +4 -0
- package/src/global-account/react/hooks/useUserQuery.ts +12 -1
- package/src/global-account/react/stores/useModalStore.ts +39 -2
- package/src/global-account/react/stores/userStore.ts +1 -0
|
@@ -12,6 +12,7 @@ export * from "./useGasPrice.js";
|
|
|
12
12
|
export * from "./useGeoOnrampOptions.js";
|
|
13
13
|
export * from "./useGetGeo.js";
|
|
14
14
|
export * from "./useHyperliquidTransfer.js";
|
|
15
|
+
export * from "./useOnOrderSuccess.js";
|
|
15
16
|
export * from "./useRecipientAddressState.js";
|
|
16
17
|
export * from "./useSigMint.js";
|
|
17
18
|
export * from "./useStripeClientSecret.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { GetOrderAndTxsResponse } from "../../types/api_req_res";
|
|
2
|
+
/**
|
|
3
|
+
* Hook to call onSuccess callback when an order is executed.
|
|
4
|
+
* Handles fallback to relayTxs when executeTx is null.
|
|
5
|
+
*/
|
|
6
|
+
export declare function useOnOrderSuccess({ orderData, orderId, onSuccess, }: {
|
|
7
|
+
orderData: GetOrderAndTxsResponse | undefined;
|
|
8
|
+
orderId: string | undefined;
|
|
9
|
+
onSuccess?: (txHash?: string) => void;
|
|
10
|
+
}): void;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Hook to call onSuccess callback when an order is executed.
|
|
4
|
+
* Handles fallback to relayTxs when executeTx is null.
|
|
5
|
+
*/
|
|
6
|
+
export function useOnOrderSuccess({ orderData, orderId, onSuccess, }) {
|
|
7
|
+
const onSuccessCalled = useRef(false);
|
|
8
|
+
const prevOrderId = useRef(orderId);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
// Reset flag when orderId changes
|
|
11
|
+
if (prevOrderId.current !== orderId) {
|
|
12
|
+
onSuccessCalled.current = false;
|
|
13
|
+
prevOrderId.current = orderId;
|
|
14
|
+
}
|
|
15
|
+
// Call onSuccess when order is executed
|
|
16
|
+
if (orderData?.data?.order.status === "executed" && !onSuccessCalled.current) {
|
|
17
|
+
const relayTxs = orderData?.data?.relayTxs;
|
|
18
|
+
const lastSuccessfulRelayTx = relayTxs?.filter(tx => tx.status === "success").pop();
|
|
19
|
+
const txHash = orderData?.data?.executeTx?.txHash || lastSuccessfulRelayTx?.txHash;
|
|
20
|
+
onSuccess?.(txHash);
|
|
21
|
+
onSuccessCalled.current = true;
|
|
22
|
+
}
|
|
23
|
+
}, [orderData, orderId, onSuccess]);
|
|
24
|
+
}
|
|
@@ -6,7 +6,7 @@ export declare const anyspendService: {
|
|
|
6
6
|
getTokenList: (chainId: number, query: string) => Promise<components["schemas"]["Token"][]>;
|
|
7
7
|
getToken: (chainId: number, tokenAddress: string) => Promise<components["schemas"]["Token"]>;
|
|
8
8
|
getQuote: (req: GetQuoteRequest, partnerId?: string) => Promise<GetQuoteResponse>;
|
|
9
|
-
createOrder: ({ recipientAddress, type, srcChain, dstChain, srcTokenAddress, dstTokenAddress, srcAmount, payload, onramp, metadata, creatorAddress, partnerId, clientReferenceId, visitorData, }: {
|
|
9
|
+
createOrder: ({ recipientAddress, type, srcChain, dstChain, srcTokenAddress, dstTokenAddress, srcAmount, payload, onramp, metadata, creatorAddress, partnerId, clientReferenceId, visitorData, callbackMetadata, }: {
|
|
10
10
|
recipientAddress: string;
|
|
11
11
|
type: string;
|
|
12
12
|
srcChain: number;
|
|
@@ -21,6 +21,7 @@ export declare const anyspendService: {
|
|
|
21
21
|
partnerId?: string;
|
|
22
22
|
clientReferenceId?: string;
|
|
23
23
|
visitorData?: VisitorData;
|
|
24
|
+
callbackMetadata?: Record<string, unknown>;
|
|
24
25
|
}) => Promise<{
|
|
25
26
|
success: boolean;
|
|
26
27
|
message: string;
|
|
@@ -36,7 +36,7 @@ export const anyspendService = {
|
|
|
36
36
|
return data;
|
|
37
37
|
},
|
|
38
38
|
// Order related
|
|
39
|
-
createOrder: async ({ recipientAddress, type, srcChain, dstChain, srcTokenAddress, dstTokenAddress, srcAmount, payload, onramp, metadata, creatorAddress, partnerId, clientReferenceId, visitorData, }) => {
|
|
39
|
+
createOrder: async ({ recipientAddress, type, srcChain, dstChain, srcTokenAddress, dstTokenAddress, srcAmount, payload, onramp, metadata, creatorAddress, partnerId, clientReferenceId, visitorData, callbackMetadata, }) => {
|
|
40
40
|
const accessToken = await app.authentication.getAccessToken();
|
|
41
41
|
const response = await fetch(`${ANYSPEND_MAINNET_BASE_URL}/orders`, {
|
|
42
42
|
method: "POST",
|
|
@@ -60,6 +60,7 @@ export const anyspendService = {
|
|
|
60
60
|
creatorAddress,
|
|
61
61
|
partnerId,
|
|
62
62
|
...(clientReferenceId && { clientReferenceId }),
|
|
63
|
+
...(callbackMetadata && { callbackMetadata }),
|
|
63
64
|
}),
|
|
64
65
|
});
|
|
65
66
|
const data = await response.json();
|
|
@@ -82,7 +82,7 @@ export declare function isTestnet(chainId: number): boolean;
|
|
|
82
82
|
export declare function getDefaultToken(chainId: number): components["schemas"]["Token"];
|
|
83
83
|
export declare function getChainName(chainId: number): string;
|
|
84
84
|
export declare function getCoingeckoName(chainId: number): string | null;
|
|
85
|
-
export declare function getPaymentUrl(address: string, amount: bigint, currency: string, chainId: number, decimals?: number): string;
|
|
85
|
+
export declare function getPaymentUrl(address: string, amount: bigint | undefined, currency: string, chainId: number, decimals?: number): string;
|
|
86
86
|
export declare function getExplorerTxUrl(chainId: number, txHash: string): string;
|
|
87
87
|
export declare function getExplorerAddressUrl(chainId: number, address: string): string;
|
|
88
88
|
export declare function getMulticall3Address(chainId: number): string;
|
|
@@ -362,8 +362,8 @@ export function getPaymentUrl(address, amount, currency, chainId, decimals) {
|
|
|
362
362
|
// For EVM chains, follow EIP-681 format
|
|
363
363
|
// Format: ethereum:[address]@[chainId]?value=[amount]&symbol=[symbol]
|
|
364
364
|
const params = new URLSearchParams();
|
|
365
|
-
// Add value for native token transfers
|
|
366
|
-
if (currency === chain.nativeToken.symbol) {
|
|
365
|
+
// Add value for native token transfers (skip if amount not provided, e.g. deposit_first)
|
|
366
|
+
if (currency === chain.nativeToken.symbol && amount !== undefined) {
|
|
367
367
|
params.append("value", amount.toString());
|
|
368
368
|
}
|
|
369
369
|
// Handle token transfers differently from native transfers
|
|
@@ -378,28 +378,31 @@ export function getPaymentUrl(address, amount, currency, chainId, decimals) {
|
|
|
378
378
|
}
|
|
379
379
|
// For ERC20 tokens, convert from smallest unit to display units using decimals
|
|
380
380
|
// For example: 2400623 (raw) with 6 decimals becomes "2.400623"
|
|
381
|
-
|
|
382
|
-
if (
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
381
|
+
// Skip amount if not provided (e.g. deposit_first orders)
|
|
382
|
+
if (amount !== undefined) {
|
|
383
|
+
let displayAmount;
|
|
384
|
+
if (decimals !== undefined && currency !== chain.nativeToken.symbol) {
|
|
385
|
+
// Convert from smallest unit to display unit for ERC20 tokens
|
|
386
|
+
const divisor = BigInt(10 ** decimals);
|
|
387
|
+
const wholePart = amount / divisor;
|
|
388
|
+
const fractionalPart = amount % divisor;
|
|
389
|
+
if (fractionalPart === BigInt(0)) {
|
|
390
|
+
displayAmount = wholePart.toString();
|
|
391
|
+
}
|
|
392
|
+
else {
|
|
393
|
+
// Format fractional part with leading zeros if needed
|
|
394
|
+
const fractionalStr = fractionalPart.toString().padStart(decimals, "0");
|
|
395
|
+
// Remove trailing zeros
|
|
396
|
+
const trimmedFractional = fractionalStr.replace(/0+$/, "");
|
|
397
|
+
displayAmount = trimmedFractional ? `${wholePart}.${trimmedFractional}` : wholePart.toString();
|
|
398
|
+
}
|
|
389
399
|
}
|
|
390
400
|
else {
|
|
391
|
-
//
|
|
392
|
-
|
|
393
|
-
// Remove trailing zeros
|
|
394
|
-
const trimmedFractional = fractionalStr.replace(/0+$/, "");
|
|
395
|
-
displayAmount = trimmedFractional ? `${wholePart}.${trimmedFractional}` : wholePart.toString();
|
|
401
|
+
// For native tokens or when decimals not provided, use raw amount
|
|
402
|
+
displayAmount = amount.toString();
|
|
396
403
|
}
|
|
404
|
+
tokenParams.append("amount", displayAmount);
|
|
397
405
|
}
|
|
398
|
-
else {
|
|
399
|
-
// For native tokens or when decimals not provided, use raw amount
|
|
400
|
-
displayAmount = amount.toString();
|
|
401
|
-
}
|
|
402
|
-
tokenParams.append("amount", displayAmount);
|
|
403
406
|
tokenParams.append("address", address); // recipient address
|
|
404
407
|
// For Arbitrum and other L2s, try a more explicit format
|
|
405
408
|
if (chainId !== mainnet.id) {
|
|
@@ -419,7 +422,9 @@ export function getPaymentUrl(address, amount, currency, chainId, decimals) {
|
|
|
419
422
|
// to make sure wallets recognize the correct chain
|
|
420
423
|
const nativeParams = new URLSearchParams();
|
|
421
424
|
nativeParams.append("chainId", chainId.toString());
|
|
422
|
-
|
|
425
|
+
if (amount !== undefined) {
|
|
426
|
+
nativeParams.append("value", amount.toString());
|
|
427
|
+
}
|
|
423
428
|
const url = `ethereum:${address}@${chainId}?${nativeParams.toString()}`;
|
|
424
429
|
return url;
|
|
425
430
|
}
|
|
@@ -438,60 +443,65 @@ export function getPaymentUrl(address, amount, currency, chainId, decimals) {
|
|
|
438
443
|
const isNativeSOL = currency === chain.nativeToken.symbol || currency === "SOL" || currency === "11111111111111111111111111111111";
|
|
439
444
|
if (isNativeSOL) {
|
|
440
445
|
// Native SOL transfers - convert from lamports to SOL
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
else {
|
|
456
|
-
// Fallback: assume SOL has 9 decimals
|
|
457
|
-
const divisor = BigInt(1000000000); // 1e9
|
|
458
|
-
const wholePart = amount / divisor;
|
|
459
|
-
const fractionalPart = amount % divisor;
|
|
460
|
-
if (fractionalPart === BigInt(0)) {
|
|
461
|
-
displayAmount = wholePart.toString();
|
|
446
|
+
if (amount !== undefined) {
|
|
447
|
+
let displayAmount;
|
|
448
|
+
if (decimals !== undefined) {
|
|
449
|
+
const divisor = BigInt(10 ** decimals);
|
|
450
|
+
const wholePart = amount / divisor;
|
|
451
|
+
const fractionalPart = amount % divisor;
|
|
452
|
+
if (fractionalPart === BigInt(0)) {
|
|
453
|
+
displayAmount = wholePart.toString();
|
|
454
|
+
}
|
|
455
|
+
else {
|
|
456
|
+
const fractionalStr = fractionalPart.toString().padStart(decimals, "0");
|
|
457
|
+
const trimmedFractional = fractionalStr.replace(/0+$/, "");
|
|
458
|
+
displayAmount = trimmedFractional ? `${wholePart}.${trimmedFractional}` : wholePart.toString();
|
|
459
|
+
}
|
|
462
460
|
}
|
|
463
461
|
else {
|
|
464
|
-
|
|
465
|
-
const
|
|
466
|
-
|
|
462
|
+
// Fallback: assume SOL has 9 decimals
|
|
463
|
+
const divisor = BigInt(1000000000); // 1e9
|
|
464
|
+
const wholePart = amount / divisor;
|
|
465
|
+
const fractionalPart = amount % divisor;
|
|
466
|
+
if (fractionalPart === BigInt(0)) {
|
|
467
|
+
displayAmount = wholePart.toString();
|
|
468
|
+
}
|
|
469
|
+
else {
|
|
470
|
+
const fractionalStr = fractionalPart.toString().padStart(9, "0");
|
|
471
|
+
const trimmedFractional = fractionalStr.replace(/0+$/, "");
|
|
472
|
+
displayAmount = trimmedFractional ? `${wholePart}.${trimmedFractional}` : wholePart.toString();
|
|
473
|
+
}
|
|
467
474
|
}
|
|
475
|
+
// For native SOL, use simple format without spl-token parameter
|
|
476
|
+
params.append("amount", displayAmount);
|
|
468
477
|
}
|
|
469
|
-
// For native SOL, use simple format without spl-token parameter
|
|
470
|
-
params.append("amount", displayAmount);
|
|
471
478
|
}
|
|
472
479
|
else {
|
|
473
480
|
// SPL token transfers
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
+
if (amount !== undefined) {
|
|
482
|
+
let displayAmount;
|
|
483
|
+
if (decimals !== undefined) {
|
|
484
|
+
const divisor = BigInt(10 ** decimals);
|
|
485
|
+
const wholePart = amount / divisor;
|
|
486
|
+
const fractionalPart = amount % divisor;
|
|
487
|
+
if (fractionalPart === BigInt(0)) {
|
|
488
|
+
displayAmount = wholePart.toString();
|
|
489
|
+
}
|
|
490
|
+
else {
|
|
491
|
+
const fractionalStr = fractionalPart.toString().padStart(decimals, "0");
|
|
492
|
+
const trimmedFractional = fractionalStr.replace(/0+$/, "");
|
|
493
|
+
displayAmount = trimmedFractional ? `${wholePart}.${trimmedFractional}` : wholePart.toString();
|
|
494
|
+
}
|
|
481
495
|
}
|
|
482
496
|
else {
|
|
483
|
-
|
|
484
|
-
const trimmedFractional = fractionalStr.replace(/0+$/, "");
|
|
485
|
-
displayAmount = trimmedFractional ? `${wholePart}.${trimmedFractional}` : wholePart.toString();
|
|
497
|
+
displayAmount = amount.toString();
|
|
486
498
|
}
|
|
499
|
+
params.append("amount", displayAmount);
|
|
487
500
|
}
|
|
488
|
-
else {
|
|
489
|
-
displayAmount = amount.toString();
|
|
490
|
-
}
|
|
491
|
-
params.append("amount", displayAmount);
|
|
492
501
|
params.append("spl-token", currency); // token mint address
|
|
493
502
|
}
|
|
494
|
-
const
|
|
503
|
+
const queryString = params.toString();
|
|
504
|
+
const url = queryString ? `solana:${address}?${queryString}` : `solana:${address}`;
|
|
495
505
|
console.log("Solana URL (isNativeSOL:", isNativeSOL, "):", url);
|
|
496
506
|
return url;
|
|
497
507
|
}
|
|
@@ -2,6 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { AnySpend, AnySpendBondKit, AnySpendBuySpin, AnySpendCollectorClubPurchase, AnySpendNFT, AnyspendSignatureMint, AnySpendStakeB3, AnySpendStakeB3ExactIn, AnySpendTournament, OrderHistory, } from "../../../anyspend/react/index.js";
|
|
3
3
|
import { AnySpendDeposit } from "../../../anyspend/react/components/AnySpendDeposit.js";
|
|
4
4
|
import { AnySpendDepositHype } from "../../../anyspend/react/components/AnyspendDepositHype.js";
|
|
5
|
+
import { AnySpendWorkflowTrigger } from "../../../anyspend/react/components/AnySpendWorkflowTrigger.js";
|
|
5
6
|
import { AnySpendDepositUpside } from "../../../anyspend/react/components/AnySpendDepositUpside.js";
|
|
6
7
|
import { AnySpendStakeUpside } from "../../../anyspend/react/components/AnySpendStakeUpside.js";
|
|
7
8
|
import { AnySpendStakeUpsideExactIn } from "../../../anyspend/react/components/AnySpendStakeUpsideExactIn.js";
|
|
@@ -52,6 +53,7 @@ export function B3DynamicModal() {
|
|
|
52
53
|
"send",
|
|
53
54
|
"notifications",
|
|
54
55
|
"anySpendDeposit",
|
|
56
|
+
"anySpendWorkflowTrigger",
|
|
55
57
|
];
|
|
56
58
|
const freestyleTypes = [
|
|
57
59
|
"anySpendNft",
|
|
@@ -122,6 +124,8 @@ export function B3DynamicModal() {
|
|
|
122
124
|
return _jsx(AnySpendCollectorClubPurchase, { ...contentType, mode: "modal" });
|
|
123
125
|
case "anySpendDeposit":
|
|
124
126
|
return _jsx(AnySpendDeposit, { ...contentType, mode: "modal" });
|
|
127
|
+
case "anySpendWorkflowTrigger":
|
|
128
|
+
return _jsx(AnySpendWorkflowTrigger, { ...contentType, mode: "modal" });
|
|
125
129
|
case "avatarEditor":
|
|
126
130
|
return _jsx(AvatarEditor, { onSetAvatar: contentType.onSuccess });
|
|
127
131
|
case "deposit":
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect } from "react";
|
|
1
|
+
import { useEffect, useLayoutEffect } from "react";
|
|
2
2
|
import { useUserStore } from "../stores/userStore.js";
|
|
3
3
|
const USER_QUERY_KEY = ["b3-user"];
|
|
4
4
|
/**
|
|
@@ -11,6 +11,16 @@ export function useUserQuery() {
|
|
|
11
11
|
const user = useUserStore(state => state.user);
|
|
12
12
|
const setUserStore = useUserStore(state => state.setUser);
|
|
13
13
|
const clearUserStore = useUserStore(state => state.clearUser);
|
|
14
|
+
// Manually rehydrate persisted store inside useLayoutEffect to avoid
|
|
15
|
+
// updating AuthenticationProvider state during Hydrate render.
|
|
16
|
+
// useLayoutEffect (not useEffect) ensures rehydration triggers a
|
|
17
|
+
// synchronous re-render before any useEffect callbacks fire, so
|
|
18
|
+
// downstream effects always see the persisted user value.
|
|
19
|
+
useLayoutEffect(() => {
|
|
20
|
+
if (!useUserStore.persist.hasHydrated()) {
|
|
21
|
+
useUserStore.persist.rehydrate();
|
|
22
|
+
}
|
|
23
|
+
}, []);
|
|
14
24
|
// Listen for storage events from other tabs/windows
|
|
15
25
|
useEffect(() => {
|
|
16
26
|
const handleStorageChange = (e) => {
|
|
@@ -470,11 +470,45 @@ export interface AnySpendCollectorClubPurchaseProps extends BaseModalProps {
|
|
|
470
470
|
forceFiatPayment?: boolean;
|
|
471
471
|
/** Staging environment support */
|
|
472
472
|
isStaging?: boolean;
|
|
473
|
+
/** Optional discount code to apply to the purchase */
|
|
474
|
+
discountCode?: string;
|
|
473
475
|
}
|
|
474
476
|
/**
|
|
475
477
|
* Props for the AnySpend Deposit modal
|
|
476
478
|
* Flexible deposit component with optional chain selection
|
|
477
479
|
*/
|
|
480
|
+
/**
|
|
481
|
+
* Props for the AnySpend Workflow Trigger modal
|
|
482
|
+
* Handles payments that trigger b3os-workflow runs
|
|
483
|
+
*/
|
|
484
|
+
export interface AnySpendWorkflowTriggerModalProps extends BaseModalProps {
|
|
485
|
+
/** Modal type identifier */
|
|
486
|
+
type: "anySpendWorkflowTrigger";
|
|
487
|
+
/** Payment recipient address (hex) */
|
|
488
|
+
recipientAddress: string;
|
|
489
|
+
/** Destination chain ID */
|
|
490
|
+
chainId: number;
|
|
491
|
+
/** Destination token address */
|
|
492
|
+
tokenAddress: string;
|
|
493
|
+
/** Required payment amount in token base units (wei) */
|
|
494
|
+
amount: string;
|
|
495
|
+
/** Workflow ID to trigger */
|
|
496
|
+
workflowId: string;
|
|
497
|
+
/** Organization ID that owns the workflow */
|
|
498
|
+
orgId: string;
|
|
499
|
+
/** Optional callback metadata */
|
|
500
|
+
callbackMetadata?: {
|
|
501
|
+
inputs?: Record<string, unknown>;
|
|
502
|
+
} & Record<string, unknown>;
|
|
503
|
+
/** Callback when payment succeeds */
|
|
504
|
+
onSuccess?: (amount: string) => void;
|
|
505
|
+
/** Callback when modal is closed */
|
|
506
|
+
onClose?: () => void;
|
|
507
|
+
/** Custom action label */
|
|
508
|
+
actionLabel?: string;
|
|
509
|
+
/** Custom class names */
|
|
510
|
+
classes?: AnySpendAllClasses;
|
|
511
|
+
}
|
|
478
512
|
export interface AnySpendDepositModalProps extends BaseModalProps {
|
|
479
513
|
/** Modal type identifier */
|
|
480
514
|
type: "anySpendDeposit";
|
|
@@ -534,11 +568,13 @@ export interface AnySpendDepositModalProps extends BaseModalProps {
|
|
|
534
568
|
classes?: AnySpendAllClasses;
|
|
535
569
|
/** Whether to allow direct transfer without swap */
|
|
536
570
|
allowDirectTransfer?: boolean;
|
|
571
|
+
/** Opaque metadata passed to the order for callbacks (e.g., workflow form data) */
|
|
572
|
+
callbackMetadata?: Record<string, unknown>;
|
|
537
573
|
}
|
|
538
574
|
/**
|
|
539
575
|
* Union type of all possible modal content types
|
|
540
576
|
*/
|
|
541
|
-
export type ModalContentType = SignInWithB3ModalProps | RequestPermissionsModalProps | ManageAccountModalProps | AnySpendModalProps | AnyspendOrderDetailsProps | AnySpendNftProps | AnySpendJoinTournamentProps | AnySpendFundTournamentProps | AnySpendOrderHistoryProps | AnySpendStakeB3Props | AnySpendStakeB3ExactInProps | AnySpendStakeUpsideProps | AnySpendStakeUpsideExactInProps | AnySpendDepositUpsideProps | AnySpendBuySpinProps | AnySpendSignatureMintProps | AnySpendBondKitProps | LinkAccountModalProps | LinkNewAccountModalProps | AnySpendDepositHypeProps | AvatarEditorModalProps | DepositModalProps | SendModalProps | NotificationsModalProps | AnySpendCollectorClubPurchaseProps | AnySpendDepositModalProps;
|
|
577
|
+
export type ModalContentType = SignInWithB3ModalProps | RequestPermissionsModalProps | ManageAccountModalProps | AnySpendModalProps | AnyspendOrderDetailsProps | AnySpendNftProps | AnySpendJoinTournamentProps | AnySpendFundTournamentProps | AnySpendOrderHistoryProps | AnySpendStakeB3Props | AnySpendStakeB3ExactInProps | AnySpendStakeUpsideProps | AnySpendStakeUpsideExactInProps | AnySpendDepositUpsideProps | AnySpendBuySpinProps | AnySpendSignatureMintProps | AnySpendBondKitProps | LinkAccountModalProps | LinkNewAccountModalProps | AnySpendDepositHypeProps | AvatarEditorModalProps | DepositModalProps | SendModalProps | NotificationsModalProps | AnySpendCollectorClubPurchaseProps | AnySpendDepositModalProps | AnySpendWorkflowTriggerModalProps;
|
|
542
578
|
/**
|
|
543
579
|
* State interface for the modal store
|
|
544
580
|
*/
|
|
@@ -53,4 +53,6 @@ export declare function AnySpend(props: {
|
|
|
53
53
|
allowDirectTransfer?: boolean;
|
|
54
54
|
/** Fixed destination token amount (in wei/smallest unit). When provided, user cannot change the amount. */
|
|
55
55
|
destinationTokenAmount?: string;
|
|
56
|
+
/** Opaque metadata passed to the order for callbacks (e.g., workflow form data) */
|
|
57
|
+
callbackMetadata?: Record<string, unknown>;
|
|
56
58
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -69,5 +69,10 @@ export interface AnySpendCollectorClubPurchaseProps {
|
|
|
69
69
|
* Force fiat payment
|
|
70
70
|
*/
|
|
71
71
|
forceFiatPayment?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Optional discount code to apply to the purchase.
|
|
74
|
+
* When provided, validates on-chain and adjusts the price accordingly.
|
|
75
|
+
*/
|
|
76
|
+
discountCode?: string;
|
|
72
77
|
}
|
|
73
|
-
export declare function AnySpendCollectorClubPurchase({ loadOrder, mode, activeTab, packId, packAmount, pricePerPack, paymentToken, recipientAddress, spenderAddress, isStaging, onSuccess, header, showRecipient, vendingMachineId, packType, forceFiatPayment, }: AnySpendCollectorClubPurchaseProps): import("react/jsx-runtime").JSX.Element;
|
|
78
|
+
export declare function AnySpendCollectorClubPurchase({ loadOrder, mode, activeTab, packId, packAmount, pricePerPack, paymentToken, recipientAddress, spenderAddress, isStaging, onSuccess, header, showRecipient, vendingMachineId, packType, forceFiatPayment, discountCode, }: AnySpendCollectorClubPurchaseProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -44,6 +44,8 @@ export interface AnySpendCustomExactInProps {
|
|
|
44
44
|
classes?: AnySpendCustomExactInClasses;
|
|
45
45
|
/** When true, allows direct transfer without swap if source and destination token/chain are the same */
|
|
46
46
|
allowDirectTransfer?: boolean;
|
|
47
|
+
/** Opaque metadata passed to the order for callbacks (e.g., workflow form data) */
|
|
48
|
+
callbackMetadata?: Record<string, unknown>;
|
|
47
49
|
}
|
|
48
50
|
export declare function AnySpendCustomExactIn(props: AnySpendCustomExactInProps): import("react/jsx-runtime").JSX.Element;
|
|
49
51
|
export {};
|
|
@@ -101,6 +101,8 @@ export interface AnySpendDepositProps {
|
|
|
101
101
|
allowDirectTransfer?: boolean;
|
|
102
102
|
/** Fixed destination token amount (in wei/smallest unit). When provided, user cannot change the amount. */
|
|
103
103
|
destinationTokenAmount?: string;
|
|
104
|
+
/** Opaque metadata passed to the order for callbacks (e.g., workflow form data) */
|
|
105
|
+
callbackMetadata?: Record<string, unknown>;
|
|
104
106
|
}
|
|
105
107
|
/**
|
|
106
108
|
* A flexible deposit component that wraps AnySpendCustomExactIn with optional chain selection.
|
|
@@ -137,4 +139,4 @@ export interface AnySpendDepositProps {
|
|
|
137
139
|
* onSuccess={(amount) => console.log(`Deposited ${amount}`)}
|
|
138
140
|
* />
|
|
139
141
|
*/
|
|
140
|
-
export declare function AnySpendDeposit({ loadOrder, mode, recipientAddress, paymentType: initialPaymentType, sourceTokenAddress, sourceTokenChainId: initialSourceChainId, destinationTokenAddress, destinationTokenChainId, onSuccess, onOpenCustomModal, mainFooter, onTokenSelect, customUsdInputValues, preferEoa, minDestinationAmount, header, orderType, depositContractConfig, showChainSelection, supportedChains, minPoolSize, topChainsCount, onClose, returnToHomeUrl, customRecipientLabel, returnHomeLabel, isCustomDeposit, classes, allowDirectTransfer, destinationTokenAmount, }: AnySpendDepositProps): import("react/jsx-runtime").JSX.Element | null;
|
|
142
|
+
export declare function AnySpendDeposit({ loadOrder, mode, recipientAddress, paymentType: initialPaymentType, sourceTokenAddress, sourceTokenChainId: initialSourceChainId, destinationTokenAddress, destinationTokenChainId, onSuccess, onOpenCustomModal, mainFooter, onTokenSelect, customUsdInputValues, preferEoa, minDestinationAmount, header, orderType, depositContractConfig, showChainSelection, supportedChains, minPoolSize, topChainsCount, onClose, returnToHomeUrl, customRecipientLabel, returnHomeLabel, isCustomDeposit, classes, allowDirectTransfer, destinationTokenAmount, callbackMetadata, }: AnySpendDepositProps): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { AnySpendAllClasses } from "./types/classes";
|
|
2
|
+
export interface AnySpendWorkflowTriggerProps {
|
|
3
|
+
/** Payment recipient address (hex) */
|
|
4
|
+
recipientAddress: string;
|
|
5
|
+
/** Destination chain ID */
|
|
6
|
+
chainId: number;
|
|
7
|
+
/** Destination token address */
|
|
8
|
+
tokenAddress: string;
|
|
9
|
+
/** Required payment amount in token base units (wei) */
|
|
10
|
+
amount: string;
|
|
11
|
+
/** Workflow ID to trigger */
|
|
12
|
+
workflowId: string;
|
|
13
|
+
/** Organization ID that owns the workflow */
|
|
14
|
+
orgId: string;
|
|
15
|
+
/** Optional callback metadata merged into the order */
|
|
16
|
+
callbackMetadata?: {
|
|
17
|
+
/** Passed as trigger result inputs — accessible via {{root.result.inputs.*}} */
|
|
18
|
+
inputs?: Record<string, unknown>;
|
|
19
|
+
} & Record<string, unknown>;
|
|
20
|
+
/** Callback when payment succeeds */
|
|
21
|
+
onSuccess?: (amount: string) => void;
|
|
22
|
+
/** Callback when modal is closed */
|
|
23
|
+
onClose?: () => void;
|
|
24
|
+
/** Display mode */
|
|
25
|
+
mode?: "modal" | "page";
|
|
26
|
+
/** Custom action label */
|
|
27
|
+
actionLabel?: string;
|
|
28
|
+
/** Custom class names */
|
|
29
|
+
classes?: AnySpendAllClasses;
|
|
30
|
+
}
|
|
31
|
+
export declare function AnySpendWorkflowTrigger({ recipientAddress, chainId, tokenAddress, amount, workflowId, orgId, callbackMetadata, onSuccess, onClose, mode, actionLabel, classes, }: AnySpendWorkflowTriggerProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
export declare const BUY_PACKS_FOR_ABI: {
|
|
2
|
+
readonly inputs: readonly [{
|
|
3
|
+
readonly internalType: "address";
|
|
4
|
+
readonly name: "user";
|
|
5
|
+
readonly type: "address";
|
|
6
|
+
}, {
|
|
7
|
+
readonly internalType: "uint256";
|
|
8
|
+
readonly name: "packId";
|
|
9
|
+
readonly type: "uint256";
|
|
10
|
+
}, {
|
|
11
|
+
readonly internalType: "uint256";
|
|
12
|
+
readonly name: "amount";
|
|
13
|
+
readonly type: "uint256";
|
|
14
|
+
}];
|
|
15
|
+
readonly name: "buyPacksFor";
|
|
16
|
+
readonly outputs: readonly [];
|
|
17
|
+
readonly stateMutability: "nonpayable";
|
|
18
|
+
readonly type: "function";
|
|
19
|
+
};
|
|
20
|
+
export declare const BUY_PACKS_FOR_WITH_DISCOUNT_ABI: {
|
|
21
|
+
readonly inputs: readonly [{
|
|
22
|
+
readonly internalType: "address";
|
|
23
|
+
readonly name: "user";
|
|
24
|
+
readonly type: "address";
|
|
25
|
+
}, {
|
|
26
|
+
readonly internalType: "uint256";
|
|
27
|
+
readonly name: "packId";
|
|
28
|
+
readonly type: "uint256";
|
|
29
|
+
}, {
|
|
30
|
+
readonly internalType: "uint256";
|
|
31
|
+
readonly name: "amount";
|
|
32
|
+
readonly type: "uint256";
|
|
33
|
+
}, {
|
|
34
|
+
readonly internalType: "string";
|
|
35
|
+
readonly name: "discountCode";
|
|
36
|
+
readonly type: "string";
|
|
37
|
+
}];
|
|
38
|
+
readonly name: "buyPacksForWithDiscount";
|
|
39
|
+
readonly outputs: readonly [];
|
|
40
|
+
readonly stateMutability: "nonpayable";
|
|
41
|
+
readonly type: "function";
|
|
42
|
+
};
|
|
43
|
+
export declare const IS_DISCOUNT_CODE_VALID_FOR_PACK_ABI: {
|
|
44
|
+
readonly inputs: readonly [{
|
|
45
|
+
readonly internalType: "string";
|
|
46
|
+
readonly name: "code";
|
|
47
|
+
readonly type: "string";
|
|
48
|
+
}, {
|
|
49
|
+
readonly internalType: "uint256";
|
|
50
|
+
readonly name: "packId";
|
|
51
|
+
readonly type: "uint256";
|
|
52
|
+
}];
|
|
53
|
+
readonly name: "isDiscountCodeValidForPack";
|
|
54
|
+
readonly outputs: readonly [{
|
|
55
|
+
readonly internalType: "bool";
|
|
56
|
+
readonly name: "isValid";
|
|
57
|
+
readonly type: "bool";
|
|
58
|
+
}, {
|
|
59
|
+
readonly internalType: "uint256";
|
|
60
|
+
readonly name: "discountAmount";
|
|
61
|
+
readonly type: "uint256";
|
|
62
|
+
}];
|
|
63
|
+
readonly stateMutability: "view";
|
|
64
|
+
readonly type: "function";
|
|
65
|
+
};
|
|
66
|
+
export declare const GET_DISCOUNT_CODE_ABI: {
|
|
67
|
+
readonly inputs: readonly [{
|
|
68
|
+
readonly internalType: "string";
|
|
69
|
+
readonly name: "code";
|
|
70
|
+
readonly type: "string";
|
|
71
|
+
}];
|
|
72
|
+
readonly name: "getDiscountCode";
|
|
73
|
+
readonly outputs: readonly [{
|
|
74
|
+
readonly components: readonly [{
|
|
75
|
+
readonly internalType: "uint256";
|
|
76
|
+
readonly name: "discountAmount";
|
|
77
|
+
readonly type: "uint256";
|
|
78
|
+
}, {
|
|
79
|
+
readonly internalType: "uint256";
|
|
80
|
+
readonly name: "expiresAt";
|
|
81
|
+
readonly type: "uint256";
|
|
82
|
+
}, {
|
|
83
|
+
readonly internalType: "bool";
|
|
84
|
+
readonly name: "used";
|
|
85
|
+
readonly type: "bool";
|
|
86
|
+
}, {
|
|
87
|
+
readonly internalType: "bool";
|
|
88
|
+
readonly name: "exists";
|
|
89
|
+
readonly type: "bool";
|
|
90
|
+
}, {
|
|
91
|
+
readonly internalType: "uint256";
|
|
92
|
+
readonly name: "maxUses";
|
|
93
|
+
readonly type: "uint256";
|
|
94
|
+
}, {
|
|
95
|
+
readonly internalType: "uint256";
|
|
96
|
+
readonly name: "usedCount";
|
|
97
|
+
readonly type: "uint256";
|
|
98
|
+
}, {
|
|
99
|
+
readonly internalType: "uint256";
|
|
100
|
+
readonly name: "packId";
|
|
101
|
+
readonly type: "uint256";
|
|
102
|
+
}, {
|
|
103
|
+
readonly internalType: "uint256";
|
|
104
|
+
readonly name: "minPurchaseAmount";
|
|
105
|
+
readonly type: "uint256";
|
|
106
|
+
}];
|
|
107
|
+
readonly internalType: "struct CCShop.DiscountCode";
|
|
108
|
+
readonly name: "";
|
|
109
|
+
readonly type: "tuple";
|
|
110
|
+
}];
|
|
111
|
+
readonly stateMutability: "view";
|
|
112
|
+
readonly type: "function";
|
|
113
|
+
};
|
|
@@ -18,8 +18,6 @@ interface CryptoPaySectionProps {
|
|
|
18
18
|
}) => void;
|
|
19
19
|
onShowFeeDetail?: () => void;
|
|
20
20
|
classes?: CryptoPaySectionClasses;
|
|
21
|
-
/** When true, skip auto-setting max balance when token changes (used for fixed destination amount mode) */
|
|
22
|
-
skipAutoMaxOnTokenChange?: boolean;
|
|
23
21
|
}
|
|
24
|
-
export declare function CryptoPaySection({ selectedSrcChainId, setSelectedSrcChainId, selectedSrcToken, setSelectedSrcToken, srcAmount, setSrcAmount, isSrcInputDirty, setIsSrcInputDirty, selectedCryptoPaymentMethod, onSelectCryptoPaymentMethod, anyspendQuote, onTokenSelect, onShowFeeDetail, classes,
|
|
22
|
+
export declare function CryptoPaySection({ selectedSrcChainId, setSelectedSrcChainId, selectedSrcToken, setSelectedSrcToken, srcAmount, setSrcAmount, isSrcInputDirty, setIsSrcInputDirty, selectedCryptoPaymentMethod, onSelectCryptoPaymentMethod, anyspendQuote, onTokenSelect, onShowFeeDetail, classes, }: CryptoPaySectionProps): import("react/jsx-runtime").JSX.Element;
|
|
25
23
|
export {};
|