@rpg-engine/long-bow 0.8.232 → 0.8.234
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/DCWallet/DCTransferPanel.d.ts +3 -0
- package/dist/components/DCWallet/DCWalletContent.d.ts +3 -0
- package/dist/components/Marketplace/CharacterListingModal.d.ts +1 -0
- package/dist/components/Marketplace/CharacterTradePanel.d.ts +1 -0
- package/dist/components/Marketplace/ManagmentPanel.d.ts +1 -0
- package/dist/components/Marketplace/Marketplace.d.ts +1 -0
- package/dist/components/Marketplace/MyCharacterListingsPanel.d.ts +1 -0
- 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 +146 -82
- 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 +146 -82
- package/dist/long-bow.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/DCWallet/DCTransferPanel.tsx +34 -4
- package/src/components/DCWallet/DCWalletContent.tsx +9 -1
- package/src/components/DCWallet/__test__/DCTransferPanel.spec.tsx +115 -0
- package/src/components/Marketplace/CharacterListingModal.tsx +16 -0
- package/src/components/Marketplace/CharacterTradePanel.tsx +3 -0
- package/src/components/Marketplace/ManagmentPanel.tsx +38 -1
- package/src/components/Marketplace/Marketplace.tsx +2 -1
- package/src/components/Marketplace/MyCharacterListingsPanel.tsx +3 -0
- package/src/components/Marketplace/__test__/CharacterListingModal.spec.tsx +114 -0
- package/src/components/Marketplace/__test__/ManagmentPanel.spec.tsx +125 -0
- 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/src/stories/Features/trading/Marketplace.stories.tsx +2 -1
|
@@ -21,11 +21,29 @@ interface ICartItem {
|
|
|
21
21
|
metadata?: Record<string, any>;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
export type PurchaseResult =
|
|
25
|
+
| { status: 'success' }
|
|
26
|
+
| { status: 'cancelled' }
|
|
27
|
+
| { status: 'failed'; error?: string };
|
|
28
|
+
|
|
29
|
+
export type LegacyPurchaseResult = boolean;
|
|
30
|
+
export type CartPurchaseResult = PurchaseResult | LegacyPurchaseResult;
|
|
31
|
+
|
|
32
|
+
const GENERIC_PURCHASE_FAILED_MESSAGE = 'Purchase failed. Please try again.';
|
|
33
|
+
|
|
34
|
+
const normalizePurchaseResult = (result: CartPurchaseResult): PurchaseResult => {
|
|
35
|
+
if (typeof result === 'boolean') {
|
|
36
|
+
return result ? { status: 'success' } : { status: 'failed' };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
41
|
+
|
|
24
42
|
export interface ICartViewProps {
|
|
25
43
|
cartItems: ICartItem[];
|
|
26
44
|
onRemoveFromCart: (itemKey: string) => void;
|
|
27
45
|
onClose: () => void;
|
|
28
|
-
onPurchase: () => Promise<
|
|
46
|
+
onPurchase: () => Promise<CartPurchaseResult>;
|
|
29
47
|
atlasJSON: Record<string, any>;
|
|
30
48
|
atlasIMG: string;
|
|
31
49
|
paymentMethodLabel?: string;
|
|
@@ -99,13 +117,13 @@ export const CartView: React.FC<ICartViewProps> = ({
|
|
|
99
117
|
const snapshot = [...cartItems];
|
|
100
118
|
const trackItems = snapshot.map(ci => ({ key: ci.item.key, name: ci.item.name, quantity: ci.quantity }));
|
|
101
119
|
onCheckoutStart?.(trackItems, total);
|
|
102
|
-
const
|
|
120
|
+
const purchaseResult = normalizePurchaseResult(await onPurchase());
|
|
103
121
|
|
|
104
|
-
if (success) {
|
|
122
|
+
if (purchaseResult.status === 'success') {
|
|
105
123
|
onPurchaseSuccess?.(trackItems, total);
|
|
106
124
|
setPurchasedItems(snapshot);
|
|
107
|
-
} else {
|
|
108
|
-
const errMsg =
|
|
125
|
+
} else if (purchaseResult.status === 'failed') {
|
|
126
|
+
const errMsg = purchaseResult.error ?? GENERIC_PURCHASE_FAILED_MESSAGE;
|
|
109
127
|
onPurchaseError?.(errMsg);
|
|
110
128
|
setError(errMsg);
|
|
111
129
|
}
|
|
@@ -13,6 +13,7 @@ export interface IPaymentMethodModalProps {
|
|
|
13
13
|
onPayWithPix: () => void;
|
|
14
14
|
onClose: () => void;
|
|
15
15
|
showPix?: boolean;
|
|
16
|
+
isProcessing?: boolean;
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
type PaymentMethod = 'dc' | 'card' | 'pix';
|
|
@@ -25,6 +26,7 @@ export const PaymentMethodModal: React.FC<IPaymentMethodModalProps> = ({
|
|
|
25
26
|
onPayWithPix,
|
|
26
27
|
onClose,
|
|
27
28
|
showPix = false,
|
|
29
|
+
isProcessing = false,
|
|
28
30
|
}) => {
|
|
29
31
|
const [selected, setSelected] = useState<PaymentMethod>('card');
|
|
30
32
|
|
|
@@ -44,6 +46,8 @@ export const PaymentMethodModal: React.FC<IPaymentMethodModalProps> = ({
|
|
|
44
46
|
);
|
|
45
47
|
|
|
46
48
|
const handleConfirm = useCallback(() => {
|
|
49
|
+
if (isProcessing) return;
|
|
50
|
+
|
|
47
51
|
if (selected === 'dc' && !dcDisabled) {
|
|
48
52
|
onPayWithDC();
|
|
49
53
|
} else if (selected === 'pix') {
|
|
@@ -51,7 +55,11 @@ export const PaymentMethodModal: React.FC<IPaymentMethodModalProps> = ({
|
|
|
51
55
|
} else {
|
|
52
56
|
onPayWithCard();
|
|
53
57
|
}
|
|
54
|
-
}, [selected, dcDisabled, onPayWithDC, onPayWithCard, onPayWithPix]);
|
|
58
|
+
}, [selected, dcDisabled, isProcessing, onPayWithDC, onPayWithCard, onPayWithPix]);
|
|
59
|
+
|
|
60
|
+
const handleClose = useCallback(() => {
|
|
61
|
+
if (!isProcessing) onClose();
|
|
62
|
+
}, [isProcessing, onClose]);
|
|
55
63
|
|
|
56
64
|
const dcSubText =
|
|
57
65
|
dcRequired !== undefined ? (
|
|
@@ -67,7 +75,7 @@ export const PaymentMethodModal: React.FC<IPaymentMethodModalProps> = ({
|
|
|
67
75
|
|
|
68
76
|
return (
|
|
69
77
|
<ModalPortal>
|
|
70
|
-
<Overlay onPointerDown={
|
|
78
|
+
<Overlay onPointerDown={handleClose} />
|
|
71
79
|
<ModalContainer>
|
|
72
80
|
<ModalContent
|
|
73
81
|
onClick={stopPropagation as React.MouseEventHandler}
|
|
@@ -76,7 +84,7 @@ export const PaymentMethodModal: React.FC<IPaymentMethodModalProps> = ({
|
|
|
76
84
|
>
|
|
77
85
|
<Header>
|
|
78
86
|
<Title>How would you like to pay?</Title>
|
|
79
|
-
<CloseButton onPointerDown={
|
|
87
|
+
<CloseButton onPointerDown={handleClose} aria-label="Close" disabled={isProcessing}>
|
|
80
88
|
<Cancel />
|
|
81
89
|
</CloseButton>
|
|
82
90
|
</Header>
|
|
@@ -84,7 +92,8 @@ export const PaymentMethodModal: React.FC<IPaymentMethodModalProps> = ({
|
|
|
84
92
|
<Options>
|
|
85
93
|
<RadioOption
|
|
86
94
|
$selected={selected === 'card'}
|
|
87
|
-
|
|
95
|
+
$disabled={isProcessing}
|
|
96
|
+
onPointerDown={isProcessing ? undefined : () => setSelected('card')}
|
|
88
97
|
>
|
|
89
98
|
<RadioCircle $selected={selected === 'card'} />
|
|
90
99
|
<OptionText>
|
|
@@ -96,7 +105,8 @@ export const PaymentMethodModal: React.FC<IPaymentMethodModalProps> = ({
|
|
|
96
105
|
{showPix && (
|
|
97
106
|
<RadioOption
|
|
98
107
|
$selected={selected === 'pix'}
|
|
99
|
-
|
|
108
|
+
$disabled={isProcessing}
|
|
109
|
+
onPointerDown={isProcessing ? undefined : () => setSelected('pix')}
|
|
100
110
|
>
|
|
101
111
|
<RadioCircle $selected={selected === 'pix'} />
|
|
102
112
|
<OptionText>
|
|
@@ -108,8 +118,8 @@ export const PaymentMethodModal: React.FC<IPaymentMethodModalProps> = ({
|
|
|
108
118
|
|
|
109
119
|
<RadioOption
|
|
110
120
|
$selected={selected === 'dc'}
|
|
111
|
-
$disabled={dcDisabled}
|
|
112
|
-
onPointerDown={dcDisabled ? undefined : () => setSelected('dc')}
|
|
121
|
+
$disabled={dcDisabled || isProcessing}
|
|
122
|
+
onPointerDown={dcDisabled || isProcessing ? undefined : () => setSelected('dc')}
|
|
113
123
|
>
|
|
114
124
|
<RadioCircle $selected={selected === 'dc'} />
|
|
115
125
|
<OptionText>
|
|
@@ -120,8 +130,8 @@ export const PaymentMethodModal: React.FC<IPaymentMethodModalProps> = ({
|
|
|
120
130
|
</Options>
|
|
121
131
|
|
|
122
132
|
<ConfirmRow>
|
|
123
|
-
<Button buttonType={ButtonTypes.RPGUIButton} onPointerDown={handleConfirm}>
|
|
124
|
-
Confirm
|
|
133
|
+
<Button buttonType={ButtonTypes.RPGUIButton} onPointerDown={handleConfirm} disabled={isProcessing}>
|
|
134
|
+
{isProcessing ? 'Processing...' : 'Confirm'}
|
|
125
135
|
</Button>
|
|
126
136
|
</ConfirmRow>
|
|
127
137
|
</ModalContent>
|
|
@@ -14,7 +14,7 @@ import { DraggableContainer } from '../DraggableContainer';
|
|
|
14
14
|
import { RPGUIContainerTypes } from '../RPGUI/RPGUIContainer';
|
|
15
15
|
import { CTAButton } from '../shared/CTAButton/CTAButton';
|
|
16
16
|
import { LabelPill } from '../shared/LabelPill/LabelPill';
|
|
17
|
-
import { CartView } from './CartView';
|
|
17
|
+
import { CartPurchaseResult, CartView } from './CartView';
|
|
18
18
|
import { FeaturedBanner, IFeaturedItem } from './FeaturedBanner';
|
|
19
19
|
import { packToBlueprint } from './internal/packToBlueprint';
|
|
20
20
|
import { useStoreCart } from './hooks/useStoreCart';
|
|
@@ -31,7 +31,7 @@ export interface IStoreProps {
|
|
|
31
31
|
packs?: IItemPack[];
|
|
32
32
|
atlasJSON: any;
|
|
33
33
|
atlasIMG: string;
|
|
34
|
-
onPurchase: (purchase: Partial<IPurchase>) => Promise<
|
|
34
|
+
onPurchase: (purchase: Partial<IPurchase>) => Promise<CartPurchaseResult>;
|
|
35
35
|
onShowHistory?: () => void;
|
|
36
36
|
onShowWallet?: () => void;
|
|
37
37
|
walletLabel?: string;
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
// @ts-nocheck
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import ReactDOM from 'react-dom';
|
|
7
|
+
import { act } from 'react-dom/test-utils';
|
|
8
|
+
import { CartView } from '../CartView';
|
|
9
|
+
|
|
10
|
+
jest.mock(
|
|
11
|
+
'../../../mocks/atlas/entities/entities.json',
|
|
12
|
+
() => ({ frames: {} }),
|
|
13
|
+
{ virtual: true }
|
|
14
|
+
);
|
|
15
|
+
jest.mock('../../../mocks/atlas/entities/entities.png', () => 'entities.png', {
|
|
16
|
+
virtual: true,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
jest.mock('../../shared/SpriteFromAtlas', () => ({
|
|
20
|
+
SpriteFromAtlas: ({ spriteKey }) => (
|
|
21
|
+
<div data-testid="sprite">{spriteKey}</div>
|
|
22
|
+
),
|
|
23
|
+
}));
|
|
24
|
+
|
|
25
|
+
jest.mock('../../shared/MMORPGNumber', () => ({
|
|
26
|
+
MMORPGNumber: ({ value }) => <span>{value}</span>,
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
jest.mock('../../shared/CTAButton/CTAButton', () => ({
|
|
30
|
+
CTAButton: ({ label, onClick, disabled }) => (
|
|
31
|
+
<button type="button" onClick={onClick} disabled={disabled}>
|
|
32
|
+
{label}
|
|
33
|
+
</button>
|
|
34
|
+
),
|
|
35
|
+
}));
|
|
36
|
+
|
|
37
|
+
jest.mock('../TrustBar', () => ({
|
|
38
|
+
TrustBar: () => <div data-testid="trust-bar" />,
|
|
39
|
+
}));
|
|
40
|
+
|
|
41
|
+
jest.mock('../PurchaseSuccess', () => ({
|
|
42
|
+
PurchaseSuccess: () => <div>Purchase Success</div>,
|
|
43
|
+
}));
|
|
44
|
+
|
|
45
|
+
jest.mock('styled-components', () => {
|
|
46
|
+
const withoutTransientProps = (props) =>
|
|
47
|
+
Object.fromEntries(
|
|
48
|
+
Object.entries(props).filter(([key]) => !key.startsWith('$'))
|
|
49
|
+
);
|
|
50
|
+
const createTag = (tag) => () => {
|
|
51
|
+
if (tag === 'button')
|
|
52
|
+
return ({ children, ...props }) => (
|
|
53
|
+
<button {...withoutTransientProps(props)}>{children}</button>
|
|
54
|
+
);
|
|
55
|
+
if (tag === 'span')
|
|
56
|
+
return ({ children, ...props }) => (
|
|
57
|
+
<span {...withoutTransientProps(props)}>{children}</span>
|
|
58
|
+
);
|
|
59
|
+
return ({ children, ...props }) => (
|
|
60
|
+
<div {...withoutTransientProps(props)}>{children}</div>
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
const styled = new Proxy(() => {}, {
|
|
64
|
+
get: (_target, prop) => {
|
|
65
|
+
if (prop === '__esModule') return true;
|
|
66
|
+
return createTag(prop);
|
|
67
|
+
},
|
|
68
|
+
apply: () => createTag('div'),
|
|
69
|
+
});
|
|
70
|
+
return {
|
|
71
|
+
__esModule: true,
|
|
72
|
+
default: styled,
|
|
73
|
+
keyframes: () => '',
|
|
74
|
+
css: () => '',
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
jest.mock('pixelarticons/react/Cancel', () => ({
|
|
79
|
+
Cancel: () => <span>x</span>,
|
|
80
|
+
}));
|
|
81
|
+
jest.mock('pixelarticons/react/Delete', () => ({
|
|
82
|
+
Delete: () => <span>delete</span>,
|
|
83
|
+
}));
|
|
84
|
+
jest.mock('pixelarticons/react/InfoBox', () => ({
|
|
85
|
+
InfoBox: () => <span>info</span>,
|
|
86
|
+
}));
|
|
87
|
+
jest.mock('pixelarticons/react/Box', () => ({ Box: () => <span>box</span> }));
|
|
88
|
+
jest.mock('pixelarticons/react/ShoppingBag', () => ({
|
|
89
|
+
ShoppingBag: () => <span>bag</span>,
|
|
90
|
+
}));
|
|
91
|
+
|
|
92
|
+
const cartItems = [
|
|
93
|
+
{
|
|
94
|
+
item: {
|
|
95
|
+
_id: 'item-1',
|
|
96
|
+
key: 'life-potion',
|
|
97
|
+
name: 'Life Potion',
|
|
98
|
+
price: 1.5,
|
|
99
|
+
texturePath: 'items/life-potion.png',
|
|
100
|
+
},
|
|
101
|
+
quantity: 2,
|
|
102
|
+
},
|
|
103
|
+
];
|
|
104
|
+
|
|
105
|
+
const renderCart = (onPurchase, onPurchaseError = jest.fn()) => {
|
|
106
|
+
const container = document.createElement('div');
|
|
107
|
+
document.body.appendChild(container);
|
|
108
|
+
|
|
109
|
+
act(() => {
|
|
110
|
+
ReactDOM.render(
|
|
111
|
+
<CartView
|
|
112
|
+
cartItems={cartItems}
|
|
113
|
+
onRemoveFromCart={jest.fn()}
|
|
114
|
+
onClose={jest.fn()}
|
|
115
|
+
onPurchase={onPurchase}
|
|
116
|
+
atlasJSON={{}}
|
|
117
|
+
atlasIMG="items.png"
|
|
118
|
+
onPurchaseError={onPurchaseError}
|
|
119
|
+
/>,
|
|
120
|
+
container
|
|
121
|
+
);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
return { container, onPurchaseError };
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const clickPay = async (container) => {
|
|
128
|
+
const button = Array.from(container.querySelectorAll('button')).find(
|
|
129
|
+
(button) => button.textContent.includes('Pay')
|
|
130
|
+
);
|
|
131
|
+
await act(async () => {
|
|
132
|
+
button.click();
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
describe('CartView purchase result handling', () => {
|
|
137
|
+
afterEach(() => {
|
|
138
|
+
ReactDOM.unmountComponentAtNode(document.body.lastElementChild);
|
|
139
|
+
document.body.innerHTML = '';
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('treats cancelled purchases as a quiet dismissal without generic error telemetry', async () => {
|
|
143
|
+
const onPurchaseError = jest.fn();
|
|
144
|
+
const { container } = renderCart(
|
|
145
|
+
jest.fn().mockResolvedValue({ status: 'cancelled' }),
|
|
146
|
+
onPurchaseError
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
await clickPay(container);
|
|
150
|
+
|
|
151
|
+
expect(container.textContent).not.toContain(
|
|
152
|
+
'Purchase failed. Please try again.'
|
|
153
|
+
);
|
|
154
|
+
expect(container.textContent).not.toContain(
|
|
155
|
+
'An error occurred during purchase. Please try again.'
|
|
156
|
+
);
|
|
157
|
+
expect(onPurchaseError).not.toHaveBeenCalled();
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('shows and reports the exact failed purchase error message', async () => {
|
|
161
|
+
const onPurchaseError = jest.fn();
|
|
162
|
+
const exactError = 'Your session has expired. Please log in again.';
|
|
163
|
+
const { container } = renderCart(
|
|
164
|
+
jest.fn().mockResolvedValue({ status: 'failed', error: exactError }),
|
|
165
|
+
onPurchaseError
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
await clickPay(container);
|
|
169
|
+
|
|
170
|
+
expect(container.textContent).toContain(exactError);
|
|
171
|
+
expect(onPurchaseError).toHaveBeenCalledWith(exactError);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('keeps legacy false purchase results as the generic failure fallback', async () => {
|
|
175
|
+
const onPurchaseError = jest.fn();
|
|
176
|
+
const { container } = renderCart(
|
|
177
|
+
jest.fn().mockResolvedValue(false),
|
|
178
|
+
onPurchaseError
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
await clickPay(container);
|
|
182
|
+
|
|
183
|
+
expect(container.textContent).toContain(
|
|
184
|
+
'Purchase failed. Please try again.'
|
|
185
|
+
);
|
|
186
|
+
expect(onPurchaseError).toHaveBeenCalledWith(
|
|
187
|
+
'Purchase failed. Please try again.'
|
|
188
|
+
);
|
|
189
|
+
});
|
|
190
|
+
});
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
// @ts-nocheck
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import ReactDOM from 'react-dom';
|
|
7
|
+
import { act } from 'react-dom/test-utils';
|
|
8
|
+
import { PaymentMethodModal } from '../PaymentMethodModal';
|
|
9
|
+
|
|
10
|
+
jest.mock('../../Abstractions/ModalPortal', () => ({
|
|
11
|
+
__esModule: true,
|
|
12
|
+
default: ({ children }) => <>{children}</>,
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
jest.mock('../../Button', () => ({
|
|
16
|
+
ButtonTypes: { RPGUIButton: 'rpgui-button' },
|
|
17
|
+
Button: ({ children, disabled, onPointerDown }) => (
|
|
18
|
+
<button type="button" disabled={disabled} onPointerDown={onPointerDown}>
|
|
19
|
+
{children}
|
|
20
|
+
</button>
|
|
21
|
+
),
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
jest.mock('../../shared/MMORPGNumber', () => ({
|
|
25
|
+
MMORPGNumber: ({ value }) => <span>{value}</span>,
|
|
26
|
+
}));
|
|
27
|
+
|
|
28
|
+
jest.mock('pixelarticons/react/Cancel', () => ({
|
|
29
|
+
Cancel: () => <span>close</span>,
|
|
30
|
+
}));
|
|
31
|
+
|
|
32
|
+
jest.mock('styled-components', () => {
|
|
33
|
+
const withoutTransientProps = (props) =>
|
|
34
|
+
Object.fromEntries(
|
|
35
|
+
Object.entries(props).filter(([key]) => !key.startsWith('$'))
|
|
36
|
+
);
|
|
37
|
+
const createTag = (tag) => () => {
|
|
38
|
+
const Tag =
|
|
39
|
+
tag === 'button'
|
|
40
|
+
? 'button'
|
|
41
|
+
: tag === 'h3'
|
|
42
|
+
? 'h3'
|
|
43
|
+
: tag === 'span'
|
|
44
|
+
? 'span'
|
|
45
|
+
: 'div';
|
|
46
|
+
return ({ children, ...props }) => (
|
|
47
|
+
<Tag {...withoutTransientProps(props)}>{children}</Tag>
|
|
48
|
+
);
|
|
49
|
+
};
|
|
50
|
+
const styled = new Proxy(() => {}, {
|
|
51
|
+
get: (_target, prop) => {
|
|
52
|
+
if (prop === '__esModule') return true;
|
|
53
|
+
return createTag(prop);
|
|
54
|
+
},
|
|
55
|
+
apply: () => createTag('div'),
|
|
56
|
+
});
|
|
57
|
+
return { __esModule: true, default: styled };
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe('PaymentMethodModal processing guard', () => {
|
|
61
|
+
afterEach(() => {
|
|
62
|
+
ReactDOM.unmountComponentAtNode(document.body.lastElementChild);
|
|
63
|
+
document.body.innerHTML = '';
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('blocks close, backdrop, and confirm while checkout is processing', () => {
|
|
67
|
+
const onClose = jest.fn();
|
|
68
|
+
const onPayWithCard = jest.fn();
|
|
69
|
+
const container = document.createElement('div');
|
|
70
|
+
document.body.appendChild(container);
|
|
71
|
+
|
|
72
|
+
act(() => {
|
|
73
|
+
ReactDOM.render(
|
|
74
|
+
<PaymentMethodModal
|
|
75
|
+
dcBalance={0}
|
|
76
|
+
onPayWithDC={jest.fn()}
|
|
77
|
+
onPayWithCard={onPayWithCard}
|
|
78
|
+
onPayWithPix={jest.fn()}
|
|
79
|
+
onClose={onClose}
|
|
80
|
+
isProcessing
|
|
81
|
+
/>,
|
|
82
|
+
container
|
|
83
|
+
);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const closeButton = container.querySelector('button[aria-label="Close"]');
|
|
87
|
+
const confirmButton = Array.from(container.querySelectorAll('button')).find(
|
|
88
|
+
(button) => button.textContent === 'Processing...'
|
|
89
|
+
);
|
|
90
|
+
const overlay = container.firstElementChild;
|
|
91
|
+
|
|
92
|
+
expect(closeButton.disabled).toBe(true);
|
|
93
|
+
expect(confirmButton.disabled).toBe(true);
|
|
94
|
+
|
|
95
|
+
act(() => {
|
|
96
|
+
closeButton.dispatchEvent(
|
|
97
|
+
new MouseEvent('pointerdown', { bubbles: true })
|
|
98
|
+
);
|
|
99
|
+
confirmButton.dispatchEvent(
|
|
100
|
+
new MouseEvent('pointerdown', { bubbles: true })
|
|
101
|
+
);
|
|
102
|
+
overlay.dispatchEvent(new MouseEvent('pointerdown', { bubbles: true }));
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
expect(onClose).not.toHaveBeenCalled();
|
|
106
|
+
expect(onPayWithCard).not.toHaveBeenCalled();
|
|
107
|
+
});
|
|
108
|
+
});
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
PurchaseType
|
|
7
7
|
} from '@rpg-engine/shared';
|
|
8
8
|
import { useEffect, useRef, useState } from 'react';
|
|
9
|
+
import { CartPurchaseResult } from '../CartView';
|
|
9
10
|
import { useStoreMetadata } from './useStoreMetadata';
|
|
10
11
|
|
|
11
12
|
interface ICartItem {
|
|
@@ -19,7 +20,7 @@ interface IUseStoreCart {
|
|
|
19
20
|
isCartOpen: boolean;
|
|
20
21
|
handleAddToCart: (item: IProductBlueprint, quantity: number, metadata?: Record<string, any>) => void;
|
|
21
22
|
handleRemoveFromCart: (itemKey: string) => void;
|
|
22
|
-
handlePurchase: (onPurchase: (purchase: IPurchase) => Promise<
|
|
23
|
+
handlePurchase: (onPurchase: (purchase: IPurchase) => Promise<CartPurchaseResult>) => Promise<CartPurchaseResult>;
|
|
23
24
|
openCart: () => void;
|
|
24
25
|
closeCart: () => void;
|
|
25
26
|
getTotalItems: () => number;
|
|
@@ -104,7 +105,7 @@ export const useStoreCart = (): IUseStoreCart => {
|
|
|
104
105
|
);
|
|
105
106
|
};
|
|
106
107
|
|
|
107
|
-
const handlePurchase = async (onPurchase: (purchase: IPurchase) => Promise<
|
|
108
|
+
const handlePurchase = async (onPurchase: (purchase: IPurchase) => Promise<CartPurchaseResult>): Promise<CartPurchaseResult> => {
|
|
108
109
|
const purchaseUnits: IPurchaseUnit[] = cartItems.map(cartItem => ({
|
|
109
110
|
purchaseKey: cartItem.item.key,
|
|
110
111
|
qty: cartItem.quantity,
|
|
@@ -122,14 +123,15 @@ export const useStoreCart = (): IUseStoreCart => {
|
|
|
122
123
|
purchases: purchaseUnits,
|
|
123
124
|
};
|
|
124
125
|
|
|
125
|
-
const
|
|
126
|
+
const result = await onPurchase(purchase);
|
|
127
|
+
const success = typeof result === 'boolean' ? result : result.status === 'success';
|
|
126
128
|
|
|
127
129
|
if (success && isMounted.current) {
|
|
128
130
|
setCartItems([]);
|
|
129
131
|
setIsCartOpen(false);
|
|
130
132
|
}
|
|
131
133
|
|
|
132
|
-
return
|
|
134
|
+
return result;
|
|
133
135
|
};
|
|
134
136
|
|
|
135
137
|
const openCart = () => setIsCartOpen(true);
|
|
@@ -171,7 +171,7 @@ const Template: Story = () => {
|
|
|
171
171
|
onDCCoinClick={() => console.log('open store: packs tab')}
|
|
172
172
|
onFulfillBuyOrder={buyOrderId => console.log('fulfill buy order:', buyOrderId)}
|
|
173
173
|
availableGold={0}
|
|
174
|
-
selectedItemToSell={
|
|
174
|
+
selectedItemToSell={items[0]}
|
|
175
175
|
onSelectedItemToSellRemove={() => console.log('click')}
|
|
176
176
|
onYourPanelToggle={() => console.log('toggle')}
|
|
177
177
|
onAddItemToMarketplace={() => console.log('add')}
|
|
@@ -179,6 +179,7 @@ const Template: Story = () => {
|
|
|
179
179
|
onMoneyWithdraw={() => console.log('withdraw')}
|
|
180
180
|
dcBalance={50}
|
|
181
181
|
dcToGoldSwapRate={5500}
|
|
182
|
+
commissionPercent={0.05}
|
|
182
183
|
totalItems={100}
|
|
183
184
|
currentPage={page}
|
|
184
185
|
itemsPerPage={30}
|