@0xsequence/marketplace-sdk 0.8.3 → 0.8.4
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/CHANGELOG.md +8 -1
- package/dist/{chunk-FH4TZRDV.js → chunk-44YGZVBS.js} +2 -2
- package/dist/{chunk-QTV77W42.js → chunk-HRL2TMXU.js} +5 -5
- package/dist/chunk-HRL2TMXU.js.map +1 -0
- package/dist/{chunk-5ATGT5S4.js → chunk-VBRJ2OPM.js} +14 -6
- package/dist/chunk-VBRJ2OPM.js.map +1 -0
- package/dist/{chunk-DFI52A2E.js → chunk-VF3LWBQB.js} +365 -243
- package/dist/chunk-VF3LWBQB.js.map +1 -0
- package/dist/{chunk-FSJKN4YN.js → chunk-ZSCZLHKX.js} +194 -2
- package/dist/chunk-ZSCZLHKX.js.map +1 -0
- package/dist/index.js +5 -5
- package/dist/{lowestListing-DUZ_nYml.d.ts → lowestListing-W7P4EkC3.d.ts} +34 -11
- package/dist/react/_internal/databeat/index.js +4 -4
- package/dist/react/hooks/index.d.ts +8 -5
- package/dist/react/hooks/index.js +5 -3
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.js +8 -6
- package/dist/react/queries/index.d.ts +1 -1
- package/dist/react/queries/index.js +5 -1
- package/dist/react/ui/components/collectible-card/index.js +6 -6
- package/dist/react/ui/icons/index.js +1 -1
- package/dist/react/ui/index.js +6 -6
- package/dist/react/ui/modals/_internal/components/actionModal/index.js +4 -4
- package/dist/utils/abi/index.js +5 -5
- package/dist/utils/index.js +5 -5
- package/package.json +1 -1
- package/src/react/_internal/api/__mocks__/marketplace.msw.ts +35 -21
- package/src/react/hooks/__tests__/useCancelTransactionSteps.test.tsx +4 -9
- package/src/react/hooks/__tests__/useGenerateCancelTransaction.test.tsx +5 -4
- package/src/react/hooks/__tests__/useGenerateListingTransaction.test.tsx +14 -10
- package/src/react/hooks/__tests__/useGenerateOfferTransaction.test.tsx +115 -65
- package/src/react/hooks/__tests__/useGenerateSellTransaction.test.tsx +10 -7
- package/src/react/hooks/__tests__/useInventory.test.tsx +294 -0
- package/src/react/hooks/index.ts +1 -0
- package/src/react/hooks/useAutoSelectFeeOption.tsx +10 -3
- package/src/react/hooks/useCancelOrder.tsx +1 -0
- package/src/react/hooks/useCancelTransactionSteps.tsx +18 -4
- package/src/react/hooks/useGenerateOfferTransaction.tsx +11 -1
- package/src/react/hooks/useInventory.tsx +15 -0
- package/src/react/hooks/util/optimisticCancelUpdates.ts +115 -0
- package/src/react/queries/index.ts +1 -0
- package/src/react/queries/inventory.ts +303 -0
- package/src/react/queries/listBalances.ts +1 -8
- package/src/react/queries/listCollectibles.ts +12 -3
- package/src/react/ui/modals/CreateListingModal/__tests__/Modal.test.tsx +74 -104
- package/src/react/ui/modals/MakeOfferModal/__tests__/Modal.test.tsx +108 -78
- package/src/react/ui/modals/_internal/components/actionModal/ActionModal.test.tsx +286 -0
- package/src/react/ui/modals/_internal/components/actionModal/ActionModal.tsx +16 -4
- package/src/react/ui/modals/_internal/components/currencyOptionsSelect/__tests__/index.test.tsx +35 -132
- package/src/react/ui/modals/_internal/components/floorPriceText/__tests__/FloorPriceText.test.tsx +199 -0
- package/src/react/ui/modals/_internal/components/priceInput/__tests__/PriceInput.test.tsx +55 -0
- package/src/react/ui/modals/_internal/components/priceInput/index.tsx +1 -1
- package/src/react/ui/modals/_internal/components/switchChainModal/index.tsx +2 -2
- package/test/const.ts +24 -0
- package/test/test-utils.tsx +74 -26
- package/.changeset/flat-parks-clean.md +0 -8
- package/.changeset/red-buckets-deny.md +0 -6
- package/.changeset/seven-doors-taste.md +0 -5
- package/dist/chunk-5ATGT5S4.js.map +0 -1
- package/dist/chunk-DFI52A2E.js.map +0 -1
- package/dist/chunk-FSJKN4YN.js.map +0 -1
- package/dist/chunk-QTV77W42.js.map +0 -1
- package/src/react/ui/modals/_internal/components/priceInput/__tests__/index.test.tsx +0 -164
- /package/dist/{chunk-FH4TZRDV.js.map → chunk-44YGZVBS.js.map} +0 -0
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import { observable } from '@legendapp/state';
|
|
2
|
-
import { act, cleanup, fireEvent, render, screen, waitFor } from '@test';
|
|
3
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
4
|
-
import PriceInput from '..';
|
|
5
|
-
import type { Currency, Price } from '../../../../../../../types';
|
|
6
|
-
import { CurrencyStatus } from '../../../../../../_internal';
|
|
7
|
-
|
|
8
|
-
vi.mock('../hooks/usePriceInput', () => ({
|
|
9
|
-
usePriceInput: vi.fn(({ onPriceChange }) => ({
|
|
10
|
-
value: '0',
|
|
11
|
-
handlePriceChange: (value: string) => {
|
|
12
|
-
try {
|
|
13
|
-
if (value === '0' || !value || Number.isNaN(Number(value))) {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
onPriceChange?.(value);
|
|
17
|
-
} catch {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
})),
|
|
22
|
-
}));
|
|
23
|
-
|
|
24
|
-
// Mock useCurrencyBalance hook
|
|
25
|
-
vi.mock('../../../../../hooks/useCurrencyBalance', () => ({
|
|
26
|
-
useCurrencyBalance: vi.fn(() => ({
|
|
27
|
-
data: { value: 100n },
|
|
28
|
-
isSuccess: true,
|
|
29
|
-
})),
|
|
30
|
-
}));
|
|
31
|
-
|
|
32
|
-
// TODO: Remove local mocks
|
|
33
|
-
// Mock currency data
|
|
34
|
-
const MOCK_CURRENCY: Currency = {
|
|
35
|
-
symbol: 'USDC',
|
|
36
|
-
contractAddress: '0x1234' as `0x${string}`,
|
|
37
|
-
chainId: 1,
|
|
38
|
-
name: 'USD Coin',
|
|
39
|
-
decimals: 6,
|
|
40
|
-
imageUrl: 'https://example.com/usdc.png',
|
|
41
|
-
status: CurrencyStatus.active,
|
|
42
|
-
exchangeRate: 1,
|
|
43
|
-
defaultChainCurrency: false,
|
|
44
|
-
nativeCurrency: false,
|
|
45
|
-
createdAt: new Date().toISOString(),
|
|
46
|
-
updatedAt: new Date().toISOString(),
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
// Mock currency with different decimals
|
|
50
|
-
const MOCK_CURRENCY_HIGH_DECIMALS: Currency = {
|
|
51
|
-
...MOCK_CURRENCY,
|
|
52
|
-
symbol: 'aPOL',
|
|
53
|
-
contractAddress: '0x5678' as `0x${string}`,
|
|
54
|
-
name: 'aPOL Token',
|
|
55
|
-
decimals: 18,
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
// Mock price data
|
|
59
|
-
const createMockPrice = (amount = '0'): Price => ({
|
|
60
|
-
amountRaw: amount,
|
|
61
|
-
currency: MOCK_CURRENCY,
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
describe('PriceInput', () => {
|
|
65
|
-
const defaultProps = {
|
|
66
|
-
collectionAddress: '0xCollection' as `0x${string}`,
|
|
67
|
-
chainId: 1,
|
|
68
|
-
$price: observable<Price | undefined>(createMockPrice()),
|
|
69
|
-
includeNativeCurrency: false,
|
|
70
|
-
secondCurrencyAsDefault: false,
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
beforeEach(() => {
|
|
74
|
-
cleanup();
|
|
75
|
-
vi.clearAllMocks();
|
|
76
|
-
});
|
|
77
|
-
afterEach(() => {
|
|
78
|
-
cleanup();
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('should render price input', () => {
|
|
82
|
-
render(<PriceInput {...defaultProps} />);
|
|
83
|
-
expect(screen.getByRole('textbox', { name: /price/i })).toBeInTheDocument();
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('should handle price changes', () => {
|
|
87
|
-
const onPriceChange = vi.fn();
|
|
88
|
-
const { getByRole } = render(
|
|
89
|
-
<PriceInput {...defaultProps} onPriceChange={onPriceChange} />,
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
const input = getByRole('textbox', { name: /price/i });
|
|
93
|
-
fireEvent.change(input, { target: { value: '100' } });
|
|
94
|
-
|
|
95
|
-
expect(onPriceChange).toHaveBeenCalled();
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('should trigger callback when balance is insufficient', () => {
|
|
99
|
-
const checkBalance = {
|
|
100
|
-
enabled: true,
|
|
101
|
-
callback: vi.fn(),
|
|
102
|
-
};
|
|
103
|
-
const price$ = observable<Price | undefined>(createMockPrice());
|
|
104
|
-
render(
|
|
105
|
-
<PriceInput
|
|
106
|
-
{...defaultProps}
|
|
107
|
-
$price={price$}
|
|
108
|
-
checkBalance={checkBalance}
|
|
109
|
-
/>,
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
expect(screen.queryByText('Insufficient balance')).not.toBeInTheDocument();
|
|
113
|
-
|
|
114
|
-
const input = screen.getByRole('textbox', { name: /price/i });
|
|
115
|
-
fireEvent.change(input, { target: { value: '2000' } });
|
|
116
|
-
|
|
117
|
-
expect(checkBalance.callback).toHaveBeenCalledWith(false);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it('should not call onPriceChange when amount is zero', () => {
|
|
121
|
-
const onPriceChange = vi.fn();
|
|
122
|
-
render(<PriceInput {...defaultProps} onPriceChange={onPriceChange} />);
|
|
123
|
-
|
|
124
|
-
const input = screen.getByRole('textbox', { name: /price/i });
|
|
125
|
-
fireEvent.change(input, { target: { value: '0' } });
|
|
126
|
-
|
|
127
|
-
expect(onPriceChange).not.toHaveBeenCalled();
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('should adjust raw amount when currency decimals change', async () => {
|
|
131
|
-
// Create a price observable with initial currency (6 decimals)
|
|
132
|
-
const price$ = observable<Price | undefined>(createMockPrice());
|
|
133
|
-
const onPriceChange = vi.fn();
|
|
134
|
-
|
|
135
|
-
render(
|
|
136
|
-
<PriceInput
|
|
137
|
-
{...defaultProps}
|
|
138
|
-
$price={price$}
|
|
139
|
-
onPriceChange={onPriceChange}
|
|
140
|
-
/>,
|
|
141
|
-
);
|
|
142
|
-
|
|
143
|
-
// Enter a price value
|
|
144
|
-
const input = screen.getByRole('textbox', { name: /price/i });
|
|
145
|
-
|
|
146
|
-
act(() => {
|
|
147
|
-
fireEvent.change(input, { target: { value: '1000' } });
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
// Verify initial raw amount (with 6 decimals)
|
|
151
|
-
expect(price$.get()?.amountRaw).toBe('1000000000');
|
|
152
|
-
|
|
153
|
-
// Change currency to one with 18 decimals
|
|
154
|
-
act(() => {
|
|
155
|
-
price$.currency.set(MOCK_CURRENCY_HIGH_DECIMALS);
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
// Wait for the effect to process
|
|
159
|
-
await waitFor(() => {
|
|
160
|
-
// The raw amount should be adjusted for the new currency's decimals
|
|
161
|
-
expect(price$.get()?.amountRaw).toBe('1000000000000000000000');
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
});
|
|
File without changes
|