@0xsequence/marketplace-sdk 0.8.3 → 0.8.5

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.
Files changed (97) hide show
  1. package/CHANGELOG.md +16 -1
  2. package/dist/{chunk-25CAMYCG.js → chunk-BB2PTJHI.js} +22 -20
  3. package/dist/chunk-BB2PTJHI.js.map +1 -0
  4. package/dist/{chunk-5ATGT5S4.js → chunk-EZFCQZHU.js} +14 -6
  5. package/dist/chunk-EZFCQZHU.js.map +1 -0
  6. package/dist/{chunk-DFI52A2E.js → chunk-KCLMSSPS.js} +364 -242
  7. package/dist/chunk-KCLMSSPS.js.map +1 -0
  8. package/dist/{chunk-XUNDLCEH.js → chunk-LDZZUYG7.js} +2 -2
  9. package/dist/{chunk-QTV77W42.js → chunk-SFSFIGHM.js} +45 -35
  10. package/dist/chunk-SFSFIGHM.js.map +1 -0
  11. package/dist/{chunk-FSJKN4YN.js → chunk-ZSCZLHKX.js} +194 -2
  12. package/dist/chunk-ZSCZLHKX.js.map +1 -0
  13. package/dist/{chunk-FH4TZRDV.js → chunk-ZVTG6US2.js} +2 -2
  14. package/dist/index.css +4 -4
  15. package/dist/index.css.map +1 -1
  16. package/dist/index.js +1 -1
  17. package/dist/{lowestListing-DUZ_nYml.d.ts → lowestListing-W7P4EkC3.d.ts} +34 -11
  18. package/dist/react/_internal/databeat/index.js +5 -5
  19. package/dist/react/_internal/index.d.ts +1 -1
  20. package/dist/react/_internal/index.js +3 -1
  21. package/dist/react/_internal/wagmi/index.d.ts +3 -2
  22. package/dist/react/_internal/wagmi/index.js +3 -1
  23. package/dist/react/hooks/index.d.ts +8 -5
  24. package/dist/react/hooks/index.js +6 -4
  25. package/dist/react/hooks/options/index.js +2 -2
  26. package/dist/react/index.d.ts +2 -2
  27. package/dist/react/index.js +9 -7
  28. package/dist/react/queries/index.d.ts +1 -1
  29. package/dist/react/queries/index.js +6 -2
  30. package/dist/react/ssr/index.js +1 -1
  31. package/dist/react/ui/components/collectible-card/index.d.ts +3 -2
  32. package/dist/react/ui/components/collectible-card/index.js +7 -7
  33. package/dist/react/ui/icons/index.js +1 -1
  34. package/dist/react/ui/index.js +7 -7
  35. package/dist/react/ui/modals/_internal/components/actionModal/index.js +5 -5
  36. package/dist/types/index.js +1 -1
  37. package/dist/utils/index.js +1 -1
  38. package/package.json +19 -19
  39. package/src/react/_internal/api/__mocks__/marketplace.msw.ts +35 -21
  40. package/src/react/_internal/wagmi/__tests__/create-config.test.ts +1 -11
  41. package/src/react/_internal/wagmi/get-connectors.ts +27 -24
  42. package/src/react/hooks/__tests__/useCancelTransactionSteps.test.tsx +4 -9
  43. package/src/react/hooks/__tests__/useGenerateCancelTransaction.test.tsx +5 -4
  44. package/src/react/hooks/__tests__/useGenerateListingTransaction.test.tsx +14 -10
  45. package/src/react/hooks/__tests__/useGenerateOfferTransaction.test.tsx +115 -65
  46. package/src/react/hooks/__tests__/useGenerateSellTransaction.test.tsx +10 -7
  47. package/src/react/hooks/__tests__/useInventory.test.tsx +294 -0
  48. package/src/react/hooks/index.ts +1 -0
  49. package/src/react/hooks/useAutoSelectFeeOption.tsx +10 -3
  50. package/src/react/hooks/useCancelOrder.tsx +1 -0
  51. package/src/react/hooks/useCancelTransactionSteps.tsx +18 -4
  52. package/src/react/hooks/useGenerateOfferTransaction.tsx +11 -1
  53. package/src/react/hooks/useInventory.tsx +15 -0
  54. package/src/react/hooks/util/optimisticCancelUpdates.ts +115 -0
  55. package/src/react/queries/index.ts +1 -0
  56. package/src/react/queries/inventory.ts +303 -0
  57. package/src/react/queries/listBalances.ts +1 -8
  58. package/src/react/queries/listCollectibles.ts +12 -3
  59. package/src/react/ui/components/_internals/action-button/__tests__/ActionButtonBody.test.tsx +27 -94
  60. package/src/react/ui/components/_internals/action-button/__tests__/NonOwnerActions.test.tsx +59 -0
  61. package/src/react/ui/components/_internals/action-button/__tests__/OwnerActions.test.tsx +73 -0
  62. package/src/react/ui/components/_internals/action-button/__tests__/useActionButtonLogic.test.tsx +77 -0
  63. package/src/react/ui/components/_internals/action-button/components/ActionButtonBody.tsx +3 -2
  64. package/src/react/ui/components/_internals/action-button/hooks/useActionButtonLogic.ts +4 -3
  65. package/src/react/ui/components/collectible-card/CollectibleAsset.tsx +1 -0
  66. package/src/react/ui/components/collectible-card/CollectibleCard.tsx +18 -12
  67. package/src/react/ui/components/collectible-card/__tests__/CollectibleAsset.test.tsx +200 -0
  68. package/src/react/ui/components/collectible-card/__tests__/CollectibleCard.test.tsx +92 -123
  69. package/src/react/ui/components/collectible-card/__tests__/Footer.test.tsx +136 -0
  70. package/src/react/ui/modals/BuyModal/__tests__/Modal.test.tsx +2 -8
  71. package/src/react/ui/modals/CreateListingModal/__tests__/Modal.test.tsx +74 -104
  72. package/src/react/ui/modals/MakeOfferModal/__tests__/Modal.test.tsx +108 -78
  73. package/src/react/ui/modals/SellModal/__tests__/Modal.test.tsx +72 -135
  74. package/src/react/ui/modals/_internal/components/actionModal/ActionModal.test.tsx +286 -0
  75. package/src/react/ui/modals/_internal/components/actionModal/ActionModal.tsx +16 -4
  76. package/src/react/ui/modals/_internal/components/currencyOptionsSelect/__tests__/index.test.tsx +35 -132
  77. package/src/react/ui/modals/_internal/components/floorPriceText/__tests__/FloorPriceText.test.tsx +199 -0
  78. package/src/react/ui/modals/_internal/components/priceInput/__tests__/PriceInput.test.tsx +55 -0
  79. package/src/react/ui/modals/_internal/components/priceInput/index.tsx +1 -1
  80. package/src/react/ui/modals/_internal/components/selectWaasFeeOptions/__tests__/ActionButtons.test.tsx +72 -0
  81. package/src/react/ui/modals/_internal/components/selectWaasFeeOptions/__tests__/BalanceIndicator.test.tsx +50 -0
  82. package/src/react/ui/modals/_internal/components/selectWaasFeeOptions/__tests__/SelectWaasFeeOptions.test.tsx +193 -0
  83. package/src/react/ui/modals/_internal/components/switchChainModal/index.tsx +2 -2
  84. package/test/const.ts +24 -0
  85. package/test/test-utils.tsx +85 -47
  86. package/.changeset/flat-parks-clean.md +0 -8
  87. package/.changeset/red-buckets-deny.md +0 -6
  88. package/.changeset/seven-doors-taste.md +0 -5
  89. package/dist/chunk-25CAMYCG.js.map +0 -1
  90. package/dist/chunk-5ATGT5S4.js.map +0 -1
  91. package/dist/chunk-DFI52A2E.js.map +0 -1
  92. package/dist/chunk-FSJKN4YN.js.map +0 -1
  93. package/dist/chunk-QTV77W42.js.map +0 -1
  94. package/src/react/ui/components/_internals/action-button/__tests__/ActionButton.test.tsx +0 -107
  95. package/src/react/ui/modals/_internal/components/priceInput/__tests__/index.test.tsx +0 -164
  96. /package/dist/{chunk-XUNDLCEH.js.map → chunk-LDZZUYG7.js.map} +0 -0
  97. /package/dist/{chunk-FH4TZRDV.js.map → chunk-ZVTG6US2.js.map} +0 -0
@@ -1,107 +0,0 @@
1
- import { fireEvent, render, screen } from '@test';
2
- import type { Hex } from 'viem';
3
- import { describe, expect, it, vi } from 'vitest';
4
- import * as wagmi from 'wagmi';
5
- import {
6
- MarketplaceKind,
7
- OrderSide,
8
- OrderStatus,
9
- } from '../../../../../_internal/api/marketplace.gen';
10
- import { ActionButton } from '../ActionButton';
11
- import { CollectibleCardAction } from '../types';
12
-
13
- describe.skip('ActionButton', () => {
14
- const defaultProps = {
15
- chainId: 1,
16
- collectionAddress: '0x123' as Hex,
17
- tokenId: '1',
18
- action: CollectibleCardAction.BUY,
19
- onCannotPerformAction: vi.fn(),
20
- lowestListing: {
21
- orderId: '1',
22
- marketplace: MarketplaceKind.sequence_marketplace_v2,
23
- side: OrderSide.listing,
24
- status: OrderStatus.active,
25
- chainId: 1,
26
- originName: 'test',
27
- collectionContractAddress: '0x123',
28
- tokenId: '1',
29
- createdBy: '0x456',
30
- priceAmount: '1000000000000000000',
31
- priceAmountFormatted: '1',
32
- priceAmountNet: '1000000000000000000',
33
- priceAmountNetFormatted: '1',
34
- priceCurrencyAddress:
35
- '0x0000000000000000000000000000000000000000' as `0x${string}`,
36
- priceDecimals: 18,
37
- priceUSD: 1,
38
- priceUSDFormatted: '1',
39
- quantityInitial: '1',
40
- quantityInitialFormatted: '1',
41
- quantityRemaining: '1',
42
- quantityRemainingFormatted: '1',
43
- quantityAvailable: '1',
44
- quantityAvailableFormatted: '1',
45
- quantityDecimals: 0,
46
- feeBps: 250,
47
- feeBreakdown: [],
48
- validFrom: new Date().toISOString(),
49
- validUntil: new Date(Date.now() + 86400000).toISOString(),
50
- blockNumber: 1,
51
- createdAt: new Date().toISOString(),
52
- updatedAt: new Date().toISOString(),
53
- },
54
- };
55
-
56
- it('renders buy action for non-owners', () => {
57
- // @ts-expect-error
58
- vi.mocked(wagmi.useAccount).mockReturnValue({ address: undefined });
59
- render(<ActionButton {...defaultProps} />);
60
- expect(screen.getByText('Buy now')).toBeInTheDocument();
61
- });
62
-
63
- it('renders list action for owners', () => {
64
- // @ts-expect-error
65
- vi.mocked(wagmi.useAccount).mockReturnValue({ address: '0x456' });
66
- render(
67
- <ActionButton {...defaultProps} action={CollectibleCardAction.LIST} />,
68
- );
69
- expect(screen.getByText('Create listing')).toBeInTheDocument();
70
- });
71
-
72
- it('calls onClick when clicked and user is connected', () => {
73
- // @ts-expect-error
74
- vi.mocked(wagmi.useAccount).mockReturnValue({ address: '0x456' });
75
- const onCannotPerformAction = vi.fn();
76
- render(
77
- <ActionButton
78
- {...defaultProps}
79
- onCannotPerformAction={onCannotPerformAction}
80
- />,
81
- );
82
- fireEvent.click(screen.getByRole('button'));
83
- expect(onCannotPerformAction).not.toHaveBeenCalled();
84
- });
85
-
86
- it('calls onCannotPerformAction when user is not connected', () => {
87
- // @ts-expect-error
88
- vi.mocked(wagmi.useAccount).mockReturnValue({ address: undefined });
89
- const onCannotPerformAction = vi.fn();
90
- render(
91
- <ActionButton
92
- {...defaultProps}
93
- onCannotPerformAction={onCannotPerformAction}
94
- />,
95
- );
96
- fireEvent.click(screen.getByRole('button'));
97
- expect(onCannotPerformAction).toHaveBeenCalledWith(
98
- CollectibleCardAction.BUY,
99
- );
100
- });
101
-
102
- it('shows loading state when loading', () => {
103
- render(<ActionButton {...defaultProps} />);
104
- const button = screen.getByRole('button');
105
- expect(button).toHaveAttribute('data-loading', 'false');
106
- });
107
- });
@@ -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
- });