@b3dotfun/sdk 0.0.70 → 0.0.71-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/anyspend/index.d.ts +1 -0
- package/dist/cjs/anyspend/index.js +1 -0
- package/dist/cjs/anyspend/react/components/AnySpendCollectorClubPurchase.d.ts +57 -0
- package/dist/cjs/anyspend/react/components/AnySpendCollectorClubPurchase.js +82 -0
- package/dist/cjs/anyspend/react/components/AnySpendCustom.js +3 -1
- package/dist/cjs/anyspend/react/components/index.d.ts +1 -0
- package/dist/cjs/anyspend/react/components/index.js +3 -1
- package/dist/cjs/anyspend/react/components/webview/WebviewOnrampPayment.js +1 -3
- package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +10 -3
- package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOrder.d.ts +0 -1
- package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOrder.js +10 -2
- package/dist/cjs/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +16 -0
- package/dist/cjs/anyspend/react/hooks/useSigMint.d.ts +1 -1
- package/dist/cjs/anyspend/react/hooks/useValidatedClientReferenceId.d.ts +5 -0
- package/dist/cjs/anyspend/react/hooks/useValidatedClientReferenceId.js +35 -0
- package/dist/cjs/anyspend/services/anyspend.d.ts +2 -1
- package/dist/cjs/anyspend/services/anyspend.js +5 -1
- package/dist/cjs/anyspend/types/api.d.ts +295 -0
- package/dist/cjs/anyspend/utils/validation.d.ts +67 -0
- package/dist/cjs/anyspend/utils/validation.js +157 -0
- package/dist/cjs/global-account/react/components/B3DynamicModal.js +2 -0
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.d.ts +4 -2
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +4 -3
- package/dist/cjs/global-account/react/components/B3Provider/types.d.ts +1 -0
- package/dist/cjs/global-account/react/components/B3Provider/types.js +1 -0
- package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +1 -1
- package/dist/cjs/global-account/react/hooks/useUserQuery.d.ts +1 -1
- package/dist/cjs/global-account/react/stores/useModalStore.d.ts +27 -1
- package/dist/esm/anyspend/index.d.ts +1 -0
- package/dist/esm/anyspend/index.js +1 -0
- package/dist/esm/anyspend/react/components/AnySpendCollectorClubPurchase.d.ts +57 -0
- package/dist/esm/anyspend/react/components/AnySpendCollectorClubPurchase.js +79 -0
- package/dist/esm/anyspend/react/components/AnySpendCustom.js +3 -1
- package/dist/esm/anyspend/react/components/index.d.ts +1 -0
- package/dist/esm/anyspend/react/components/index.js +1 -0
- package/dist/esm/anyspend/react/components/webview/WebviewOnrampPayment.js +1 -3
- package/dist/esm/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +8 -1
- package/dist/esm/anyspend/react/hooks/useAnyspendCreateOrder.d.ts +0 -1
- package/dist/esm/anyspend/react/hooks/useAnyspendCreateOrder.js +8 -0
- package/dist/esm/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +16 -0
- package/dist/esm/anyspend/react/hooks/useSigMint.d.ts +1 -1
- package/dist/esm/anyspend/react/hooks/useValidatedClientReferenceId.d.ts +5 -0
- package/dist/esm/anyspend/react/hooks/useValidatedClientReferenceId.js +32 -0
- package/dist/esm/anyspend/services/anyspend.d.ts +2 -1
- package/dist/esm/anyspend/services/anyspend.js +5 -1
- package/dist/esm/anyspend/types/api.d.ts +295 -0
- package/dist/esm/anyspend/utils/validation.d.ts +67 -0
- package/dist/esm/anyspend/utils/validation.js +153 -0
- package/dist/esm/global-account/react/components/B3DynamicModal.js +3 -1
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.d.ts +4 -2
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +4 -3
- package/dist/esm/global-account/react/components/B3Provider/types.d.ts +1 -0
- package/dist/esm/global-account/react/components/B3Provider/types.js +1 -0
- package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +1 -1
- package/dist/esm/global-account/react/hooks/useUserQuery.d.ts +1 -1
- package/dist/esm/global-account/react/stores/useModalStore.d.ts +27 -1
- package/dist/types/anyspend/index.d.ts +1 -0
- package/dist/types/anyspend/react/components/AnySpendCollectorClubPurchase.d.ts +57 -0
- package/dist/types/anyspend/react/components/index.d.ts +1 -0
- package/dist/types/anyspend/react/hooks/useAnyspendCreateOrder.d.ts +0 -1
- package/dist/types/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +16 -0
- package/dist/types/anyspend/react/hooks/useSigMint.d.ts +1 -1
- package/dist/types/anyspend/react/hooks/useValidatedClientReferenceId.d.ts +5 -0
- package/dist/types/anyspend/services/anyspend.d.ts +2 -1
- package/dist/types/anyspend/types/api.d.ts +295 -0
- package/dist/types/anyspend/utils/validation.d.ts +67 -0
- package/dist/types/global-account/react/components/B3Provider/B3Provider.d.ts +4 -2
- package/dist/types/global-account/react/components/B3Provider/types.d.ts +1 -0
- package/dist/types/global-account/react/hooks/useAuthentication.d.ts +1 -1
- package/dist/types/global-account/react/hooks/useUserQuery.d.ts +1 -1
- package/dist/types/global-account/react/stores/useModalStore.d.ts +27 -1
- package/package.json +1 -1
- package/src/anyspend/index.ts +1 -0
- package/src/anyspend/react/components/AnySpendCollectorClubPurchase.tsx +178 -0
- package/src/anyspend/react/components/AnySpendCustom.tsx +3 -1
- package/src/anyspend/react/components/index.ts +1 -0
- package/src/anyspend/react/components/webview/WebviewOnrampPayment.tsx +0 -3
- package/src/anyspend/react/hooks/useAnyspendCreateOnrampOrder.ts +9 -1
- package/src/anyspend/react/hooks/useAnyspendCreateOrder.ts +10 -1
- package/src/anyspend/react/hooks/useValidatedClientReferenceId.ts +40 -0
- package/src/anyspend/services/anyspend.ts +6 -0
- package/src/anyspend/types/api.ts +295 -0
- package/src/anyspend/utils/validation.ts +209 -0
- package/src/global-account/react/components/B3DynamicModal.tsx +3 -0
- package/src/global-account/react/components/B3Provider/B3Provider.tsx +6 -0
- package/src/global-account/react/components/B3Provider/types.ts +2 -0
- package/src/global-account/react/stores/useModalStore.ts +29 -1
|
@@ -6,6 +6,7 @@ export * from "./utils/json";
|
|
|
6
6
|
export * from "./utils/number";
|
|
7
7
|
export * from "./utils/string";
|
|
8
8
|
export * from "./utils/token";
|
|
9
|
+
export * from "./utils/validation";
|
|
9
10
|
export * from "./constants";
|
|
10
11
|
export * from "./abis/abiUsdcBase";
|
|
11
12
|
export * from "./abis/erc20Staking";
|
|
@@ -24,6 +24,7 @@ __exportStar(require("./utils/json"), exports);
|
|
|
24
24
|
__exportStar(require("./utils/number"), exports);
|
|
25
25
|
__exportStar(require("./utils/string"), exports);
|
|
26
26
|
__exportStar(require("./utils/token"), exports);
|
|
27
|
+
__exportStar(require("./utils/validation"), exports);
|
|
27
28
|
// Constants
|
|
28
29
|
__exportStar(require("./constants"), exports);
|
|
29
30
|
// Abis
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { components } from "../../../anyspend/types/api";
|
|
2
|
+
import { GetQuoteResponse } from "../../../anyspend/types/api_req_res";
|
|
3
|
+
import React from "react";
|
|
4
|
+
export interface AnySpendCollectorClubPurchaseProps {
|
|
5
|
+
/**
|
|
6
|
+
* Optional order ID to load existing order
|
|
7
|
+
*/
|
|
8
|
+
loadOrder?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Display mode
|
|
11
|
+
*/
|
|
12
|
+
mode?: "modal" | "page";
|
|
13
|
+
/**
|
|
14
|
+
* Active tab (crypto or fiat payment)
|
|
15
|
+
*/
|
|
16
|
+
activeTab?: "crypto" | "fiat";
|
|
17
|
+
/**
|
|
18
|
+
* The pack ID to purchase
|
|
19
|
+
*/
|
|
20
|
+
packId: number;
|
|
21
|
+
/**
|
|
22
|
+
* The number of packs to purchase
|
|
23
|
+
*/
|
|
24
|
+
packAmount: number;
|
|
25
|
+
/**
|
|
26
|
+
* Price per pack in wei (e.g., "10000" for 0.01 USDC with 6 decimals)
|
|
27
|
+
*/
|
|
28
|
+
pricePerPack: string;
|
|
29
|
+
/**
|
|
30
|
+
* The payment token (defaults to USDC on Base)
|
|
31
|
+
*/
|
|
32
|
+
paymentToken?: components["schemas"]["Token"];
|
|
33
|
+
/**
|
|
34
|
+
* Address that will receive the packs
|
|
35
|
+
*/
|
|
36
|
+
recipientAddress: string;
|
|
37
|
+
/**
|
|
38
|
+
* Optional spender address (defaults to contract address)
|
|
39
|
+
*/
|
|
40
|
+
spenderAddress?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Success callback
|
|
43
|
+
*/
|
|
44
|
+
onSuccess?: (txHash?: string) => void;
|
|
45
|
+
/**
|
|
46
|
+
* Optional custom header component
|
|
47
|
+
*/
|
|
48
|
+
header?: (props: {
|
|
49
|
+
anyspendPrice: GetQuoteResponse | undefined;
|
|
50
|
+
isLoadingAnyspendPrice: boolean;
|
|
51
|
+
}) => React.JSX.Element;
|
|
52
|
+
/**
|
|
53
|
+
* Show recipient selection (default: true)
|
|
54
|
+
*/
|
|
55
|
+
showRecipient?: boolean;
|
|
56
|
+
}
|
|
57
|
+
export declare function AnySpendCollectorClubPurchase({ loadOrder, mode, activeTab, packId, packAmount, pricePerPack, paymentToken, recipientAddress, spenderAddress, onSuccess, header, showRecipient, }: AnySpendCollectorClubPurchaseProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AnySpendCollectorClubPurchase = AnySpendCollectorClubPurchase;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
/**
|
|
6
|
+
* AnySpend component for Collector Club pack purchases
|
|
7
|
+
*
|
|
8
|
+
* This component enables users to purchase Collector Club packs using any token via AnySpend.
|
|
9
|
+
* It calls the `buyPacksFor` function on the Collector Club Shop contract on Base.
|
|
10
|
+
* Uses exact-out flow to ensure the contract receives exactly the required USDC amount.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* import { AnySpendCollectorClubPurchase } from "../../..";
|
|
15
|
+
* import { USDC_BASE } from "../../../anyspend/constants";
|
|
16
|
+
*
|
|
17
|
+
* function MyComponent() {
|
|
18
|
+
* return (
|
|
19
|
+
* <AnySpendCollectorClubPurchase
|
|
20
|
+
* packId={1}
|
|
21
|
+
* packAmount={5}
|
|
22
|
+
* pricePerPack="10000" // 0.01 USDC in wei (6 decimals)
|
|
23
|
+
* paymentToken={USDC_BASE}
|
|
24
|
+
* recipientAddress="0x123..."
|
|
25
|
+
* onSuccess={(txHash) => console.log("Purchase successful!", txHash)}
|
|
26
|
+
* />
|
|
27
|
+
* );
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
const constants_1 = require("../../../anyspend/constants");
|
|
32
|
+
const react_1 = require("react");
|
|
33
|
+
const viem_1 = require("viem");
|
|
34
|
+
const AnySpendCustom_1 = require("./AnySpendCustom");
|
|
35
|
+
// Collector Club Shop contract on Base
|
|
36
|
+
const CC_SHOP_ADDRESS = "0x68B32D594E3c7E5B8cd8046BD66AfB0DB5b9BF9c";
|
|
37
|
+
const BASE_CHAIN_ID = 8453;
|
|
38
|
+
// ABI for buyPacksFor function only
|
|
39
|
+
const BUY_PACKS_FOR_ABI = {
|
|
40
|
+
inputs: [
|
|
41
|
+
{ internalType: "address", name: "user", type: "address" },
|
|
42
|
+
{ internalType: "uint256", name: "packId", type: "uint256" },
|
|
43
|
+
{ internalType: "uint256", name: "amount", type: "uint256" },
|
|
44
|
+
],
|
|
45
|
+
name: "buyPacksFor",
|
|
46
|
+
outputs: [],
|
|
47
|
+
stateMutability: "nonpayable",
|
|
48
|
+
type: "function",
|
|
49
|
+
};
|
|
50
|
+
function AnySpendCollectorClubPurchase({ loadOrder, mode = "modal", activeTab = "crypto", packId, packAmount, pricePerPack, paymentToken = constants_1.USDC_BASE, recipientAddress, spenderAddress = CC_SHOP_ADDRESS, onSuccess, header, showRecipient = true, }) {
|
|
51
|
+
// Calculate total amount needed (pricePerPack * packAmount)
|
|
52
|
+
const totalAmount = (0, react_1.useMemo)(() => {
|
|
53
|
+
try {
|
|
54
|
+
return (BigInt(pricePerPack) * BigInt(packAmount)).toString();
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
console.error("Failed to calculate total amount from props", { pricePerPack, packAmount, error });
|
|
58
|
+
return "0";
|
|
59
|
+
}
|
|
60
|
+
}, [pricePerPack, packAmount]);
|
|
61
|
+
// Encode the buyPacksFor function call
|
|
62
|
+
const encodedData = (0, react_1.useMemo)(() => {
|
|
63
|
+
try {
|
|
64
|
+
return (0, viem_1.encodeFunctionData)({
|
|
65
|
+
abi: [BUY_PACKS_FOR_ABI],
|
|
66
|
+
functionName: "buyPacksFor",
|
|
67
|
+
args: [recipientAddress, BigInt(packId), BigInt(packAmount)],
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
console.error("Failed to encode function data", { recipientAddress, packId, packAmount, error });
|
|
72
|
+
return "0x";
|
|
73
|
+
}
|
|
74
|
+
}, [recipientAddress, packId, packAmount]);
|
|
75
|
+
// Default header if not provided
|
|
76
|
+
const defaultHeader = () => ((0, jsx_runtime_1.jsx)("div", { className: "mb-4 flex flex-col items-center gap-3 text-center", children: (0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("h1", { className: "text-as-primary text-xl font-bold", children: "Buy Collector Club Packs" }), (0, jsx_runtime_1.jsxs)("p", { className: "text-as-secondary text-sm", children: ["Purchase ", packAmount, " pack", packAmount !== 1 ? "s" : "", " using any token"] })] }) }));
|
|
77
|
+
return ((0, jsx_runtime_1.jsx)(AnySpendCustom_1.AnySpendCustom, { loadOrder: loadOrder, mode: mode, activeTab: activeTab, recipientAddress: recipientAddress, spenderAddress: spenderAddress, orderType: "custom", dstChainId: BASE_CHAIN_ID, dstToken: paymentToken, dstAmount: totalAmount, contractAddress: CC_SHOP_ADDRESS, encodedData: encodedData, metadata: {
|
|
78
|
+
packId,
|
|
79
|
+
packAmount,
|
|
80
|
+
pricePerPack,
|
|
81
|
+
}, header: header || defaultHeader, onSuccess: onSuccess, showRecipient: showRecipient }));
|
|
82
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { AnySpend } from "./AnySpend";
|
|
2
2
|
export { AnySpendBondKit } from "./AnySpendBondKit";
|
|
3
3
|
export { AnySpendBuySpin } from "./AnySpendBuySpin";
|
|
4
|
+
export { AnySpendCollectorClubPurchase } from "./AnySpendCollectorClubPurchase";
|
|
4
5
|
export { AnySpendCustom } from "./AnySpendCustom";
|
|
5
6
|
export { AnySpendCustomExactIn } from "./AnySpendCustomExactIn";
|
|
6
7
|
export { AnySpendDepositHype, HYPE_TOKEN_DETAILS } from "./AnyspendDepositHype";
|
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.WebviewOnrampPayment = exports.WebviewOnrampOrderStatus = exports.TransferCryptoDetails = exports.TokenBalance = exports.StepProgress = exports.RecipientSelection = exports.OrderTokenAmount = exports.OrderToken = exports.OrderStatus = exports.OrderHistoryItem = exports.OrderHistory = exports.OrderDetailsCollapsible = exports.OrderDetails = exports.CryptoReceiveSection = exports.CryptoPaySection = exports.ChainTokenIcon = exports.AnySpendNFTButton = exports.AnySpendTournament = exports.AnySpendStakeUpsideExactIn = exports.AnySpendStakeUpside = exports.AnySpendStakeB3ExactIn = exports.AnySpendStakeB3 = exports.AnyspendSignatureMint = exports.AnySpendNFT = exports.HYPE_TOKEN_DETAILS = exports.AnySpendDepositHype = exports.AnySpendCustomExactIn = exports.AnySpendCustom = exports.AnySpendBuySpin = exports.AnySpendBondKit = exports.AnySpend = void 0;
|
|
17
|
+
exports.WebviewOnrampPayment = exports.WebviewOnrampOrderStatus = exports.TransferCryptoDetails = exports.TokenBalance = exports.StepProgress = exports.RecipientSelection = exports.OrderTokenAmount = exports.OrderToken = exports.OrderStatus = exports.OrderHistoryItem = exports.OrderHistory = exports.OrderDetailsCollapsible = exports.OrderDetails = exports.CryptoReceiveSection = exports.CryptoPaySection = exports.ChainTokenIcon = exports.AnySpendNFTButton = exports.AnySpendTournament = exports.AnySpendStakeUpsideExactIn = exports.AnySpendStakeUpside = exports.AnySpendStakeB3ExactIn = exports.AnySpendStakeB3 = exports.AnyspendSignatureMint = exports.AnySpendNFT = exports.HYPE_TOKEN_DETAILS = exports.AnySpendDepositHype = exports.AnySpendCustomExactIn = exports.AnySpendCustom = exports.AnySpendCollectorClubPurchase = exports.AnySpendBuySpin = exports.AnySpendBondKit = exports.AnySpend = void 0;
|
|
18
18
|
// Components
|
|
19
19
|
var AnySpend_1 = require("./AnySpend");
|
|
20
20
|
Object.defineProperty(exports, "AnySpend", { enumerable: true, get: function () { return AnySpend_1.AnySpend; } });
|
|
@@ -22,6 +22,8 @@ var AnySpendBondKit_1 = require("./AnySpendBondKit");
|
|
|
22
22
|
Object.defineProperty(exports, "AnySpendBondKit", { enumerable: true, get: function () { return AnySpendBondKit_1.AnySpendBondKit; } });
|
|
23
23
|
var AnySpendBuySpin_1 = require("./AnySpendBuySpin");
|
|
24
24
|
Object.defineProperty(exports, "AnySpendBuySpin", { enumerable: true, get: function () { return AnySpendBuySpin_1.AnySpendBuySpin; } });
|
|
25
|
+
var AnySpendCollectorClubPurchase_1 = require("./AnySpendCollectorClubPurchase");
|
|
26
|
+
Object.defineProperty(exports, "AnySpendCollectorClubPurchase", { enumerable: true, get: function () { return AnySpendCollectorClubPurchase_1.AnySpendCollectorClubPurchase; } });
|
|
25
27
|
var AnySpendCustom_1 = require("./AnySpendCustom");
|
|
26
28
|
Object.defineProperty(exports, "AnySpendCustom", { enumerable: true, get: function () { return AnySpendCustom_1.AnySpendCustom; } });
|
|
27
29
|
var AnySpendCustomExactIn_1 = require("./AnySpendCustomExactIn");
|
|
@@ -90,7 +90,7 @@ function StripePaymentForm({ order, onPaymentSuccess, }) {
|
|
|
90
90
|
},
|
|
91
91
|
} }) })), error && ((0, jsx_runtime_1.jsx)("div", { className: "mt-4 rounded-lg border border-red-200 bg-red-50 p-3 text-sm text-red-600", children: error })), (0, jsx_runtime_1.jsx)("button", { type: "submit", disabled: !stripe || isProcessing, className: "mt-6 w-full rounded-xl bg-blue-600 px-4 py-3 font-medium text-white hover:bg-blue-700 disabled:cursor-not-allowed disabled:opacity-50", children: isProcessing ? ((0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-center gap-2", children: [(0, jsx_runtime_1.jsx)(lucide_react_1.Loader2, { className: "h-5 w-5 animate-spin" }), (0, jsx_runtime_1.jsx)("span", { children: "Processing..." })] })) : ((0, jsx_runtime_1.jsx)("span", { children: "Complete Payment" })) })] }) }) }));
|
|
92
92
|
}
|
|
93
|
-
function WebviewOnrampPaymentInner({ srcAmountOnRamp, recipientAddress, destinationToken, anyspendQuote, onPaymentSuccess, userId,
|
|
93
|
+
function WebviewOnrampPaymentInner({ srcAmountOnRamp, recipientAddress, destinationToken, anyspendQuote, onPaymentSuccess, userId, }) {
|
|
94
94
|
const [createdOrder, setCreatedOrder] = (0, react_3.useState)(null);
|
|
95
95
|
const orderCreationAttempted = (0, react_3.useRef)(false);
|
|
96
96
|
const { geoData, stripeWeb2Support, isLoading: isLoadingGeoOnramp } = (0, react_1.useGeoOnrampOptions)(srcAmountOnRamp);
|
|
@@ -136,7 +136,6 @@ function WebviewOnrampPaymentInner({ srcAmountOnRamp, recipientAddress, destinat
|
|
|
136
136
|
redirectUrl: `${window.location.origin}${userId ? `?userId=${userId}` : ""}`,
|
|
137
137
|
},
|
|
138
138
|
expectedDstAmount: anyspendQuote.data?.currencyOut?.amount?.toString() || "0",
|
|
139
|
-
partnerId,
|
|
140
139
|
});
|
|
141
140
|
}
|
|
142
141
|
catch (err) {
|
|
@@ -154,7 +153,6 @@ function WebviewOnrampPaymentInner({ srcAmountOnRamp, recipientAddress, destinat
|
|
|
154
153
|
createOrder,
|
|
155
154
|
destinationToken,
|
|
156
155
|
userId,
|
|
157
|
-
partnerId,
|
|
158
156
|
stripeWeb2Support.isSupport,
|
|
159
157
|
]);
|
|
160
158
|
// Check if all required data is loaded
|
|
@@ -4,16 +4,22 @@ exports.useAnyspendCreateOnrampOrder = useAnyspendCreateOnrampOrder;
|
|
|
4
4
|
const constants_1 = require("../../../anyspend/constants");
|
|
5
5
|
const anyspend_1 = require("../../../anyspend/services/anyspend");
|
|
6
6
|
const utils_1 = require("../../../anyspend/utils");
|
|
7
|
+
const react_1 = require("../../../global-account/react");
|
|
7
8
|
const fingerprintjs_pro_react_1 = require("@fingerprintjs/fingerprintjs-pro-react");
|
|
8
9
|
const react_query_1 = require("@tanstack/react-query");
|
|
9
|
-
const
|
|
10
|
+
const react_2 = require("react");
|
|
10
11
|
const viem_1 = require("viem");
|
|
11
12
|
const chains_1 = require("viem/chains");
|
|
13
|
+
const useValidatedClientReferenceId_1 = require("./useValidatedClientReferenceId");
|
|
12
14
|
/**
|
|
13
15
|
* Hook for creating onramp orders in the Anyspend protocol
|
|
14
16
|
* Specifically handles orders that involve fiat-to-crypto onramp functionality
|
|
15
17
|
*/
|
|
16
18
|
function useAnyspendCreateOnrampOrder({ onSuccess, onError } = {}) {
|
|
19
|
+
// Get B3 context values
|
|
20
|
+
const { partnerId } = (0, react_1.useB3)();
|
|
21
|
+
// Get validated client reference ID from B3 context
|
|
22
|
+
const validatedClientReferenceId = (0, useValidatedClientReferenceId_1.useValidatedClientReferenceId)();
|
|
17
23
|
// Get fingerprint data
|
|
18
24
|
const { data: fpData } = (0, fingerprintjs_pro_react_1.useVisitorData)({ extendedResult: true }, { immediate: true });
|
|
19
25
|
const visitorData = fpData && {
|
|
@@ -22,7 +28,7 @@ function useAnyspendCreateOnrampOrder({ onSuccess, onError } = {}) {
|
|
|
22
28
|
};
|
|
23
29
|
const { mutate: createOrder, isPending } = (0, react_query_1.useMutation)({
|
|
24
30
|
mutationFn: async (params) => {
|
|
25
|
-
const { recipientAddress, orderType, dstChain, dstToken, srcFiatAmount, onramp, creatorAddress, expectedDstAmount, nft, tournament, payload,
|
|
31
|
+
const { recipientAddress, orderType, dstChain, dstToken, srcFiatAmount, onramp, creatorAddress, expectedDstAmount, nft, tournament, payload, } = params;
|
|
26
32
|
try {
|
|
27
33
|
// Validate required onramp fields
|
|
28
34
|
if (!onramp.vendor || !onramp.country) {
|
|
@@ -65,6 +71,7 @@ function useAnyspendCreateOnrampOrder({ onSuccess, onError } = {}) {
|
|
|
65
71
|
}),
|
|
66
72
|
creatorAddress: creatorAddress ? (0, utils_1.normalizeAddress)(creatorAddress) : undefined,
|
|
67
73
|
partnerId,
|
|
74
|
+
clientReferenceId: validatedClientReferenceId,
|
|
68
75
|
visitorData,
|
|
69
76
|
});
|
|
70
77
|
}
|
|
@@ -84,7 +91,7 @@ function useAnyspendCreateOnrampOrder({ onSuccess, onError } = {}) {
|
|
|
84
91
|
onError?.(error);
|
|
85
92
|
},
|
|
86
93
|
});
|
|
87
|
-
return (0,
|
|
94
|
+
return (0, react_2.useMemo)(() => ({
|
|
88
95
|
createOrder,
|
|
89
96
|
isCreatingOrder: isPending,
|
|
90
97
|
}), [createOrder, isPending]);
|
|
@@ -3,15 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useAnyspendCreateOrder = useAnyspendCreateOrder;
|
|
4
4
|
const anyspend_1 = require("../../../anyspend/services/anyspend");
|
|
5
5
|
const utils_1 = require("../../../anyspend/utils");
|
|
6
|
+
const react_1 = require("../../../global-account/react");
|
|
6
7
|
const fingerprintjs_pro_react_1 = require("@fingerprintjs/fingerprintjs-pro-react");
|
|
7
8
|
const react_query_1 = require("@tanstack/react-query");
|
|
8
|
-
const
|
|
9
|
+
const react_2 = require("react");
|
|
10
|
+
const useValidatedClientReferenceId_1 = require("./useValidatedClientReferenceId");
|
|
9
11
|
/**
|
|
10
12
|
* Hook for creating orders in the Anyspend protocol
|
|
11
13
|
* Handles regular order creation for swaps, NFT minting, tournament participation, etc.
|
|
12
14
|
* For onramp orders, use useAnyspendCreateOnrampOrder instead.
|
|
13
15
|
*/
|
|
14
16
|
function useAnyspendCreateOrder({ onSuccess, onError } = {}) {
|
|
17
|
+
// Get B3 context values
|
|
18
|
+
const { partnerId } = (0, react_1.useB3)();
|
|
19
|
+
// Get validated client reference ID from B3 context
|
|
20
|
+
const validatedClientReferenceId = (0, useValidatedClientReferenceId_1.useValidatedClientReferenceId)();
|
|
15
21
|
// Get fingerprint data
|
|
16
22
|
const { data: fpData } = (0, fingerprintjs_pro_react_1.useVisitorData)({ extendedResult: true }, { immediate: true });
|
|
17
23
|
const visitorData = fpData && {
|
|
@@ -53,6 +59,8 @@ function useAnyspendCreateOrder({ onSuccess, onError } = {}) {
|
|
|
53
59
|
},
|
|
54
60
|
}),
|
|
55
61
|
creatorAddress: creatorAddress ? (0, utils_1.normalizeAddress)(creatorAddress) : undefined,
|
|
62
|
+
partnerId,
|
|
63
|
+
clientReferenceId: validatedClientReferenceId,
|
|
56
64
|
visitorData,
|
|
57
65
|
});
|
|
58
66
|
}
|
|
@@ -72,7 +80,7 @@ function useAnyspendCreateOrder({ onSuccess, onError } = {}) {
|
|
|
72
80
|
onError?.(error);
|
|
73
81
|
},
|
|
74
82
|
});
|
|
75
|
-
return (0,
|
|
83
|
+
return (0, react_2.useMemo)(() => ({
|
|
76
84
|
createOrder,
|
|
77
85
|
isCreatingOrder: isPending,
|
|
78
86
|
}), [createOrder, isPending]);
|
|
@@ -16,6 +16,7 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
|
|
|
16
16
|
receivedDepositAt: number | null;
|
|
17
17
|
creatorAddress: string | null;
|
|
18
18
|
partnerId: string | null;
|
|
19
|
+
clientReferenceId?: string | null;
|
|
19
20
|
onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
|
|
20
21
|
oneClickBuyUrl: string | null;
|
|
21
22
|
stripePaymentIntentId: string | null;
|
|
@@ -45,6 +46,7 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
|
|
|
45
46
|
receivedDepositAt: number | null;
|
|
46
47
|
creatorAddress: string | null;
|
|
47
48
|
partnerId: string | null;
|
|
49
|
+
clientReferenceId?: string | null;
|
|
48
50
|
onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
|
|
49
51
|
oneClickBuyUrl: string | null;
|
|
50
52
|
stripePaymentIntentId: string | null;
|
|
@@ -74,6 +76,7 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
|
|
|
74
76
|
receivedDepositAt: number | null;
|
|
75
77
|
creatorAddress: string | null;
|
|
76
78
|
partnerId: string | null;
|
|
79
|
+
clientReferenceId?: string | null;
|
|
77
80
|
onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
|
|
78
81
|
oneClickBuyUrl: string | null;
|
|
79
82
|
stripePaymentIntentId: string | null;
|
|
@@ -103,6 +106,7 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
|
|
|
103
106
|
receivedDepositAt: number | null;
|
|
104
107
|
creatorAddress: string | null;
|
|
105
108
|
partnerId: string | null;
|
|
109
|
+
clientReferenceId?: string | null;
|
|
106
110
|
onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
|
|
107
111
|
oneClickBuyUrl: string | null;
|
|
108
112
|
stripePaymentIntentId: string | null;
|
|
@@ -132,6 +136,7 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
|
|
|
132
136
|
receivedDepositAt: number | null;
|
|
133
137
|
creatorAddress: string | null;
|
|
134
138
|
partnerId: string | null;
|
|
139
|
+
clientReferenceId?: string | null;
|
|
135
140
|
onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
|
|
136
141
|
oneClickBuyUrl: string | null;
|
|
137
142
|
stripePaymentIntentId: string | null;
|
|
@@ -161,6 +166,7 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
|
|
|
161
166
|
receivedDepositAt: number | null;
|
|
162
167
|
creatorAddress: string | null;
|
|
163
168
|
partnerId: string | null;
|
|
169
|
+
clientReferenceId?: string | null;
|
|
164
170
|
onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
|
|
165
171
|
oneClickBuyUrl: string | null;
|
|
166
172
|
stripePaymentIntentId: string | null;
|
|
@@ -190,6 +196,7 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
|
|
|
190
196
|
receivedDepositAt: number | null;
|
|
191
197
|
creatorAddress: string | null;
|
|
192
198
|
partnerId: string | null;
|
|
199
|
+
clientReferenceId?: string | null;
|
|
193
200
|
onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
|
|
194
201
|
oneClickBuyUrl: string | null;
|
|
195
202
|
stripePaymentIntentId: string | null;
|
|
@@ -219,6 +226,7 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
|
|
|
219
226
|
receivedDepositAt: number | null;
|
|
220
227
|
creatorAddress: string | null;
|
|
221
228
|
partnerId: string | null;
|
|
229
|
+
clientReferenceId?: string | null;
|
|
222
230
|
onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
|
|
223
231
|
oneClickBuyUrl: string | null;
|
|
224
232
|
stripePaymentIntentId: string | null;
|
|
@@ -251,6 +259,7 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
|
|
|
251
259
|
receivedDepositAt: number | null;
|
|
252
260
|
creatorAddress: string | null;
|
|
253
261
|
partnerId: string | null;
|
|
262
|
+
clientReferenceId?: string | null;
|
|
254
263
|
onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
|
|
255
264
|
oneClickBuyUrl: string | null;
|
|
256
265
|
stripePaymentIntentId: string | null;
|
|
@@ -280,6 +289,7 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
|
|
|
280
289
|
receivedDepositAt: number | null;
|
|
281
290
|
creatorAddress: string | null;
|
|
282
291
|
partnerId: string | null;
|
|
292
|
+
clientReferenceId?: string | null;
|
|
283
293
|
onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
|
|
284
294
|
oneClickBuyUrl: string | null;
|
|
285
295
|
stripePaymentIntentId: string | null;
|
|
@@ -309,6 +319,7 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
|
|
|
309
319
|
receivedDepositAt: number | null;
|
|
310
320
|
creatorAddress: string | null;
|
|
311
321
|
partnerId: string | null;
|
|
322
|
+
clientReferenceId?: string | null;
|
|
312
323
|
onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
|
|
313
324
|
oneClickBuyUrl: string | null;
|
|
314
325
|
stripePaymentIntentId: string | null;
|
|
@@ -338,6 +349,7 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
|
|
|
338
349
|
receivedDepositAt: number | null;
|
|
339
350
|
creatorAddress: string | null;
|
|
340
351
|
partnerId: string | null;
|
|
352
|
+
clientReferenceId?: string | null;
|
|
341
353
|
onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
|
|
342
354
|
oneClickBuyUrl: string | null;
|
|
343
355
|
stripePaymentIntentId: string | null;
|
|
@@ -367,6 +379,7 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
|
|
|
367
379
|
receivedDepositAt: number | null;
|
|
368
380
|
creatorAddress: string | null;
|
|
369
381
|
partnerId: string | null;
|
|
382
|
+
clientReferenceId?: string | null;
|
|
370
383
|
onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
|
|
371
384
|
oneClickBuyUrl: string | null;
|
|
372
385
|
stripePaymentIntentId: string | null;
|
|
@@ -396,6 +409,7 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
|
|
|
396
409
|
receivedDepositAt: number | null;
|
|
397
410
|
creatorAddress: string | null;
|
|
398
411
|
partnerId: string | null;
|
|
412
|
+
clientReferenceId?: string | null;
|
|
399
413
|
onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
|
|
400
414
|
oneClickBuyUrl: string | null;
|
|
401
415
|
stripePaymentIntentId: string | null;
|
|
@@ -425,6 +439,7 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
|
|
|
425
439
|
receivedDepositAt: number | null;
|
|
426
440
|
creatorAddress: string | null;
|
|
427
441
|
partnerId: string | null;
|
|
442
|
+
clientReferenceId?: string | null;
|
|
428
443
|
onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
|
|
429
444
|
oneClickBuyUrl: string | null;
|
|
430
445
|
stripePaymentIntentId: string | null;
|
|
@@ -454,6 +469,7 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
|
|
|
454
469
|
receivedDepositAt: number | null;
|
|
455
470
|
creatorAddress: string | null;
|
|
456
471
|
partnerId: string | null;
|
|
472
|
+
clientReferenceId?: string | null;
|
|
457
473
|
onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
|
|
458
474
|
oneClickBuyUrl: string | null;
|
|
459
475
|
stripePaymentIntentId: string | null;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useValidatedClientReferenceId = useValidatedClientReferenceId;
|
|
4
|
+
const validation_1 = require("../../../anyspend/utils/validation");
|
|
5
|
+
const react_1 = require("../../../global-account/react");
|
|
6
|
+
const react_2 = require("react");
|
|
7
|
+
/**
|
|
8
|
+
* Hook that provides a validated client reference ID
|
|
9
|
+
* Gets the createClientReferenceId function from B3 context and validates the result
|
|
10
|
+
*/
|
|
11
|
+
function useValidatedClientReferenceId() {
|
|
12
|
+
const { createClientReferenceId } = (0, react_1.useB3)();
|
|
13
|
+
const validatedClientReferenceId = (0, react_2.useMemo)(() => {
|
|
14
|
+
// If no function provided, return undefined
|
|
15
|
+
if (!createClientReferenceId) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
// Call the function to generate the ID
|
|
20
|
+
const generatedId = createClientReferenceId();
|
|
21
|
+
// Validate the generated ID
|
|
22
|
+
const validation = validation_1.Validators.clientReferenceId(generatedId);
|
|
23
|
+
if (!validation.isValid) {
|
|
24
|
+
console.error(`[AnySpend] Invalid clientReferenceId generated: ${validation.error || "Validation failed"}. Will be set to undefined.`);
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
return validation.cleaned;
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
console.error("[AnySpend] Error generating clientReferenceId:", error);
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
}, [createClientReferenceId]);
|
|
34
|
+
return validatedClientReferenceId;
|
|
35
|
+
}
|
|
@@ -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) => Promise<GetQuoteResponse>;
|
|
9
|
-
createOrder: ({ recipientAddress, type, srcChain, dstChain, srcTokenAddress, dstTokenAddress, srcAmount, payload, onramp, metadata, creatorAddress, partnerId, visitorData, }: {
|
|
9
|
+
createOrder: ({ recipientAddress, type, srcChain, dstChain, srcTokenAddress, dstTokenAddress, srcAmount, payload, onramp, metadata, creatorAddress, partnerId, clientReferenceId, visitorData, }: {
|
|
10
10
|
recipientAddress: string;
|
|
11
11
|
type: string;
|
|
12
12
|
srcChain: number;
|
|
@@ -19,6 +19,7 @@ export declare const anyspendService: {
|
|
|
19
19
|
metadata: Record<string, any>;
|
|
20
20
|
creatorAddress?: string;
|
|
21
21
|
partnerId?: string;
|
|
22
|
+
clientReferenceId?: string;
|
|
22
23
|
visitorData?: VisitorData;
|
|
23
24
|
}) => Promise<{
|
|
24
25
|
success: boolean;
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.anyspendService = void 0;
|
|
7
7
|
const constants_1 = require("../../anyspend/constants");
|
|
8
8
|
const utils_1 = require("../../anyspend/utils");
|
|
9
|
+
const app_1 = __importDefault(require("../../global-account/app"));
|
|
9
10
|
const invariant_1 = __importDefault(require("invariant"));
|
|
10
11
|
// Service functions
|
|
11
12
|
exports.anyspendService = {
|
|
@@ -41,13 +42,15 @@ exports.anyspendService = {
|
|
|
41
42
|
return data;
|
|
42
43
|
},
|
|
43
44
|
// Order related
|
|
44
|
-
createOrder: async ({ recipientAddress, type, srcChain, dstChain, srcTokenAddress, dstTokenAddress, srcAmount, payload, onramp, metadata, creatorAddress, partnerId, visitorData, }) => {
|
|
45
|
+
createOrder: async ({ recipientAddress, type, srcChain, dstChain, srcTokenAddress, dstTokenAddress, srcAmount, payload, onramp, metadata, creatorAddress, partnerId, clientReferenceId, visitorData, }) => {
|
|
46
|
+
const accessToken = await app_1.default.authentication.getAccessToken();
|
|
45
47
|
const response = await fetch(`${constants_1.ANYSPEND_MAINNET_BASE_URL}/orders`, {
|
|
46
48
|
method: "POST",
|
|
47
49
|
headers: {
|
|
48
50
|
"Content-Type": "application/json",
|
|
49
51
|
...(visitorData?.requestId && { "X-Fingerprint-Request-Id": visitorData.requestId }),
|
|
50
52
|
...(visitorData?.visitorId && { "X-Fingerprint-Visitor-Id": visitorData.visitorId }),
|
|
53
|
+
...(accessToken && { Authorization: `Bearer ${accessToken}` }),
|
|
51
54
|
},
|
|
52
55
|
body: JSON.stringify({
|
|
53
56
|
recipientAddress,
|
|
@@ -62,6 +65,7 @@ exports.anyspendService = {
|
|
|
62
65
|
metadata,
|
|
63
66
|
creatorAddress,
|
|
64
67
|
partnerId,
|
|
68
|
+
...(clientReferenceId && { clientReferenceId }),
|
|
65
69
|
}),
|
|
66
70
|
});
|
|
67
71
|
const data = await response.json();
|