@0xsequence/marketplace-sdk 2.0.1 → 2.0.2
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 +10 -0
- package/dist/BellIcon.js +1 -1
- package/dist/Card.js +1 -1
- package/dist/ShopCard.d.ts +4 -4
- package/dist/builder-api.js +1 -1
- package/dist/collectible.js +1 -1
- package/dist/collection.js +1 -1
- package/dist/create-config.d.ts +597 -201
- package/dist/create-config.js +1 -1
- package/dist/currency.js +1 -1
- package/dist/dist.js +167 -148
- package/dist/dist.js.map +1 -1
- package/dist/expirationDateSelect.js +1 -1
- package/dist/filter-state.d.ts +1 -1
- package/dist/filters.d.ts +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/index10.d.ts +3 -3
- package/dist/index11.d.ts +17 -17
- package/dist/index12.d.ts +26 -26
- package/dist/index14.d.ts +3 -3
- package/dist/index15.d.ts +3 -3
- package/dist/index16.d.ts +2 -2
- package/dist/index17.d.ts +86 -86
- package/dist/index18.d.ts +40 -40
- package/dist/index19.d.ts +5 -5
- package/dist/index2.d.ts +4 -1
- package/dist/index21.d.ts +15 -15
- package/dist/index22.d.ts +8 -65
- package/dist/index23.d.ts +21 -13
- package/dist/index26.d.ts +4 -4
- package/dist/index27.d.ts +4 -4
- package/dist/index28.d.ts +10 -10
- package/dist/index3.d.ts +2 -2194
- package/dist/index31.d.ts +5 -5
- package/dist/index33.d.ts +3 -3
- package/dist/index34.d.ts +4 -4
- package/dist/index35.d.ts +1 -1
- package/dist/index36.d.ts +7 -7
- package/dist/index37.d.ts +6 -6
- package/dist/index38.d.ts +8 -8
- package/dist/index39.d.ts +1 -1
- package/dist/index4.d.ts +995 -995
- package/dist/index40.d.ts +2 -2
- package/dist/index8.d.ts +2 -2
- package/dist/index9.d.ts +2811 -3
- package/dist/inventory.d.ts +4 -4
- package/dist/inventory.js +2 -2
- package/dist/marketplace2.js +2 -2
- package/dist/metadata.d.ts +73 -73
- package/dist/primary-sale-checkout-options.d.ts +4 -4
- package/dist/quantityInput.js +1 -1
- package/dist/ranges.d.ts +17 -17
- package/dist/react/_internal/index.d.ts +1 -1
- package/dist/react/_internal/index.js +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/queries/collectible/index.d.ts +1 -1
- package/dist/react/queries/index.d.ts +1 -1
- package/dist/react/ssr/index.d.ts +1 -1
- package/dist/react/ssr/index.js +2 -2
- package/dist/react/ui/components/marketplace-collectible-card/index.d.ts +1 -1
- package/dist/react/ui/components/marketplace-logos/index.d.ts +21 -21
- package/dist/react/ui/modals/CreateListingModal/internal/hooks/index.d.ts +1 -1
- package/dist/react/ui/modals/MakeOfferModal/internal/hooks/index.d.ts +1 -1
- package/dist/react/ui/modals/_internal/components/alertMessage/index.d.ts +2 -2
- package/dist/react/ui/modals/_internal/components/baseModal/index.d.ts +6 -6
- package/dist/react/ui/modals/_internal/components/calendar/index.d.ts +2 -2
- package/dist/react/ui/modals/_internal/components/calendarDropdown/index.d.ts +2 -2
- package/dist/react/ui/modals/_internal/components/currencyImage/index.d.ts +2 -2
- package/dist/react/ui/modals/_internal/components/currencyOptionsSelect/index.d.ts +3 -3
- package/dist/react/ui/modals/_internal/components/floorPriceText/index.d.ts +2 -2
- package/dist/react/ui/modals/_internal/components/priceInput/index.d.ts +3 -3
- package/dist/react/ui/modals/_internal/components/quantityInput/index.d.ts +2 -2
- package/dist/react/ui/modals/_internal/components/selectWaasFeeOptions/index.d.ts +2 -2
- package/dist/react/ui/modals/_internal/components/switchChainErrorModal/index.d.ts +2 -2
- package/dist/react/ui/modals/_internal/components/timeAgo/index.d.ts +2 -2
- package/dist/react/ui/modals/_internal/components/tokenPreview/index.d.ts +3 -3
- package/dist/react/ui/modals/_internal/components/transaction-footer/index.d.ts +3 -3
- package/dist/react/ui/modals/_internal/components/transactionDetails/index.d.ts +3 -3
- package/dist/react/ui/modals/_internal/components/transactionPreview/index.d.ts +3 -3
- package/dist/react/ui/modals/_internal/components/transactionStatusModal/index.d.ts +3 -3
- package/dist/react.js +2192 -1903
- package/dist/react.js.map +1 -1
- package/dist/token-balances.d.ts +28 -28
- package/dist/transaction-footer.js +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.js +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/url-state.js +1 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils.js +20 -4
- package/dist/utils.js.map +1 -1
- package/package.json +7 -5
- package/src/react/hooks/config/useMarketplaceConfig.test.tsx +1 -0
- package/src/react/hooks/transactions/useCancelTransactionSteps.tsx +4 -1
- package/src/react/hooks/utils/useEnsureCorrectChain.ts +10 -5
- package/src/react/ui/modals/BuyModal/components/BuyModalContent.tsx +34 -31
- package/src/react/ui/modals/BuyModal/components/CryptoPaymentModal.tsx +74 -11
- package/src/react/ui/modals/BuyModal/components/Modal.tsx +62 -1
- package/src/react/ui/modals/BuyModal/hooks/useExecuteBundledTransactions.ts +13 -26
- package/src/react/ui/modals/BuyModal/internal/__tests__/buildTrailsMarketBuyActions.test.ts +213 -0
- package/src/react/ui/modals/BuyModal/internal/buildTrailsMarketBuyActions.ts +259 -0
- package/src/react/ui/modals/BuyModal/internal/buyModalContext.ts +79 -10
- package/src/react/ui/modals/BuyModal/internal/cryptoPaymentModalContext.tsx +44 -17
- package/src/react/ui/modals/MakeOfferModal/internal/context.ts +2 -1
- package/src/react/ui/modals/_internal/components/currencyOptionsSelect/index.tsx +2 -1
- package/src/react/ui/modals/_internal/components/priceInput/index.tsx +12 -11
- package/src/react/ui/modals/_internal/helpers/currency.test.ts +27 -0
- package/src/react/ui/modals/_internal/helpers/currency.ts +4 -2
- package/src/utils/__tests__/getMarketplaceDetails.test.ts +10 -0
- package/src/utils/__tests__/getWebRPCErrorMessage.test.ts +28 -0
- package/src/utils/__tests__/marketplaceNormalization.test.ts +38 -0
- package/src/utils/getConduitAddressForOrderbook.ts +2 -10
- package/src/utils/getMarketplaceDetails.ts +11 -4
- package/src/utils/getWebRPCErrorMessage.ts +21 -0
- package/src/utils/normalizeMarketplace.ts +31 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { zeroAddress } from 'viem';
|
|
2
2
|
import { OrderbookKind } from '../../../../../types';
|
|
3
3
|
import { compareAddress } from '../../../../../utils';
|
|
4
|
+
import { isOpenSeaOrderbook, normalizeOrderbookKind } from '../../../../../utils/normalizeMarketplace';
|
|
4
5
|
import type { Currency } from '../../../../_internal';
|
|
5
6
|
import { getOpenseaCurrencyForChain } from '../../_internal/constants/opensea-currencies';
|
|
6
7
|
|
|
@@ -12,7 +13,7 @@ export function filterCurrenciesForOrderbook(
|
|
|
12
13
|
): Currency[] {
|
|
13
14
|
if (!currencies || currencies.length === 0) return [];
|
|
14
15
|
|
|
15
|
-
if (orderbookKind
|
|
16
|
+
if (isOpenSeaOrderbook(orderbookKind)) {
|
|
16
17
|
const openseaCurrency = getOpenseaCurrencyForChain(chainId, side);
|
|
17
18
|
if (openseaCurrency) {
|
|
18
19
|
return currencies.filter((currency) =>
|
|
@@ -35,8 +36,9 @@ export function getDefaultCurrency(
|
|
|
35
36
|
return currencies[0];
|
|
36
37
|
}
|
|
37
38
|
|
|
39
|
+
const normalizedOrderbookKind = normalizeOrderbookKind(orderbookKind);
|
|
38
40
|
const shouldSkipNative =
|
|
39
|
-
|
|
41
|
+
normalizedOrderbookKind !== OrderbookKind.sequence_marketplace_v2 &&
|
|
40
42
|
currencies.length > 1;
|
|
41
43
|
|
|
42
44
|
return shouldSkipNative ? currencies[1] : currencies[0];
|
|
@@ -38,6 +38,16 @@ describe('getMarketplaceDetails', () => {
|
|
|
38
38
|
expect(result?.logo).toBe(OpenSeaLogo);
|
|
39
39
|
expect(result?.displayName).toBe('OpenSea');
|
|
40
40
|
});
|
|
41
|
+
|
|
42
|
+
test('should map Magic Eden kind to OpenSea', () => {
|
|
43
|
+
const result = getMarketplaceDetails({
|
|
44
|
+
originName: 'Magic Eden',
|
|
45
|
+
kind: MarketplaceKind.magic_eden,
|
|
46
|
+
});
|
|
47
|
+
expect(result).toBeDefined();
|
|
48
|
+
expect(result?.logo).toBe(OpenSeaLogo);
|
|
49
|
+
expect(result?.displayName).toBe('OpenSea');
|
|
50
|
+
});
|
|
41
51
|
});
|
|
42
52
|
|
|
43
53
|
describe('detection by marketplace name', () => {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { WebrpcError } from '@0xsequence/api-client';
|
|
2
|
+
import { describe, expect, test } from 'vitest';
|
|
3
|
+
import { getWebRPCErrorMessage } from '../getWebRPCErrorMessage';
|
|
4
|
+
|
|
5
|
+
describe('getWebRPCErrorMessage', () => {
|
|
6
|
+
test('maps OutOfFund endpoint errors to an insufficient balance message', () => {
|
|
7
|
+
const message = getWebRPCErrorMessage({
|
|
8
|
+
code: 0,
|
|
9
|
+
status: 400,
|
|
10
|
+
name: 'WebrpcEndpoint',
|
|
11
|
+
message: 'endpoint error',
|
|
12
|
+
cause: 'evm error: OutOfFund',
|
|
13
|
+
} as WebrpcError);
|
|
14
|
+
|
|
15
|
+
expect(message).toBe('Insufficient balance to complete this transaction.');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test('continues to map known WebRPC error codes', () => {
|
|
19
|
+
const message = getWebRPCErrorMessage({
|
|
20
|
+
code: 3000,
|
|
21
|
+
status: 404,
|
|
22
|
+
name: 'WebrpcNotFound',
|
|
23
|
+
message: 'not found',
|
|
24
|
+
} as WebrpcError);
|
|
25
|
+
|
|
26
|
+
expect(message).toBe('Item not found or no longer available.');
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { MarketplaceKind, OrderbookKind } from '@0xsequence/api-client';
|
|
2
|
+
import * as BuilderMocks from '@0xsequence/api-client/mocks/builder';
|
|
3
|
+
import * as MarketplaceMocks from '@0xsequence/api-client/mocks/marketplace';
|
|
4
|
+
import { describe, expect, it } from 'vitest';
|
|
5
|
+
import { toLookupMarketplaceReturn } from '../../../../api/src/adapters/builder/transforms';
|
|
6
|
+
import { toOrder } from '../../../../api/src/adapters/marketplace/transforms';
|
|
7
|
+
|
|
8
|
+
const { mockConfig } = BuilderMocks;
|
|
9
|
+
const { mockOrder } = MarketplaceMocks;
|
|
10
|
+
|
|
11
|
+
describe('marketplace normalization adapters', () => {
|
|
12
|
+
it('should map Magic Eden destination marketplaces to OpenSea', () => {
|
|
13
|
+
const normalizedConfig = toLookupMarketplaceReturn({
|
|
14
|
+
...mockConfig,
|
|
15
|
+
marketCollections: mockConfig.marketCollections.map((collection, index) =>
|
|
16
|
+
index === 1
|
|
17
|
+
? {
|
|
18
|
+
...collection,
|
|
19
|
+
destinationMarketplace: OrderbookKind.magic_eden,
|
|
20
|
+
}
|
|
21
|
+
: collection,
|
|
22
|
+
),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
expect(
|
|
26
|
+
normalizedConfig.marketplace.market.collections[1]?.destinationMarketplace,
|
|
27
|
+
).toBe(OrderbookKind.opensea);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should map Magic Eden order marketplaces to OpenSea', () => {
|
|
31
|
+
const normalizedOrder = toOrder({
|
|
32
|
+
...mockOrder,
|
|
33
|
+
marketplace: MarketplaceKind.magic_eden,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
expect(normalizedOrder.marketplace).toBe(MarketplaceKind.opensea);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
SEQUENCE_MARKET_V2_ADDRESS,
|
|
5
5
|
} from '../consts';
|
|
6
6
|
import { OrderbookKind } from '../types';
|
|
7
|
+
import { normalizeOrderbookKind } from './normalizeMarketplace';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* OpenSea Conduit address
|
|
@@ -12,25 +13,16 @@ import { OrderbookKind } from '../types';
|
|
|
12
13
|
export const OPENSEA_SEAPORT_CONDUIT_ADDRESS =
|
|
13
14
|
'0x1E0049783F008A0085193E00003D00cd54003c71' as Address;
|
|
14
15
|
|
|
15
|
-
/**
|
|
16
|
-
* Magic Eden Conduit address
|
|
17
|
-
* https://etherscan.io/address/0x2052f8A2Ff46283B30084e5d84c89A2fdBE7f74b
|
|
18
|
-
*/
|
|
19
|
-
export const MAGICEDEN_CONDUIT_ADDRESS =
|
|
20
|
-
'0x2052f8A2Ff46283B30084e5d84c89A2fdBE7f74b' as Address;
|
|
21
|
-
|
|
22
16
|
export function getConduitAddressForOrderbook(
|
|
23
17
|
orderbookKind: OrderbookKind | undefined,
|
|
24
18
|
): Address | undefined {
|
|
25
|
-
switch (orderbookKind) {
|
|
19
|
+
switch (normalizeOrderbookKind(orderbookKind)) {
|
|
26
20
|
case OrderbookKind.sequence_marketplace_v1:
|
|
27
21
|
return SEQUENCE_MARKET_V1_ADDRESS as Address;
|
|
28
22
|
case OrderbookKind.sequence_marketplace_v2:
|
|
29
23
|
return SEQUENCE_MARKET_V2_ADDRESS as Address;
|
|
30
24
|
case OrderbookKind.opensea:
|
|
31
25
|
return OPENSEA_SEAPORT_CONDUIT_ADDRESS;
|
|
32
|
-
case OrderbookKind.magic_eden:
|
|
33
|
-
return MAGICEDEN_CONDUIT_ADDRESS;
|
|
34
26
|
default:
|
|
35
27
|
// Default to v2 for unknown orderbooks
|
|
36
28
|
return SEQUENCE_MARKET_V2_ADDRESS as Address;
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
SequenceLogo,
|
|
12
12
|
X2y2Logo,
|
|
13
13
|
} from '../react/ui/components/marketplace-logos';
|
|
14
|
+
import { normalizeMarketplaceKind } from './normalizeMarketplace';
|
|
14
15
|
|
|
15
16
|
interface Marketplace {
|
|
16
17
|
logo: ComponentType<React.ComponentProps<typeof Image>>;
|
|
@@ -75,13 +76,19 @@ export function getMarketplaceDetails({
|
|
|
75
76
|
originName,
|
|
76
77
|
kind,
|
|
77
78
|
}: MarketplaceDetailsProp) {
|
|
79
|
+
const normalizedKind = normalizeMarketplaceKind(kind);
|
|
80
|
+
|
|
78
81
|
if (
|
|
79
|
-
|
|
80
|
-
|
|
82
|
+
normalizedKind === MarketplaceKind.sequence_marketplace_v1 ||
|
|
83
|
+
normalizedKind === MarketplaceKind.sequence_marketplace_v2
|
|
81
84
|
) {
|
|
82
85
|
return MARKETPLACES.sequence;
|
|
83
86
|
}
|
|
84
87
|
|
|
88
|
+
if (normalizedKind === MarketplaceKind.opensea) {
|
|
89
|
+
return MARKETPLACES.opensea;
|
|
90
|
+
}
|
|
91
|
+
|
|
85
92
|
let name = originName.toLowerCase();
|
|
86
93
|
|
|
87
94
|
try {
|
|
@@ -99,8 +106,8 @@ export function getMarketplaceDetails({
|
|
|
99
106
|
return details;
|
|
100
107
|
}
|
|
101
108
|
|
|
102
|
-
if (KIND_TO_MARKETPLACE[
|
|
103
|
-
return MARKETPLACES[KIND_TO_MARKETPLACE[
|
|
109
|
+
if (normalizedKind && KIND_TO_MARKETPLACE[normalizedKind]) {
|
|
110
|
+
return MARKETPLACES[KIND_TO_MARKETPLACE[normalizedKind]];
|
|
104
111
|
}
|
|
105
112
|
}
|
|
106
113
|
|
|
@@ -1,6 +1,27 @@
|
|
|
1
1
|
import type { WebrpcError } from '@0xsequence/api-client';
|
|
2
2
|
|
|
3
3
|
export const getWebRPCErrorMessage = (error: WebrpcError): string => {
|
|
4
|
+
const causeMessage =
|
|
5
|
+
typeof error.cause === 'string'
|
|
6
|
+
? error.cause
|
|
7
|
+
: error.cause instanceof Error
|
|
8
|
+
? error.cause.message
|
|
9
|
+
: '';
|
|
10
|
+
|
|
11
|
+
const rawDetails = [error.message, causeMessage]
|
|
12
|
+
.join(' ')
|
|
13
|
+
.toLowerCase();
|
|
14
|
+
|
|
15
|
+
if (
|
|
16
|
+
rawDetails.includes('outoffund') ||
|
|
17
|
+
rawDetails.includes('out of fund') ||
|
|
18
|
+
rawDetails.includes('insufficient funds') ||
|
|
19
|
+
rawDetails.includes('insufficient balance') ||
|
|
20
|
+
rawDetails.includes('not enough balance')
|
|
21
|
+
) {
|
|
22
|
+
return 'Insufficient balance to complete this transaction.';
|
|
23
|
+
}
|
|
24
|
+
|
|
4
25
|
switch (error.code) {
|
|
5
26
|
// Protocol Errors (negative numbers)
|
|
6
27
|
case -1: // WebrpcRequestFailed
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { MarketplaceKind, OrderbookKind } from '@0xsequence/api-client';
|
|
2
|
+
|
|
3
|
+
export function normalizeMarketplaceKind(
|
|
4
|
+
kind: MarketplaceKind | undefined,
|
|
5
|
+
): MarketplaceKind | undefined {
|
|
6
|
+
if (!kind) {
|
|
7
|
+
return kind;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return kind === MarketplaceKind.magic_eden
|
|
11
|
+
? MarketplaceKind.opensea
|
|
12
|
+
: kind;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function normalizeOrderbookKind(
|
|
16
|
+
kind: OrderbookKind | undefined,
|
|
17
|
+
): OrderbookKind | undefined {
|
|
18
|
+
if (!kind) {
|
|
19
|
+
return kind;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return kind === OrderbookKind.magic_eden
|
|
23
|
+
? OrderbookKind.opensea
|
|
24
|
+
: kind;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function isOpenSeaOrderbook(
|
|
28
|
+
kind: OrderbookKind | undefined,
|
|
29
|
+
): boolean {
|
|
30
|
+
return normalizeOrderbookKind(kind) === OrderbookKind.opensea;
|
|
31
|
+
}
|