@superlogic/spree-pay 0.1.19 → 0.1.20

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 CHANGED
@@ -39,7 +39,7 @@ __export(index_exports, {
39
39
  module.exports = __toCommonJS(index_exports);
40
40
 
41
41
  // src/SpreePay.tsx
42
- var import_react17 = require("react");
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 = (config2) => {
602
- cfg.baseUrl = config2.baseUrl;
603
- cfg.accessToken = config2.accessToken;
604
- cfg.tenantId = config2.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);
@@ -2449,11 +2449,11 @@ var CreditCardTab = () => {
2449
2449
  };
2450
2450
 
2451
2451
  // src/components/CryptoTab/Crypto/CryptoWrapper.tsx
2452
+ var import_react16 = require("react");
2452
2453
  var import_react_query = require("@tanstack/react-query");
2453
2454
  var import_nice_modal_react6 = __toESM(require("@ebay/nice-modal-react"), 1);
2454
2455
  var import_rainbowkit2 = require("@rainbow-me/rainbowkit");
2455
2456
  var import_styles = require("@rainbow-me/rainbowkit/styles.css");
2456
- var import_wallets = require("@rainbow-me/rainbowkit/wallets");
2457
2457
  var import_wagmi5 = require("wagmi");
2458
2458
  var import_chains = require("wagmi/chains");
2459
2459
 
@@ -2474,9 +2474,9 @@ function getAction(client, actionFn, name) {
2474
2474
 
2475
2475
  // ../../node_modules/@wagmi/core/dist/esm/actions/readContract.js
2476
2476
  var import_actions = require("viem/actions");
2477
- function readContract(config2, parameters) {
2477
+ function readContract(config, parameters) {
2478
2478
  const { chainId, ...rest } = parameters;
2479
- const client = config2.getClient({ chainId });
2479
+ const client = config.getClient({ chainId });
2480
2480
  const action = getAction(client, import_actions.readContract, "readContract");
2481
2481
  return action(rest);
2482
2482
  }
@@ -2484,9 +2484,9 @@ function readContract(config2, parameters) {
2484
2484
  // ../../node_modules/@wagmi/core/dist/esm/actions/waitForTransactionReceipt.js
2485
2485
  var import_viem2 = require("viem");
2486
2486
  var import_actions2 = require("viem/actions");
2487
- async function waitForTransactionReceipt(config2, parameters) {
2487
+ async function waitForTransactionReceipt(config, parameters) {
2488
2488
  const { chainId, timeout = 0, ...rest } = parameters;
2489
- const client = config2.getClient({ chainId });
2489
+ const client = config.getClient({ chainId });
2490
2490
  const action = getAction(client, import_actions2.waitForTransactionReceipt, "waitForTransactionReceipt");
2491
2491
  const receipt = await action({ ...rest, timeout });
2492
2492
  if (receipt.status === "reverted") {
@@ -2558,7 +2558,7 @@ var MAX_UINT256 = BigInt(2) ** BigInt(256) - BigInt(1);
2558
2558
  var ONE_INCH_AGGREGATION_ROUTER_V6 = "0x111111125421ca6dc452d289314280a0f8842a65";
2559
2559
  var useCryptoPayment = () => {
2560
2560
  const { data: walletClient } = (0, import_wagmi.useWalletClient)();
2561
- const config2 = (0, import_wagmi.useConfig)();
2561
+ const config = (0, import_wagmi.useConfig)();
2562
2562
  const { selectedPaymentMethod } = useSpreePaymentMethod();
2563
2563
  const cryptoPayment = async (params) => {
2564
2564
  if (!walletClient) {
@@ -2574,7 +2574,7 @@ var useCryptoPayment = () => {
2574
2574
  if (!tokenAddress) {
2575
2575
  throw new Error("Token address not found");
2576
2576
  }
2577
- const allowance = await readContract(config2, {
2577
+ const allowance = await readContract(config, {
2578
2578
  address: tokenAddress,
2579
2579
  abi: import_viem4.erc20Abi,
2580
2580
  functionName: "allowance",
@@ -2587,7 +2587,7 @@ var useCryptoPayment = () => {
2587
2587
  functionName: "approve",
2588
2588
  args: [ONE_INCH_AGGREGATION_ROUTER_V6, MAX_UINT256]
2589
2589
  });
2590
- await waitForTransactionReceipt(config2, {
2590
+ await waitForTransactionReceipt(config, {
2591
2591
  hash: result,
2592
2592
  confirmations: 1
2593
2593
  // You can change the number of block confirmations as per your requirement
@@ -2646,9 +2646,9 @@ var ConnectButton = () => {
2646
2646
  return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
2647
2647
  "button",
2648
2648
  {
2649
- className: "h-[34px] rounded-md border-1 border-black px-3 text-sm font-medium text-red-500",
2649
+ className: "h-[34px] rounded-md border-1 border-black px-3 text-sm font-medium text-black",
2650
2650
  onClick: openChainModal,
2651
- children: "Wrong network"
2651
+ children: "Select a Network"
2652
2652
  }
2653
2653
  );
2654
2654
  }
@@ -3145,23 +3145,19 @@ var Crypto = () => {
3145
3145
  // src/components/CryptoTab/Crypto/CryptoWrapper.tsx
3146
3146
  var import_jsx_runtime38 = require("react/jsx-runtime");
3147
3147
  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
3148
  var CryptoWrapper = () => {
3164
- 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, { children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(import_nice_modal_react6.default.Provider, { children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(Crypto, {}) }) }) }) });
3149
+ const { spreePayConfig } = useSpreePayConfig();
3150
+ const config = (0, import_react16.useMemo)(() => {
3151
+ if (!spreePayConfig) return null;
3152
+ return (0, import_rainbowkit2.getDefaultConfig)({
3153
+ appName: spreePayConfig.rainbowAppName || "AIR Shop",
3154
+ projectId: spreePayConfig.rainbowProjectId || "3fdcd5ff50cb84917cd05e40146975d8",
3155
+ chains: [import_chains.base],
3156
+ ssr: true
3157
+ });
3158
+ }, [spreePayConfig]);
3159
+ if (!config) return null;
3160
+ 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
3161
  };
3166
3162
 
3167
3163
  // src/components/CryptoTab/CryptoTab.tsx
@@ -3274,18 +3270,18 @@ var SpreePayContent = ({ isLoggedIn }) => {
3274
3270
  };
3275
3271
 
3276
3272
  // src/hooks/useKeycloakSSO.ts
3277
- var import_react16 = require("react");
3273
+ var import_react17 = require("react");
3278
3274
  var import_keycloak_js = __toESM(require("keycloak-js"), 1);
3279
3275
  var refreshAheadSeconds = 60;
3280
- function useKeycloakSSO(config2) {
3281
- const { url, realm, clientId, ssoPageURI, enabled } = config2;
3282
- const initRef = (0, import_react16.useRef)(false);
3283
- const kcRef = (0, import_react16.useRef)(null);
3284
- const refreshTimerRef = (0, import_react16.useRef)(null);
3285
- const [error, setError] = (0, import_react16.useState)(null);
3286
- const [isChecking, setIsChecking] = (0, import_react16.useState)(enabled);
3287
- const [accessToken, setAccessToken] = (0, import_react16.useState)(null);
3288
- const scheduleRefresh = (0, import_react16.useCallback)(() => {
3276
+ function useKeycloakSSO(config) {
3277
+ const { url, realm, clientId, ssoPageURI, enabled } = config;
3278
+ const initRef = (0, import_react17.useRef)(false);
3279
+ const kcRef = (0, import_react17.useRef)(null);
3280
+ const refreshTimerRef = (0, import_react17.useRef)(null);
3281
+ const [error, setError] = (0, import_react17.useState)(null);
3282
+ const [isChecking, setIsChecking] = (0, import_react17.useState)(enabled);
3283
+ const [accessToken, setAccessToken] = (0, import_react17.useState)(null);
3284
+ const scheduleRefresh = (0, import_react17.useCallback)(() => {
3289
3285
  const kc = kcRef.current;
3290
3286
  if (!kc || !kc.tokenParsed || !kc.tokenParsed.exp) {
3291
3287
  return;
@@ -3306,7 +3302,7 @@ function useKeycloakSSO(config2) {
3306
3302
  });
3307
3303
  }, delayMs);
3308
3304
  }, []);
3309
- (0, import_react16.useEffect)(() => {
3305
+ (0, import_react17.useEffect)(() => {
3310
3306
  if (initRef.current || !enabled) return;
3311
3307
  initRef.current = true;
3312
3308
  setIsChecking(true);
@@ -3343,9 +3339,9 @@ function useKeycloakSSO(config2) {
3343
3339
  // src/SpreePay.tsx
3344
3340
  var import_jsx_runtime43 = require("react/jsx-runtime");
3345
3341
  var SpreePayInner = () => {
3346
- const rootRef = (0, import_react17.useRef)(null);
3347
- const [portalEl, setPortalEl] = (0, import_react17.useState)(null);
3348
- (0, import_react17.useLayoutEffect)(() => {
3342
+ const rootRef = (0, import_react18.useRef)(null);
3343
+ const [portalEl, setPortalEl] = (0, import_react18.useState)(null);
3344
+ (0, import_react18.useLayoutEffect)(() => {
3349
3345
  if (!rootRef.current) return;
3350
3346
  const el = rootRef.current.querySelector(":scope > .sl-spreepay__portal");
3351
3347
  setPortalEl(el ?? null);
@@ -3360,7 +3356,7 @@ var SpreePayInner = () => {
3360
3356
  ssoPageURI: env?.ssoPageURI,
3361
3357
  enabled: !env?.accessToken
3362
3358
  });
3363
- const slapiFetcher = (0, import_react17.useMemo)(() => {
3359
+ const slapiFetcher = (0, import_react18.useMemo)(() => {
3364
3360
  if (accessToken || env.accessToken) {
3365
3361
  return registerApi({
3366
3362
  accessToken: env.accessToken || accessToken,
@@ -3400,9 +3396,9 @@ var SpreePay = (props) => {
3400
3396
  };
3401
3397
 
3402
3398
  // src/hooks/useCapture3DS.ts
3403
- var import_react18 = require("react");
3399
+ var import_react19 = require("react");
3404
3400
  var useCapture3DS = (searchParams) => {
3405
- (0, import_react18.useEffect)(() => {
3401
+ (0, import_react19.useEffect)(() => {
3406
3402
  if (typeof window !== "undefined" && window.parent && searchParams?.paymentIntent) {
3407
3403
  window.parent.SP_EVENT_BUS?.emit("paymentIntent", { paymentIntent: searchParams.paymentIntent });
3408
3404
  }
package/build/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/SpreePay.tsx
2
- import { useLayoutEffect as useLayoutEffect3, useMemo as useMemo9, useRef as useRef7, useState as useState14 } from "react";
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 = (config2) => {
562
- cfg.baseUrl = config2.baseUrl;
563
- cfg.accessToken = config2.accessToken;
564
- cfg.tenantId = config2.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);
@@ -2409,12 +2409,12 @@ var CreditCardTab = () => {
2409
2409
  };
2410
2410
 
2411
2411
  // src/components/CryptoTab/Crypto/CryptoWrapper.tsx
2412
+ import { useMemo as useMemo9 } from "react";
2412
2413
  import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
2413
2414
  import NiceModal6 from "@ebay/nice-modal-react";
2414
- import { RainbowKitProvider, connectorsForWallets } from "@rainbow-me/rainbowkit";
2415
+ import { RainbowKitProvider, getDefaultConfig, lightTheme } from "@rainbow-me/rainbowkit";
2415
2416
  import "@rainbow-me/rainbowkit/styles.css";
2416
- import { injectedWallet, walletConnectWallet } from "@rainbow-me/rainbowkit/wallets";
2417
- import { WagmiProvider, createConfig, http as http2 } from "wagmi";
2417
+ import { WagmiProvider } from "wagmi";
2418
2418
  import { base } from "wagmi/chains";
2419
2419
 
2420
2420
  // src/components/CryptoTab/Crypto/Crypto.tsx
@@ -2434,9 +2434,9 @@ function getAction(client, actionFn, name) {
2434
2434
 
2435
2435
  // ../../node_modules/@wagmi/core/dist/esm/actions/readContract.js
2436
2436
  import { readContract as viem_readContract } from "viem/actions";
2437
- function readContract(config2, parameters) {
2437
+ function readContract(config, parameters) {
2438
2438
  const { chainId, ...rest } = parameters;
2439
- const client = config2.getClient({ chainId });
2439
+ const client = config.getClient({ chainId });
2440
2440
  const action = getAction(client, viem_readContract, "readContract");
2441
2441
  return action(rest);
2442
2442
  }
@@ -2444,9 +2444,9 @@ function readContract(config2, parameters) {
2444
2444
  // ../../node_modules/@wagmi/core/dist/esm/actions/waitForTransactionReceipt.js
2445
2445
  import { hexToString } from "viem";
2446
2446
  import { call, getTransaction, waitForTransactionReceipt as viem_waitForTransactionReceipt } from "viem/actions";
2447
- async function waitForTransactionReceipt(config2, parameters) {
2447
+ async function waitForTransactionReceipt(config, parameters) {
2448
2448
  const { chainId, timeout = 0, ...rest } = parameters;
2449
- const client = config2.getClient({ chainId });
2449
+ const client = config.getClient({ chainId });
2450
2450
  const action = getAction(client, viem_waitForTransactionReceipt, "waitForTransactionReceipt");
2451
2451
  const receipt = await action({ ...rest, timeout });
2452
2452
  if (receipt.status === "reverted") {
@@ -2518,7 +2518,7 @@ var MAX_UINT256 = BigInt(2) ** BigInt(256) - BigInt(1);
2518
2518
  var ONE_INCH_AGGREGATION_ROUTER_V6 = "0x111111125421ca6dc452d289314280a0f8842a65";
2519
2519
  var useCryptoPayment = () => {
2520
2520
  const { data: walletClient } = useWalletClient();
2521
- const config2 = useConfig();
2521
+ const config = useConfig();
2522
2522
  const { selectedPaymentMethod } = useSpreePaymentMethod();
2523
2523
  const cryptoPayment = async (params) => {
2524
2524
  if (!walletClient) {
@@ -2534,7 +2534,7 @@ var useCryptoPayment = () => {
2534
2534
  if (!tokenAddress) {
2535
2535
  throw new Error("Token address not found");
2536
2536
  }
2537
- const allowance = await readContract(config2, {
2537
+ const allowance = await readContract(config, {
2538
2538
  address: tokenAddress,
2539
2539
  abi: erc20Abi2,
2540
2540
  functionName: "allowance",
@@ -2547,7 +2547,7 @@ var useCryptoPayment = () => {
2547
2547
  functionName: "approve",
2548
2548
  args: [ONE_INCH_AGGREGATION_ROUTER_V6, MAX_UINT256]
2549
2549
  });
2550
- await waitForTransactionReceipt(config2, {
2550
+ await waitForTransactionReceipt(config, {
2551
2551
  hash: result,
2552
2552
  confirmations: 1
2553
2553
  // You can change the number of block confirmations as per your requirement
@@ -2606,9 +2606,9 @@ var ConnectButton = () => {
2606
2606
  return /* @__PURE__ */ jsx28(
2607
2607
  "button",
2608
2608
  {
2609
- className: "h-[34px] rounded-md border-1 border-black px-3 text-sm font-medium text-red-500",
2609
+ className: "h-[34px] rounded-md border-1 border-black px-3 text-sm font-medium text-black",
2610
2610
  onClick: openChainModal,
2611
- children: "Wrong network"
2611
+ children: "Select a Network"
2612
2612
  }
2613
2613
  );
2614
2614
  }
@@ -3105,23 +3105,19 @@ var Crypto = () => {
3105
3105
  // src/components/CryptoTab/Crypto/CryptoWrapper.tsx
3106
3106
  import { jsx as jsx38 } from "react/jsx-runtime";
3107
3107
  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
3108
  var CryptoWrapper = () => {
3124
- return /* @__PURE__ */ jsx38(WagmiProvider, { config, children: /* @__PURE__ */ jsx38(QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ jsx38(RainbowKitProvider, { children: /* @__PURE__ */ jsx38(NiceModal6.Provider, { children: /* @__PURE__ */ jsx38(Crypto, {}) }) }) }) });
3109
+ const { spreePayConfig } = useSpreePayConfig();
3110
+ const config = useMemo9(() => {
3111
+ if (!spreePayConfig) return null;
3112
+ return getDefaultConfig({
3113
+ appName: spreePayConfig.rainbowAppName || "AIR Shop",
3114
+ projectId: spreePayConfig.rainbowProjectId || "3fdcd5ff50cb84917cd05e40146975d8",
3115
+ chains: [base],
3116
+ ssr: true
3117
+ });
3118
+ }, [spreePayConfig]);
3119
+ if (!config) return null;
3120
+ 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
3121
  };
3126
3122
 
3127
3123
  // src/components/CryptoTab/CryptoTab.tsx
@@ -3237,8 +3233,8 @@ var SpreePayContent = ({ isLoggedIn }) => {
3237
3233
  import { useCallback as useCallback7, useEffect as useEffect10, useRef as useRef6, useState as useState13 } from "react";
3238
3234
  import Keycloak from "keycloak-js";
3239
3235
  var refreshAheadSeconds = 60;
3240
- function useKeycloakSSO(config2) {
3241
- const { url, realm, clientId, ssoPageURI, enabled } = config2;
3236
+ function useKeycloakSSO(config) {
3237
+ const { url, realm, clientId, ssoPageURI, enabled } = config;
3242
3238
  const initRef = useRef6(false);
3243
3239
  const kcRef = useRef6(null);
3244
3240
  const refreshTimerRef = useRef6(null);
@@ -3320,7 +3316,7 @@ var SpreePayInner = () => {
3320
3316
  ssoPageURI: env?.ssoPageURI,
3321
3317
  enabled: !env?.accessToken
3322
3318
  });
3323
- const slapiFetcher = useMemo9(() => {
3319
+ const slapiFetcher = useMemo10(() => {
3324
3320
  if (accessToken || env.accessToken) {
3325
3321
  return registerApi({
3326
3322
  accessToken: env.accessToken || accessToken,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superlogic/spree-pay",
3
- "version": "0.1.19",
3
+ "version": "0.1.20",
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.8",
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",