@0xsequence/marketplace-sdk 0.3.2 → 0.3.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/dist/{chunk-NII6JJGH.js → chunk-3CXEYH2I.js} +5 -3
- package/dist/chunk-3CXEYH2I.js.map +1 -0
- package/dist/{chunk-GJAKQ5Q3.js → chunk-53Q7BNZH.js} +8 -2
- package/dist/chunk-53Q7BNZH.js.map +1 -0
- package/dist/{chunk-O7UQGT43.js → chunk-6LQST3KZ.js} +553 -283
- package/dist/chunk-6LQST3KZ.js.map +1 -0
- package/dist/{chunk-GZG2QO64.js → chunk-D3HRXVYJ.js} +72 -21
- package/dist/chunk-D3HRXVYJ.js.map +1 -0
- package/dist/{chunk-4YU2UPYH.js → chunk-FFCNYF3S.js} +61 -61
- package/dist/chunk-FFCNYF3S.js.map +1 -0
- package/dist/chunk-G2FYRJMK.js +38 -0
- package/dist/chunk-G2FYRJMK.js.map +1 -0
- package/dist/{chunk-WA433WAJ.js → chunk-L6GSYPCR.js} +20 -6
- package/dist/chunk-L6GSYPCR.js.map +1 -0
- package/dist/{chunk-SPW24Y7I.js → chunk-OUZ42I6B.js} +7 -2
- package/dist/chunk-OUZ42I6B.js.map +1 -0
- package/dist/{chunk-22NLQ3AS.js → chunk-PMDJARYX.js} +1081 -980
- package/dist/chunk-PMDJARYX.js.map +1 -0
- package/dist/chunk-T2AMWIKD.js +277 -0
- package/dist/chunk-T2AMWIKD.js.map +1 -0
- package/dist/{chunk-G33554LK.js → chunk-WQCWBXBM.js} +8 -16
- package/dist/chunk-WQCWBXBM.js.map +1 -0
- package/dist/index.css +40 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +172 -71
- package/dist/index.js.map +1 -1
- package/dist/{marketplace.gen-BLP7822q.d.ts → marketplace.gen-jdKqutnd.d.ts} +57 -18
- package/dist/react/_internal/api/index.d.ts +4 -2
- package/dist/react/_internal/api/index.js +8 -3
- package/dist/react/_internal/index.d.ts +3 -3
- package/dist/react/_internal/index.js +9 -4
- package/dist/react/_internal/wagmi/index.js +2 -1
- package/dist/react/hooks/index.d.ts +285 -12
- package/dist/react/hooks/index.js +14 -5
- package/dist/react/index.css +29 -29
- package/dist/react/index.css.map +1 -1
- package/dist/react/index.d.ts +4 -4
- package/dist/react/index.js +17 -8
- package/dist/react/ssr/index.js +55 -4
- package/dist/react/ssr/index.js.map +1 -1
- package/dist/react/ui/components/index.css +13 -13
- package/dist/react/ui/components/index.css.map +1 -1
- package/dist/react/ui/components/index.d.ts +3 -3
- package/dist/react/ui/components/index.js +9 -8
- package/dist/react/ui/icons/index.js +1 -1
- package/dist/react/ui/icons/index.js.map +1 -1
- package/dist/react/ui/index.css +29 -29
- package/dist/react/ui/index.css.map +1 -1
- package/dist/react/ui/index.d.ts +3 -3
- package/dist/react/ui/index.js +9 -8
- package/dist/react/ui/modals/_internal/components/actionModal/index.js +3 -2
- package/dist/react/ui/styles/index.d.ts +1 -1
- package/dist/{services-C9-lvWcC.d.ts → services-C2O-7p_M.d.ts} +2 -2
- package/dist/styles/index.css +40 -0
- package/dist/styles/index.css.map +1 -1
- package/dist/styles/index.d.ts +9 -2
- package/dist/styles/index.js +14 -2
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.js +3 -2
- package/dist/{types-QqXjNuUP.d.ts → types-BlDoGvJV.d.ts} +1 -1
- package/dist/utils/index.d.ts +2 -2
- package/dist/utils/index.js +2 -1
- package/package.json +18 -15
- package/src/react/_internal/api/marketplace.gen.ts +85 -20
- package/src/react/_internal/api/query-keys.ts +2 -0
- package/src/react/_internal/api/services.ts +4 -3
- package/src/react/_internal/api/zod-schema.ts +20 -0
- package/src/react/_internal/transaction-machine/execute-transaction.ts +311 -224
- package/src/react/_internal/transaction-machine/logger.ts +66 -0
- package/src/react/_internal/transaction-machine/useTransactionMachine.ts +69 -19
- package/src/react/_internal/wagmi/embedded.ts +2 -2
- package/src/react/hooks/index.ts +2 -0
- package/src/react/hooks/options/marketplaceConfigOptions.ts +6 -2
- package/src/react/hooks/useBuyCollectable.tsx +14 -8
- package/src/react/hooks/useCancelOrder.tsx +4 -3
- package/src/react/hooks/useCheckoutOptions.tsx +2 -2
- package/src/react/hooks/useConfig.tsx +2 -3
- package/src/react/hooks/useCountListingsForCollectible.tsx +64 -0
- package/src/react/hooks/useCountOffersForCollectible.tsx +64 -0
- package/src/react/hooks/useCreateListing.tsx +13 -14
- package/src/react/hooks/useCurrencies.tsx +9 -8
- package/src/react/hooks/useCurrency.tsx +6 -6
- package/src/react/hooks/useGenerateBuyTransaction.tsx +3 -3
- package/src/react/hooks/useMakeOffer.tsx +14 -13
- package/src/react/hooks/useRoyaltyPercentage.tsx +1 -1
- package/src/react/hooks/useSell.tsx +12 -12
- package/src/react/hooks/useTransferTokens.tsx +2 -1
- package/src/react/ui/components/_internals/action-button/ActionButton.tsx +3 -2
- package/src/react/ui/components/_internals/custom-select/CustomSelect.tsx +4 -4
- package/src/react/ui/components/collectible-card/CollectibleCard.tsx +2 -2
- package/src/react/ui/components/collectible-card/Footer.tsx +33 -29
- package/src/react/ui/icons/ArrowUp.tsx +1 -1
- package/src/react/ui/modals/BuyModal/_store.ts +8 -6
- package/src/react/ui/modals/BuyModal/index.tsx +120 -81
- package/src/react/ui/modals/CreateListingModal/_store.ts +1 -0
- package/src/react/ui/modals/CreateListingModal/index.tsx +34 -14
- package/src/react/ui/modals/MakeOfferModal/_store.ts +2 -0
- package/src/react/ui/modals/MakeOfferModal/index.tsx +21 -11
- package/src/react/ui/modals/SellModal/index.tsx +21 -13
- package/src/react/ui/modals/SuccessfulPurchaseModal/_store.ts +1 -1
- package/src/react/ui/modals/SuccessfulPurchaseModal/index.tsx +1 -1
- package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/index.tsx +12 -7
- package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/useHandleTransfer.tsx +2 -1
- package/src/react/ui/modals/TransferModal/_views/followWalletInstructions/index.tsx +2 -2
- package/src/react/ui/modals/TransferModal/styles.css.ts +1 -1
- package/src/react/ui/modals/_internal/components/actionModal/ErrorModal.tsx +1 -1
- package/src/react/ui/modals/_internal/components/actionModal/LoadingModal.tsx +1 -1
- package/src/react/ui/modals/_internal/components/alertMessage/index.tsx +7 -2
- package/src/react/ui/modals/_internal/components/currencyOptionsSelect/index.tsx +2 -7
- package/src/react/ui/modals/_internal/components/expirationDateSelect/index.tsx +2 -1
- package/src/react/ui/modals/_internal/components/floorPriceText/index.tsx +1 -0
- package/src/react/ui/modals/_internal/components/quantityInput/index.tsx +42 -102
- package/src/react/ui/modals/_internal/components/switchChainModal/styles.css.ts +1 -1
- package/src/react/ui/modals/_internal/components/timeAgo/index.tsx +1 -1
- package/src/react/ui/modals/_internal/components/tokenPreview/index.tsx +1 -1
- package/src/react/ui/modals/_internal/components/transaction-footer/index.tsx +32 -11
- package/src/react/ui/modals/_internal/components/transactionDetails/index.tsx +2 -2
- package/src/react/ui/modals/_internal/components/transactionHeader/index.tsx +14 -2
- package/src/react/ui/modals/_internal/components/transactionPreview/index.tsx +17 -5
- package/src/react/ui/modals/_internal/components/transactionStatusModal/index.tsx +12 -4
- package/src/react/ui/modals/_internal/components/transactionStatusModal/styles.css.ts +1 -1
- package/src/react/ui/modals/modal-provider.tsx +3 -3
- package/src/styles/index.ts +3 -0
- package/src/utils/_internal/error/base.ts +32 -0
- package/src/utils/_internal/error/context.ts +13 -0
- package/src/utils/_internal/error/transaction.ts +369 -0
- package/src/utils/get-public-rpc-client.ts +4 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/tsup.config.ts +3 -0
- package/dist/chess-tile-6BS5MQT5.png +0 -0
- package/dist/chunk-22NLQ3AS.js.map +0 -1
- package/dist/chunk-4YU2UPYH.js.map +0 -1
- package/dist/chunk-G33554LK.js.map +0 -1
- package/dist/chunk-GJAKQ5Q3.js.map +0 -1
- package/dist/chunk-GZG2QO64.js.map +0 -1
- package/dist/chunk-NII6JJGH.js.map +0 -1
- package/dist/chunk-O7UQGT43.js.map +0 -1
- package/dist/chunk-SPW24Y7I.js.map +0 -1
- package/dist/chunk-WA433WAJ.js.map +0 -1
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export class TransactionLogger {
|
|
2
|
+
constructor(
|
|
3
|
+
private readonly context: string,
|
|
4
|
+
private readonly enabled: boolean = true,
|
|
5
|
+
) {}
|
|
6
|
+
|
|
7
|
+
private formatData(data: unknown): unknown {
|
|
8
|
+
if (data instanceof Error) {
|
|
9
|
+
return {
|
|
10
|
+
name: data.name,
|
|
11
|
+
message: data.message,
|
|
12
|
+
cause:
|
|
13
|
+
data.cause instanceof Error
|
|
14
|
+
? this.formatData(data.cause)
|
|
15
|
+
: data.cause,
|
|
16
|
+
stack: data.stack?.split('\n').slice(0, 3),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (Array.isArray(data)) {
|
|
21
|
+
return data.map((item) => this.formatData(item));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (typeof data === 'object' && data !== null) {
|
|
25
|
+
return Object.fromEntries(
|
|
26
|
+
Object.entries(data).map(([key, value]) => [
|
|
27
|
+
key,
|
|
28
|
+
this.formatData(value),
|
|
29
|
+
]),
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return data;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
private log(
|
|
37
|
+
level: 'debug' | 'error' | 'info',
|
|
38
|
+
message: string,
|
|
39
|
+
data?: unknown,
|
|
40
|
+
) {
|
|
41
|
+
if (!this.enabled) return;
|
|
42
|
+
console[level](
|
|
43
|
+
`[${this.context}] ${message}`,
|
|
44
|
+
data ? this.formatData(data) : '',
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
debug(message: string, data?: unknown) {
|
|
49
|
+
this.log('debug', message, data);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
error(message: string, error: unknown) {
|
|
53
|
+
this.log('error', message, error);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
info(message: string, data?: unknown) {
|
|
57
|
+
this.log('info', message, data);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
state(from: string, to: string) {
|
|
61
|
+
this.info(`State transition: ${from} -> ${to}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export const createLogger = (context: string, enabled = true) =>
|
|
66
|
+
new TransactionLogger(context, enabled);
|
|
@@ -2,10 +2,16 @@ import { useSelectPaymentModal } from '@0xsequence/kit-checkout';
|
|
|
2
2
|
import type { Hash } from 'viem';
|
|
3
3
|
import { useAccount, useSwitchChain, useWalletClient } from 'wagmi';
|
|
4
4
|
import { getPublicRpcClient } from '../../../utils';
|
|
5
|
+
import {
|
|
6
|
+
NoMarketplaceConfigError,
|
|
7
|
+
NoWalletConnectedError,
|
|
8
|
+
TransactionError,
|
|
9
|
+
} from '../../../utils/_internal/error/transaction';
|
|
5
10
|
import { useConfig, useMarketplaceConfig } from '../../hooks';
|
|
6
11
|
import { useSwitchChainModal } from '../../ui/modals/_internal/components/switchChainModal';
|
|
7
12
|
import { WalletKind } from '../api';
|
|
8
13
|
import {
|
|
14
|
+
type Input,
|
|
9
15
|
type TransactionConfig,
|
|
10
16
|
TransactionMachine,
|
|
11
17
|
} from './execute-transaction';
|
|
@@ -18,49 +24,93 @@ export type UseTransactionMachineConfig = Omit<
|
|
|
18
24
|
export const useTransactionMachine = (
|
|
19
25
|
config: UseTransactionMachineConfig,
|
|
20
26
|
onSuccess?: (hash: Hash) => void,
|
|
21
|
-
onError?: (error:
|
|
27
|
+
onError?: (error: TransactionError) => void,
|
|
22
28
|
onTransactionSent?: (hash: Hash) => void,
|
|
23
29
|
) => {
|
|
24
|
-
const { data: walletClient } =
|
|
30
|
+
const { data: walletClient, isLoading: walletClientIsLoading } =
|
|
31
|
+
useWalletClient();
|
|
25
32
|
const { show: showSwitchChainModal } = useSwitchChainModal();
|
|
26
33
|
const sdkConfig = useConfig();
|
|
27
|
-
const {
|
|
28
|
-
|
|
34
|
+
const {
|
|
35
|
+
data: marketplaceConfig,
|
|
36
|
+
error: marketplaceError,
|
|
37
|
+
isLoading: marketplaceConfigIsLoading,
|
|
38
|
+
} = useMarketplaceConfig();
|
|
29
39
|
const { openSelectPaymentModal } = useSelectPaymentModal();
|
|
30
40
|
const { chains } = useSwitchChain();
|
|
31
41
|
|
|
32
|
-
const { connector } = useAccount();
|
|
42
|
+
const { connector, isConnected } = useAccount();
|
|
33
43
|
const walletKind =
|
|
34
44
|
connector?.id === 'sequence' ? WalletKind.sequence : WalletKind.unknown;
|
|
35
45
|
|
|
46
|
+
if (!isConnected) {
|
|
47
|
+
// No wallet connected, TODO: add some sort of state for this
|
|
48
|
+
return { machine: null, error: null, isLoading: false };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (walletClientIsLoading || marketplaceConfigIsLoading) {
|
|
52
|
+
return { machine: null, error: null, isLoading: true };
|
|
53
|
+
}
|
|
54
|
+
|
|
36
55
|
if (marketplaceError) {
|
|
37
|
-
|
|
56
|
+
const error = new TransactionError('Marketplace config error', {
|
|
57
|
+
cause: marketplaceError,
|
|
58
|
+
});
|
|
59
|
+
onError?.(error);
|
|
60
|
+
return { machine: null, error };
|
|
38
61
|
}
|
|
39
62
|
|
|
40
|
-
if (!walletClient
|
|
63
|
+
if (!walletClient) {
|
|
64
|
+
const error = new NoWalletConnectedError();
|
|
65
|
+
onError?.(error);
|
|
66
|
+
return { machine: null, error };
|
|
67
|
+
}
|
|
41
68
|
|
|
42
|
-
|
|
69
|
+
if (!marketplaceConfig) {
|
|
70
|
+
const error = new NoMarketplaceConfigError();
|
|
71
|
+
onError?.(error);
|
|
72
|
+
return { machine: null, error };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const machine = new TransactionMachine(
|
|
43
76
|
{
|
|
44
77
|
config: { sdkConfig, marketplaceConfig, walletKind, chains, ...config },
|
|
45
78
|
onSuccess,
|
|
46
|
-
onError,
|
|
47
79
|
onTransactionSent,
|
|
48
80
|
},
|
|
49
81
|
walletClient,
|
|
50
82
|
getPublicRpcClient(config.chainId),
|
|
51
83
|
openSelectPaymentModal,
|
|
52
|
-
async (chainId) =>
|
|
53
|
-
|
|
84
|
+
async (chainId) =>
|
|
85
|
+
new Promise((resolve, reject) => {
|
|
54
86
|
showSwitchChainModal({
|
|
55
87
|
chainIdToSwitchTo: Number(chainId),
|
|
56
|
-
onSuccess:
|
|
57
|
-
|
|
58
|
-
},
|
|
59
|
-
onError: (error) => {
|
|
60
|
-
reject(error);
|
|
61
|
-
},
|
|
88
|
+
onSuccess: resolve,
|
|
89
|
+
onError: reject,
|
|
62
90
|
});
|
|
63
|
-
})
|
|
64
|
-
},
|
|
91
|
+
}),
|
|
65
92
|
);
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
machine: {
|
|
96
|
+
getTransactionSteps: async (props: Input) => {
|
|
97
|
+
try {
|
|
98
|
+
return await machine.getTransactionSteps(props);
|
|
99
|
+
} catch (e) {
|
|
100
|
+
const error = e as TransactionError;
|
|
101
|
+
onError?.(error);
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
start: async (props: Input) => {
|
|
105
|
+
try {
|
|
106
|
+
await machine.start(props);
|
|
107
|
+
} catch (e) {
|
|
108
|
+
const error = e as TransactionError;
|
|
109
|
+
onError?.(error);
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
error: null,
|
|
114
|
+
isLoading: false,
|
|
115
|
+
};
|
|
66
116
|
};
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
} from '@0xsequence/kit';
|
|
10
10
|
import type { CreateConnectorFn } from 'wagmi';
|
|
11
11
|
import type { MarketplaceConfig, SdkConfig } from '../../../types';
|
|
12
|
+
import { MissingConfigError } from '../../../utils/_internal/error/transaction';
|
|
12
13
|
import { DEFAULT_NETWORK } from '../consts';
|
|
13
14
|
|
|
14
15
|
export function getWaasConnectors(
|
|
@@ -19,8 +20,7 @@ export function getWaasConnectors(
|
|
|
19
20
|
|
|
20
21
|
const waasConfigKey = sdkConfig.wallet?.embedded?.waasConfigKey;
|
|
21
22
|
|
|
22
|
-
if (!waasConfigKey)
|
|
23
|
-
throw new Error('waasConfigKey is required for embedded wallet');
|
|
23
|
+
if (!waasConfigKey) throw new MissingConfigError('waasConfigKey');
|
|
24
24
|
|
|
25
25
|
const walletConnectProjectId = sdkConfig.wallet?.walletConnectProjectId;
|
|
26
26
|
const { googleClientId, appleClientId, appleRedirectURI } =
|
package/src/react/hooks/index.ts
CHANGED
|
@@ -11,7 +11,9 @@ export * from './useHighestOffer';
|
|
|
11
11
|
export * from './useListBalances';
|
|
12
12
|
export * from './useListCollectibles';
|
|
13
13
|
export * from './useListOffersForCollectible';
|
|
14
|
+
export * from './useCountOffersForCollectible';
|
|
14
15
|
export * from './useListListingsForCollectible';
|
|
16
|
+
export * from './useCountListingsForCollectible';
|
|
15
17
|
export * from './useLowestListing';
|
|
16
18
|
export * from './useMarketplaceConfig';
|
|
17
19
|
export * from './useRoyaltyPercentage';
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { queryOptions } from '@tanstack/react-query';
|
|
2
2
|
import type { Env, MarketplaceConfig, SdkConfig } from '../../../types';
|
|
3
|
+
import {
|
|
4
|
+
MarketplaceConfigFetchError,
|
|
5
|
+
ProjectNotFoundError,
|
|
6
|
+
} from '../../../utils/_internal/error/transaction';
|
|
3
7
|
import { builderMarketplaceApi, configKeys } from '../../_internal';
|
|
4
8
|
|
|
5
9
|
const fetchBuilderConfig = async (projectId: string, env: Env) => {
|
|
@@ -12,10 +16,10 @@ const fetchBuilderConfig = async (projectId: string, env: Env) => {
|
|
|
12
16
|
//@ts-ignore
|
|
13
17
|
switch (json.code) {
|
|
14
18
|
case 3000: // Throws 3000 if the project is not found
|
|
15
|
-
throw new
|
|
19
|
+
throw new ProjectNotFoundError(projectId, url);
|
|
16
20
|
default:
|
|
17
21
|
//@ts-ignore
|
|
18
|
-
throw new
|
|
22
|
+
throw new MarketplaceConfigFetchError(json.msg);
|
|
19
23
|
}
|
|
20
24
|
}
|
|
21
25
|
return json as MarketplaceConfig;
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
+
import type { Hash } from 'viem';
|
|
2
|
+
import type { TransactionErrorTypes } from '../../utils/_internal/error/transaction';
|
|
1
3
|
import {
|
|
2
4
|
type BuyInput,
|
|
3
5
|
TransactionType,
|
|
4
6
|
} from '../_internal/transaction-machine/execute-transaction';
|
|
5
7
|
import {
|
|
6
|
-
useTransactionMachine,
|
|
7
8
|
type UseTransactionMachineConfig,
|
|
9
|
+
useTransactionMachine,
|
|
8
10
|
} from '../_internal/transaction-machine/useTransactionMachine';
|
|
9
11
|
|
|
12
|
+
type UseBuyOrderError = TransactionErrorTypes;
|
|
13
|
+
|
|
10
14
|
interface UseBuyOrderArgs extends Omit<UseTransactionMachineConfig, 'type'> {
|
|
11
|
-
onSuccess?: (hash:
|
|
12
|
-
onError?: (error:
|
|
15
|
+
onSuccess?: (hash: Hash) => void;
|
|
16
|
+
onError?: (error: UseBuyOrderError) => void;
|
|
13
17
|
onTransactionSent?: (hash: string) => void;
|
|
14
18
|
}
|
|
15
19
|
|
|
@@ -19,7 +23,7 @@ export const useBuyCollectable = ({
|
|
|
19
23
|
onTransactionSent,
|
|
20
24
|
...config
|
|
21
25
|
}: UseBuyOrderArgs) => {
|
|
22
|
-
const machine = useTransactionMachine(
|
|
26
|
+
const { machine, error, isLoading } = useTransactionMachine(
|
|
23
27
|
{
|
|
24
28
|
...config,
|
|
25
29
|
type: TransactionType.BUY,
|
|
@@ -30,9 +34,11 @@ export const useBuyCollectable = ({
|
|
|
30
34
|
);
|
|
31
35
|
|
|
32
36
|
return {
|
|
33
|
-
buy: (props: BuyInput) =>
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
buy: (props: BuyInput) => {
|
|
38
|
+
if (!machine || isLoading) return;
|
|
39
|
+
machine.start(props);
|
|
40
|
+
},
|
|
41
|
+
isLoading,
|
|
42
|
+
error,
|
|
37
43
|
};
|
|
38
44
|
};
|
|
@@ -3,8 +3,8 @@ import {
|
|
|
3
3
|
TransactionType,
|
|
4
4
|
} from '../_internal/transaction-machine/execute-transaction';
|
|
5
5
|
import {
|
|
6
|
-
useTransactionMachine,
|
|
7
6
|
type UseTransactionMachineConfig,
|
|
7
|
+
useTransactionMachine,
|
|
8
8
|
} from '../_internal/transaction-machine/useTransactionMachine';
|
|
9
9
|
|
|
10
10
|
interface UseCancelOrderArgs extends Omit<UseTransactionMachineConfig, 'type'> {
|
|
@@ -19,7 +19,7 @@ export const useCancelOrder = ({
|
|
|
19
19
|
onTransactionSent,
|
|
20
20
|
...config
|
|
21
21
|
}: UseCancelOrderArgs) => {
|
|
22
|
-
const machine = useTransactionMachine(
|
|
22
|
+
const { machine, isLoading } = useTransactionMachine(
|
|
23
23
|
{
|
|
24
24
|
...config,
|
|
25
25
|
type: TransactionType.CANCEL,
|
|
@@ -30,9 +30,10 @@ export const useCancelOrder = ({
|
|
|
30
30
|
);
|
|
31
31
|
|
|
32
32
|
return {
|
|
33
|
-
cancel: (props: CancelInput) => machine?.start(
|
|
33
|
+
cancel: (props: CancelInput) => machine?.start(props),
|
|
34
34
|
onError,
|
|
35
35
|
onSuccess,
|
|
36
36
|
onTransactionSent,
|
|
37
|
+
isLoading,
|
|
37
38
|
};
|
|
38
39
|
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { queryOptions, useQuery } from '@tanstack/react-query';
|
|
2
|
+
import type { Hex } from 'viem';
|
|
3
|
+
import { useAccount } from 'wagmi';
|
|
2
4
|
import { z } from 'zod';
|
|
3
5
|
import type { SdkConfig } from '../../types';
|
|
4
6
|
import {
|
|
@@ -9,8 +11,6 @@ import {
|
|
|
9
11
|
getMarketplaceClient,
|
|
10
12
|
} from '../_internal';
|
|
11
13
|
import { useConfig } from './useConfig';
|
|
12
|
-
import { useAccount } from 'wagmi';
|
|
13
|
-
import type { Hex } from 'viem';
|
|
14
14
|
|
|
15
15
|
const UseCheckoutOptionsSchema = z.object({
|
|
16
16
|
chainId: ChainIdSchema.pipe(z.coerce.string()),
|
|
@@ -2,14 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
import { useContext } from 'react';
|
|
4
4
|
|
|
5
|
+
import { MarketplaceSdkProviderNotFoundError } from '../../utils/_internal/error/context';
|
|
5
6
|
import { MarketplaceSdkContext } from '../provider';
|
|
6
7
|
|
|
7
8
|
export function useConfig() {
|
|
8
9
|
const context = useContext(MarketplaceSdkContext);
|
|
9
10
|
if (!context) {
|
|
10
|
-
throw new
|
|
11
|
-
'Marketplace SDK must be used within a MarketplaceSdkProvider',
|
|
12
|
-
);
|
|
11
|
+
throw new MarketplaceSdkProviderNotFoundError();
|
|
13
12
|
}
|
|
14
13
|
return context;
|
|
15
14
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { queryOptions, useQuery } from '@tanstack/react-query';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import type { SdkConfig } from '../../types';
|
|
4
|
+
import {
|
|
5
|
+
AddressSchema,
|
|
6
|
+
ChainIdSchema,
|
|
7
|
+
QueryArgSchema,
|
|
8
|
+
collectableKeys,
|
|
9
|
+
getMarketplaceClient,
|
|
10
|
+
} from '../_internal';
|
|
11
|
+
import { countListingsForCollectibleArgsSchema } from '../_internal/api/zod-schema';
|
|
12
|
+
import { useConfig } from './useConfig';
|
|
13
|
+
|
|
14
|
+
const UseCountListingsForCollectibleArgsSchema =
|
|
15
|
+
countListingsForCollectibleArgsSchema
|
|
16
|
+
.omit({
|
|
17
|
+
contractAddress: true,
|
|
18
|
+
tokenId: true,
|
|
19
|
+
})
|
|
20
|
+
.extend({
|
|
21
|
+
collectionAddress: AddressSchema,
|
|
22
|
+
collectibleId: z.string(),
|
|
23
|
+
chainId: ChainIdSchema.pipe(z.coerce.string()),
|
|
24
|
+
query: QueryArgSchema,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export type UseCountListingsForCollectibleArgs = z.infer<
|
|
28
|
+
typeof UseCountListingsForCollectibleArgsSchema
|
|
29
|
+
>;
|
|
30
|
+
|
|
31
|
+
export type UseCountListingsForCollectibleReturn = Awaited<
|
|
32
|
+
ReturnType<typeof fetchCountListingsForCollectible>
|
|
33
|
+
>;
|
|
34
|
+
|
|
35
|
+
const fetchCountListingsForCollectible = async (
|
|
36
|
+
args: UseCountListingsForCollectibleArgs,
|
|
37
|
+
config: SdkConfig,
|
|
38
|
+
) => {
|
|
39
|
+
const parsedArgs = UseCountListingsForCollectibleArgsSchema.parse(args);
|
|
40
|
+
const marketplaceClient = getMarketplaceClient(parsedArgs.chainId, config);
|
|
41
|
+
return marketplaceClient.getCountOfListingsForCollectible({
|
|
42
|
+
...parsedArgs,
|
|
43
|
+
contractAddress: parsedArgs.collectionAddress,
|
|
44
|
+
tokenId: parsedArgs.collectibleId,
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const countListingsForCollectibleOptions = (
|
|
49
|
+
args: UseCountListingsForCollectibleArgs,
|
|
50
|
+
config: SdkConfig,
|
|
51
|
+
) => {
|
|
52
|
+
return queryOptions({
|
|
53
|
+
...args.query,
|
|
54
|
+
queryKey: [...collectableKeys.listingsCount, args, config],
|
|
55
|
+
queryFn: () => fetchCountListingsForCollectible(args, config),
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export const useCountListingsForCollectible = (
|
|
60
|
+
args: UseCountListingsForCollectibleArgs,
|
|
61
|
+
) => {
|
|
62
|
+
const config = useConfig();
|
|
63
|
+
return useQuery(countListingsForCollectibleOptions(args, config));
|
|
64
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { queryOptions, useQuery } from '@tanstack/react-query';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import type { SdkConfig } from '../../types';
|
|
4
|
+
import {
|
|
5
|
+
AddressSchema,
|
|
6
|
+
ChainIdSchema,
|
|
7
|
+
QueryArgSchema,
|
|
8
|
+
collectableKeys,
|
|
9
|
+
getMarketplaceClient,
|
|
10
|
+
} from '../_internal';
|
|
11
|
+
import { countOffersForCollectibleArgsSchema } from '../_internal/api/zod-schema';
|
|
12
|
+
import { useConfig } from './useConfig';
|
|
13
|
+
|
|
14
|
+
const UseCountOffersForCollectibleArgsSchema =
|
|
15
|
+
countOffersForCollectibleArgsSchema
|
|
16
|
+
.omit({
|
|
17
|
+
contractAddress: true,
|
|
18
|
+
tokenId: true,
|
|
19
|
+
})
|
|
20
|
+
.extend({
|
|
21
|
+
collectionAddress: AddressSchema,
|
|
22
|
+
collectibleId: z.string(),
|
|
23
|
+
chainId: ChainIdSchema.pipe(z.coerce.string()),
|
|
24
|
+
query: QueryArgSchema,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export type UseCountOffersForCollectibleArgs = z.infer<
|
|
28
|
+
typeof UseCountOffersForCollectibleArgsSchema
|
|
29
|
+
>;
|
|
30
|
+
|
|
31
|
+
export type UseCountOffersForCollectibleReturn = Awaited<
|
|
32
|
+
ReturnType<typeof fetchCountOffersForCollectible>
|
|
33
|
+
>;
|
|
34
|
+
|
|
35
|
+
const fetchCountOffersForCollectible = async (
|
|
36
|
+
args: UseCountOffersForCollectibleArgs,
|
|
37
|
+
config: SdkConfig,
|
|
38
|
+
) => {
|
|
39
|
+
const parsedArgs = UseCountOffersForCollectibleArgsSchema.parse(args);
|
|
40
|
+
const marketplaceClient = getMarketplaceClient(parsedArgs.chainId, config);
|
|
41
|
+
return marketplaceClient.getCountOfOffersForCollectible({
|
|
42
|
+
...parsedArgs,
|
|
43
|
+
contractAddress: parsedArgs.collectionAddress,
|
|
44
|
+
tokenId: parsedArgs.collectibleId,
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const countOffersForCollectibleOptions = (
|
|
49
|
+
args: UseCountOffersForCollectibleArgs,
|
|
50
|
+
config: SdkConfig,
|
|
51
|
+
) => {
|
|
52
|
+
return queryOptions({
|
|
53
|
+
...args.query,
|
|
54
|
+
queryKey: [...collectableKeys.offersCount, args, config],
|
|
55
|
+
queryFn: () => fetchCountOffersForCollectible(args, config),
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export const useCountOffersForCollectible = (
|
|
60
|
+
args: UseCountOffersForCollectibleArgs,
|
|
61
|
+
) => {
|
|
62
|
+
const config = useConfig();
|
|
63
|
+
return useQuery(countOffersForCollectibleOptions(args, config));
|
|
64
|
+
};
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useCallback, useState } from 'react';
|
|
2
2
|
import type { Hash } from 'viem';
|
|
3
|
+
import type { TransactionError } from '../../utils/_internal/error/transaction';
|
|
3
4
|
import {
|
|
4
5
|
type ListingInput,
|
|
5
|
-
TransactionType,
|
|
6
6
|
type TransactionSteps,
|
|
7
|
+
TransactionType,
|
|
7
8
|
} from '../_internal/transaction-machine/execute-transaction';
|
|
8
9
|
import {
|
|
9
|
-
useTransactionMachine,
|
|
10
10
|
type UseTransactionMachineConfig,
|
|
11
|
+
useTransactionMachine,
|
|
11
12
|
} from '../_internal/transaction-machine/useTransactionMachine';
|
|
12
13
|
|
|
13
14
|
interface UseCreateListingArgs
|
|
14
15
|
extends Omit<UseTransactionMachineConfig, 'type'> {
|
|
15
16
|
onSuccess?: (hash: Hash) => void;
|
|
16
|
-
onError?: (error:
|
|
17
|
+
onError?: (error: TransactionError) => void;
|
|
17
18
|
onTransactionSent?: (hash: Hash) => void;
|
|
18
19
|
}
|
|
19
20
|
|
|
@@ -26,7 +27,7 @@ export const useCreateListing = ({
|
|
|
26
27
|
const [isLoading, setIsLoading] = useState(false);
|
|
27
28
|
const [steps, setSteps] = useState<TransactionSteps | null>(null);
|
|
28
29
|
|
|
29
|
-
const machine = useTransactionMachine(
|
|
30
|
+
const { machine, isLoading: isMachineLoading } = useTransactionMachine(
|
|
30
31
|
{
|
|
31
32
|
...config,
|
|
32
33
|
type: TransactionType.LISTING,
|
|
@@ -40,26 +41,24 @@ export const useCreateListing = ({
|
|
|
40
41
|
async (props: ListingInput) => {
|
|
41
42
|
if (!machine) return;
|
|
42
43
|
setIsLoading(true);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
setSteps(generatedSteps);
|
|
46
|
-
} catch (error) {
|
|
47
|
-
onError?.(error as Error);
|
|
48
|
-
} finally {
|
|
44
|
+
const generatedSteps = await machine.getTransactionSteps(props);
|
|
45
|
+
if (!generatedSteps) {
|
|
49
46
|
setIsLoading(false);
|
|
47
|
+
return;
|
|
50
48
|
}
|
|
49
|
+
setSteps(generatedSteps);
|
|
50
|
+
setIsLoading(false);
|
|
51
51
|
},
|
|
52
52
|
[machine, onError],
|
|
53
53
|
);
|
|
54
54
|
|
|
55
55
|
return {
|
|
56
|
-
createListing: (props: ListingInput) => machine?.start(
|
|
56
|
+
createListing: (props: ListingInput) => machine?.start(props),
|
|
57
57
|
getListingSteps: (props: ListingInput) => ({
|
|
58
58
|
isLoading,
|
|
59
59
|
steps,
|
|
60
60
|
refreshSteps: () => loadSteps(props),
|
|
61
61
|
}),
|
|
62
|
-
|
|
63
|
-
onSuccess,
|
|
62
|
+
isLoading: isMachineLoading,
|
|
64
63
|
};
|
|
65
64
|
};
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { queryOptions, useQuery } from '@tanstack/react-query';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import {
|
|
3
|
+
import type { MarketplaceConfig, SdkConfig } from '../../types';
|
|
4
|
+
import { CollectionNotFoundError } from '../../utils/_internal/error/transaction';
|
|
4
5
|
import {
|
|
5
|
-
ChainIdSchema,
|
|
6
6
|
AddressSchema,
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
type ChainId,
|
|
8
|
+
ChainIdSchema,
|
|
9
9
|
type Currency,
|
|
10
|
-
|
|
10
|
+
QueryArgSchema,
|
|
11
11
|
configKeys,
|
|
12
12
|
currencyKeys,
|
|
13
|
-
|
|
13
|
+
getMarketplaceClient,
|
|
14
|
+
getQueryClient,
|
|
14
15
|
} from '../_internal';
|
|
15
|
-
import
|
|
16
|
+
import { useConfig } from './useConfig';
|
|
16
17
|
|
|
17
18
|
const ChainIdCoerce = ChainIdSchema.transform((val) => val.toString());
|
|
18
19
|
|
|
@@ -48,7 +49,7 @@ const selectCurrencies = (data: Currency[], args: UseCurrenciesArgs) => {
|
|
|
48
49
|
);
|
|
49
50
|
|
|
50
51
|
if (!collection) {
|
|
51
|
-
throw new
|
|
52
|
+
throw new CollectionNotFoundError(argsParsed.collectionAddress!);
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
return data.filter(
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { queryOptions, useQuery } from '@tanstack/react-query';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import {
|
|
3
|
+
import type { SdkConfig } from '../../types';
|
|
4
4
|
import {
|
|
5
|
-
ChainIdSchema,
|
|
6
5
|
AddressSchema,
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
type ChainId,
|
|
7
|
+
ChainIdSchema,
|
|
9
8
|
type Currency,
|
|
9
|
+
QueryArgSchema,
|
|
10
10
|
currencyKeys,
|
|
11
|
-
|
|
11
|
+
getMarketplaceClient,
|
|
12
12
|
getQueryClient,
|
|
13
13
|
} from '../_internal';
|
|
14
|
-
import
|
|
14
|
+
import { useConfig } from './useConfig';
|
|
15
15
|
|
|
16
16
|
const ChainIdCoerce = ChainIdSchema.transform((val) => val.toString());
|
|
17
17
|
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { queryOptions, useQuery } from '@tanstack/react-query';
|
|
2
|
+
import type { Hex } from 'viem';
|
|
3
|
+
import { useAccount } from 'wagmi';
|
|
2
4
|
import { z } from 'zod';
|
|
3
5
|
import type { SdkConfig } from '../../types';
|
|
4
6
|
import {
|
|
5
7
|
AddressSchema,
|
|
6
8
|
ChainIdSchema,
|
|
7
|
-
getMarketplaceClient,
|
|
8
9
|
MarketplaceKind,
|
|
9
10
|
QueryArgSchema,
|
|
10
11
|
WalletKind,
|
|
12
|
+
getMarketplaceClient,
|
|
11
13
|
} from '../_internal';
|
|
12
14
|
import { useConfig } from './useConfig';
|
|
13
|
-
import { useAccount } from 'wagmi';
|
|
14
|
-
import type { Hex } from 'viem';
|
|
15
15
|
|
|
16
16
|
export const UseGenerateBuyTransactionArgsSchema = z.object({
|
|
17
17
|
chainId: ChainIdSchema.pipe(z.coerce.string()),
|