@rpg-engine/long-bow 0.8.149 → 0.8.151

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpg-engine/long-bow",
3
- "version": "0.8.149",
3
+ "version": "0.8.151",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -84,7 +84,7 @@
84
84
  "dependencies": {
85
85
  "@capacitor/core": "^6.1.0",
86
86
  "@rollup/plugin-image": "^2.1.1",
87
- "@rpg-engine/shared": "^0.10.90",
87
+ "@rpg-engine/shared": "^0.10.91",
88
88
  "dayjs": "^1.11.2",
89
89
  "font-awesome": "^4.7.0",
90
90
  "fs-extra": "^10.1.0",
@@ -117,11 +117,11 @@ export const BuyOrderDetailsModal: React.FC<IBuyOrderDetailsModalProps> = ({
117
117
  </FieldRow>
118
118
 
119
119
  <FieldRow>
120
- <Label>Max Gold</Label>
120
+ <Label>Gold Offer</Label>
121
121
  <StyledInput
122
122
  value={maxPrice || ''}
123
123
  onChange={(e) => onMaxPriceChange(Number(e.target.value))}
124
- placeholder="Max gold"
124
+ placeholder="Gold offer"
125
125
  type="number"
126
126
  min={1}
127
127
  onFocus={disableHotkeys}
@@ -91,7 +91,7 @@ export const BuyPanel: React.FC<IBuyPanelProps> = ({
91
91
  openBuyOrdersTotal = 0,
92
92
  openBuyOrdersPage = 1,
93
93
  onOpenBuyOrdersPageChange,
94
- isLoading = false,
94
+
95
95
  }) => {
96
96
  const [name, setName] = useState('');
97
97
  const [showFilters, setShowFilters] = useState(false);
@@ -371,82 +371,83 @@ export const BuyPanel: React.FC<IBuyPanelProps> = ({
371
371
  )}
372
372
 
373
373
  <ItemComponentScrollWrapper id="MarketContainer" ref={itemsContainer}>
374
- {isLoading && !hasVisibleContent && (
374
+ {!hasVisibleContent ? (
375
375
  <LoadingState>
376
376
  <Spinner />
377
377
  <LoadingText>Loading marketplace...</LoadingText>
378
378
  </LoadingState>
379
- )}
380
- {!isLoading && !hasVisibleContent && <EmptyState>No offers match the current filters.</EmptyState>}
381
-
382
- {showSellSection && (
383
- <MarketSection>
384
- <SectionHeader>
385
- <SectionTitle>Sell Offers</SectionTitle>
386
- <SectionMeta>{groupedItems.length} groups</SectionMeta>
387
- </SectionHeader>
388
- {groupedItems.length === 0 ? (
389
- <SectionEmpty>No sell offers found.</SectionEmpty>
390
- ) : (
391
- groupedItems.map(({ bestListing, otherListings }) => (
392
- <GroupedMarketplaceRow
393
- key={bestListing.item.key}
394
- bestListing={bestListing}
395
- otherListings={otherListings}
396
- atlasIMG={atlasIMG}
397
- atlasJSON={atlasJSON}
398
- equipmentSet={equipmentSet}
399
- dcToGoldSwapRate={dcToGoldSwapRate}
400
- getDCEquivalentPrice={getDCEquivalentPrice}
401
- characterId={characterId}
402
- onBuy={setBuyingItemId}
403
- />
404
- ))
405
- )}
406
- {totalItems > itemsPerPage && (
407
- <SectionPager>
408
- <Pager
409
- totalItems={totalItems}
410
- currentPage={currentPage}
411
- itemsPerPage={itemsPerPage}
412
- onPageChange={onPageChange}
413
- />
414
- </SectionPager>
379
+ ) : (
380
+ <>
381
+ {showSellSection && (
382
+ <MarketSection>
383
+ <SectionHeader>
384
+ <SectionTitle>Sell Offers</SectionTitle>
385
+ <SectionMeta>{groupedItems.length} groups</SectionMeta>
386
+ </SectionHeader>
387
+ {groupedItems.length === 0 ? (
388
+ <SectionEmpty>No sell offers found.</SectionEmpty>
389
+ ) : (
390
+ groupedItems.map(({ bestListing, otherListings }) => (
391
+ <GroupedMarketplaceRow
392
+ key={bestListing.item.key}
393
+ bestListing={bestListing}
394
+ otherListings={otherListings}
395
+ atlasIMG={atlasIMG}
396
+ atlasJSON={atlasJSON}
397
+ equipmentSet={equipmentSet}
398
+ dcToGoldSwapRate={dcToGoldSwapRate}
399
+ getDCEquivalentPrice={getDCEquivalentPrice}
400
+ characterId={characterId}
401
+ onBuy={setBuyingItemId}
402
+ />
403
+ ))
404
+ )}
405
+ {totalItems > itemsPerPage && (
406
+ <SectionPager>
407
+ <Pager
408
+ totalItems={totalItems}
409
+ currentPage={currentPage}
410
+ itemsPerPage={itemsPerPage}
411
+ onPageChange={onPageChange}
412
+ />
413
+ </SectionPager>
414
+ )}
415
+ </MarketSection>
415
416
  )}
416
- </MarketSection>
417
- )}
418
417
 
419
- {showBuySection && (
420
- <MarketSection>
421
- <SectionHeader>
422
- <SectionTitle>Buy Requests</SectionTitle>
423
- <SectionMeta>{visibleBuyOrders.length} visible</SectionMeta>
424
- </SectionHeader>
425
- {visibleBuyOrders.length === 0 ? (
426
- <SectionEmpty>No public buy requests found.</SectionEmpty>
427
- ) : (
428
- visibleBuyOrders.map(order => (
429
- <BuyOrderRow
430
- key={order._id}
431
- buyOrder={order}
432
- atlasJSON={atlasJSON}
433
- atlasIMG={atlasIMG}
434
- onFulfill={setFulfillingBuyOrderId}
435
- showRequestTag
436
- />
437
- ))
438
- )}
439
- {openBuyOrdersTotal > BUY_REQUESTS_PER_PAGE && (
440
- <SectionPager>
441
- <Pager
442
- totalItems={openBuyOrdersTotal}
443
- currentPage={openBuyOrdersPage}
444
- itemsPerPage={BUY_REQUESTS_PER_PAGE}
445
- onPageChange={onOpenBuyOrdersPageChange ?? (() => {})}
446
- />
447
- </SectionPager>
418
+ {showBuySection && (
419
+ <MarketSection>
420
+ <SectionHeader>
421
+ <SectionTitle>Buy Requests</SectionTitle>
422
+ <SectionMeta>{visibleBuyOrders.length} visible</SectionMeta>
423
+ </SectionHeader>
424
+ {visibleBuyOrders.length === 0 ? (
425
+ <SectionEmpty>No public buy requests found.</SectionEmpty>
426
+ ) : (
427
+ visibleBuyOrders.map(order => (
428
+ <BuyOrderRow
429
+ key={order._id}
430
+ buyOrder={order}
431
+ atlasJSON={atlasJSON}
432
+ atlasIMG={atlasIMG}
433
+ onFulfill={setFulfillingBuyOrderId}
434
+ showRequestTag
435
+ />
436
+ ))
437
+ )}
438
+ {openBuyOrdersTotal > BUY_REQUESTS_PER_PAGE && (
439
+ <SectionPager>
440
+ <Pager
441
+ totalItems={openBuyOrdersTotal}
442
+ currentPage={openBuyOrdersPage}
443
+ itemsPerPage={BUY_REQUESTS_PER_PAGE}
444
+ onPageChange={onOpenBuyOrdersPageChange ?? (() => {})}
445
+ />
446
+ </SectionPager>
447
+ )}
448
+ </MarketSection>
448
449
  )}
449
- </MarketSection>
450
+ </>
450
451
  )}
451
452
  </ItemComponentScrollWrapper>
452
453
  </>
@@ -630,18 +631,6 @@ const SectionEmpty = styled.div`
630
631
  border-radius: 6px;
631
632
  `;
632
633
 
633
- const EmptyState = styled.div`
634
- min-height: 96px;
635
- display: flex;
636
- align-items: center;
637
- justify-content: center;
638
- color: #71717a;
639
- font-size: 0.52rem;
640
- text-transform: uppercase;
641
- letter-spacing: 1px;
642
- padding: 0 16px;
643
- text-align: center;
644
- `;
645
634
 
646
635
  const SectionPager = styled.div`
647
636
  display: flex;
@@ -0,0 +1,129 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+ // @ts-nocheck
5
+ import { MarketplaceBuyOrderStatus } from '@rpg-engine/shared';
6
+ import React from 'react';
7
+ import ReactDOM from 'react-dom';
8
+ import { act } from 'react-dom/test-utils';
9
+ import { BuyPanel } from '../BuyPanel';
10
+
11
+ jest.mock('../../ConfirmModal', () => ({
12
+ ConfirmModal: ({ message, onConfirm, onClose }) => (
13
+ <div data-testid="confirm-modal">
14
+ <div>{message}</div>
15
+ <button onClick={onConfirm}>Confirm fulfill</button>
16
+ <button onClick={onClose}>Cancel fulfill</button>
17
+ </div>
18
+ ),
19
+ }));
20
+
21
+ jest.mock('../../shared/CTAButton/CTAButton', () => ({
22
+ CTAButton: ({ label, onClick }) => <button onClick={onClick}>{label}</button>,
23
+ }));
24
+
25
+ describe('BuyPanel fulfill flow', () => {
26
+ let container;
27
+
28
+ const openBuyOrder = {
29
+ _id: 'buy-order-123',
30
+ owner: 'buyer-id',
31
+ itemBlueprintKey: 'short-sword',
32
+ maxPrice: 1000,
33
+ status: MarketplaceBuyOrderStatus.Active,
34
+ createdAt: new Date().toISOString(),
35
+ expiresAt: new Date(Date.now() + 60_000).toISOString(),
36
+ };
37
+
38
+ const renderBuyPanel = (onFulfillBuyOrder = jest.fn()) => {
39
+ act(() => {
40
+ ReactDOM.render(
41
+ <BuyPanel
42
+ items={[]}
43
+ atlasIMG=""
44
+ atlasJSON={{}}
45
+ onClose={jest.fn()}
46
+ onChangeType={jest.fn()}
47
+ onChangeRarity={jest.fn()}
48
+ onChangeOrder={jest.fn()}
49
+ onChangeNameInput={jest.fn()}
50
+ onChangeMainLevelInput={jest.fn()}
51
+ onChangeSecondaryLevelInput={jest.fn()}
52
+ onChangePriceInput={jest.fn()}
53
+ characterId="seller-id"
54
+ totalItems={0}
55
+ currentPage={1}
56
+ itemsPerPage={10}
57
+ onPageChange={jest.fn()}
58
+ openBuyOrders={[openBuyOrder]}
59
+ openBuyOrdersTotal={1}
60
+ openBuyOrdersPage={1}
61
+ onOpenBuyOrdersPageChange={jest.fn()}
62
+ onFulfillBuyOrder={onFulfillBuyOrder}
63
+ />,
64
+ container
65
+ );
66
+ });
67
+
68
+ return onFulfillBuyOrder;
69
+ };
70
+
71
+ beforeEach(() => {
72
+ container = document.createElement('div');
73
+ document.body.appendChild(container);
74
+ HTMLElement.prototype.scrollTo = jest.fn();
75
+ });
76
+
77
+ afterEach(() => {
78
+ ReactDOM.unmountComponentAtNode(container);
79
+ container.remove();
80
+ jest.clearAllMocks();
81
+ });
82
+
83
+ it('waits for confirmation before calling onFulfillBuyOrder', () => {
84
+ const onFulfillBuyOrder = renderBuyPanel();
85
+
86
+ const fulfillButton = Array.from(container.querySelectorAll('button')).find(
87
+ (button) => button.textContent === 'Fulfill'
88
+ );
89
+
90
+ act(() => {
91
+ fulfillButton.dispatchEvent(new MouseEvent('click', { bubbles: true }));
92
+ });
93
+
94
+ expect(onFulfillBuyOrder).not.toHaveBeenCalled();
95
+ expect(container.textContent).toContain('Try to fulfill this buy request with a matching item from your inventory or depot?');
96
+
97
+ const confirmButton = Array.from(container.querySelectorAll('button')).find(
98
+ (button) => button.textContent === 'Confirm fulfill'
99
+ );
100
+
101
+ act(() => {
102
+ confirmButton.dispatchEvent(new MouseEvent('click', { bubbles: true }));
103
+ });
104
+
105
+ expect(onFulfillBuyOrder).toHaveBeenCalledWith('buy-order-123');
106
+ });
107
+
108
+ it('does not call onFulfillBuyOrder when the confirm modal is cancelled', () => {
109
+ const onFulfillBuyOrder = renderBuyPanel();
110
+
111
+ const fulfillButton = Array.from(container.querySelectorAll('button')).find(
112
+ (button) => button.textContent === 'Fulfill'
113
+ );
114
+
115
+ act(() => {
116
+ fulfillButton.dispatchEvent(new MouseEvent('click', { bubbles: true }));
117
+ });
118
+
119
+ const cancelButton = Array.from(container.querySelectorAll('button')).find(
120
+ (button) => button.textContent === 'Cancel fulfill'
121
+ );
122
+
123
+ act(() => {
124
+ cancelButton.dispatchEvent(new MouseEvent('click', { bubbles: true }));
125
+ });
126
+
127
+ expect(onFulfillBuyOrder).not.toHaveBeenCalled();
128
+ });
129
+ });