@superlogic/spree-pay 0.1.20 → 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 CHANGED
@@ -747,7 +747,8 @@ async function createAndInit(opts) {
747
747
  chain: opts.mocaChain,
748
748
  account: address
749
749
  }) : null;
750
- return { walletReady: true, address, walletClient, air, chain: opts.mocaChain };
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)(async (pointsChain) => {
2360
- if (!pointsChain) {
2361
- return;
2362
- }
2363
- try {
2364
- const res = await getAirWallet({
2365
- mocaChain: pointsChain.mocaChain,
2366
- partnerId: pointsChain.partnerId
2367
- });
2368
- setAddress(res.address ?? null);
2369
- } catch (e) {
2370
- console.error("Air Wallet init failed:", e);
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)(SplitBlock, { isSelected: selectedPointsType === "air", onSelect: setSelectedPointsType })
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
 
package/build/index.js CHANGED
@@ -707,7 +707,8 @@ async function createAndInit(opts) {
707
707
  chain: opts.mocaChain,
708
708
  account: address
709
709
  }) : null;
710
- return { walletReady: true, address, walletClient, air, chain: opts.mocaChain };
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(async (pointsChain) => {
2320
- if (!pointsChain) {
2321
- return;
2322
- }
2323
- try {
2324
- const res = await getAirWallet({
2325
- mocaChain: pointsChain.mocaChain,
2326
- partnerId: pointsChain.partnerId
2327
- });
2328
- setAddress(res.address ?? null);
2329
- } catch (e) {
2330
- console.error("Air Wallet init failed:", e);
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(SplitBlock, { isSelected: selectedPointsType === "air", onSelect: setSelectedPointsType })
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superlogic/spree-pay",
3
- "version": "0.1.20",
3
+ "version": "0.1.21",
4
4
  "description": "Spree-pay React component and utilities",
5
5
  "private": false,
6
6
  "type": "module",