@superlogic/spree-pay 0.1.19 → 0.1.21
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/build/index.cjs +87 -69
- package/build/index.js +75 -57
- package/package.json +2 -2
package/build/index.cjs
CHANGED
|
@@ -39,7 +39,7 @@ __export(index_exports, {
|
|
|
39
39
|
module.exports = __toCommonJS(index_exports);
|
|
40
40
|
|
|
41
41
|
// src/SpreePay.tsx
|
|
42
|
-
var
|
|
42
|
+
var import_react18 = require("react");
|
|
43
43
|
var import_nice_modal_react7 = __toESM(require("@ebay/nice-modal-react"), 1);
|
|
44
44
|
var import_swr5 = require("swr");
|
|
45
45
|
|
|
@@ -598,10 +598,10 @@ var slapiApi = {
|
|
|
598
598
|
throw new Error("slapiApi is not configured. Call registerApi(...) first.");
|
|
599
599
|
}
|
|
600
600
|
};
|
|
601
|
-
var registerApi = (
|
|
602
|
-
cfg.baseUrl =
|
|
603
|
-
cfg.accessToken =
|
|
604
|
-
cfg.tenantId =
|
|
601
|
+
var registerApi = (config) => {
|
|
602
|
+
cfg.baseUrl = config.baseUrl;
|
|
603
|
+
cfg.accessToken = config.accessToken;
|
|
604
|
+
cfg.tenantId = config.tenantId;
|
|
605
605
|
slapiApi = {
|
|
606
606
|
get: async (key) => {
|
|
607
607
|
const url = buildUrl(key);
|
|
@@ -747,7 +747,8 @@ async function createAndInit(opts) {
|
|
|
747
747
|
chain: opts.mocaChain,
|
|
748
748
|
account: address
|
|
749
749
|
}) : null;
|
|
750
|
-
|
|
750
|
+
const walletReady = Boolean(address && walletClient);
|
|
751
|
+
return { walletReady, address, walletClient, air, chain: opts.mocaChain };
|
|
751
752
|
} catch (e) {
|
|
752
753
|
const msg = e instanceof Error ? e.message : "Unknown error during AirWallet initialization";
|
|
753
754
|
return { walletReady: false, address: null, walletClient: null, air: null, chain: null, error: msg };
|
|
@@ -755,6 +756,10 @@ async function createAndInit(opts) {
|
|
|
755
756
|
}
|
|
756
757
|
async function getAirWallet(options) {
|
|
757
758
|
const key = optionsKey(options);
|
|
759
|
+
if (cachedKey === key && singletonState && !singletonState.walletReady) {
|
|
760
|
+
singletonState = null;
|
|
761
|
+
initPromise = null;
|
|
762
|
+
}
|
|
758
763
|
if (singletonState && cachedKey === key) return singletonState;
|
|
759
764
|
if (initPromise && cachedKey === key) return initPromise;
|
|
760
765
|
cachedKey = key;
|
|
@@ -2282,7 +2287,7 @@ function Slider2({
|
|
|
2282
2287
|
// src/components/CreditCardTab/Points/PointsSelector.tsx
|
|
2283
2288
|
var import_jsx_runtime24 = require("react/jsx-runtime");
|
|
2284
2289
|
var PointsSelector = (props) => {
|
|
2285
|
-
const { isSelected, onSelect, children } = props;
|
|
2290
|
+
const { isDisabled, isSelected, onSelect, children } = props;
|
|
2286
2291
|
const { balance } = useSlapiBalance();
|
|
2287
2292
|
const { selectedPaymentMethod, setSelectedPaymentMethod } = useSpreePaymentMethod();
|
|
2288
2293
|
const { appProps, staticConfig } = useStaticConfig();
|
|
@@ -2297,9 +2302,11 @@ var PointsSelector = (props) => {
|
|
|
2297
2302
|
return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
|
|
2298
2303
|
"button",
|
|
2299
2304
|
{
|
|
2305
|
+
disabled: isDisabled,
|
|
2300
2306
|
onClick: onSelect,
|
|
2301
2307
|
className: cn("bg-primary/8 cursor-pointer overflow-hidden rounded-md border-1 border-transparent", {
|
|
2302
|
-
"border-primary": isSelected
|
|
2308
|
+
"border-primary": isSelected,
|
|
2309
|
+
"cursor-not-allowed opacity-50": isDisabled
|
|
2303
2310
|
}),
|
|
2304
2311
|
children: [
|
|
2305
2312
|
/* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { className: cn("flex h-11 w-full", { "bg-black/4": isSelected }), children: [
|
|
@@ -2350,30 +2357,38 @@ var PointsSelector = (props) => {
|
|
|
2350
2357
|
// src/components/CreditCardTab/Points/SplitBlock.tsx
|
|
2351
2358
|
var import_jsx_runtime25 = require("react/jsx-runtime");
|
|
2352
2359
|
var SplitBlock = (props) => {
|
|
2353
|
-
const { isSelected, onSelect } = props;
|
|
2360
|
+
const { onToggle, isSelected, onSelect } = props;
|
|
2354
2361
|
const { balance, isBalanceLoading } = useSlapiBalance();
|
|
2355
2362
|
const { spreePayConfig } = useSpreePayConfig();
|
|
2356
2363
|
const [address, setAddress] = (0, import_react11.useState)(null);
|
|
2364
|
+
const [walletReady, setWalletReady] = (0, import_react11.useState)(false);
|
|
2357
2365
|
const { staticConfig } = useStaticConfig();
|
|
2358
2366
|
const { pointsConversionRatio, pointsTitle } = staticConfig;
|
|
2359
|
-
const initWallet = (0, import_react11.useCallback)(
|
|
2360
|
-
|
|
2361
|
-
return;
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2367
|
+
const initWallet = (0, import_react11.useCallback)(
|
|
2368
|
+
async (pointsChain) => {
|
|
2369
|
+
if (!pointsChain) return;
|
|
2370
|
+
try {
|
|
2371
|
+
const res = await getAirWallet({
|
|
2372
|
+
mocaChain: pointsChain.mocaChain,
|
|
2373
|
+
partnerId: pointsChain.partnerId
|
|
2374
|
+
});
|
|
2375
|
+
setAddress(res.address ?? null);
|
|
2376
|
+
setWalletReady(res.walletReady);
|
|
2377
|
+
if (!res.walletReady && res.error) {
|
|
2378
|
+
onToggle(false);
|
|
2379
|
+
}
|
|
2380
|
+
} catch (e) {
|
|
2381
|
+
console.error("Air Wallet init failed:", e);
|
|
2382
|
+
}
|
|
2383
|
+
},
|
|
2384
|
+
[onToggle]
|
|
2385
|
+
);
|
|
2373
2386
|
(0, import_react11.useEffect)(() => {
|
|
2387
|
+
setAddress(null);
|
|
2388
|
+
setWalletReady(false);
|
|
2374
2389
|
initWallet(spreePayConfig?.pointsChain);
|
|
2375
|
-
}, [spreePayConfig, initWallet]);
|
|
2376
|
-
return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: "flex flex-col gap-1", children: /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(PointsSelector, { onSelect: () => onSelect("air"), isSelected, children: [
|
|
2390
|
+
}, [spreePayConfig?.pointsChain, initWallet]);
|
|
2391
|
+
return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: "flex flex-col gap-1", children: /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(PointsSelector, { isDisabled: !walletReady, onSelect: () => onSelect("air"), isSelected, children: [
|
|
2377
2392
|
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: "flex items-center gap-2", children: balance?.availablePoints ? /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("p", { className: "text-sm font-medium text-black", children: [
|
|
2378
2393
|
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "text-black/50", children: "Available" }),
|
|
2379
2394
|
" ",
|
|
@@ -2402,7 +2417,14 @@ var Points = () => {
|
|
|
2402
2417
|
};
|
|
2403
2418
|
return /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(import_jsx_runtime26.Fragment, { children: [
|
|
2404
2419
|
/* @__PURE__ */ (0, import_jsx_runtime26.jsx)(PointsSwitch, { disabled: !spreePayConfig?.creditCard.enabled, value: usePoints, onChange: handleTogglePoints }),
|
|
2405
|
-
usePoints && /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
2420
|
+
usePoints && /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
2421
|
+
SplitBlock,
|
|
2422
|
+
{
|
|
2423
|
+
onToggle: handleTogglePoints,
|
|
2424
|
+
isSelected: selectedPointsType === "air",
|
|
2425
|
+
onSelect: setSelectedPointsType
|
|
2426
|
+
}
|
|
2427
|
+
)
|
|
2406
2428
|
] });
|
|
2407
2429
|
};
|
|
2408
2430
|
|
|
@@ -2449,11 +2471,11 @@ var CreditCardTab = () => {
|
|
|
2449
2471
|
};
|
|
2450
2472
|
|
|
2451
2473
|
// src/components/CryptoTab/Crypto/CryptoWrapper.tsx
|
|
2474
|
+
var import_react16 = require("react");
|
|
2452
2475
|
var import_react_query = require("@tanstack/react-query");
|
|
2453
2476
|
var import_nice_modal_react6 = __toESM(require("@ebay/nice-modal-react"), 1);
|
|
2454
2477
|
var import_rainbowkit2 = require("@rainbow-me/rainbowkit");
|
|
2455
2478
|
var import_styles = require("@rainbow-me/rainbowkit/styles.css");
|
|
2456
|
-
var import_wallets = require("@rainbow-me/rainbowkit/wallets");
|
|
2457
2479
|
var import_wagmi5 = require("wagmi");
|
|
2458
2480
|
var import_chains = require("wagmi/chains");
|
|
2459
2481
|
|
|
@@ -2474,9 +2496,9 @@ function getAction(client, actionFn, name) {
|
|
|
2474
2496
|
|
|
2475
2497
|
// ../../node_modules/@wagmi/core/dist/esm/actions/readContract.js
|
|
2476
2498
|
var import_actions = require("viem/actions");
|
|
2477
|
-
function readContract(
|
|
2499
|
+
function readContract(config, parameters) {
|
|
2478
2500
|
const { chainId, ...rest } = parameters;
|
|
2479
|
-
const client =
|
|
2501
|
+
const client = config.getClient({ chainId });
|
|
2480
2502
|
const action = getAction(client, import_actions.readContract, "readContract");
|
|
2481
2503
|
return action(rest);
|
|
2482
2504
|
}
|
|
@@ -2484,9 +2506,9 @@ function readContract(config2, parameters) {
|
|
|
2484
2506
|
// ../../node_modules/@wagmi/core/dist/esm/actions/waitForTransactionReceipt.js
|
|
2485
2507
|
var import_viem2 = require("viem");
|
|
2486
2508
|
var import_actions2 = require("viem/actions");
|
|
2487
|
-
async function waitForTransactionReceipt(
|
|
2509
|
+
async function waitForTransactionReceipt(config, parameters) {
|
|
2488
2510
|
const { chainId, timeout = 0, ...rest } = parameters;
|
|
2489
|
-
const client =
|
|
2511
|
+
const client = config.getClient({ chainId });
|
|
2490
2512
|
const action = getAction(client, import_actions2.waitForTransactionReceipt, "waitForTransactionReceipt");
|
|
2491
2513
|
const receipt = await action({ ...rest, timeout });
|
|
2492
2514
|
if (receipt.status === "reverted") {
|
|
@@ -2558,7 +2580,7 @@ var MAX_UINT256 = BigInt(2) ** BigInt(256) - BigInt(1);
|
|
|
2558
2580
|
var ONE_INCH_AGGREGATION_ROUTER_V6 = "0x111111125421ca6dc452d289314280a0f8842a65";
|
|
2559
2581
|
var useCryptoPayment = () => {
|
|
2560
2582
|
const { data: walletClient } = (0, import_wagmi.useWalletClient)();
|
|
2561
|
-
const
|
|
2583
|
+
const config = (0, import_wagmi.useConfig)();
|
|
2562
2584
|
const { selectedPaymentMethod } = useSpreePaymentMethod();
|
|
2563
2585
|
const cryptoPayment = async (params) => {
|
|
2564
2586
|
if (!walletClient) {
|
|
@@ -2574,7 +2596,7 @@ var useCryptoPayment = () => {
|
|
|
2574
2596
|
if (!tokenAddress) {
|
|
2575
2597
|
throw new Error("Token address not found");
|
|
2576
2598
|
}
|
|
2577
|
-
const allowance = await readContract(
|
|
2599
|
+
const allowance = await readContract(config, {
|
|
2578
2600
|
address: tokenAddress,
|
|
2579
2601
|
abi: import_viem4.erc20Abi,
|
|
2580
2602
|
functionName: "allowance",
|
|
@@ -2587,7 +2609,7 @@ var useCryptoPayment = () => {
|
|
|
2587
2609
|
functionName: "approve",
|
|
2588
2610
|
args: [ONE_INCH_AGGREGATION_ROUTER_V6, MAX_UINT256]
|
|
2589
2611
|
});
|
|
2590
|
-
await waitForTransactionReceipt(
|
|
2612
|
+
await waitForTransactionReceipt(config, {
|
|
2591
2613
|
hash: result,
|
|
2592
2614
|
confirmations: 1
|
|
2593
2615
|
// You can change the number of block confirmations as per your requirement
|
|
@@ -2646,9 +2668,9 @@ var ConnectButton = () => {
|
|
|
2646
2668
|
return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
|
2647
2669
|
"button",
|
|
2648
2670
|
{
|
|
2649
|
-
className: "h-[34px] rounded-md border-1 border-black px-3 text-sm font-medium text-
|
|
2671
|
+
className: "h-[34px] rounded-md border-1 border-black px-3 text-sm font-medium text-black",
|
|
2650
2672
|
onClick: openChainModal,
|
|
2651
|
-
children: "
|
|
2673
|
+
children: "Select a Network"
|
|
2652
2674
|
}
|
|
2653
2675
|
);
|
|
2654
2676
|
}
|
|
@@ -3145,23 +3167,19 @@ var Crypto = () => {
|
|
|
3145
3167
|
// src/components/CryptoTab/Crypto/CryptoWrapper.tsx
|
|
3146
3168
|
var import_jsx_runtime38 = require("react/jsx-runtime");
|
|
3147
3169
|
var queryClient = new import_react_query.QueryClient();
|
|
3148
|
-
var connectors = (0, import_rainbowkit2.connectorsForWallets)(
|
|
3149
|
-
[
|
|
3150
|
-
{
|
|
3151
|
-
groupName: "Supported",
|
|
3152
|
-
wallets: [import_wallets.injectedWallet, import_wallets.walletConnectWallet]
|
|
3153
|
-
}
|
|
3154
|
-
],
|
|
3155
|
-
{ appName: "Spree Pay", projectId: "YOUR_PROJECT_ID" }
|
|
3156
|
-
);
|
|
3157
|
-
var config = (0, import_wagmi5.createConfig)({
|
|
3158
|
-
chains: [import_chains.base],
|
|
3159
|
-
connectors,
|
|
3160
|
-
transports: { [import_chains.base.id]: (0, import_wagmi5.http)() },
|
|
3161
|
-
ssr: true
|
|
3162
|
-
});
|
|
3163
3170
|
var CryptoWrapper = () => {
|
|
3164
|
-
|
|
3171
|
+
const { spreePayConfig } = useSpreePayConfig();
|
|
3172
|
+
const config = (0, import_react16.useMemo)(() => {
|
|
3173
|
+
if (!spreePayConfig) return null;
|
|
3174
|
+
return (0, import_rainbowkit2.getDefaultConfig)({
|
|
3175
|
+
appName: spreePayConfig.rainbowAppName || "AIR Shop",
|
|
3176
|
+
projectId: spreePayConfig.rainbowProjectId || "3fdcd5ff50cb84917cd05e40146975d8",
|
|
3177
|
+
chains: [import_chains.base],
|
|
3178
|
+
ssr: true
|
|
3179
|
+
});
|
|
3180
|
+
}, [spreePayConfig]);
|
|
3181
|
+
if (!config) return null;
|
|
3182
|
+
return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(import_wagmi5.WagmiProvider, { config, children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(import_react_query.QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(import_rainbowkit2.RainbowKitProvider, { theme: (0, import_rainbowkit2.lightTheme)({ borderRadius: "large" }), children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(import_nice_modal_react6.default.Provider, { children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(Crypto, {}) }) }) }) });
|
|
3165
3183
|
};
|
|
3166
3184
|
|
|
3167
3185
|
// src/components/CryptoTab/CryptoTab.tsx
|
|
@@ -3274,18 +3292,18 @@ var SpreePayContent = ({ isLoggedIn }) => {
|
|
|
3274
3292
|
};
|
|
3275
3293
|
|
|
3276
3294
|
// src/hooks/useKeycloakSSO.ts
|
|
3277
|
-
var
|
|
3295
|
+
var import_react17 = require("react");
|
|
3278
3296
|
var import_keycloak_js = __toESM(require("keycloak-js"), 1);
|
|
3279
3297
|
var refreshAheadSeconds = 60;
|
|
3280
|
-
function useKeycloakSSO(
|
|
3281
|
-
const { url, realm, clientId, ssoPageURI, enabled } =
|
|
3282
|
-
const initRef = (0,
|
|
3283
|
-
const kcRef = (0,
|
|
3284
|
-
const refreshTimerRef = (0,
|
|
3285
|
-
const [error, setError] = (0,
|
|
3286
|
-
const [isChecking, setIsChecking] = (0,
|
|
3287
|
-
const [accessToken, setAccessToken] = (0,
|
|
3288
|
-
const scheduleRefresh = (0,
|
|
3298
|
+
function useKeycloakSSO(config) {
|
|
3299
|
+
const { url, realm, clientId, ssoPageURI, enabled } = config;
|
|
3300
|
+
const initRef = (0, import_react17.useRef)(false);
|
|
3301
|
+
const kcRef = (0, import_react17.useRef)(null);
|
|
3302
|
+
const refreshTimerRef = (0, import_react17.useRef)(null);
|
|
3303
|
+
const [error, setError] = (0, import_react17.useState)(null);
|
|
3304
|
+
const [isChecking, setIsChecking] = (0, import_react17.useState)(enabled);
|
|
3305
|
+
const [accessToken, setAccessToken] = (0, import_react17.useState)(null);
|
|
3306
|
+
const scheduleRefresh = (0, import_react17.useCallback)(() => {
|
|
3289
3307
|
const kc = kcRef.current;
|
|
3290
3308
|
if (!kc || !kc.tokenParsed || !kc.tokenParsed.exp) {
|
|
3291
3309
|
return;
|
|
@@ -3306,7 +3324,7 @@ function useKeycloakSSO(config2) {
|
|
|
3306
3324
|
});
|
|
3307
3325
|
}, delayMs);
|
|
3308
3326
|
}, []);
|
|
3309
|
-
(0,
|
|
3327
|
+
(0, import_react17.useEffect)(() => {
|
|
3310
3328
|
if (initRef.current || !enabled) return;
|
|
3311
3329
|
initRef.current = true;
|
|
3312
3330
|
setIsChecking(true);
|
|
@@ -3343,9 +3361,9 @@ function useKeycloakSSO(config2) {
|
|
|
3343
3361
|
// src/SpreePay.tsx
|
|
3344
3362
|
var import_jsx_runtime43 = require("react/jsx-runtime");
|
|
3345
3363
|
var SpreePayInner = () => {
|
|
3346
|
-
const rootRef = (0,
|
|
3347
|
-
const [portalEl, setPortalEl] = (0,
|
|
3348
|
-
(0,
|
|
3364
|
+
const rootRef = (0, import_react18.useRef)(null);
|
|
3365
|
+
const [portalEl, setPortalEl] = (0, import_react18.useState)(null);
|
|
3366
|
+
(0, import_react18.useLayoutEffect)(() => {
|
|
3349
3367
|
if (!rootRef.current) return;
|
|
3350
3368
|
const el = rootRef.current.querySelector(":scope > .sl-spreepay__portal");
|
|
3351
3369
|
setPortalEl(el ?? null);
|
|
@@ -3360,7 +3378,7 @@ var SpreePayInner = () => {
|
|
|
3360
3378
|
ssoPageURI: env?.ssoPageURI,
|
|
3361
3379
|
enabled: !env?.accessToken
|
|
3362
3380
|
});
|
|
3363
|
-
const slapiFetcher = (0,
|
|
3381
|
+
const slapiFetcher = (0, import_react18.useMemo)(() => {
|
|
3364
3382
|
if (accessToken || env.accessToken) {
|
|
3365
3383
|
return registerApi({
|
|
3366
3384
|
accessToken: env.accessToken || accessToken,
|
|
@@ -3400,9 +3418,9 @@ var SpreePay = (props) => {
|
|
|
3400
3418
|
};
|
|
3401
3419
|
|
|
3402
3420
|
// src/hooks/useCapture3DS.ts
|
|
3403
|
-
var
|
|
3421
|
+
var import_react19 = require("react");
|
|
3404
3422
|
var useCapture3DS = (searchParams) => {
|
|
3405
|
-
(0,
|
|
3423
|
+
(0, import_react19.useEffect)(() => {
|
|
3406
3424
|
if (typeof window !== "undefined" && window.parent && searchParams?.paymentIntent) {
|
|
3407
3425
|
window.parent.SP_EVENT_BUS?.emit("paymentIntent", { paymentIntent: searchParams.paymentIntent });
|
|
3408
3426
|
}
|
package/build/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/SpreePay.tsx
|
|
2
|
-
import { useLayoutEffect as useLayoutEffect3, useMemo as
|
|
2
|
+
import { useLayoutEffect as useLayoutEffect3, useMemo as useMemo10, useRef as useRef7, useState as useState14 } from "react";
|
|
3
3
|
import NiceModal7 from "@ebay/nice-modal-react";
|
|
4
4
|
import { SWRConfig } from "swr";
|
|
5
5
|
|
|
@@ -558,10 +558,10 @@ var slapiApi = {
|
|
|
558
558
|
throw new Error("slapiApi is not configured. Call registerApi(...) first.");
|
|
559
559
|
}
|
|
560
560
|
};
|
|
561
|
-
var registerApi = (
|
|
562
|
-
cfg.baseUrl =
|
|
563
|
-
cfg.accessToken =
|
|
564
|
-
cfg.tenantId =
|
|
561
|
+
var registerApi = (config) => {
|
|
562
|
+
cfg.baseUrl = config.baseUrl;
|
|
563
|
+
cfg.accessToken = config.accessToken;
|
|
564
|
+
cfg.tenantId = config.tenantId;
|
|
565
565
|
slapiApi = {
|
|
566
566
|
get: async (key) => {
|
|
567
567
|
const url = buildUrl(key);
|
|
@@ -707,7 +707,8 @@ async function createAndInit(opts) {
|
|
|
707
707
|
chain: opts.mocaChain,
|
|
708
708
|
account: address
|
|
709
709
|
}) : null;
|
|
710
|
-
|
|
710
|
+
const walletReady = Boolean(address && walletClient);
|
|
711
|
+
return { walletReady, address, walletClient, air, chain: opts.mocaChain };
|
|
711
712
|
} catch (e) {
|
|
712
713
|
const msg = e instanceof Error ? e.message : "Unknown error during AirWallet initialization";
|
|
713
714
|
return { walletReady: false, address: null, walletClient: null, air: null, chain: null, error: msg };
|
|
@@ -715,6 +716,10 @@ async function createAndInit(opts) {
|
|
|
715
716
|
}
|
|
716
717
|
async function getAirWallet(options) {
|
|
717
718
|
const key = optionsKey(options);
|
|
719
|
+
if (cachedKey === key && singletonState && !singletonState.walletReady) {
|
|
720
|
+
singletonState = null;
|
|
721
|
+
initPromise = null;
|
|
722
|
+
}
|
|
718
723
|
if (singletonState && cachedKey === key) return singletonState;
|
|
719
724
|
if (initPromise && cachedKey === key) return initPromise;
|
|
720
725
|
cachedKey = key;
|
|
@@ -2242,7 +2247,7 @@ function Slider2({
|
|
|
2242
2247
|
// src/components/CreditCardTab/Points/PointsSelector.tsx
|
|
2243
2248
|
import { jsx as jsx24, jsxs as jsxs12 } from "react/jsx-runtime";
|
|
2244
2249
|
var PointsSelector = (props) => {
|
|
2245
|
-
const { isSelected, onSelect, children } = props;
|
|
2250
|
+
const { isDisabled, isSelected, onSelect, children } = props;
|
|
2246
2251
|
const { balance } = useSlapiBalance();
|
|
2247
2252
|
const { selectedPaymentMethod, setSelectedPaymentMethod } = useSpreePaymentMethod();
|
|
2248
2253
|
const { appProps, staticConfig } = useStaticConfig();
|
|
@@ -2257,9 +2262,11 @@ var PointsSelector = (props) => {
|
|
|
2257
2262
|
return /* @__PURE__ */ jsxs12(
|
|
2258
2263
|
"button",
|
|
2259
2264
|
{
|
|
2265
|
+
disabled: isDisabled,
|
|
2260
2266
|
onClick: onSelect,
|
|
2261
2267
|
className: cn("bg-primary/8 cursor-pointer overflow-hidden rounded-md border-1 border-transparent", {
|
|
2262
|
-
"border-primary": isSelected
|
|
2268
|
+
"border-primary": isSelected,
|
|
2269
|
+
"cursor-not-allowed opacity-50": isDisabled
|
|
2263
2270
|
}),
|
|
2264
2271
|
children: [
|
|
2265
2272
|
/* @__PURE__ */ jsxs12("div", { className: cn("flex h-11 w-full", { "bg-black/4": isSelected }), children: [
|
|
@@ -2310,30 +2317,38 @@ var PointsSelector = (props) => {
|
|
|
2310
2317
|
// src/components/CreditCardTab/Points/SplitBlock.tsx
|
|
2311
2318
|
import { jsx as jsx25, jsxs as jsxs13 } from "react/jsx-runtime";
|
|
2312
2319
|
var SplitBlock = (props) => {
|
|
2313
|
-
const { isSelected, onSelect } = props;
|
|
2320
|
+
const { onToggle, isSelected, onSelect } = props;
|
|
2314
2321
|
const { balance, isBalanceLoading } = useSlapiBalance();
|
|
2315
2322
|
const { spreePayConfig } = useSpreePayConfig();
|
|
2316
2323
|
const [address, setAddress] = useState9(null);
|
|
2324
|
+
const [walletReady, setWalletReady] = useState9(false);
|
|
2317
2325
|
const { staticConfig } = useStaticConfig();
|
|
2318
2326
|
const { pointsConversionRatio, pointsTitle } = staticConfig;
|
|
2319
|
-
const initWallet = useCallback4(
|
|
2320
|
-
|
|
2321
|
-
return;
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2327
|
+
const initWallet = useCallback4(
|
|
2328
|
+
async (pointsChain) => {
|
|
2329
|
+
if (!pointsChain) return;
|
|
2330
|
+
try {
|
|
2331
|
+
const res = await getAirWallet({
|
|
2332
|
+
mocaChain: pointsChain.mocaChain,
|
|
2333
|
+
partnerId: pointsChain.partnerId
|
|
2334
|
+
});
|
|
2335
|
+
setAddress(res.address ?? null);
|
|
2336
|
+
setWalletReady(res.walletReady);
|
|
2337
|
+
if (!res.walletReady && res.error) {
|
|
2338
|
+
onToggle(false);
|
|
2339
|
+
}
|
|
2340
|
+
} catch (e) {
|
|
2341
|
+
console.error("Air Wallet init failed:", e);
|
|
2342
|
+
}
|
|
2343
|
+
},
|
|
2344
|
+
[onToggle]
|
|
2345
|
+
);
|
|
2333
2346
|
useEffect6(() => {
|
|
2347
|
+
setAddress(null);
|
|
2348
|
+
setWalletReady(false);
|
|
2334
2349
|
initWallet(spreePayConfig?.pointsChain);
|
|
2335
|
-
}, [spreePayConfig, initWallet]);
|
|
2336
|
-
return /* @__PURE__ */ jsx25("div", { className: "flex flex-col gap-1", children: /* @__PURE__ */ jsxs13(PointsSelector, { onSelect: () => onSelect("air"), isSelected, children: [
|
|
2350
|
+
}, [spreePayConfig?.pointsChain, initWallet]);
|
|
2351
|
+
return /* @__PURE__ */ jsx25("div", { className: "flex flex-col gap-1", children: /* @__PURE__ */ jsxs13(PointsSelector, { isDisabled: !walletReady, onSelect: () => onSelect("air"), isSelected, children: [
|
|
2337
2352
|
/* @__PURE__ */ jsx25("div", { className: "flex items-center gap-2", children: balance?.availablePoints ? /* @__PURE__ */ jsxs13("p", { className: "text-sm font-medium text-black", children: [
|
|
2338
2353
|
/* @__PURE__ */ jsx25("span", { className: "text-black/50", children: "Available" }),
|
|
2339
2354
|
" ",
|
|
@@ -2362,7 +2377,14 @@ var Points = () => {
|
|
|
2362
2377
|
};
|
|
2363
2378
|
return /* @__PURE__ */ jsxs14(Fragment3, { children: [
|
|
2364
2379
|
/* @__PURE__ */ jsx26(PointsSwitch, { disabled: !spreePayConfig?.creditCard.enabled, value: usePoints, onChange: handleTogglePoints }),
|
|
2365
|
-
usePoints && /* @__PURE__ */ jsx26(
|
|
2380
|
+
usePoints && /* @__PURE__ */ jsx26(
|
|
2381
|
+
SplitBlock,
|
|
2382
|
+
{
|
|
2383
|
+
onToggle: handleTogglePoints,
|
|
2384
|
+
isSelected: selectedPointsType === "air",
|
|
2385
|
+
onSelect: setSelectedPointsType
|
|
2386
|
+
}
|
|
2387
|
+
)
|
|
2366
2388
|
] });
|
|
2367
2389
|
};
|
|
2368
2390
|
|
|
@@ -2409,12 +2431,12 @@ var CreditCardTab = () => {
|
|
|
2409
2431
|
};
|
|
2410
2432
|
|
|
2411
2433
|
// src/components/CryptoTab/Crypto/CryptoWrapper.tsx
|
|
2434
|
+
import { useMemo as useMemo9 } from "react";
|
|
2412
2435
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
2413
2436
|
import NiceModal6 from "@ebay/nice-modal-react";
|
|
2414
|
-
import { RainbowKitProvider,
|
|
2437
|
+
import { RainbowKitProvider, getDefaultConfig, lightTheme } from "@rainbow-me/rainbowkit";
|
|
2415
2438
|
import "@rainbow-me/rainbowkit/styles.css";
|
|
2416
|
-
import {
|
|
2417
|
-
import { WagmiProvider, createConfig, http as http2 } from "wagmi";
|
|
2439
|
+
import { WagmiProvider } from "wagmi";
|
|
2418
2440
|
import { base } from "wagmi/chains";
|
|
2419
2441
|
|
|
2420
2442
|
// src/components/CryptoTab/Crypto/Crypto.tsx
|
|
@@ -2434,9 +2456,9 @@ function getAction(client, actionFn, name) {
|
|
|
2434
2456
|
|
|
2435
2457
|
// ../../node_modules/@wagmi/core/dist/esm/actions/readContract.js
|
|
2436
2458
|
import { readContract as viem_readContract } from "viem/actions";
|
|
2437
|
-
function readContract(
|
|
2459
|
+
function readContract(config, parameters) {
|
|
2438
2460
|
const { chainId, ...rest } = parameters;
|
|
2439
|
-
const client =
|
|
2461
|
+
const client = config.getClient({ chainId });
|
|
2440
2462
|
const action = getAction(client, viem_readContract, "readContract");
|
|
2441
2463
|
return action(rest);
|
|
2442
2464
|
}
|
|
@@ -2444,9 +2466,9 @@ function readContract(config2, parameters) {
|
|
|
2444
2466
|
// ../../node_modules/@wagmi/core/dist/esm/actions/waitForTransactionReceipt.js
|
|
2445
2467
|
import { hexToString } from "viem";
|
|
2446
2468
|
import { call, getTransaction, waitForTransactionReceipt as viem_waitForTransactionReceipt } from "viem/actions";
|
|
2447
|
-
async function waitForTransactionReceipt(
|
|
2469
|
+
async function waitForTransactionReceipt(config, parameters) {
|
|
2448
2470
|
const { chainId, timeout = 0, ...rest } = parameters;
|
|
2449
|
-
const client =
|
|
2471
|
+
const client = config.getClient({ chainId });
|
|
2450
2472
|
const action = getAction(client, viem_waitForTransactionReceipt, "waitForTransactionReceipt");
|
|
2451
2473
|
const receipt = await action({ ...rest, timeout });
|
|
2452
2474
|
if (receipt.status === "reverted") {
|
|
@@ -2518,7 +2540,7 @@ var MAX_UINT256 = BigInt(2) ** BigInt(256) - BigInt(1);
|
|
|
2518
2540
|
var ONE_INCH_AGGREGATION_ROUTER_V6 = "0x111111125421ca6dc452d289314280a0f8842a65";
|
|
2519
2541
|
var useCryptoPayment = () => {
|
|
2520
2542
|
const { data: walletClient } = useWalletClient();
|
|
2521
|
-
const
|
|
2543
|
+
const config = useConfig();
|
|
2522
2544
|
const { selectedPaymentMethod } = useSpreePaymentMethod();
|
|
2523
2545
|
const cryptoPayment = async (params) => {
|
|
2524
2546
|
if (!walletClient) {
|
|
@@ -2534,7 +2556,7 @@ var useCryptoPayment = () => {
|
|
|
2534
2556
|
if (!tokenAddress) {
|
|
2535
2557
|
throw new Error("Token address not found");
|
|
2536
2558
|
}
|
|
2537
|
-
const allowance = await readContract(
|
|
2559
|
+
const allowance = await readContract(config, {
|
|
2538
2560
|
address: tokenAddress,
|
|
2539
2561
|
abi: erc20Abi2,
|
|
2540
2562
|
functionName: "allowance",
|
|
@@ -2547,7 +2569,7 @@ var useCryptoPayment = () => {
|
|
|
2547
2569
|
functionName: "approve",
|
|
2548
2570
|
args: [ONE_INCH_AGGREGATION_ROUTER_V6, MAX_UINT256]
|
|
2549
2571
|
});
|
|
2550
|
-
await waitForTransactionReceipt(
|
|
2572
|
+
await waitForTransactionReceipt(config, {
|
|
2551
2573
|
hash: result,
|
|
2552
2574
|
confirmations: 1
|
|
2553
2575
|
// You can change the number of block confirmations as per your requirement
|
|
@@ -2606,9 +2628,9 @@ var ConnectButton = () => {
|
|
|
2606
2628
|
return /* @__PURE__ */ jsx28(
|
|
2607
2629
|
"button",
|
|
2608
2630
|
{
|
|
2609
|
-
className: "h-[34px] rounded-md border-1 border-black px-3 text-sm font-medium text-
|
|
2631
|
+
className: "h-[34px] rounded-md border-1 border-black px-3 text-sm font-medium text-black",
|
|
2610
2632
|
onClick: openChainModal,
|
|
2611
|
-
children: "
|
|
2633
|
+
children: "Select a Network"
|
|
2612
2634
|
}
|
|
2613
2635
|
);
|
|
2614
2636
|
}
|
|
@@ -3105,23 +3127,19 @@ var Crypto = () => {
|
|
|
3105
3127
|
// src/components/CryptoTab/Crypto/CryptoWrapper.tsx
|
|
3106
3128
|
import { jsx as jsx38 } from "react/jsx-runtime";
|
|
3107
3129
|
var queryClient = new QueryClient();
|
|
3108
|
-
var connectors = connectorsForWallets(
|
|
3109
|
-
[
|
|
3110
|
-
{
|
|
3111
|
-
groupName: "Supported",
|
|
3112
|
-
wallets: [injectedWallet, walletConnectWallet]
|
|
3113
|
-
}
|
|
3114
|
-
],
|
|
3115
|
-
{ appName: "Spree Pay", projectId: "YOUR_PROJECT_ID" }
|
|
3116
|
-
);
|
|
3117
|
-
var config = createConfig({
|
|
3118
|
-
chains: [base],
|
|
3119
|
-
connectors,
|
|
3120
|
-
transports: { [base.id]: http2() },
|
|
3121
|
-
ssr: true
|
|
3122
|
-
});
|
|
3123
3130
|
var CryptoWrapper = () => {
|
|
3124
|
-
|
|
3131
|
+
const { spreePayConfig } = useSpreePayConfig();
|
|
3132
|
+
const config = useMemo9(() => {
|
|
3133
|
+
if (!spreePayConfig) return null;
|
|
3134
|
+
return getDefaultConfig({
|
|
3135
|
+
appName: spreePayConfig.rainbowAppName || "AIR Shop",
|
|
3136
|
+
projectId: spreePayConfig.rainbowProjectId || "3fdcd5ff50cb84917cd05e40146975d8",
|
|
3137
|
+
chains: [base],
|
|
3138
|
+
ssr: true
|
|
3139
|
+
});
|
|
3140
|
+
}, [spreePayConfig]);
|
|
3141
|
+
if (!config) return null;
|
|
3142
|
+
return /* @__PURE__ */ jsx38(WagmiProvider, { config, children: /* @__PURE__ */ jsx38(QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ jsx38(RainbowKitProvider, { theme: lightTheme({ borderRadius: "large" }), children: /* @__PURE__ */ jsx38(NiceModal6.Provider, { children: /* @__PURE__ */ jsx38(Crypto, {}) }) }) }) });
|
|
3125
3143
|
};
|
|
3126
3144
|
|
|
3127
3145
|
// src/components/CryptoTab/CryptoTab.tsx
|
|
@@ -3237,8 +3255,8 @@ var SpreePayContent = ({ isLoggedIn }) => {
|
|
|
3237
3255
|
import { useCallback as useCallback7, useEffect as useEffect10, useRef as useRef6, useState as useState13 } from "react";
|
|
3238
3256
|
import Keycloak from "keycloak-js";
|
|
3239
3257
|
var refreshAheadSeconds = 60;
|
|
3240
|
-
function useKeycloakSSO(
|
|
3241
|
-
const { url, realm, clientId, ssoPageURI, enabled } =
|
|
3258
|
+
function useKeycloakSSO(config) {
|
|
3259
|
+
const { url, realm, clientId, ssoPageURI, enabled } = config;
|
|
3242
3260
|
const initRef = useRef6(false);
|
|
3243
3261
|
const kcRef = useRef6(null);
|
|
3244
3262
|
const refreshTimerRef = useRef6(null);
|
|
@@ -3320,7 +3338,7 @@ var SpreePayInner = () => {
|
|
|
3320
3338
|
ssoPageURI: env?.ssoPageURI,
|
|
3321
3339
|
enabled: !env?.accessToken
|
|
3322
3340
|
});
|
|
3323
|
-
const slapiFetcher =
|
|
3341
|
+
const slapiFetcher = useMemo10(() => {
|
|
3324
3342
|
if (accessToken || env.accessToken) {
|
|
3325
3343
|
return registerApi({
|
|
3326
3344
|
accessToken: env.accessToken || accessToken,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superlogic/spree-pay",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.21",
|
|
4
4
|
"description": "Spree-pay React component and utilities",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"@radix-ui/react-label": "^2.1.1",
|
|
46
46
|
"@radix-ui/react-slot": "^1.1.1",
|
|
47
47
|
"@radix-ui/react-switch": "^1.1.2",
|
|
48
|
-
"@rainbow-me/rainbowkit": "^2.2.
|
|
48
|
+
"@rainbow-me/rainbowkit": "^2.2.9",
|
|
49
49
|
"@stripe/react-stripe-js": "^3.9.0",
|
|
50
50
|
"@stripe/stripe-js": "^7.8.0",
|
|
51
51
|
"@tanstack/react-query": "^5.85.5",
|