@coinlist-co/react 0.4.0 → 0.5.1
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-CRACFEJ4.js +17 -0
- package/dist/chunk-CRACFEJ4.js.map +1 -0
- package/dist/{chunk-NC45IO63.js → chunk-N3WBC2VS.js} +20 -325
- package/dist/chunk-N3WBC2VS.js.map +1 -0
- package/dist/chunk-V6WO67RO.js +311 -0
- package/dist/chunk-V6WO67RO.js.map +1 -0
- package/dist/client/index.cjs +1013 -220
- package/dist/client/index.cjs.map +1 -1
- package/dist/client/index.d.cts +526 -9
- package/dist/client/index.d.ts +526 -9
- package/dist/client/index.js +1464 -94
- package/dist/client/index.js.map +1 -1
- package/dist/{participation-DMMEDxON.d.cts → requirement-BEO42QOr.d.cts} +204 -2
- package/dist/{participation-E-bT-GXJ.d.ts → requirement-BEO42QOr.d.ts} +204 -2
- package/dist/server/index.cjs +50 -100
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.cts +67 -24
- package/dist/server/index.d.ts +67 -24
- package/dist/server/index.js +54 -87
- package/dist/server/index.js.map +1 -1
- package/dist/shared/index.cjs +375 -0
- package/dist/shared/index.cjs.map +1 -0
- package/dist/shared/index.d.cts +35 -0
- package/dist/shared/index.d.ts +35 -0
- package/dist/{client/core → shared}/index.js +35 -16
- package/dist/shared/index.js.map +1 -0
- package/package.json +7 -22
- package/dist/RequirementItem-B-MvcxSr.d.cts +0 -37
- package/dist/RequirementItem-DcYot2uC.d.ts +0 -37
- package/dist/chunk-EHZ6PIGN.js +0 -414
- package/dist/chunk-EHZ6PIGN.js.map +0 -1
- package/dist/chunk-NC45IO63.js.map +0 -1
- package/dist/chunk-RIFATQB5.js +0 -257
- package/dist/chunk-RIFATQB5.js.map +0 -1
- package/dist/chunk-UGJUTRXC.js +0 -304
- package/dist/chunk-UGJUTRXC.js.map +0 -1
- package/dist/chunk-YJQMJFA7.js +0 -16
- package/dist/chunk-YJQMJFA7.js.map +0 -1
- package/dist/client/components/index.cjs +0 -1108
- package/dist/client/components/index.cjs.map +0 -1
- package/dist/client/components/index.d.cts +0 -139
- package/dist/client/components/index.d.ts +0 -139
- package/dist/client/components/index.js +0 -558
- package/dist/client/components/index.js.map +0 -1
- package/dist/client/core/index.cjs +0 -1047
- package/dist/client/core/index.cjs.map +0 -1
- package/dist/client/core/index.d.cts +0 -23
- package/dist/client/core/index.d.ts +0 -23
- package/dist/client/core/index.js.map +0 -1
- package/dist/client/hooks/index.cjs +0 -307
- package/dist/client/hooks/index.cjs.map +0 -1
- package/dist/client/hooks/index.d.cts +0 -126
- package/dist/client/hooks/index.d.ts +0 -126
- package/dist/client/hooks/index.js +0 -19
- package/dist/client/hooks/index.js.map +0 -1
- package/dist/coinlist-client-BSxpqylo.d.ts +0 -158
- package/dist/coinlist-client-Cah5c_aF.d.cts +0 -158
- package/dist/requirement-XWT0T_zO.d.cts +0 -205
- package/dist/requirement-XWT0T_zO.d.ts +0 -205
- package/dist/useCoinListRequirements-B5-ZPOMz.d.ts +0 -80
- package/dist/useCoinListRequirements-Cuc32Tqw.d.cts +0 -80
package/dist/client/index.d.cts
CHANGED
|
@@ -1,14 +1,170 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as react from 'react';
|
|
2
3
|
import { ReactNode } from 'react';
|
|
3
|
-
import { C as
|
|
4
|
-
export { A as AuthState, a as CoinListClient, O as OauthClientErrorReason, b as OauthClientResult, c as createCoinListClient } from '../coinlist-client-Cah5c_aF.cjs';
|
|
5
|
-
export { C as ChecklistStatus, R as RequirementStatus, a as RequirementVariant } from '../RequirementItem-B-MvcxSr.cjs';
|
|
6
|
-
export { CompleteCoinListOAuthFailureReason, LoadOfferDetailsReason, LoadOfferDetailsState, LoadParticipationsReason, LoadParticipationsState, UseCoinListOfferDetailsOptions, UseCoinListOfferDetailsResult, UseCompleteCoinListOAuthOptions, UseParticipationsOptions, UseParticipationsResult, useCoinList, useCoinListOfferDetails, useCompleteCoinListOAuth, useParticipations } from './hooks/index.cjs';
|
|
7
|
-
export { L as LoadOffersReason, a as LoadOffersState, b as LoadRequirementsReason, c as LoadRequirementsState, U as UseCoinListOffersOptions, d as UseCoinListOffersResult, e as UseCoinListRequirementsOptions, f as UseCoinListRequirementsResult, u as useCoinListOffers, g as useCoinListRequirements } from '../useCoinListRequirements-Cuc32Tqw.cjs';
|
|
8
|
-
export { A as AuthorizationCode, B as Blockchain, C as ClientId, a as ClientSecret, b as CodeChallenge, c as CodeVerifier, d as CreateParticipationParams, e as Cursor, O as OAuthAccessToken, f as OAuthRefreshToken, g as OAuthSession, P as PaginatedResponse, h as PaginatedResponseDto, i as PaginationParams, j as Participation, k as ParticipationId, l as ParticipationStatus, m as ParticipationsPaginationParams, R as RedirectUri, W as WalletAddress, n as fetchAllPages } from '../participation-DMMEDxON.cjs';
|
|
9
|
-
export { F as FaqItem, L as Link, M as Milestone, O as Offer, a as OfferDetail, b as OfferId, c as OfferOption, d as OfferOptionId, e as OfferOptionSlug, f as OfferSlug, R as Requirement, g as RequirementId, h as RequirementStatusInfo, i as RequirementStatusValue, j as RequirementType, T as TermItem } from '../requirement-XWT0T_zO.cjs';
|
|
10
|
-
export { User, UserEmail, UserId } from './core/index.cjs';
|
|
4
|
+
import { A as AuthorizationCode, C as CodeVerifier, a as Config, O as OAuthAccessToken, b as Offer, P as PaginationParams, c as PaginatedResponse, d as OfferId, e as OfferDetail, f as Participation, g as ParticipationsPaginationParams, h as ParticipationId, i as CreateParticipationParams, j as OfferOptionId, R as Requirement, k as RequirementStatusInfo, l as RequirementType, m as RequirementStatusValue } from '../requirement-BEO42QOr.cjs';
|
|
11
5
|
|
|
6
|
+
type AuthState = 'unknown' | 'logged-in' | 'logged-out';
|
|
7
|
+
/** Discriminated error reasons from {@link CoinListClient.completeOAuth}. */
|
|
8
|
+
type OauthClientErrorReason = 'user_canceled' | 'missing_state' | 'invalid_state' | 'missing_code' | 'missing_code_verifier';
|
|
9
|
+
type OauthClientResult = {
|
|
10
|
+
type: 'ok';
|
|
11
|
+
code: AuthorizationCode;
|
|
12
|
+
codeVerifier: CodeVerifier;
|
|
13
|
+
} | {
|
|
14
|
+
type: 'error';
|
|
15
|
+
reason: OauthClientErrorReason;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/** Session storage keys for OAuth PKCE (used by startOauth and completeOauth). */
|
|
19
|
+
declare const OAUTH_STATE_KEY = "coinlist.oauth_state";
|
|
20
|
+
declare const OAUTH_CODE_VERIFIER_KEY = "coinlist.oauth_code_verifier";
|
|
21
|
+
interface ClientConfig extends Config {
|
|
22
|
+
/**
|
|
23
|
+
* The SDK user must provide this function. It is responsible for fetching a
|
|
24
|
+
* valid {@link OAuthAccessToken}, or **null** for logged-out users. If your
|
|
25
|
+
* backend is in TypeScript, it is recommended to use
|
|
26
|
+
* {@link CoinListServer#accessToken} from `@/server/coinlist.server`.
|
|
27
|
+
*/
|
|
28
|
+
getAccessToken: () => Promise<OAuthAccessToken | null>;
|
|
29
|
+
/**
|
|
30
|
+
* Recommended to leave undefined. Used to change the CoinList environment;
|
|
31
|
+
* default is production.
|
|
32
|
+
*/
|
|
33
|
+
coinlistBaseUrl?: string;
|
|
34
|
+
}
|
|
35
|
+
interface CoinListClient {
|
|
36
|
+
/**
|
|
37
|
+
* Calls the provided {@link ClientConfig.getAccessToken} lambda to determine
|
|
38
|
+
* the user's {@link AuthState}. This is called automatically by {@link CoinListProvider};
|
|
39
|
+
* you typically do not need to call it yourself unless you are using the client
|
|
40
|
+
* outside of the provider.
|
|
41
|
+
*/
|
|
42
|
+
init(): Promise<AuthState>;
|
|
43
|
+
/**
|
|
44
|
+
* Returns the current auth state: `'logged-in'`, `'logged-out'`, or `'unknown'`.
|
|
45
|
+
* Returns **unknown** until {@link CoinListClient.init} has completed. It is
|
|
46
|
+
* recommended to use the `const { isReady, coinlist } = useCoinList()` hook to know when
|
|
47
|
+
* the SDK has initialized, or to manually await {@link CoinListClient.init}
|
|
48
|
+
* before relying on this value.
|
|
49
|
+
*/
|
|
50
|
+
getAuthState(): AuthState;
|
|
51
|
+
/**
|
|
52
|
+
* Starts the OAuth flow with PKCE. Generates a random `state` and `code_verifier`,
|
|
53
|
+
* stores them in sessionStorage (for validation in {@link CoinListClient.completeOAuth}
|
|
54
|
+
* on redirect), then redirects the user to the CoinList authorization page. After
|
|
55
|
+
* the user authorizes, they are sent back to your application's redirect URI; call
|
|
56
|
+
* {@link CoinListClient.completeOAuth} on that page to finish the flow.
|
|
57
|
+
*/
|
|
58
|
+
startOAuth(): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Completes the OAuth flow on the FE with PKCE and state validation. Parses the
|
|
61
|
+
* redirect URL (state, code) and validates them against sessionStorage
|
|
62
|
+
* (state, code_verifier). The state check protects against CSRF (cross-site
|
|
63
|
+
* request forgery). Call this on the frontend page the user is redirected
|
|
64
|
+
* to after authorizing.
|
|
65
|
+
*
|
|
66
|
+
* On `ok`: Call your backend to exchange the short-lived `authorizationCode`
|
|
67
|
+
* (and the returned `codeVerifier`) for a long-lived session. If your backend
|
|
68
|
+
* is in TypeScript, you can use {@link CoinListServer#completeOAuth} from
|
|
69
|
+
* `@/server/coinlist.server` (CoinListServer) to perform that exchange.
|
|
70
|
+
*
|
|
71
|
+
* On `error`: `reason` is an {@link OauthClientErrorReason} (e.g. `'missing_state'`, `'invalid_state'`) so you can switch on it and surface a message to the user.
|
|
72
|
+
*/
|
|
73
|
+
completeOAuth(): OauthClientResult;
|
|
74
|
+
/**
|
|
75
|
+
* Clears the in-memory access token. Note: you need to manually
|
|
76
|
+
* also logout on the backend via CoinListServer#logout to clear the session cookie.
|
|
77
|
+
*/
|
|
78
|
+
logout(): void;
|
|
79
|
+
/**
|
|
80
|
+
* Fetches all offers by iterating through every paginated response.
|
|
81
|
+
*
|
|
82
|
+
* This method must be called only when the user's {@link AuthState} is
|
|
83
|
+
* `'logged-in'`. If the user is not authenticated, it throws
|
|
84
|
+
* {@link NotAuthenticatedError}.
|
|
85
|
+
*/
|
|
86
|
+
fetchOffers(): Promise<Offer[]>;
|
|
87
|
+
/**
|
|
88
|
+
* Fetches a single page of offers.
|
|
89
|
+
*
|
|
90
|
+
* This method must be called only when the user's {@link AuthState} is
|
|
91
|
+
* `'logged-in'`. If the user is not authenticated, it throws
|
|
92
|
+
* {@link NotAuthenticatedError}.
|
|
93
|
+
*/
|
|
94
|
+
fetchOffersPage(params: PaginationParams): Promise<PaginatedResponse<Offer>>;
|
|
95
|
+
/**
|
|
96
|
+
* Fetches details for a given offer by its id.
|
|
97
|
+
*
|
|
98
|
+
* This method must be called only when the user's {@link AuthState} is
|
|
99
|
+
* `'logged-in'`. If the user is not authenticated, it throws
|
|
100
|
+
* {@link NotAuthenticatedError}.
|
|
101
|
+
*/
|
|
102
|
+
fetchOfferDetails(id: OfferId): Promise<OfferDetail>;
|
|
103
|
+
/**
|
|
104
|
+
* Fetches all participations by iterating through every paginated response.
|
|
105
|
+
*
|
|
106
|
+
* This method must be called only when the user's {@link AuthState} is
|
|
107
|
+
* `'logged-in'`. If the user is not authenticated, it throws
|
|
108
|
+
* {@link NotAuthenticatedError}.
|
|
109
|
+
*/
|
|
110
|
+
fetchParticipations(offerId?: OfferId): Promise<Participation[]>;
|
|
111
|
+
/**
|
|
112
|
+
* Fetches a single page of participations, optionally filtered by offer.
|
|
113
|
+
*
|
|
114
|
+
* This method must be called only when the user's {@link AuthState} is
|
|
115
|
+
* `'logged-in'`. If the user is not authenticated, it throws
|
|
116
|
+
* {@link NotAuthenticatedError}.
|
|
117
|
+
*/
|
|
118
|
+
fetchParticipationsPage(params: ParticipationsPaginationParams): Promise<PaginatedResponse<Participation>>;
|
|
119
|
+
/**
|
|
120
|
+
* Fetches a participation by id.
|
|
121
|
+
*
|
|
122
|
+
* This method must be called only when the user's {@link AuthState} is
|
|
123
|
+
* `'logged-in'`. If the user is not authenticated, it throws
|
|
124
|
+
* {@link NotAuthenticatedError}.
|
|
125
|
+
*/
|
|
126
|
+
fetchParticipation(id: ParticipationId): Promise<Participation>;
|
|
127
|
+
/**
|
|
128
|
+
* Creates a participation.
|
|
129
|
+
*
|
|
130
|
+
* This method must be called only when the user's {@link AuthState} is
|
|
131
|
+
* `'logged-in'`. If the user is not authenticated, it throws
|
|
132
|
+
* {@link NotAuthenticatedError}.
|
|
133
|
+
*/
|
|
134
|
+
createParticipation(params: CreateParticipationParams): Promise<Participation>;
|
|
135
|
+
/**
|
|
136
|
+
* Fetches the requirements for all options of a given offer, grouped by option ID.
|
|
137
|
+
*
|
|
138
|
+
* This method must be called only when the user's {@link AuthState} is
|
|
139
|
+
* `'logged-in'`. If the user is not authenticated, it throws
|
|
140
|
+
* {@link NotAuthenticatedError}.
|
|
141
|
+
*/
|
|
142
|
+
fetchOfferRequirements(offerId: OfferId): Promise<Record<OfferOptionId, Requirement[]>>;
|
|
143
|
+
/**
|
|
144
|
+
* Fetches the user's requirement statuses for a given offer.
|
|
145
|
+
*
|
|
146
|
+
* This method must be called only when the user's {@link AuthState} is
|
|
147
|
+
* `'logged-in'`. If the user is not authenticated, it throws
|
|
148
|
+
* {@link NotAuthenticatedError}.
|
|
149
|
+
*/
|
|
150
|
+
fetchRequirementStatuses(offerId: OfferId): Promise<RequirementStatusInfo[]>;
|
|
151
|
+
/**
|
|
152
|
+
* Opens the CoinList page for completing a given requirement in a new tab.
|
|
153
|
+
* For `jurisdiction` requirements there is no CTA, so this is a no-op.
|
|
154
|
+
*/
|
|
155
|
+
handleRequirement(requirement: Requirement): void;
|
|
156
|
+
/**
|
|
157
|
+
* Opens the CoinList support ticket page in a new tab.
|
|
158
|
+
*/
|
|
159
|
+
contactSupport(): void;
|
|
160
|
+
}
|
|
161
|
+
declare function createCoinListClient(config: ClientConfig): CoinListClient;
|
|
162
|
+
|
|
163
|
+
type CoinListContextValue = {
|
|
164
|
+
coinlist: CoinListClient;
|
|
165
|
+
isReady: boolean;
|
|
166
|
+
};
|
|
167
|
+
declare const CoinListContext: react.Context<CoinListContextValue | null>;
|
|
12
168
|
type CoinListProviderProps = {
|
|
13
169
|
config: ClientConfig;
|
|
14
170
|
children: ReactNode;
|
|
@@ -18,4 +174,365 @@ type CoinListProviderProps = {
|
|
|
18
174
|
*/
|
|
19
175
|
declare function CoinListProvider({ config, children }: CoinListProviderProps): react_jsx_runtime.JSX.Element;
|
|
20
176
|
|
|
21
|
-
|
|
177
|
+
interface CoinListSignInCardProps {
|
|
178
|
+
state?: 'idle' | 'error';
|
|
179
|
+
/**
|
|
180
|
+
* Called when the user clicks the sign-in button. Defaults to
|
|
181
|
+
* {@link CoinListClient#startOAuth}, which redirects to the CoinList
|
|
182
|
+
* authorization page. Pass your own handler to override this behavior.
|
|
183
|
+
*/
|
|
184
|
+
onSignIn?: () => void;
|
|
185
|
+
/** Called when the user clicks the close button. When omitted, no close button is rendered. */
|
|
186
|
+
onClose?: () => void;
|
|
187
|
+
className?: string;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Sign-in card that prompts the user to authenticate with CoinList.
|
|
191
|
+
*
|
|
192
|
+
* Use this component only inside a tree wrapped by {@link CoinListProvider}.
|
|
193
|
+
* By default, clicking the sign-in button starts the CoinList OAuth flow via
|
|
194
|
+
* {@link CoinListClient#startOAuth}; pass `onSignIn` to override.
|
|
195
|
+
*/
|
|
196
|
+
declare function CoinListSignInCard({ state, onSignIn, onClose, className, }?: CoinListSignInCardProps): ReactNode;
|
|
197
|
+
|
|
198
|
+
type OfferCardUi = {
|
|
199
|
+
tagline: string | null;
|
|
200
|
+
bannerUrl: string | null;
|
|
201
|
+
logoUrl: string | null;
|
|
202
|
+
formattedStartsAt: string;
|
|
203
|
+
formattedEndsAt: string;
|
|
204
|
+
};
|
|
205
|
+
declare const OfferCardUi: {
|
|
206
|
+
fromDomain: (offer: Offer) => OfferCardUi;
|
|
207
|
+
};
|
|
208
|
+
interface Props {
|
|
209
|
+
offer: OfferCardUi;
|
|
210
|
+
/** Optional click handler. When provided, the card renders as interactive. */
|
|
211
|
+
onClick?: () => void;
|
|
212
|
+
/** Optional className applied to the card root element. */
|
|
213
|
+
className?: string;
|
|
214
|
+
/** Optional className applied to an outer wrapper element. */
|
|
215
|
+
containerClassName?: string;
|
|
216
|
+
}
|
|
217
|
+
declare function OfferCard({ offer, onClick, className, containerClassName, }: Props): ReactNode;
|
|
218
|
+
|
|
219
|
+
interface OffersGridProps {
|
|
220
|
+
/** Maximum number of columns to render when horizontal space allows. */
|
|
221
|
+
maxColumns?: number;
|
|
222
|
+
/** Optional className applied to the grid element. */
|
|
223
|
+
className?: string;
|
|
224
|
+
/** Optional className applied to the outer wrapper element. */
|
|
225
|
+
containerClassName?: string;
|
|
226
|
+
/** Optional loading slot shown while offers are being fetched. */
|
|
227
|
+
loading?: ReactNode;
|
|
228
|
+
/** Optional error slot shown when loading offers fails. */
|
|
229
|
+
error?: ReactNode;
|
|
230
|
+
/** Optional empty state slot shown when there are no available offers. */
|
|
231
|
+
emptyState?: ReactNode;
|
|
232
|
+
/** Optional per-offer click handler; when omitted, cards are not clickable. */
|
|
233
|
+
onOfferClick?: (offer: Offer) => void;
|
|
234
|
+
/**
|
|
235
|
+
* Offers pre-fetched on the server (e.g. via `CoinListServer.fetchOffers()`).
|
|
236
|
+
* When provided, the component uses this data as-is and skips the client-side fetch entirely.
|
|
237
|
+
*/
|
|
238
|
+
data?: Offer[];
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Displays a responsive grid of offers backed by {@link useOffers}.
|
|
242
|
+
*
|
|
243
|
+
* Pass `data` (pre-fetched server-side) to use that data as-is and skip
|
|
244
|
+
* the client-side fetch entirely.
|
|
245
|
+
*
|
|
246
|
+
* Uses `loading` / `error` slots when provided; otherwise renders standard
|
|
247
|
+
* fallback loading and error states. Offer cards are interactive only when
|
|
248
|
+
* `onOfferClick` is provided.
|
|
249
|
+
*/
|
|
250
|
+
declare function OffersGrid({ data, maxColumns, className, containerClassName, loading, error, emptyState, onOfferClick, }?: OffersGridProps): ReactNode;
|
|
251
|
+
|
|
252
|
+
type RequirementVariant = 'verification' | 'wallet';
|
|
253
|
+
declare const RequirementVariant: {
|
|
254
|
+
fromType(type: RequirementType): RequirementVariant;
|
|
255
|
+
};
|
|
256
|
+
type RequirementStatus = 'required' | 'pending' | 'completed' | 'rejected';
|
|
257
|
+
declare const RequirementStatus: {
|
|
258
|
+
fromStatusValue(status: RequirementStatusValue): RequirementStatus;
|
|
259
|
+
};
|
|
260
|
+
type ChecklistStatus = 'inProgress' | 'eligible' | 'ineligible';
|
|
261
|
+
declare const ChecklistStatus: {
|
|
262
|
+
derive(statuses: RequirementStatusInfo[]): ChecklistStatus;
|
|
263
|
+
};
|
|
264
|
+
type RequirementItemUi = {
|
|
265
|
+
variant: RequirementVariant;
|
|
266
|
+
status: RequirementStatus;
|
|
267
|
+
label: string;
|
|
268
|
+
description: string;
|
|
269
|
+
walletAddress?: string;
|
|
270
|
+
};
|
|
271
|
+
declare const RequirementItemUi: {
|
|
272
|
+
fromDomain(req: Requirement, statusInfo: RequirementStatusInfo | undefined, label: string, description: string, walletAddress?: string): RequirementItemUi;
|
|
273
|
+
};
|
|
274
|
+
interface RequirementItemProps {
|
|
275
|
+
ui: RequirementItemUi;
|
|
276
|
+
expanded?: boolean;
|
|
277
|
+
onToggle?: () => void;
|
|
278
|
+
walletAddress?: string;
|
|
279
|
+
className?: string;
|
|
280
|
+
onAction?: (() => void) | null;
|
|
281
|
+
onContactSupport?: (() => void) | null;
|
|
282
|
+
}
|
|
283
|
+
declare function RequirementItem({ ui, expanded, onToggle, className, onAction, onContactSupport, }: RequirementItemProps): react_jsx_runtime.JSX.Element;
|
|
284
|
+
|
|
285
|
+
type LoadRequirementsReason = 'not-authenticated' | 'generic-error';
|
|
286
|
+
type LoadRequirementsState = {
|
|
287
|
+
type: 'LOADING';
|
|
288
|
+
} | {
|
|
289
|
+
type: 'ERROR';
|
|
290
|
+
reason: LoadRequirementsReason;
|
|
291
|
+
} | {
|
|
292
|
+
type: 'CONTENT';
|
|
293
|
+
requirements: Record<OfferOptionId, Requirement[]>;
|
|
294
|
+
statuses: RequirementStatusInfo[];
|
|
295
|
+
};
|
|
296
|
+
type RequirementsData = {
|
|
297
|
+
requirements: Record<OfferOptionId, Requirement[]>;
|
|
298
|
+
statuses: RequirementStatusInfo[];
|
|
299
|
+
};
|
|
300
|
+
interface UseRequirementsOptions {
|
|
301
|
+
/**
|
|
302
|
+
* Requirements data pre-fetched on the server (e.g. via
|
|
303
|
+
* `CoinListServer.fetchOfferRequirements()` + `fetchRequirementStatuses()`).
|
|
304
|
+
* When provided, the hook uses this data as-is and skips the initial client-side fetch.
|
|
305
|
+
* Calling `refetch()` will still trigger a fresh fetch.
|
|
306
|
+
*/
|
|
307
|
+
data?: RequirementsData;
|
|
308
|
+
}
|
|
309
|
+
interface UseRequirementsResult {
|
|
310
|
+
requirementsState: LoadRequirementsState;
|
|
311
|
+
/** Triggers a re-fetch of requirements and statuses. */
|
|
312
|
+
refetch: () => void;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Loads requirements (grouped by option ID) and requirement statuses for a
|
|
316
|
+
* given offer, then exposes them via a state machine.
|
|
317
|
+
*
|
|
318
|
+
* Pass `data` (pre-fetched server-side) to use that data as-is and skip
|
|
319
|
+
* the initial client-side fetch. Calling `refetch()` will still trigger a fresh fetch.
|
|
320
|
+
*
|
|
321
|
+
* Returns `LOADING` while CoinList is initializing or while data is being fetched.
|
|
322
|
+
* Returns `CONTENT` with requirements and statuses on success.
|
|
323
|
+
* Returns `ERROR` with:
|
|
324
|
+
* - `not-authenticated` when fetching fails with {@link NotAuthenticatedError}
|
|
325
|
+
* - `generic-error` for any other failure
|
|
326
|
+
*/
|
|
327
|
+
declare function useRequirements(offerId: OfferId, options?: UseRequirementsOptions): UseRequirementsResult;
|
|
328
|
+
|
|
329
|
+
interface RequirementsChecklistProps {
|
|
330
|
+
offerId: OfferId;
|
|
331
|
+
optionId: OfferOptionId;
|
|
332
|
+
title: string;
|
|
333
|
+
description: string;
|
|
334
|
+
onContinue?: () => void;
|
|
335
|
+
/**
|
|
336
|
+
* Called when the user clicks a requirement's action button (e.g. "Continue", "Connect wallet").
|
|
337
|
+
* Defaults to {@link CoinListClient#handleRequirement}, which opens the corresponding CoinList
|
|
338
|
+
* page in a new tab. Pass your own handler to override this behavior, or pass `null` to disable
|
|
339
|
+
* the action button entirely.
|
|
340
|
+
*/
|
|
341
|
+
onRequirementActionOverride?: ((requirement: Requirement) => void) | null;
|
|
342
|
+
/**
|
|
343
|
+
* Called when the user clicks "Contact support" on a rejected requirement.
|
|
344
|
+
* Defaults to {@link CoinListClient#contactSupport}, which opens the CoinList support ticket
|
|
345
|
+
* page in a new tab. Pass your own handler to override this behavior, or pass `null` to disable
|
|
346
|
+
* the contact support button entirely.
|
|
347
|
+
*/
|
|
348
|
+
onContactSupportOverride?: ((requirement: Requirement) => void) | null;
|
|
349
|
+
/** Override the default label for a requirement type. */
|
|
350
|
+
getLabel?: (requirement: Requirement) => string;
|
|
351
|
+
/** Override the default description for a requirement type. */
|
|
352
|
+
getDescription?: (requirement: Requirement) => string | null;
|
|
353
|
+
/** Optional loading slot. */
|
|
354
|
+
loading?: ReactNode;
|
|
355
|
+
/** Optional error slot. */
|
|
356
|
+
error?: ReactNode;
|
|
357
|
+
className?: string;
|
|
358
|
+
/**
|
|
359
|
+
* Requirements data pre-fetched on the server (e.g. via
|
|
360
|
+
* `CoinListServer.fetchOfferRequirements()` + `fetchRequirementStatuses()`).
|
|
361
|
+
* When provided, the component uses this data as-is and skips the client-side fetch entirely.
|
|
362
|
+
*/
|
|
363
|
+
data?: RequirementsData;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Connected requirements checklist that fetches requirements and statuses
|
|
367
|
+
* via {@link useRequirements} and renders requirement items for the
|
|
368
|
+
* specified option.
|
|
369
|
+
*
|
|
370
|
+
* Pass `data` (pre-fetched server-side) to use that data as-is and skip
|
|
371
|
+
* the initial client-side fetch.
|
|
372
|
+
*
|
|
373
|
+
* By default, clicking a requirement's action button opens the corresponding
|
|
374
|
+
* CoinList page in a new tab via {@link CoinListClient#handleRequirement}. It is
|
|
375
|
+
* recommended to omit `onRequirementActionOverride` and rely on this default.
|
|
376
|
+
* Pass your own handler only if you need custom navigation behavior, or `null`
|
|
377
|
+
* to disable the action button entirely.
|
|
378
|
+
*/
|
|
379
|
+
declare function RequirementsChecklist({ offerId, optionId, title, description, onContinue, onRequirementActionOverride, onContactSupportOverride, getLabel, getDescription, loading, error, className, data, }: RequirementsChecklistProps): ReactNode;
|
|
380
|
+
|
|
381
|
+
interface UseCoinListResult {
|
|
382
|
+
/**
|
|
383
|
+
* Indicates whether the CoinList client has been initialized and ready to use.
|
|
384
|
+
* While isReady is false, then the current user state will be `unknown`.
|
|
385
|
+
*/
|
|
386
|
+
isReady: boolean;
|
|
387
|
+
coinlist: CoinListClient;
|
|
388
|
+
}
|
|
389
|
+
declare function useCoinList(): UseCoinListResult;
|
|
390
|
+
declare class CoinListClientInitializationError extends Error {
|
|
391
|
+
constructor(message?: string);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Reasons passed to {@link UseCompleteOAuthOptions.onFailure} when the
|
|
396
|
+
* OAuth callback cannot be completed. Includes PKCE / redirect validation
|
|
397
|
+
* errors from {@link CoinListClient.completeOAuth} and a dedicated value when
|
|
398
|
+
* {@link UseCompleteOAuthOptions.postOAuthComplete} fails or rejects.
|
|
399
|
+
*/
|
|
400
|
+
type CompleteOAuthFailureReason = OauthClientErrorReason | 'complete_request_failed';
|
|
401
|
+
interface UseCompleteOAuthOptions {
|
|
402
|
+
/**
|
|
403
|
+
* Exchange the authorization code on your backend (e.g. POST to your API).
|
|
404
|
+
* Return `true` when the session was established successfully, `false` when
|
|
405
|
+
* the request completed but signing in failed. Rejections are treated like
|
|
406
|
+
* `false` and reported as {@link CompleteOAuthFailureReason}
|
|
407
|
+
* `"complete_request_failed"`.
|
|
408
|
+
*/
|
|
409
|
+
postOAuthComplete: (payload: {
|
|
410
|
+
code: AuthorizationCode;
|
|
411
|
+
codeVerifier: CodeVerifier;
|
|
412
|
+
}) => Promise<boolean>;
|
|
413
|
+
/**
|
|
414
|
+
* Called when the user denied access (`error` query parameter), when
|
|
415
|
+
* {@link CoinListClient.completeOAuth} fails PKCE/state validation, or when
|
|
416
|
+
* {@link UseCompleteOAuthOptions.postOAuthComplete} fails.
|
|
417
|
+
*/
|
|
418
|
+
onFailure: (reason: CompleteOAuthFailureReason) => void | Promise<void>;
|
|
419
|
+
/** Invoked after {@link UseCompleteOAuthOptions.postOAuthComplete} succeeds and {@link CoinListClient.init} has refreshed the client session. */
|
|
420
|
+
onSuccess: () => void | Promise<void>;
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Runs the CoinList OAuth callback once on mount: validates the redirect URL via
|
|
424
|
+
* {@link CoinListClient.completeOAuth}, exchanges the code via {@link UseCompleteOAuthOptions.postOAuthComplete},
|
|
425
|
+
* refreshes tokens with {@link CoinListClient.init}, then calls {@link UseCompleteOAuthOptions.onSuccess}.
|
|
426
|
+
*
|
|
427
|
+
* Framework-agnostic: reads `window.location` like {@link CoinListClient.completeOAuth}. Supply
|
|
428
|
+
* {@link UseCompleteOAuthOptions.postOAuthComplete}, {@link UseCompleteOAuthOptions.onFailure},
|
|
429
|
+
* and {@link UseCompleteOAuthOptions.onSuccess} to perform redirects or routing in your app.
|
|
430
|
+
*
|
|
431
|
+
* Must be used within {@link CoinListProvider}.
|
|
432
|
+
*/
|
|
433
|
+
declare function useCompleteOAuth(options: UseCompleteOAuthOptions): void;
|
|
434
|
+
|
|
435
|
+
type LoadOfferDetailsReason = 'not-authenticated' | 'generic-error';
|
|
436
|
+
type LoadOfferDetailsState = {
|
|
437
|
+
type: 'LOADING';
|
|
438
|
+
} | {
|
|
439
|
+
type: 'ERROR';
|
|
440
|
+
reason: LoadOfferDetailsReason;
|
|
441
|
+
} | {
|
|
442
|
+
type: 'CONTENT';
|
|
443
|
+
offerDetail: OfferDetail;
|
|
444
|
+
};
|
|
445
|
+
interface UseOfferDetailsOptions {
|
|
446
|
+
/**
|
|
447
|
+
* Offer detail pre-fetched on the server (e.g. via `CoinListServer.fetchOfferDetails()`).
|
|
448
|
+
* When provided, the hook uses this data as-is and skips the client-side fetch entirely.
|
|
449
|
+
*/
|
|
450
|
+
data?: OfferDetail;
|
|
451
|
+
}
|
|
452
|
+
interface UseOfferDetailsResult {
|
|
453
|
+
offerDetailsState: LoadOfferDetailsState;
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Loads CoinList offer details for a given offer id and exposes a UI-friendly state.
|
|
457
|
+
*
|
|
458
|
+
* Pass `data` (pre-fetched server-side) to use that data as-is and skip
|
|
459
|
+
* the client-side fetch entirely.
|
|
460
|
+
*
|
|
461
|
+
* Returns `LOADING` while CoinList is initializing or while details are being fetched.
|
|
462
|
+
* Returns `CONTENT` with the offer when `fetchOfferDetails()` succeeds.
|
|
463
|
+
* Returns `ERROR` with:
|
|
464
|
+
* - `not-authenticated` when fetching fails with {@link NotAuthenticatedError}
|
|
465
|
+
* - `generic-error` for any other failure
|
|
466
|
+
*/
|
|
467
|
+
declare function useOfferDetails(offerId: OfferId, options?: UseOfferDetailsOptions): UseOfferDetailsResult;
|
|
468
|
+
|
|
469
|
+
type LoadOffersReason = 'not-authenticated' | 'generic-error';
|
|
470
|
+
type LoadOffersState = {
|
|
471
|
+
type: 'LOADING';
|
|
472
|
+
} | {
|
|
473
|
+
type: 'ERROR';
|
|
474
|
+
reason: LoadOffersReason;
|
|
475
|
+
} | {
|
|
476
|
+
type: 'CONTENT';
|
|
477
|
+
offers: Offer[];
|
|
478
|
+
};
|
|
479
|
+
interface UseOffersOptions {
|
|
480
|
+
/**
|
|
481
|
+
* Offers pre-fetched on the server (e.g. via `CoinListServer.fetchOffers()`).
|
|
482
|
+
* When provided, the hook uses this data as-is and skips the client-side fetch entirely.
|
|
483
|
+
*/
|
|
484
|
+
data?: Offer[];
|
|
485
|
+
}
|
|
486
|
+
interface UseOffersResult {
|
|
487
|
+
offersState: LoadOffersState;
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* Loads all CoinList offers for the current user and exposes a UI-friendly state.
|
|
491
|
+
*
|
|
492
|
+
* Pass `data` (pre-fetched server-side) to use that data as-is and skip
|
|
493
|
+
* the client-side fetch entirely.
|
|
494
|
+
*
|
|
495
|
+
* Returns `LOADING` while CoinList is initializing or while offers are being fetched.
|
|
496
|
+
* Returns `CONTENT` with all offers when `fetchOffers()` succeeds.
|
|
497
|
+
* Returns `ERROR` with:
|
|
498
|
+
* - `not-authenticated` when fetching fails with {@link NotAuthenticatedError}
|
|
499
|
+
* - `generic-error` for any other failure
|
|
500
|
+
*/
|
|
501
|
+
declare function useOffers(options?: UseOffersOptions): UseOffersResult;
|
|
502
|
+
|
|
503
|
+
type LoadParticipationsReason = 'not-authenticated' | 'generic-error';
|
|
504
|
+
type LoadParticipationsState = {
|
|
505
|
+
type: 'LOADING';
|
|
506
|
+
} | {
|
|
507
|
+
type: 'ERROR';
|
|
508
|
+
reason: LoadParticipationsReason;
|
|
509
|
+
} | {
|
|
510
|
+
type: 'CONTENT';
|
|
511
|
+
participations: Participation[];
|
|
512
|
+
};
|
|
513
|
+
interface UseParticipationsOptions {
|
|
514
|
+
/**
|
|
515
|
+
* Participations pre-fetched on the server (e.g. via `CoinListServer.fetchParticipations()`).
|
|
516
|
+
* When provided, the hook uses this data as-is and skips the client-side fetch entirely.
|
|
517
|
+
*/
|
|
518
|
+
data?: Participation[];
|
|
519
|
+
}
|
|
520
|
+
interface UseParticipationsResult {
|
|
521
|
+
participationsState: LoadParticipationsState;
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* Loads all CoinList participations for the current user and exposes a UI-friendly state.
|
|
525
|
+
* Optionally filters by offer when `offerId` is provided.
|
|
526
|
+
*
|
|
527
|
+
* Pass `data` (pre-fetched server-side) to use that data as-is and skip
|
|
528
|
+
* the client-side fetch entirely.
|
|
529
|
+
*
|
|
530
|
+
* Returns `LOADING` while CoinList is initializing or while participations are being fetched.
|
|
531
|
+
* Returns `CONTENT` with all participations when `fetchParticipations()` succeeds.
|
|
532
|
+
* Returns `ERROR` with:
|
|
533
|
+
* - `not-authenticated` when fetching fails with {@link NotAuthenticatedError}
|
|
534
|
+
* - `generic-error` for any other failure
|
|
535
|
+
*/
|
|
536
|
+
declare function useParticipations(offerId?: OfferId, options?: UseParticipationsOptions): UseParticipationsResult;
|
|
537
|
+
|
|
538
|
+
export { type AuthState, ChecklistStatus, type ClientConfig, type CoinListClient, CoinListClientInitializationError, CoinListContext, type CoinListContextValue, CoinListProvider, type CoinListProviderProps, CoinListSignInCard, type CoinListSignInCardProps, type CompleteOAuthFailureReason, type LoadOfferDetailsReason, type LoadOfferDetailsState, type LoadOffersReason, type LoadOffersState, type LoadParticipationsReason, type LoadParticipationsState, type LoadRequirementsReason, type LoadRequirementsState, OAUTH_CODE_VERIFIER_KEY, OAUTH_STATE_KEY, type OauthClientErrorReason, type OauthClientResult, OfferCard, type Props as OfferCardProps, OfferCardUi, OffersGrid, type OffersGridProps, RequirementItem, type RequirementItemProps, RequirementItemUi, RequirementStatus, RequirementVariant, RequirementsChecklist, type RequirementsChecklistProps, type RequirementsData, type UseCoinListResult, type UseCompleteOAuthOptions, type UseOfferDetailsOptions, type UseOfferDetailsResult, type UseOffersOptions, type UseOffersResult, type UseParticipationsOptions, type UseParticipationsResult, type UseRequirementsOptions, type UseRequirementsResult, createCoinListClient, useCoinList, useCompleteOAuth, useOfferDetails, useOffers, useParticipations, useRequirements };
|