@coinlist-co/react 0.9.0 → 0.10.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.
Files changed (34) hide show
  1. package/dist/{chunk-I5YTJ5SL.js → chunk-AQVCOWOV.js} +163 -69
  2. package/dist/chunk-AQVCOWOV.js.map +1 -0
  3. package/dist/{chunk-MKCOK3DF.js → chunk-TBU3EBNM.js} +2 -43
  4. package/dist/chunk-TBU3EBNM.js.map +1 -0
  5. package/dist/{chunk-Z2HAA2TI.js → chunk-UOHD7US2.js} +150 -63
  6. package/dist/chunk-UOHD7US2.js.map +1 -0
  7. package/dist/client/index.cjs +415 -292
  8. package/dist/client/index.cjs.map +1 -1
  9. package/dist/client/index.d.cts +131 -49
  10. package/dist/client/index.d.ts +131 -49
  11. package/dist/client/index.js +169 -76
  12. package/dist/client/index.js.map +1 -1
  13. package/dist/{collections-BQbFJS3g.d.ts → collections-Bv1Oxzu_.d.ts} +1 -1
  14. package/dist/{collections-B84Vw55t.d.cts → collections-DDyxbOPZ.d.cts} +1 -1
  15. package/dist/{requirement-C2w45Q11.d.cts → requirement-oVZA1INj.d.cts} +271 -200
  16. package/dist/{requirement-C2w45Q11.d.ts → requirement-oVZA1INj.d.ts} +271 -200
  17. package/dist/server/index.cjs +135 -116
  18. package/dist/server/index.cjs.map +1 -1
  19. package/dist/server/index.d.cts +20 -27
  20. package/dist/server/index.d.ts +20 -27
  21. package/dist/server/index.js +10 -27
  22. package/dist/server/index.js.map +1 -1
  23. package/dist/shared/index.cjs +145 -75
  24. package/dist/shared/index.cjs.map +1 -1
  25. package/dist/shared/index.d.cts +4 -4
  26. package/dist/shared/index.d.ts +4 -4
  27. package/dist/shared/index.js +16 -92
  28. package/dist/shared/index.js.map +1 -1
  29. package/package.json +1 -1
  30. package/dist/chunk-AAER5LOL.js +0 -22
  31. package/dist/chunk-AAER5LOL.js.map +0 -1
  32. package/dist/chunk-I5YTJ5SL.js.map +0 -1
  33. package/dist/chunk-MKCOK3DF.js.map +0 -1
  34. package/dist/chunk-Z2HAA2TI.js.map +0 -1
@@ -13,18 +13,14 @@ import {
13
13
  VERIFY_IDENTITY_VERIFIED_PATH,
14
14
  WALLET_PATH,
15
15
  createKycToken,
16
- createParticipation,
17
16
  fetchOfferDetails,
18
17
  fetchOfferRequirements,
19
18
  fetchOffers,
20
19
  fetchOffersPage,
21
- fetchParticipation,
22
- fetchParticipations,
23
- fetchParticipationsPage,
24
20
  fetchPii,
25
21
  fetchRequirementStatuses,
26
22
  submitDocument
27
- } from "../chunk-MKCOK3DF.js";
23
+ } from "../chunk-TBU3EBNM.js";
28
24
  import {
29
25
  AuthorizationCode,
30
26
  CodeVerifier,
@@ -36,23 +32,28 @@ import {
36
32
  computePrice,
37
33
  computeSlip,
38
34
  decodeSwappedOutputAmount,
35
+ formatRawAmount,
39
36
  generatePKCEParams,
40
37
  isStopped,
41
38
  shortenAddress
42
- } from "../chunk-I5YTJ5SL.js";
39
+ } from "../chunk-AQVCOWOV.js";
43
40
  import {
44
41
  Attributes,
42
+ Blockchain,
45
43
  BlockchainAmount,
44
+ Erc20NamespaceImpl,
46
45
  KycToken,
47
46
  NotAuthenticatedError,
48
47
  OfferOptionAddressId,
49
48
  SwapNamespaceImpl,
49
+ TokenSaleNamespaceImpl,
50
+ WalletAddress,
50
51
  connectExternalWallet,
51
52
  createWalletOwnershipChallenge,
52
53
  getUUIDv4,
53
54
  listOptionAddresses,
54
55
  removeOptionAddress
55
- } from "../chunk-Z2HAA2TI.js";
56
+ } from "../chunk-UOHD7US2.js";
56
57
 
57
58
  // src/client/CoinListProvider.tsx
58
59
  import {
@@ -132,10 +133,55 @@ function classifyWalletError(error, ctx) {
132
133
  return { type: "unknown", cause: error };
133
134
  }
134
135
 
136
+ // src/client/core/blockchain/erc20-approval.ts
137
+ async function submitErc20Approval(args) {
138
+ const {
139
+ wallet,
140
+ tokenAddress,
141
+ spender,
142
+ chain,
143
+ value,
144
+ pending,
145
+ confirming,
146
+ emit
147
+ } = args;
148
+ emit(pending);
149
+ let hash;
150
+ try {
151
+ hash = await wallet.writeContract({
152
+ abi: ERC20_ABI,
153
+ address: tokenAddress,
154
+ functionName: "approve",
155
+ args: [spender, value],
156
+ chain
157
+ });
158
+ } catch (error) {
159
+ return {
160
+ type: "error",
161
+ error: { step: "approval", cause: classifyWalletError(error) }
162
+ };
163
+ }
164
+ emit(confirming);
165
+ let receipt;
166
+ try {
167
+ receipt = await wallet.awaitTx(hash, chain);
168
+ } catch (error) {
169
+ return {
170
+ type: "error",
171
+ error: { step: "approval", cause: classifyWalletError(error, { hash }) }
172
+ };
173
+ }
174
+ if (receipt.status !== "success") {
175
+ return { type: "error", error: { step: "approval-reverted" } };
176
+ }
177
+ return { type: "ok", txHash: hash };
178
+ }
179
+
135
180
  // src/client/core/blockchain/swap-flows.ts
136
181
  async function executeSwap(params) {
137
182
  const {
138
183
  swap,
184
+ erc20,
139
185
  wallet,
140
186
  contractAddress,
141
187
  chain,
@@ -163,7 +209,7 @@ async function executeSwap(params) {
163
209
  emit("checking-allowance");
164
210
  let allowance;
165
211
  try {
166
- allowance = await swap.getTokenAllowance({
212
+ allowance = await erc20.getTokenAllowance({
167
213
  tokenAddress: inputTokenAddress,
168
214
  owner: wallet.address,
169
215
  spender: contractAddress,
@@ -174,7 +220,7 @@ async function executeSwap(params) {
174
220
  }
175
221
  if (allowance.allowance < inputAmount) {
176
222
  if (allowance.allowance > 0n) {
177
- const reset = await submitApproval({
223
+ const reset = await submitErc20Approval({
178
224
  wallet,
179
225
  tokenAddress: inputTokenAddress,
180
226
  spender: contractAddress,
@@ -186,7 +232,7 @@ async function executeSwap(params) {
186
232
  });
187
233
  if (reset.type === "error") return { type: "error", error: reset.error };
188
234
  }
189
- const approve = await submitApproval({
235
+ const approve = await submitErc20Approval({
190
236
  wallet,
191
237
  tokenAddress: inputTokenAddress,
192
238
  spender: contractAddress,
@@ -243,48 +289,6 @@ async function executeSwap(params) {
243
289
  recipientAddress: wallet.address
244
290
  };
245
291
  }
246
- async function submitApproval(args) {
247
- const {
248
- wallet,
249
- tokenAddress,
250
- spender,
251
- chain,
252
- value,
253
- pending,
254
- confirming,
255
- emit
256
- } = args;
257
- emit(pending);
258
- let hash;
259
- try {
260
- hash = await wallet.writeContract({
261
- abi: ERC20_ABI,
262
- address: tokenAddress,
263
- functionName: "approve",
264
- args: [spender, value],
265
- chain
266
- });
267
- } catch (error) {
268
- return {
269
- type: "error",
270
- error: { step: "approval", cause: classifyWalletError(error) }
271
- };
272
- }
273
- emit(confirming);
274
- let receipt;
275
- try {
276
- receipt = await wallet.awaitTx(hash, chain);
277
- } catch (error) {
278
- return {
279
- type: "error",
280
- error: { step: "approval", cause: classifyWalletError(error, { hash }) }
281
- };
282
- }
283
- if (receipt.status !== "success") {
284
- return { type: "error", error: { step: "approval-reverted" } };
285
- }
286
- return { type: "ok" };
287
- }
288
292
  async function authorizeWallet(params) {
289
293
  const { swap, wallet, offerId, contractAddress, chain, onProgress } = params;
290
294
  const emit = (phase) => onProgress?.(phase);
@@ -381,14 +385,108 @@ async function authorizeWallet(params) {
381
385
 
382
386
  // src/client/core/client-swap-namespace.ts
383
387
  var ClientSwapNamespaceImpl = class extends SwapNamespaceImpl {
388
+ constructor(ctx, erc20) {
389
+ super(ctx);
390
+ this.erc20 = erc20;
391
+ }
384
392
  executeSwap(params) {
385
- return executeSwap({ ...params, swap: this });
393
+ return executeSwap({ ...params, swap: this, erc20: this.erc20 });
386
394
  }
387
395
  authorizeWallet(params) {
388
396
  return authorizeWallet({ ...params, swap: this });
389
397
  }
390
398
  };
391
399
 
400
+ // src/client/core/blockchain/token-sale-flow.ts
401
+ async function executeTokenSale(params) {
402
+ const {
403
+ erc20,
404
+ tokenSale,
405
+ wallet,
406
+ offerId,
407
+ offerOptionId,
408
+ assetId,
409
+ paymentTokenAddress,
410
+ fundingContractAddress,
411
+ chain,
412
+ amount,
413
+ onProgress
414
+ } = params;
415
+ const emit = (phase) => onProgress?.(phase);
416
+ emit("checking-allowance");
417
+ let currentAllowance;
418
+ try {
419
+ const allowance = await erc20.getTokenAllowance({
420
+ tokenAddress: paymentTokenAddress,
421
+ owner: wallet.address,
422
+ spender: fundingContractAddress,
423
+ chain
424
+ });
425
+ currentAllowance = allowance.allowance;
426
+ } catch {
427
+ return { type: "error", error: { step: "allowance-check" } };
428
+ }
429
+ if (currentAllowance > 0n) {
430
+ const reset = await submitErc20Approval({
431
+ wallet,
432
+ tokenAddress: paymentTokenAddress,
433
+ spender: fundingContractAddress,
434
+ chain,
435
+ value: 0n,
436
+ pending: "resetting-allowance",
437
+ confirming: "confirming-allowance-reset",
438
+ emit
439
+ });
440
+ if (reset.type === "error") {
441
+ return {
442
+ type: "error",
443
+ error: reset.error.step === "approval-reverted" ? { step: "allowance-reset-reverted" } : { step: "allowance-reset", cause: reset.error.cause }
444
+ };
445
+ }
446
+ }
447
+ const approve = await submitErc20Approval({
448
+ wallet,
449
+ tokenAddress: paymentTokenAddress,
450
+ spender: fundingContractAddress,
451
+ chain,
452
+ value: amount.raw,
453
+ pending: "approving",
454
+ confirming: "confirming-approval",
455
+ emit
456
+ });
457
+ if (approve.type === "error") {
458
+ return { type: "error", error: approve.error };
459
+ }
460
+ const approvalTxHash = approve.txHash;
461
+ emit("recording-participation");
462
+ let participation;
463
+ try {
464
+ participation = await tokenSale.createParticipation({
465
+ offerId,
466
+ offerOptionId,
467
+ chain: Blockchain(chain),
468
+ walletAddress: WalletAddress(wallet.address),
469
+ amount: formatRawAmount(amount),
470
+ assetId,
471
+ approvalTransactionHash: approvalTxHash
472
+ });
473
+ } catch {
474
+ return { type: "error", error: { step: "participation", approvalTxHash } };
475
+ }
476
+ return { type: "success", participation, approvalTxHash };
477
+ }
478
+
479
+ // src/client/core/client-token-sale-namespace.ts
480
+ var ClientTokenSaleNamespaceImpl = class extends TokenSaleNamespaceImpl {
481
+ constructor(ctx, erc20) {
482
+ super(ctx);
483
+ this.erc20 = erc20;
484
+ }
485
+ executeTokenSale(params) {
486
+ return executeTokenSale({ ...params, erc20: this.erc20, tokenSale: this });
487
+ }
488
+ };
489
+
392
490
  // src/client/core/coinlist-client.ts
393
491
  var OAUTH_STATE_KEY = "coinlist.oauth_state";
394
492
  var OAUTH_CODE_VERIFIER_KEY = "coinlist.oauth_code_verifier";
@@ -404,10 +502,13 @@ var CoinListClientImpl = class {
404
502
  },
405
503
  this.fetchAccessToken.bind(this)
406
504
  );
407
- this.swap = new ClientSwapNamespaceImpl({
505
+ const ctx = {
408
506
  api: this.api,
409
507
  ensureUserAuthenticated: async () => this.ensureAuthenticated()
410
- });
508
+ };
509
+ this.erc20 = new Erc20NamespaceImpl(ctx);
510
+ this.tokenSale = new ClientTokenSaleNamespaceImpl(ctx, this.erc20);
511
+ this.swap = new ClientSwapNamespaceImpl(ctx, this.erc20);
411
512
  }
412
513
  async init() {
413
514
  await this.fetchAccessToken(true);
@@ -489,22 +590,6 @@ var CoinListClientImpl = class {
489
590
  this.ensureAuthenticated();
490
591
  return fetchOfferDetails(this.api, id, void 0);
491
592
  }
492
- async fetchParticipations(offerId) {
493
- this.ensureAuthenticated();
494
- return fetchParticipations(this.api, offerId);
495
- }
496
- async fetchParticipationsPage(params) {
497
- this.ensureAuthenticated();
498
- return fetchParticipationsPage(this.api, params);
499
- }
500
- async fetchParticipation(id) {
501
- this.ensureAuthenticated();
502
- return fetchParticipation(this.api, id);
503
- }
504
- async createParticipation(params) {
505
- this.ensureAuthenticated();
506
- return createParticipation(this.api, params);
507
- }
508
593
  async createWalletOwnershipChallenge(params) {
509
594
  this.ensureAuthenticated();
510
595
  return createWalletOwnershipChallenge(this.api, params);
@@ -1107,7 +1192,7 @@ var OfferCardUi = {
1107
1192
  bannerUrl: offer.bannerUrl,
1108
1193
  logoUrl: offer.logoUrl,
1109
1194
  formattedStartsAt: monthYearFormatter.format(offer.startsAt),
1110
- formattedEndsAt: monthYearFormatter.format(offer.endsAt)
1195
+ formattedEndsAt: offer.endsAt ? monthYearFormatter.format(offer.endsAt) : null
1111
1196
  })
1112
1197
  };
1113
1198
  function OfferCard({
@@ -1158,7 +1243,7 @@ function OfferCard({
1158
1243
  ),
1159
1244
  /* @__PURE__ */ jsx11("span", { className: cn(typeClasses.label, "clcosdk:text-text-primary"), children: offer.formattedStartsAt })
1160
1245
  ] }),
1161
- /* @__PURE__ */ jsxs8("div", { className: "clcosdk:flex clcosdk:flex-col clcosdk:gap-1", children: [
1246
+ offer.formattedEndsAt && /* @__PURE__ */ jsxs8("div", { className: "clcosdk:flex clcosdk:flex-col clcosdk:gap-1", children: [
1162
1247
  /* @__PURE__ */ jsx11(
1163
1248
  "span",
1164
1249
  {
@@ -1166,7 +1251,13 @@ function OfferCard({
1166
1251
  children: "Ends"
1167
1252
  }
1168
1253
  ),
1169
- /* @__PURE__ */ jsx11("span", { className: cn(typeClasses.label, "clcosdk:text-text-primary"), children: offer.formattedEndsAt })
1254
+ /* @__PURE__ */ jsx11(
1255
+ "span",
1256
+ {
1257
+ className: cn(typeClasses.label, "clcosdk:text-text-primary"),
1258
+ children: offer.formattedEndsAt
1259
+ }
1260
+ )
1170
1261
  ] })
1171
1262
  ] })
1172
1263
  ] });
@@ -3146,7 +3237,7 @@ function useSwapTokenBalances(options) {
3146
3237
  }
3147
3238
  const results = await Promise.allSettled(
3148
3239
  symbols.map(
3149
- (symbol) => coinlist.swap.getTokenBalance({
3240
+ (symbol) => coinlist.erc20.getTokenBalance({
3150
3241
  tokenAddress: TOKEN_REGISTRY.contractAddress(symbol, chain),
3151
3242
  owner: address,
3152
3243
  chain
@@ -3298,7 +3389,7 @@ function useParticipations(offerId, options = {}) {
3298
3389
  };
3299
3390
  }
3300
3391
  setParticipationsState(LOADING_STATE8);
3301
- coinlist.fetchParticipations(offerId).then((participations) => {
3392
+ coinlist.tokenSale.fetchParticipations(offerId).then((participations) => {
3302
3393
  if (!isCancelled) {
3303
3394
  setParticipationsState({ type: "CONTENT", participations });
3304
3395
  }
@@ -3317,6 +3408,7 @@ function useParticipations(offerId, options = {}) {
3317
3408
  export {
3318
3409
  ChecklistStatus,
3319
3410
  ClientSwapNamespaceImpl,
3411
+ ClientTokenSaleNamespaceImpl,
3320
3412
  CoinListClientInitializationError,
3321
3413
  CoinListContext,
3322
3414
  CoinListContextProvider,
@@ -3343,6 +3435,7 @@ export {
3343
3435
  connectExternalWalletFlow,
3344
3436
  createCoinListClient,
3345
3437
  executeSwap,
3438
+ executeTokenSale,
3346
3439
  useCoinList,
3347
3440
  useCompleteOAuth,
3348
3441
  useConnectWallet,