@rpg-engine/long-bow 0.8.232 → 0.8.233
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/components/Store/CartView.d.ts +11 -1
- package/dist/components/Store/PaymentMethodModal.d.ts +1 -0
- package/dist/components/Store/Store.d.ts +2 -1
- package/dist/components/Store/hooks/useStoreCart.d.ts +2 -1
- package/dist/long-bow.cjs.development.js +56 -32
- package/dist/long-bow.cjs.development.js.map +1 -1
- package/dist/long-bow.cjs.production.min.js +1 -1
- package/dist/long-bow.cjs.production.min.js.map +1 -1
- package/dist/long-bow.esm.js +56 -32
- package/dist/long-bow.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Store/CartView.tsx +23 -5
- package/src/components/Store/PaymentMethodModal.tsx +19 -9
- package/src/components/Store/Store.tsx +2 -2
- package/src/components/Store/__test__/CartView.spec.tsx +190 -0
- package/src/components/Store/__test__/PaymentMethodModal.spec.tsx +108 -0
- package/src/components/Store/hooks/useStoreCart.ts +6 -4
package/dist/long-bow.esm.js
CHANGED
|
@@ -38004,6 +38004,17 @@ var CloseLink = /*#__PURE__*/styled.div.withConfig({
|
|
|
38004
38004
|
componentId: "sc-18z5q21-16"
|
|
38005
38005
|
})(["font-family:'Press Start 2P',cursive;font-size:0.5rem;color:rgba(255,255,255,0.45);cursor:pointer;display:flex;align-items:center;gap:0.3rem;transition:color 0.15s;&:hover{color:rgba(255,255,255,0.7);}"]);
|
|
38006
38006
|
|
|
38007
|
+
var GENERIC_PURCHASE_FAILED_MESSAGE = 'Purchase failed. Please try again.';
|
|
38008
|
+
var normalizePurchaseResult = function normalizePurchaseResult(result) {
|
|
38009
|
+
if (typeof result === 'boolean') {
|
|
38010
|
+
return result ? {
|
|
38011
|
+
status: 'success'
|
|
38012
|
+
} : {
|
|
38013
|
+
status: 'failed'
|
|
38014
|
+
};
|
|
38015
|
+
}
|
|
38016
|
+
return result;
|
|
38017
|
+
};
|
|
38007
38018
|
var MetadataDisplay = function MetadataDisplay(_ref) {
|
|
38008
38019
|
var type = _ref.type,
|
|
38009
38020
|
metadata = _ref.metadata;
|
|
@@ -38051,7 +38062,7 @@ var CartView = function CartView(_ref2) {
|
|
|
38051
38062
|
};
|
|
38052
38063
|
var handlePurchase = /*#__PURE__*/function () {
|
|
38053
38064
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
38054
|
-
var snapshot, trackItems,
|
|
38065
|
+
var snapshot, trackItems, purchaseResult, _purchaseResult$error, errMsg, _errMsg;
|
|
38055
38066
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
38056
38067
|
while (1) switch (_context.prev = _context.next) {
|
|
38057
38068
|
case 0:
|
|
@@ -38067,36 +38078,38 @@ var CartView = function CartView(_ref2) {
|
|
|
38067
38078
|
};
|
|
38068
38079
|
});
|
|
38069
38080
|
onCheckoutStart == null ? void 0 : onCheckoutStart(trackItems, total);
|
|
38070
|
-
_context.
|
|
38081
|
+
_context.t0 = normalizePurchaseResult;
|
|
38082
|
+
_context.next = 9;
|
|
38071
38083
|
return onPurchase();
|
|
38072
|
-
case
|
|
38073
|
-
|
|
38074
|
-
|
|
38084
|
+
case 9:
|
|
38085
|
+
_context.t1 = _context.sent;
|
|
38086
|
+
purchaseResult = (0, _context.t0)(_context.t1);
|
|
38087
|
+
if (purchaseResult.status === 'success') {
|
|
38075
38088
|
onPurchaseSuccess == null ? void 0 : onPurchaseSuccess(trackItems, total);
|
|
38076
38089
|
setPurchasedItems(snapshot);
|
|
38077
|
-
} else {
|
|
38078
|
-
errMsg =
|
|
38090
|
+
} else if (purchaseResult.status === 'failed') {
|
|
38091
|
+
errMsg = (_purchaseResult$error = purchaseResult.error) != null ? _purchaseResult$error : GENERIC_PURCHASE_FAILED_MESSAGE;
|
|
38079
38092
|
onPurchaseError == null ? void 0 : onPurchaseError(errMsg);
|
|
38080
38093
|
setError(errMsg);
|
|
38081
38094
|
}
|
|
38082
|
-
_context.next =
|
|
38095
|
+
_context.next = 20;
|
|
38083
38096
|
break;
|
|
38084
|
-
case
|
|
38085
|
-
_context.prev =
|
|
38086
|
-
_context.
|
|
38097
|
+
case 14:
|
|
38098
|
+
_context.prev = 14;
|
|
38099
|
+
_context.t2 = _context["catch"](0);
|
|
38087
38100
|
_errMsg = 'An error occurred during purchase. Please try again.';
|
|
38088
38101
|
onPurchaseError == null ? void 0 : onPurchaseError(_errMsg);
|
|
38089
38102
|
setError(_errMsg);
|
|
38090
|
-
console.error('Purchase error:', _context.
|
|
38091
|
-
case
|
|
38092
|
-
_context.prev =
|
|
38103
|
+
console.error('Purchase error:', _context.t2);
|
|
38104
|
+
case 20:
|
|
38105
|
+
_context.prev = 20;
|
|
38093
38106
|
setIsLoading(false);
|
|
38094
|
-
return _context.finish(
|
|
38095
|
-
case
|
|
38107
|
+
return _context.finish(20);
|
|
38108
|
+
case 23:
|
|
38096
38109
|
case "end":
|
|
38097
38110
|
return _context.stop();
|
|
38098
38111
|
}
|
|
38099
|
-
}, _callee, null, [[0,
|
|
38112
|
+
}, _callee, null, [[0, 14, 20, 23]]);
|
|
38100
38113
|
}));
|
|
38101
38114
|
return function handlePurchase() {
|
|
38102
38115
|
return _ref3.apply(this, arguments);
|
|
@@ -38615,7 +38628,7 @@ var useStoreCart = function useStoreCart() {
|
|
|
38615
38628
|
};
|
|
38616
38629
|
var handlePurchase = /*#__PURE__*/function () {
|
|
38617
38630
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(onPurchase) {
|
|
38618
|
-
var purchaseUnits, purchase, success;
|
|
38631
|
+
var purchaseUnits, purchase, result, success;
|
|
38619
38632
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
38620
38633
|
while (1) switch (_context2.prev = _context2.next) {
|
|
38621
38634
|
case 0:
|
|
@@ -38639,13 +38652,14 @@ var useStoreCart = function useStoreCart() {
|
|
|
38639
38652
|
_context2.next = 4;
|
|
38640
38653
|
return onPurchase(purchase);
|
|
38641
38654
|
case 4:
|
|
38642
|
-
|
|
38655
|
+
result = _context2.sent;
|
|
38656
|
+
success = typeof result === 'boolean' ? result : result.status === 'success';
|
|
38643
38657
|
if (success && isMounted.current) {
|
|
38644
38658
|
setCartItems([]);
|
|
38645
38659
|
setIsCartOpen(false);
|
|
38646
38660
|
}
|
|
38647
|
-
return _context2.abrupt("return",
|
|
38648
|
-
case
|
|
38661
|
+
return _context2.abrupt("return", result);
|
|
38662
|
+
case 8:
|
|
38649
38663
|
case "end":
|
|
38650
38664
|
return _context2.stop();
|
|
38651
38665
|
}
|
|
@@ -38779,7 +38793,9 @@ var PaymentMethodModal = function PaymentMethodModal(_ref) {
|
|
|
38779
38793
|
onPayWithPix = _ref.onPayWithPix,
|
|
38780
38794
|
onClose = _ref.onClose,
|
|
38781
38795
|
_ref$showPix = _ref.showPix,
|
|
38782
|
-
showPix = _ref$showPix === void 0 ? false : _ref$showPix
|
|
38796
|
+
showPix = _ref$showPix === void 0 ? false : _ref$showPix,
|
|
38797
|
+
_ref$isProcessing = _ref.isProcessing,
|
|
38798
|
+
isProcessing = _ref$isProcessing === void 0 ? false : _ref$isProcessing;
|
|
38783
38799
|
var _useState = useState('card'),
|
|
38784
38800
|
selected = _useState[0],
|
|
38785
38801
|
setSelected = _useState[1];
|
|
@@ -38793,6 +38809,7 @@ var PaymentMethodModal = function PaymentMethodModal(_ref) {
|
|
|
38793
38809
|
e.stopPropagation();
|
|
38794
38810
|
}, []);
|
|
38795
38811
|
var handleConfirm = useCallback(function () {
|
|
38812
|
+
if (isProcessing) return;
|
|
38796
38813
|
if (selected === 'dc' && !dcDisabled) {
|
|
38797
38814
|
onPayWithDC();
|
|
38798
38815
|
} else if (selected === 'pix') {
|
|
@@ -38800,7 +38817,10 @@ var PaymentMethodModal = function PaymentMethodModal(_ref) {
|
|
|
38800
38817
|
} else {
|
|
38801
38818
|
onPayWithCard();
|
|
38802
38819
|
}
|
|
38803
|
-
}, [selected, dcDisabled, onPayWithDC, onPayWithCard, onPayWithPix]);
|
|
38820
|
+
}, [selected, dcDisabled, isProcessing, onPayWithDC, onPayWithCard, onPayWithPix]);
|
|
38821
|
+
var handleClose = useCallback(function () {
|
|
38822
|
+
if (!isProcessing) onClose();
|
|
38823
|
+
}, [isProcessing, onClose]);
|
|
38804
38824
|
var dcSubText = dcRequired !== undefined ? React.createElement(React.Fragment, null, React.createElement(MMORPGNumber, {
|
|
38805
38825
|
value: dcBalance
|
|
38806
38826
|
}), " DC available \xB7", ' ', React.createElement(MMORPGNumber, {
|
|
@@ -38809,40 +38829,44 @@ var PaymentMethodModal = function PaymentMethodModal(_ref) {
|
|
|
38809
38829
|
value: dcBalance
|
|
38810
38830
|
}), " DC available");
|
|
38811
38831
|
return React.createElement(ModalPortal, null, React.createElement(Overlay$b, {
|
|
38812
|
-
onPointerDown:
|
|
38832
|
+
onPointerDown: handleClose
|
|
38813
38833
|
}), React.createElement(ModalContainer$8, null, React.createElement(ModalContent$8, {
|
|
38814
38834
|
onClick: stopPropagation,
|
|
38815
38835
|
onTouchStart: stopPropagation,
|
|
38816
38836
|
onPointerDown: stopPropagation
|
|
38817
38837
|
}, React.createElement(Header$i, null, React.createElement(Title$p, null, "How would you like to pay?"), React.createElement(CloseButton$j, {
|
|
38818
|
-
onPointerDown:
|
|
38819
|
-
"aria-label": "Close"
|
|
38838
|
+
onPointerDown: handleClose,
|
|
38839
|
+
"aria-label": "Close",
|
|
38840
|
+
disabled: isProcessing
|
|
38820
38841
|
}, React.createElement(Cancel, null))), React.createElement(Options$1, null, React.createElement(RadioOption$2, {
|
|
38821
38842
|
"$selected": selected === 'card',
|
|
38822
|
-
|
|
38843
|
+
"$disabled": isProcessing,
|
|
38844
|
+
onPointerDown: isProcessing ? undefined : function () {
|
|
38823
38845
|
return setSelected('card');
|
|
38824
38846
|
}
|
|
38825
38847
|
}, React.createElement(RadioCircle$3, {
|
|
38826
38848
|
"$selected": selected === 'card'
|
|
38827
38849
|
}), React.createElement(OptionText$1, null, React.createElement(OptionLabel$2, null, "Credit Card"), React.createElement(OptionSub$1, null, "Stripe secure checkout"))), showPix && React.createElement(RadioOption$2, {
|
|
38828
38850
|
"$selected": selected === 'pix',
|
|
38829
|
-
|
|
38851
|
+
"$disabled": isProcessing,
|
|
38852
|
+
onPointerDown: isProcessing ? undefined : function () {
|
|
38830
38853
|
return setSelected('pix');
|
|
38831
38854
|
}
|
|
38832
38855
|
}, React.createElement(RadioCircle$3, {
|
|
38833
38856
|
"$selected": selected === 'pix'
|
|
38834
38857
|
}), React.createElement(OptionText$1, null, React.createElement(OptionLabel$2, null, "Pix"), React.createElement(OptionSub$1, null, "Instant payment via Pix"))), React.createElement(RadioOption$2, {
|
|
38835
38858
|
"$selected": selected === 'dc',
|
|
38836
|
-
"$disabled": dcDisabled,
|
|
38837
|
-
onPointerDown: dcDisabled ? undefined : function () {
|
|
38859
|
+
"$disabled": dcDisabled || isProcessing,
|
|
38860
|
+
onPointerDown: dcDisabled || isProcessing ? undefined : function () {
|
|
38838
38861
|
return setSelected('dc');
|
|
38839
38862
|
}
|
|
38840
38863
|
}, React.createElement(RadioCircle$3, {
|
|
38841
38864
|
"$selected": selected === 'dc'
|
|
38842
38865
|
}), React.createElement(OptionText$1, null, React.createElement(OptionLabel$2, null, "Definya Coin"), React.createElement(OptionSub$1, null, dcSubText)))), React.createElement(ConfirmRow$1, null, React.createElement(Button, {
|
|
38843
38866
|
buttonType: ButtonTypes.RPGUIButton,
|
|
38844
|
-
onPointerDown: handleConfirm
|
|
38845
|
-
|
|
38867
|
+
onPointerDown: handleConfirm,
|
|
38868
|
+
disabled: isProcessing
|
|
38869
|
+
}, isProcessing ? 'Processing...' : 'Confirm')))));
|
|
38846
38870
|
};
|
|
38847
38871
|
var Overlay$b = /*#__PURE__*/styled.div.withConfig({
|
|
38848
38872
|
displayName: "PaymentMethodModal__Overlay",
|