@0xsequence/marketplace-sdk 0.8.7 → 0.8.9
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 +32 -0
- package/dist/chunk-2PSNAIAT.js +1 -0
- package/dist/chunk-2PSNAIAT.js.map +1 -0
- package/dist/{chunk-7FVZD2LL.js → chunk-4XLXOEXQ.js} +2 -2
- package/dist/{chunk-5HEZNTSU.js → chunk-D7RVSZAQ.js} +131 -83
- package/dist/chunk-D7RVSZAQ.js.map +1 -0
- package/dist/chunk-DWTLVJAW.js +42 -0
- package/dist/chunk-DWTLVJAW.js.map +1 -0
- package/dist/{chunk-YAUZLETY.js → chunk-G3447GIP.js} +37 -18
- package/dist/chunk-G3447GIP.js.map +1 -0
- package/dist/{chunk-O6GWM7C3.js → chunk-HHYNOPPI.js} +2 -2
- package/dist/{chunk-Y6AOCO3Q.js → chunk-I2BYHDFE.js} +419 -161
- package/dist/chunk-I2BYHDFE.js.map +1 -0
- package/dist/{chunk-KTT27YUN.js → chunk-KGM2WLSP.js} +12 -156
- package/dist/chunk-KGM2WLSP.js.map +1 -0
- package/dist/chunk-MAD64DLJ.js +81 -0
- package/dist/chunk-MAD64DLJ.js.map +1 -0
- package/dist/chunk-N7BPFK46.js +1 -0
- package/dist/chunk-N7BPFK46.js.map +1 -0
- package/dist/chunk-NX52D7NX.js +135 -0
- package/dist/chunk-NX52D7NX.js.map +1 -0
- package/dist/chunk-O34GCB47.js +32 -0
- package/dist/chunk-O34GCB47.js.map +1 -0
- package/dist/{chunk-Q2DA477S.js → chunk-YALXP2PW.js} +3 -3
- package/dist/{chunk-A6V7XDY4.js → chunk-YBOFRP65.js} +2 -2
- package/dist/{create-config-CdooE7aU.d.ts → create-config-DwrnzwpM.d.ts} +2 -2
- package/dist/{index-ClKHzm0B.d.ts → index-DGsVBflk.d.ts} +3 -12
- package/dist/index.css +83 -35
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +13 -4
- package/dist/index.js +13 -5
- package/dist/{lowestListing-kFyrUGha.d.ts → lowestListing-BQHIuvNF.d.ts} +2 -2
- package/dist/{marketplace.gen-BU6T6f0m.d.ts → marketplace.gen-DQzWciwC.d.ts} +1 -1
- package/dist/marketplaceConfig-B4Fdsmxu.d.ts +17 -0
- package/dist/react/_internal/api/index.d.ts +3 -3
- package/dist/react/_internal/api/index.js +4 -3
- package/dist/react/_internal/databeat/index.d.ts +2 -1
- package/dist/react/_internal/databeat/index.js +11 -7
- package/dist/react/_internal/index.d.ts +6 -6
- package/dist/react/_internal/index.js +13 -10
- package/dist/react/_internal/wagmi/index.d.ts +6 -5
- package/dist/react/_internal/wagmi/index.js +2 -2
- package/dist/react/hooks/index.d.ts +9 -8
- package/dist/react/hooks/index.js +10 -6
- package/dist/react/hooks/options/index.d.ts +4 -4
- package/dist/react/hooks/options/index.js +7 -4
- package/dist/react/index.css +2696 -0
- package/dist/react/index.css.map +1 -1
- package/dist/react/index.d.ts +9 -9
- package/dist/react/index.js +18 -11
- package/dist/react/queries/index.d.ts +3 -3
- package/dist/react/queries/index.js +6 -3
- package/dist/react/ssr/index.d.ts +3 -3
- package/dist/react/ssr/index.js +6 -3
- package/dist/react/ssr/index.js.map +1 -1
- package/dist/react/ui/components/collectible-card/index.css +2696 -0
- package/dist/react/ui/components/collectible-card/index.css.map +1 -1
- package/dist/react/ui/components/collectible-card/index.d.ts +23 -2
- package/dist/react/ui/components/collectible-card/index.js +16 -9
- package/dist/react/ui/icons/index.js +5 -2
- package/dist/react/ui/index.css +2696 -0
- package/dist/react/ui/index.css.map +1 -1
- package/dist/react/ui/index.d.ts +3 -2
- package/dist/react/ui/index.js +16 -9
- package/dist/react/ui/modals/_internal/components/actionModal/index.js +11 -7
- package/dist/sdk-config-txlivEKe.d.ts +133 -0
- package/dist/{services-9ApY0U-o.d.ts → services-BI_w8Eq4.d.ts} +4 -4
- package/dist/types/index.d.ts +5 -4
- package/dist/types/index.js +9 -6
- package/dist/{types-DsTwmKG-.d.ts → types-isjvwapz.d.ts} +3 -3
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +5 -2
- package/package.json +6 -5
- package/src/index.ts +1 -0
- package/src/react/{hooks/options/__mocks__/marketplaceConfig.msw.ts → _internal/api/__mocks__/builder.msw.ts} +70 -63
- package/src/react/_internal/api/__mocks__/metadata.msw.ts +30 -10
- package/src/react/_internal/api/builder-api.ts +32 -0
- package/src/react/_internal/api/builder.gen.ts +215 -0
- package/src/react/_internal/api/services.ts +9 -2
- package/src/react/_internal/databeat/types.ts +1 -0
- package/src/react/_internal/wagmi/__tests__/create-config.test.ts +16 -41
- package/src/react/_internal/wagmi/create-config.ts +3 -16
- package/src/react/_internal/wagmi/get-connectors.ts +31 -21
- package/src/react/_internal/wallet/__tests__/wallet.test.ts +30 -0
- package/src/react/_internal/wallet/wallet.ts +25 -2
- package/src/react/hooks/__tests__/__snapshots__/useMarketplaceConfig.test.tsx.snap +96 -0
- package/src/react/hooks/__tests__/useCollection.test.tsx +4 -5
- package/src/react/hooks/__tests__/useCurrencies.test.tsx +1 -1
- package/src/react/hooks/__tests__/useInventory.test.tsx +15 -16
- package/src/react/hooks/__tests__/useListCollections.test.tsx +18 -163
- package/src/react/hooks/__tests__/useMarketplaceConfig.test.tsx +10 -11
- package/src/react/hooks/options/index.ts +1 -1
- package/src/react/hooks/useAutoSelectFeeOption.tsx +1 -0
- package/src/react/hooks/useMarketplaceConfig.tsx +2 -2
- package/src/react/queries/marketplaceConfig.ts +101 -0
- package/src/react/ssr/__tests__/__snapshots__/create-ssr-client.test.ts.snap +1 -0
- package/src/react/ssr/create-ssr-client.ts +1 -1
- package/src/react/ui/components/ModelViewer.tsx +54 -0
- package/src/react/ui/components/_internals/custom-select/CustomSelect.tsx +0 -1
- package/src/react/ui/components/collectible-card/CollectibleCard.tsx +7 -3
- package/src/react/ui/components/collectible-card/__tests__/CollectibleAsset.test.tsx +76 -46
- package/src/react/ui/components/collectible-card/collectible-asset/CollectibleAsset.tsx +174 -0
- package/src/react/ui/components/collectible-card/collectible-asset/CollectibleAssetSkeleton.tsx +14 -0
- package/src/react/ui/components/collectible-card/collectible-asset/utils.ts +40 -0
- package/src/react/ui/components/collectible-card/index.ts +1 -0
- package/src/react/ui/index.ts +1 -0
- package/src/react/ui/modals/BuyModal/hooks/usePaymentModalParams.ts +6 -1
- package/src/react/ui/modals/BuyModal/store.ts +1 -0
- package/src/react/ui/modals/CreateListingModal/hooks/useTransactionSteps.tsx +20 -2
- package/src/react/ui/modals/MakeOfferModal/hooks/useTransactionSteps.tsx +17 -1
- package/src/react/ui/modals/SellModal/hooks/useTransactionSteps.tsx +4 -0
- package/src/react/ui/modals/SuccessfulPurchaseModal/index.tsx +9 -7
- package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/_components/TokenQuantityInput.tsx +1 -1
- package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/_components/WalletAddressInput.tsx +1 -1
- package/src/react/ui/modals/_internal/components/actionModal/ActionModal.test.tsx +7 -2
- package/src/react/ui/modals/_internal/components/priceInput/index.tsx +1 -1
- package/src/react/ui/modals/_internal/components/quantityInput/index.tsx +1 -2
- package/src/react/ui/modals/_internal/components/waasFeeOptionsSelect/WaasFeeOptionsSelect.tsx +0 -1
- package/src/types/index.ts +7 -1
- package/src/types/sdk-config.ts +4 -9
- package/src/utils/fetchContentType.ts +104 -0
- package/src/utils/getSequenceMarketRequestId.ts +32 -0
- package/test/mocks/wallet.ts +3 -1
- package/test/test-utils.tsx +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/builder-types-D5HgAUWR.d.ts +0 -82
- package/dist/chunk-5HEZNTSU.js.map +0 -1
- package/dist/chunk-KTT27YUN.js.map +0 -1
- package/dist/chunk-N7E37ENQ.js +0 -58
- package/dist/chunk-N7E37ENQ.js.map +0 -1
- package/dist/chunk-Y6AOCO3Q.js.map +0 -1
- package/dist/chunk-YAUZLETY.js.map +0 -1
- package/dist/sdk-config-DIzJk_tI.d.ts +0 -26
- package/src/react/hooks/options/__tests__/marketplaceConfigOptions.test.tsx +0 -134
- package/src/react/hooks/options/marketplaceConfigOptions.ts +0 -71
- package/src/react/ui/components/collectible-card/CollectibleAsset.tsx +0 -139
- package/src/types/builder-types.ts +0 -88
- /package/dist/{chunk-7FVZD2LL.js.map → chunk-4XLXOEXQ.js.map} +0 -0
- /package/dist/{chunk-O6GWM7C3.js.map → chunk-HHYNOPPI.js.map} +0 -0
- /package/dist/{chunk-Q2DA477S.js.map → chunk-YALXP2PW.js.map} +0 -0
- /package/dist/{chunk-A6V7XDY4.js.map → chunk-YBOFRP65.js.map} +0 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { renderHook, server, waitFor } from '@test';
|
|
2
2
|
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import { createLookupMarketplaceConfigErrorHandler } from '../../_internal/api/__mocks__/builder.msw';
|
|
4
|
+
|
|
3
5
|
import {
|
|
4
|
-
createConfigHandler,
|
|
5
|
-
createErrorHandler,
|
|
6
6
|
createStylesErrorHandler,
|
|
7
7
|
mockConfig,
|
|
8
8
|
mockStyles,
|
|
9
|
-
} from '
|
|
9
|
+
} from '../../_internal/api/__mocks__/builder.msw';
|
|
10
10
|
import { useMarketplaceConfig } from '../useMarketplaceConfig';
|
|
11
11
|
|
|
12
12
|
describe('useMarketplaceConfig', () => {
|
|
@@ -24,17 +24,13 @@ describe('useMarketplaceConfig', () => {
|
|
|
24
24
|
|
|
25
25
|
// Verify the data matches our mock
|
|
26
26
|
expect(result.current.data).toBeDefined();
|
|
27
|
-
expect(result.current.data).
|
|
28
|
-
...mockConfig,
|
|
29
|
-
cssString: mockStyles.replaceAll(/['"]/g, ''),
|
|
30
|
-
manifestUrl: expect.stringContaining('/manifest.json'),
|
|
31
|
-
});
|
|
27
|
+
expect(result.current.data).toMatchSnapshot();
|
|
32
28
|
expect(result.current.error).toBeNull();
|
|
33
29
|
});
|
|
34
30
|
|
|
35
31
|
it('should handle config fetch error', async () => {
|
|
36
32
|
// Override the handler for this test to return an error
|
|
37
|
-
server.use(
|
|
33
|
+
server.use(createLookupMarketplaceConfigErrorHandler());
|
|
38
34
|
|
|
39
35
|
const { result } = renderHook(() => useMarketplaceConfig());
|
|
40
36
|
|
|
@@ -48,7 +44,7 @@ describe('useMarketplaceConfig', () => {
|
|
|
48
44
|
|
|
49
45
|
it('should handle styles fetch error', async () => {
|
|
50
46
|
// Override the handler for this test to return an error
|
|
51
|
-
server.use(createStylesErrorHandler()
|
|
47
|
+
server.use(createStylesErrorHandler());
|
|
52
48
|
|
|
53
49
|
const { result } = renderHook(() => useMarketplaceConfig());
|
|
54
50
|
|
|
@@ -63,7 +59,10 @@ describe('useMarketplaceConfig', () => {
|
|
|
63
59
|
|
|
64
60
|
it('should handle both config and styles fetch errors', async () => {
|
|
65
61
|
// Override both handlers to return errors
|
|
66
|
-
server.use(
|
|
62
|
+
server.use(
|
|
63
|
+
createLookupMarketplaceConfigErrorHandler(),
|
|
64
|
+
createStylesErrorHandler(),
|
|
65
|
+
);
|
|
67
66
|
|
|
68
67
|
const { result } = renderHook(() => useMarketplaceConfig());
|
|
69
68
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { fetchCollection, collectionOptions } from './collectionOptions';
|
|
2
|
-
export * from '
|
|
2
|
+
export * from '../../queries/marketplaceConfig';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useQuery } from '@tanstack/react-query';
|
|
2
|
-
import { marketplaceConfigOptions } from '
|
|
2
|
+
import { marketplaceConfigOptions } from '../queries/marketplaceConfig';
|
|
3
3
|
import { useConfig } from './useConfig';
|
|
4
4
|
|
|
5
|
-
export * from '
|
|
5
|
+
export * from '../queries/marketplaceConfig';
|
|
6
6
|
|
|
7
7
|
export const useMarketplaceConfig = () => {
|
|
8
8
|
const config = useConfig();
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { queryOptions } from '@tanstack/react-query';
|
|
2
|
+
import type { Env, SdkConfig } from '../../types';
|
|
3
|
+
import { builderMarketplaceApi, builderRpcApi, configKeys } from '../_internal';
|
|
4
|
+
import { BuilderAPI } from '../_internal/api/builder-api';
|
|
5
|
+
import type { MarketplaceSettings } from '../_internal/api/builder.gen';
|
|
6
|
+
|
|
7
|
+
export type MarketplaceConfig = MarketplaceSettings & {
|
|
8
|
+
cssString: string;
|
|
9
|
+
manifestUrl: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const fetchBuilderConfig = async ({
|
|
13
|
+
projectId,
|
|
14
|
+
projectAccessKey,
|
|
15
|
+
env,
|
|
16
|
+
prefetchedMarketplaceSettings,
|
|
17
|
+
}: {
|
|
18
|
+
projectId: string;
|
|
19
|
+
projectAccessKey: string;
|
|
20
|
+
env: Env;
|
|
21
|
+
prefetchedMarketplaceSettings?: MarketplaceSettings;
|
|
22
|
+
}) => {
|
|
23
|
+
if (prefetchedMarketplaceSettings) {
|
|
24
|
+
return prefetchedMarketplaceSettings;
|
|
25
|
+
}
|
|
26
|
+
const baseUrl = builderRpcApi(env);
|
|
27
|
+
const builderApi = new BuilderAPI(baseUrl, projectAccessKey);
|
|
28
|
+
const response = await builderApi.lookupMarketplaceConfig({
|
|
29
|
+
projectId: Number(projectId),
|
|
30
|
+
});
|
|
31
|
+
return response.settings;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const fetchStyles = async (projectId: string, env: Env) => {
|
|
35
|
+
const response = await fetch(
|
|
36
|
+
`${builderMarketplaceApi(projectId, env)}/styles.css`,
|
|
37
|
+
);
|
|
38
|
+
const styles = await response.text();
|
|
39
|
+
// React sanitizes this string, so we need to remove all quotes, they are not needed anyway
|
|
40
|
+
return styles.replaceAll(/['"]/g, '');
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const fetchMarketplaceConfig = async ({
|
|
44
|
+
env,
|
|
45
|
+
projectId,
|
|
46
|
+
projectAccessKey,
|
|
47
|
+
prefetchedMarketplaceSettings,
|
|
48
|
+
}: {
|
|
49
|
+
env: Env;
|
|
50
|
+
projectId: string;
|
|
51
|
+
projectAccessKey: string;
|
|
52
|
+
prefetchedMarketplaceSettings?: MarketplaceSettings;
|
|
53
|
+
}): Promise<MarketplaceConfig> => {
|
|
54
|
+
const [marketplaceConfig, cssString] = await Promise.all([
|
|
55
|
+
fetchBuilderConfig({
|
|
56
|
+
projectId,
|
|
57
|
+
projectAccessKey,
|
|
58
|
+
env,
|
|
59
|
+
prefetchedMarketplaceSettings,
|
|
60
|
+
}),
|
|
61
|
+
fetchStyles(projectId, env),
|
|
62
|
+
]);
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
...marketplaceConfig,
|
|
66
|
+
cssString,
|
|
67
|
+
manifestUrl: `${builderMarketplaceApi(projectId, env)}/manifest.json`,
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const marketplaceConfigOptions = (
|
|
72
|
+
config: Pick<SdkConfig, 'projectId' | 'projectAccessKey'> | SdkConfig,
|
|
73
|
+
) => {
|
|
74
|
+
let env: Env = 'production';
|
|
75
|
+
if ('_internal' in config && config._internal !== undefined) {
|
|
76
|
+
env = config._internal.builderEnv ?? env;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
let prefetchedMarketplaceSettings: MarketplaceSettings | undefined;
|
|
80
|
+
if (
|
|
81
|
+
'_internal' in config &&
|
|
82
|
+
config._internal?.prefetchedMarketplaceSettings
|
|
83
|
+
) {
|
|
84
|
+
prefetchedMarketplaceSettings =
|
|
85
|
+
config._internal.prefetchedMarketplaceSettings;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const projectId = config.projectId;
|
|
89
|
+
const projectAccessKey = config.projectAccessKey;
|
|
90
|
+
|
|
91
|
+
return queryOptions({
|
|
92
|
+
queryKey: [...configKeys.marketplace, env, projectId],
|
|
93
|
+
queryFn: () =>
|
|
94
|
+
fetchMarketplaceConfig({
|
|
95
|
+
env,
|
|
96
|
+
projectId,
|
|
97
|
+
projectAccessKey,
|
|
98
|
+
prefetchedMarketplaceSettings,
|
|
99
|
+
}),
|
|
100
|
+
});
|
|
101
|
+
};
|
|
@@ -71,6 +71,7 @@ exports[`createSSRClient > should fetch marketplace config successfully 1`] = `
|
|
|
71
71
|
"landingPageLayout": "default",
|
|
72
72
|
"logoUrl": "https://example.com/logo.png",
|
|
73
73
|
"manifestUrl": "https://api.sequence.build/marketplace/test-project/manifest.json",
|
|
74
|
+
"projectId": 1,
|
|
74
75
|
"publisherId": "test-publisher",
|
|
75
76
|
"shortDescription": "A test marketplace",
|
|
76
77
|
"socials": {
|
|
@@ -2,7 +2,7 @@ import type { QueryClient } from '@tanstack/react-query';
|
|
|
2
2
|
import { type State, cookieToInitialState } from 'wagmi';
|
|
3
3
|
import type { SdkConfig } from '../../types/sdk-config';
|
|
4
4
|
import { createWagmiConfig } from '../_internal/wagmi/create-config';
|
|
5
|
-
import { marketplaceConfigOptions } from '../
|
|
5
|
+
import { marketplaceConfigOptions } from '../queries/marketplaceConfig';
|
|
6
6
|
|
|
7
7
|
type InitSSRClientArgs = {
|
|
8
8
|
cookie: string;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Skeleton } from '@0xsequence/design-system';
|
|
2
|
+
import { Suspense, lazy } from 'react';
|
|
3
|
+
|
|
4
|
+
const ModelViewerComponent = lazy(() =>
|
|
5
|
+
import('@google/model-viewer').then(() => ({
|
|
6
|
+
default: ({
|
|
7
|
+
posterSrc,
|
|
8
|
+
src,
|
|
9
|
+
onLoad,
|
|
10
|
+
onError,
|
|
11
|
+
}: {
|
|
12
|
+
posterSrc: string;
|
|
13
|
+
src?: string;
|
|
14
|
+
onLoad?: () => void;
|
|
15
|
+
onError?: () => void;
|
|
16
|
+
}) => (
|
|
17
|
+
<div className="h-full w-full bg-background-raised">
|
|
18
|
+
{/* @ts-expect-error - This is a web component */}
|
|
19
|
+
<model-viewer
|
|
20
|
+
alt="3d model"
|
|
21
|
+
auto-rotate
|
|
22
|
+
autoplay
|
|
23
|
+
camera-controls
|
|
24
|
+
class="h-full w-full"
|
|
25
|
+
error={onError}
|
|
26
|
+
load={onLoad}
|
|
27
|
+
loading="eager"
|
|
28
|
+
poster={posterSrc}
|
|
29
|
+
reveal="auto"
|
|
30
|
+
shadow-intensity="1"
|
|
31
|
+
src={src}
|
|
32
|
+
touch-action="pan-y"
|
|
33
|
+
/>
|
|
34
|
+
</div>
|
|
35
|
+
),
|
|
36
|
+
})),
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const ModelViewerLoading = () => <Skeleton className="h-full w-full" />;
|
|
40
|
+
|
|
41
|
+
const ModelViewer = (props: {
|
|
42
|
+
posterSrc: string;
|
|
43
|
+
src?: string;
|
|
44
|
+
onLoad?: () => void;
|
|
45
|
+
onError?: () => void;
|
|
46
|
+
}) => {
|
|
47
|
+
return (
|
|
48
|
+
<Suspense fallback={<ModelViewerLoading />}>
|
|
49
|
+
<ModelViewerComponent {...props} />
|
|
50
|
+
</Suspense>
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export default ModelViewer;
|
|
@@ -11,8 +11,8 @@ import type {
|
|
|
11
11
|
import { useCurrency } from '../../../hooks';
|
|
12
12
|
import { ActionButton } from '../_internals/action-button/ActionButton';
|
|
13
13
|
import { CollectibleCardAction } from '../_internals/action-button/types';
|
|
14
|
-
import { CollectibleAsset } from './CollectibleAsset';
|
|
15
14
|
import { Footer } from './Footer';
|
|
15
|
+
import { CollectibleAsset } from './collectible-asset/CollectibleAsset';
|
|
16
16
|
|
|
17
17
|
function CollectibleSkeleton() {
|
|
18
18
|
return (
|
|
@@ -129,7 +129,11 @@ export function CollectibleCard({
|
|
|
129
129
|
<article className="w-full rounded-xl">
|
|
130
130
|
<CollectibleAsset
|
|
131
131
|
name={collectibleMetadata?.name || ''}
|
|
132
|
-
|
|
132
|
+
assets={[
|
|
133
|
+
collectibleMetadata?.image,
|
|
134
|
+
collectibleMetadata?.video,
|
|
135
|
+
collectibleMetadata?.animation_url,
|
|
136
|
+
]}
|
|
133
137
|
assetSrcPrefixUrl={assetSrcPrefixUrl}
|
|
134
138
|
/>
|
|
135
139
|
|
|
@@ -145,7 +149,7 @@ export function CollectibleCard({
|
|
|
145
149
|
/>
|
|
146
150
|
|
|
147
151
|
{(highestOffer || collectible) && !balanceIsLoading && (
|
|
148
|
-
<div className="-bottom-
|
|
152
|
+
<div className="-bottom-16 absolute flex w-full origin-bottom items-center justify-center bg-overlay-light p-2 backdrop-blur transition-transform duration-200 ease-in-out group-hover:translate-y-[-64px]">
|
|
149
153
|
<ActionButton
|
|
150
154
|
chainId={chainId}
|
|
151
155
|
collectionAddress={collectionAddress}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { render, screen } from '@test/test-utils';
|
|
1
|
+
import { render, screen, waitFor } from '@test/test-utils';
|
|
2
2
|
import { describe, expect, it, vi } from 'vitest';
|
|
3
|
+
import * as fetchContentTypeModule from '../../../../../utils/fetchContentType';
|
|
3
4
|
import type { TokenMetadata } from '../../../../_internal';
|
|
4
|
-
import { CollectibleAsset } from '../CollectibleAsset';
|
|
5
|
+
import { CollectibleAsset } from '../collectible-asset/CollectibleAsset';
|
|
6
|
+
import * as contentTypeUtils from '../collectible-asset/utils';
|
|
5
7
|
|
|
6
8
|
describe('CollectibleAsset', () => {
|
|
7
9
|
it('renders image content correctly with proper loading states and fallback', async () => {
|
|
@@ -30,7 +32,7 @@ describe('CollectibleAsset', () => {
|
|
|
30
32
|
const { rerender } = render(
|
|
31
33
|
<CollectibleAsset
|
|
32
34
|
name="Test Collectible"
|
|
33
|
-
|
|
35
|
+
assets={[mockMetadata.image]}
|
|
34
36
|
/>,
|
|
35
37
|
);
|
|
36
38
|
|
|
@@ -69,7 +71,7 @@ describe('CollectibleAsset', () => {
|
|
|
69
71
|
rerender(
|
|
70
72
|
<CollectibleAsset
|
|
71
73
|
name="Test Collectible"
|
|
72
|
-
|
|
74
|
+
assets={[mockMetadataWithBadImage.image]}
|
|
73
75
|
/>,
|
|
74
76
|
);
|
|
75
77
|
|
|
@@ -86,7 +88,16 @@ describe('CollectibleAsset', () => {
|
|
|
86
88
|
window.Image = originalImage;
|
|
87
89
|
});
|
|
88
90
|
|
|
89
|
-
it('handles video content with appropriate controls and loading states', () => {
|
|
91
|
+
it('handles video content with appropriate controls and loading states', async () => {
|
|
92
|
+
const getContentTypeSpy = vi.spyOn(contentTypeUtils, 'getContentType');
|
|
93
|
+
getContentTypeSpy.mockResolvedValue('video');
|
|
94
|
+
|
|
95
|
+
const fetchContentTypeSpy = vi.spyOn(
|
|
96
|
+
fetchContentTypeModule,
|
|
97
|
+
'fetchContentType',
|
|
98
|
+
);
|
|
99
|
+
fetchContentTypeSpy.mockResolvedValue('video');
|
|
100
|
+
|
|
90
101
|
// Create a mock for the HTMLVideoElement addEventListener
|
|
91
102
|
const originalAddEventListener =
|
|
92
103
|
HTMLVideoElement.prototype.addEventListener;
|
|
@@ -118,38 +129,43 @@ describe('CollectibleAsset', () => {
|
|
|
118
129
|
render(
|
|
119
130
|
<CollectibleAsset
|
|
120
131
|
name="Video Collectible"
|
|
121
|
-
|
|
132
|
+
assets={[mockVideoMetadata.video]}
|
|
122
133
|
/>,
|
|
123
134
|
);
|
|
124
135
|
|
|
125
|
-
|
|
126
|
-
|
|
136
|
+
await waitFor(() => {
|
|
137
|
+
expect(screen.getByTestId('collectible-asset-video')).toBeInTheDocument();
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
const videoElement = screen.getByTestId(
|
|
141
|
+
'collectible-asset-video',
|
|
142
|
+
) as HTMLVideoElement;
|
|
143
|
+
|
|
127
144
|
expect(videoElement).not.toBeNull();
|
|
128
145
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
);
|
|
146
|
+
// Video source should be set correctly
|
|
147
|
+
const sourceElement = videoElement.querySelector('source');
|
|
148
|
+
expect(sourceElement).not.toBeNull();
|
|
149
|
+
expect(sourceElement?.getAttribute('src')).toBe(
|
|
150
|
+
'https://example.com/video.mp4',
|
|
151
|
+
);
|
|
136
152
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
153
|
+
// Video should have correct attributes for NFT display
|
|
154
|
+
expect(videoElement.autoplay).toBe(true);
|
|
155
|
+
expect(videoElement.loop).toBe(true);
|
|
156
|
+
expect(videoElement.controls).toBe(true);
|
|
157
|
+
expect(videoElement.playsInline).toBe(true);
|
|
158
|
+
expect(videoElement.muted).toBe(true);
|
|
143
159
|
|
|
144
|
-
|
|
145
|
-
|
|
160
|
+
// In Safari, pointer-events-none should be applied
|
|
161
|
+
expect(videoElement.className).toContain('pointer-events-none');
|
|
146
162
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
expect(videoElement.className).not.toContain('invisible');
|
|
150
|
-
}
|
|
163
|
+
// After metadata loaded, video should be visible
|
|
164
|
+
expect(videoElement.className).toContain('visible');
|
|
151
165
|
|
|
152
166
|
// Clean up mocks
|
|
167
|
+
getContentTypeSpy.mockRestore();
|
|
168
|
+
fetchContentTypeSpy.mockRestore();
|
|
153
169
|
HTMLVideoElement.prototype.addEventListener = originalAddEventListener;
|
|
154
170
|
Object.defineProperty(navigator, 'userAgent', {
|
|
155
171
|
value: originalUserAgent,
|
|
@@ -157,7 +173,16 @@ describe('CollectibleAsset', () => {
|
|
|
157
173
|
});
|
|
158
174
|
});
|
|
159
175
|
|
|
160
|
-
it('handles HTML content in iframes with proper sandboxing', () => {
|
|
176
|
+
it('handles HTML content in iframes with proper sandboxing', async () => {
|
|
177
|
+
const getContentTypeSpy = vi.spyOn(contentTypeUtils, 'getContentType');
|
|
178
|
+
getContentTypeSpy.mockResolvedValue('html');
|
|
179
|
+
|
|
180
|
+
const fetchContentTypeSpy = vi.spyOn(
|
|
181
|
+
fetchContentTypeModule,
|
|
182
|
+
'fetchContentType',
|
|
183
|
+
);
|
|
184
|
+
fetchContentTypeSpy.mockResolvedValue('html');
|
|
185
|
+
|
|
161
186
|
// Mock HTML content metadata
|
|
162
187
|
const mockHtmlMetadata: Partial<TokenMetadata> = {
|
|
163
188
|
tokenId: '1',
|
|
@@ -169,32 +194,37 @@ describe('CollectibleAsset', () => {
|
|
|
169
194
|
render(
|
|
170
195
|
<CollectibleAsset
|
|
171
196
|
name="HTML Collectible"
|
|
172
|
-
|
|
197
|
+
assets={[mockHtmlMetadata.animation_url]}
|
|
173
198
|
/>,
|
|
174
199
|
);
|
|
175
200
|
|
|
201
|
+
await waitFor(() => {
|
|
202
|
+
expect(document.querySelector('iframe')).toBeInTheDocument();
|
|
203
|
+
});
|
|
204
|
+
|
|
176
205
|
// Check that iframe element is present with correct attributes
|
|
177
|
-
const iframeElement = document.querySelector('iframe');
|
|
178
|
-
expect(iframeElement).
|
|
206
|
+
const iframeElement = document.querySelector('iframe') as HTMLIFrameElement;
|
|
207
|
+
expect(iframeElement).toBeInTheDocument();
|
|
179
208
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
);
|
|
209
|
+
// iframe source should be set correctly
|
|
210
|
+
expect(iframeElement.getAttribute('src')).toBe(
|
|
211
|
+
'https://example.com/interactive.html',
|
|
212
|
+
);
|
|
185
213
|
|
|
186
|
-
|
|
187
|
-
|
|
214
|
+
// iframe should have appropriate attributes for security
|
|
215
|
+
expect(iframeElement.getAttribute('sandbox')).toBe('allow-scripts');
|
|
188
216
|
|
|
189
|
-
|
|
190
|
-
|
|
217
|
+
// iframe should have title for accessibility
|
|
218
|
+
expect(iframeElement.getAttribute('title')).toBe('HTML Collectible');
|
|
191
219
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
220
|
+
// iframe should have proper styling
|
|
221
|
+
expect(iframeElement.className).toContain('aspect-square');
|
|
222
|
+
expect(iframeElement.className).toContain('w-full');
|
|
195
223
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
224
|
+
// Verify border styling
|
|
225
|
+
expect(iframeElement.style.border).toBe('0px');
|
|
226
|
+
|
|
227
|
+
getContentTypeSpy.mockRestore();
|
|
228
|
+
fetchContentTypeSpy.mockRestore();
|
|
199
229
|
});
|
|
200
230
|
});
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useEffect, useRef, useState } from 'react';
|
|
4
|
+
import { cn } from '../../../../../utils';
|
|
5
|
+
import { fetchContentType } from '../../../../../utils/fetchContentType';
|
|
6
|
+
import ChessTileImage from '../../../images/chess-tile.png';
|
|
7
|
+
import ModelViewer from '../../ModelViewer';
|
|
8
|
+
import CollectibleAssetSkeleton from './CollectibleAssetSkeleton';
|
|
9
|
+
import { getContentType } from './utils';
|
|
10
|
+
|
|
11
|
+
type CollectibleImageProps = {
|
|
12
|
+
name?: string;
|
|
13
|
+
assets?: (string | undefined)[];
|
|
14
|
+
assetSrcPrefixUrl?: string;
|
|
15
|
+
className?: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @description This component is used to display a collectible asset.
|
|
20
|
+
* It will display the first valid asset from the assets array.
|
|
21
|
+
* If no valid asset is found, it will display the placeholder image.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* <CollectibleAsset
|
|
25
|
+
* name="Collectible"
|
|
26
|
+
* assets={[undefined, "some-image-url", undefined]} // undefined assets will be ignored, "some-image-url" will be rendered
|
|
27
|
+
* assetSrcPrefixUrl="https://example.com/"
|
|
28
|
+
* className="w-full h-full"
|
|
29
|
+
* />
|
|
30
|
+
*/
|
|
31
|
+
export function CollectibleAsset({
|
|
32
|
+
name,
|
|
33
|
+
assets,
|
|
34
|
+
assetSrcPrefixUrl,
|
|
35
|
+
className,
|
|
36
|
+
}: CollectibleImageProps) {
|
|
37
|
+
const [assetLoadFailed, setAssetLoadFailed] = useState(false);
|
|
38
|
+
const [assetLoading, setAssetLoading] = useState(true);
|
|
39
|
+
const [contentType, setContentType] = useState<{
|
|
40
|
+
type: 'image' | 'video' | 'html' | '3d-model' | null;
|
|
41
|
+
loading: boolean;
|
|
42
|
+
failed: boolean;
|
|
43
|
+
}>({ type: null, loading: true, failed: false });
|
|
44
|
+
const videoRef = useRef<HTMLVideoElement>(null);
|
|
45
|
+
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
|
|
46
|
+
|
|
47
|
+
const placeholderImage = ChessTileImage;
|
|
48
|
+
const assetUrl = assets?.find((asset) => asset) || placeholderImage;
|
|
49
|
+
const proxiedAssetUrl = assetSrcPrefixUrl
|
|
50
|
+
? `${assetSrcPrefixUrl}${assetUrl}` // assetSrcPrefixUrl must have a trailing slash at the end
|
|
51
|
+
: assetUrl;
|
|
52
|
+
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
getContentType(proxiedAssetUrl)
|
|
55
|
+
.then((contentType) => {
|
|
56
|
+
setContentType({ type: contentType, loading: false, failed: false });
|
|
57
|
+
})
|
|
58
|
+
.catch(() => {
|
|
59
|
+
fetchContentType(proxiedAssetUrl)
|
|
60
|
+
.then((contentType) => {
|
|
61
|
+
setContentType({
|
|
62
|
+
type: contentType,
|
|
63
|
+
loading: false,
|
|
64
|
+
failed: false,
|
|
65
|
+
});
|
|
66
|
+
})
|
|
67
|
+
.catch(() => {
|
|
68
|
+
setContentType({ type: null, loading: false, failed: true });
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
}, [proxiedAssetUrl]);
|
|
72
|
+
|
|
73
|
+
if (contentType.type === 'html' && !assetLoadFailed) {
|
|
74
|
+
return (
|
|
75
|
+
<div
|
|
76
|
+
className={cn(
|
|
77
|
+
'flex aspect-square w-full items-center justify-center overflow-hidden rounded-lg bg-background-secondary',
|
|
78
|
+
className,
|
|
79
|
+
)}
|
|
80
|
+
>
|
|
81
|
+
{(assetLoading || contentType.loading) && <CollectibleAssetSkeleton />}
|
|
82
|
+
|
|
83
|
+
<iframe
|
|
84
|
+
title={name || 'Collectible'}
|
|
85
|
+
className="aspect-square w-full"
|
|
86
|
+
src={proxiedAssetUrl}
|
|
87
|
+
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
|
|
88
|
+
sandbox="allow-scripts"
|
|
89
|
+
style={{
|
|
90
|
+
border: '0px',
|
|
91
|
+
}}
|
|
92
|
+
onError={() => setAssetLoadFailed(true)}
|
|
93
|
+
onLoad={() => setAssetLoading(false)}
|
|
94
|
+
/>
|
|
95
|
+
</div>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (contentType.type === '3d-model' && !assetLoadFailed) {
|
|
100
|
+
return (
|
|
101
|
+
<div className="h-full w-full">
|
|
102
|
+
<ModelViewer
|
|
103
|
+
src={proxiedAssetUrl}
|
|
104
|
+
posterSrc={placeholderImage}
|
|
105
|
+
onLoad={() => setAssetLoading(false)}
|
|
106
|
+
onError={() => setAssetLoadFailed(true)}
|
|
107
|
+
/>
|
|
108
|
+
</div>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
if (contentType.type === 'video' && !assetLoadFailed) {
|
|
112
|
+
return (
|
|
113
|
+
<div
|
|
114
|
+
className={cn(
|
|
115
|
+
'relative flex aspect-square w-full items-center justify-center overflow-hidden rounded-lg bg-background-secondary',
|
|
116
|
+
className,
|
|
117
|
+
)}
|
|
118
|
+
>
|
|
119
|
+
{(assetLoading || contentType.loading) && <CollectibleAssetSkeleton />}
|
|
120
|
+
|
|
121
|
+
<video
|
|
122
|
+
ref={videoRef}
|
|
123
|
+
className={cn(
|
|
124
|
+
`absolute inset-0 h-full w-full object-cover transition-transform duration-200 ease-in-out group-hover:scale-hover ${
|
|
125
|
+
assetLoading ? 'invisible' : 'visible'
|
|
126
|
+
}`,
|
|
127
|
+
// we can't hide the video controls in safari, when user hovers over the video they show up. `pointer-events-none` is the only way to hide them on hover
|
|
128
|
+
isSafari && 'pointer-events-none',
|
|
129
|
+
)}
|
|
130
|
+
autoPlay
|
|
131
|
+
loop
|
|
132
|
+
controls
|
|
133
|
+
playsInline
|
|
134
|
+
muted
|
|
135
|
+
controlsList="nodownload noremoteplayback nofullscreen "
|
|
136
|
+
onError={() => {
|
|
137
|
+
setAssetLoadFailed(true);
|
|
138
|
+
}}
|
|
139
|
+
onLoadedMetadata={() => {
|
|
140
|
+
setAssetLoading(false);
|
|
141
|
+
}}
|
|
142
|
+
data-testid="collectible-asset-video"
|
|
143
|
+
>
|
|
144
|
+
<source src={proxiedAssetUrl} />
|
|
145
|
+
</video>
|
|
146
|
+
</div>
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return (
|
|
151
|
+
<div
|
|
152
|
+
className={cn(
|
|
153
|
+
'relative aspect-square overflow-hidden bg-background-secondary',
|
|
154
|
+
className,
|
|
155
|
+
)}
|
|
156
|
+
>
|
|
157
|
+
{(assetLoading || contentType.loading) && <CollectibleAssetSkeleton />}
|
|
158
|
+
|
|
159
|
+
<img
|
|
160
|
+
src={
|
|
161
|
+
assetLoadFailed || contentType.failed
|
|
162
|
+
? placeholderImage
|
|
163
|
+
: proxiedAssetUrl
|
|
164
|
+
}
|
|
165
|
+
alt={name || 'Collectible'}
|
|
166
|
+
className={`absolute inset-0 h-full w-full object-cover transition-transform duration-200 ease-in-out group-hover:scale-hover ${
|
|
167
|
+
assetLoading || contentType.loading ? 'invisible' : 'visible'
|
|
168
|
+
}`}
|
|
169
|
+
onError={() => setAssetLoadFailed(true)}
|
|
170
|
+
onLoad={() => setAssetLoading(false)}
|
|
171
|
+
/>
|
|
172
|
+
</div>
|
|
173
|
+
);
|
|
174
|
+
}
|
package/src/react/ui/components/collectible-card/collectible-asset/CollectibleAssetSkeleton.tsx
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Skeleton } from '@0xsequence/design-system';
|
|
2
|
+
|
|
3
|
+
export default function CollectibleAssetSkeleton() {
|
|
4
|
+
return (
|
|
5
|
+
<Skeleton
|
|
6
|
+
data-testid="collectible-asset-skeleton"
|
|
7
|
+
size="lg"
|
|
8
|
+
className="absolute inset-0 h-full w-full animate-shimmer"
|
|
9
|
+
style={{
|
|
10
|
+
borderRadius: 0,
|
|
11
|
+
}}
|
|
12
|
+
/>
|
|
13
|
+
);
|
|
14
|
+
}
|