@coinlist-co/react 0.1.2 → 0.3.0

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 (49) hide show
  1. package/dist/RequirementItem-BpkJQep8.d.ts +37 -0
  2. package/dist/RequirementItem-BvwsFu9e.d.cts +37 -0
  3. package/dist/{chunk-WFA6X7E2.js → chunk-IADBIDY6.js} +3 -3
  4. package/dist/chunk-IDCROXPS.js +412 -0
  5. package/dist/chunk-IDCROXPS.js.map +1 -0
  6. package/dist/{chunk-6CG7JT7Q.js → chunk-P4DTIPEX.js} +144 -5
  7. package/dist/chunk-P4DTIPEX.js.map +1 -0
  8. package/dist/{chunk-DLEKT4T4.js → chunk-V5M7SA3C.js} +47 -4
  9. package/dist/chunk-V5M7SA3C.js.map +1 -0
  10. package/dist/client/components/index.cjs +467 -5
  11. package/dist/client/components/index.cjs.map +1 -1
  12. package/dist/client/components/index.d.cts +61 -11
  13. package/dist/client/components/index.d.ts +61 -11
  14. package/dist/client/components/index.js +268 -240
  15. package/dist/client/components/index.js.map +1 -1
  16. package/dist/client/core/index.cjs +146 -4
  17. package/dist/client/core/index.cjs.map +1 -1
  18. package/dist/client/core/index.d.cts +2 -2
  19. package/dist/client/core/index.d.ts +2 -2
  20. package/dist/client/core/index.js +13 -1
  21. package/dist/client/hooks/index.cjs +49 -6
  22. package/dist/client/hooks/index.cjs.map +1 -1
  23. package/dist/client/hooks/index.d.cts +6 -5
  24. package/dist/client/hooks/index.d.ts +6 -5
  25. package/dist/client/hooks/index.js +5 -3
  26. package/dist/client/index.cjs +244 -10
  27. package/dist/client/index.cjs.map +1 -1
  28. package/dist/client/index.d.cts +6 -4
  29. package/dist/client/index.d.ts +6 -4
  30. package/dist/client/index.js +30 -2
  31. package/dist/client/styles.css +1 -1
  32. package/dist/coinlist-client-B_dJkbwB.d.ts +283 -0
  33. package/dist/coinlist-client-DBKa6j3f.d.cts +283 -0
  34. package/dist/requirement-CxbdY8l4.d.cts +202 -0
  35. package/dist/requirement-fJsQ3f9_.d.ts +202 -0
  36. package/dist/{useCoinListOffers-DIdOb5hB.d.ts → useCoinListOffers-C5lBlzcC.d.ts} +1 -1
  37. package/dist/{useCoinListOffers-DvJxu6qj.d.cts → useCoinListOffers-CguwXaCX.d.cts} +1 -1
  38. package/dist/useCoinListRequirements-BECx1cIw.d.ts +31 -0
  39. package/dist/useCoinListRequirements-CX2gV9gJ.d.cts +31 -0
  40. package/dist/{useCompleteCoinListOAuth-6Z4DGuiH.d.cts → useCompleteCoinListOAuth-BRhAqD4_.d.cts} +1 -1
  41. package/dist/{useCompleteCoinListOAuth-C3G1Vsf8.d.ts → useCompleteCoinListOAuth-DEZpHjd6.d.ts} +1 -1
  42. package/package.json +4 -4
  43. package/dist/chunk-6CG7JT7Q.js.map +0 -1
  44. package/dist/chunk-DLEKT4T4.js.map +0 -1
  45. package/dist/coinlist-client-BiA8a2yU.d.ts +0 -272
  46. package/dist/coinlist-client-DXKFDGhP.d.cts +0 -272
  47. package/dist/offer-D6p_Ijme.d.cts +0 -30
  48. package/dist/offer-DnFEFJw9.d.ts +0 -30
  49. /package/dist/{chunk-WFA6X7E2.js.map → chunk-IADBIDY6.js.map} +0 -0
@@ -1,7 +1,8 @@
1
- export { C as CompleteCoinListOAuthFailureReason, U as UseCompleteCoinListOAuthOptions, u as useCoinList, a as useCompleteCoinListOAuth } from '../../useCompleteCoinListOAuth-C3G1Vsf8.js';
2
- import { a as OfferId } from '../../offer-DnFEFJw9.js';
3
- import { d as OfferDetail } from '../../coinlist-client-BiA8a2yU.js';
4
- export { u as useCoinListOffers } from '../../useCoinListOffers-DIdOb5hB.js';
1
+ export { C as CompleteCoinListOAuthFailureReason, U as UseCompleteCoinListOAuthOptions, u as useCoinList, a as useCompleteCoinListOAuth } from '../../useCompleteCoinListOAuth-DEZpHjd6.js';
2
+ import { a as OfferDetail, b as OfferId } from '../../requirement-fJsQ3f9_.js';
3
+ export { u as useCoinListOffers } from '../../useCoinListOffers-C5lBlzcC.js';
4
+ export { L as LoadRequirementsReason, a as LoadRequirementsState, U as UseCoinListRequirementsResult, u as useCoinListRequirements } from '../../useCoinListRequirements-BECx1cIw.js';
5
+ import '../../coinlist-client-B_dJkbwB.js';
5
6
  import '../../oauth-session-DnKDI5ou.js';
6
7
  import '../../newtype-yKTvFdg_.js';
7
8
 
@@ -29,4 +30,4 @@ interface UseCoinListOfferDetailsResult {
29
30
  */
30
31
  declare function useCoinListOfferDetails(offerId: OfferId): UseCoinListOfferDetailsResult;
31
32
 
32
- export { useCoinListOfferDetails };
33
+ export { type LoadOfferDetailsReason, type LoadOfferDetailsState, type UseCoinListOfferDetailsResult, useCoinListOfferDetails };
@@ -1,17 +1,19 @@
1
1
  import {
2
2
  useCoinListOfferDetails,
3
3
  useCoinListOffers
4
- } from "../../chunk-WFA6X7E2.js";
4
+ } from "../../chunk-IADBIDY6.js";
5
5
  import {
6
6
  useCoinList,
7
+ useCoinListRequirements,
7
8
  useCompleteCoinListOAuth
8
- } from "../../chunk-DLEKT4T4.js";
9
- import "../../chunk-6CG7JT7Q.js";
9
+ } from "../../chunk-V5M7SA3C.js";
10
+ import "../../chunk-P4DTIPEX.js";
10
11
  import "../../chunk-GRVV7NLV.js";
11
12
  export {
12
13
  useCoinList,
13
14
  useCoinListOfferDetails,
14
15
  useCoinListOffers,
16
+ useCoinListRequirements,
15
17
  useCompleteCoinListOAuth
16
18
  };
17
19
  //# sourceMappingURL=index.js.map
@@ -21,11 +21,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var client_exports = {};
22
22
  __export(client_exports, {
23
23
  AuthorizationCode: () => AuthorizationCode,
24
+ Blockchain: () => Blockchain,
25
+ ChecklistStatus: () => ChecklistStatus,
24
26
  ClientId: () => ClientId,
25
27
  ClientSecret: () => ClientSecret,
26
28
  CodeChallenge: () => CodeChallenge,
27
29
  CodeVerifier: () => CodeVerifier,
28
30
  CoinListProvider: () => CoinListProvider,
31
+ CreateParticipationParams: () => CreateParticipationParams,
29
32
  Cursor: () => Cursor,
30
33
  FaqItem: () => FaqItem,
31
34
  Link: () => Link,
@@ -41,14 +44,24 @@ __export(client_exports, {
41
44
  OfferSlug: () => OfferSlug,
42
45
  PaginatedResponse: () => PaginatedResponse,
43
46
  PaginationParams: () => PaginationParams,
47
+ Participation: () => Participation,
48
+ ParticipationId: () => ParticipationId,
49
+ ParticipationsPaginationParams: () => ParticipationsPaginationParams,
44
50
  RedirectUri: () => RedirectUri,
51
+ Requirement: () => Requirement,
52
+ RequirementId: () => RequirementId,
53
+ RequirementStatus: () => RequirementStatus,
54
+ RequirementStatusInfo: () => RequirementStatusInfo,
55
+ RequirementVariant: () => RequirementVariant,
45
56
  TermItem: () => TermItem,
46
57
  User: () => User,
47
58
  UserEmail: () => UserEmail,
48
59
  UserId: () => UserId,
60
+ WalletAddress: () => WalletAddress,
49
61
  createCoinListClient: () => createCoinListClient,
50
62
  fetchAllPages: () => fetchAllPages,
51
63
  useCoinList: () => useCoinList,
64
+ useCoinListRequirements: () => useCoinListRequirements,
52
65
  useCompleteCoinListOAuth: () => useCompleteCoinListOAuth
53
66
  });
54
67
  module.exports = __toCommonJS(client_exports);
@@ -488,13 +501,15 @@ var ApiClient = class {
488
501
 
489
502
  // src/shared/api/pagination.ts
490
503
  var Cursor = (value) => value;
491
- async function fetchAllPages(fetchPage) {
504
+ async function fetchAllPages(fetchPage, baseParams) {
492
505
  const items = [];
493
506
  let cursor = null;
494
507
  do {
495
- const page = await fetchPage({
508
+ const params = {
509
+ ...baseParams ?? {},
496
510
  after: cursor ?? void 0
497
- });
511
+ };
512
+ const page = await fetchPage(params);
498
513
  items.push(...page.data);
499
514
  cursor = page.startingAfter;
500
515
  } while (cursor);
@@ -648,6 +663,69 @@ var Milestone = {
648
663
  })
649
664
  };
650
665
 
666
+ // src/shared/types/participation.ts
667
+ var ParticipationId = (value) => value;
668
+ var Blockchain = (value) => value;
669
+ var WalletAddress = (value) => value;
670
+ var ParticipationsPaginationParams = {
671
+ toQueryParams: (params) => {
672
+ const queryParams = PaginationParams.toQueryParams(params);
673
+ if (params.offerId) {
674
+ queryParams["filters[0][field]"] = "offer_id";
675
+ queryParams["filters[0][op]"] = "==";
676
+ queryParams["filters[0][value]"] = params.offerId;
677
+ }
678
+ return queryParams;
679
+ }
680
+ };
681
+ var Participation = {
682
+ /** Maps API DTO shape into the SDK participation domain model. */
683
+ fromDto: (dto) => {
684
+ const walletAddress = notBlankStringOrNull(dto.wallet_address);
685
+ return {
686
+ id: ParticipationId(dto.id),
687
+ offerId: OfferId(dto.offer_id),
688
+ offerOptionId: OfferOptionId(dto.offer_option_id),
689
+ status: dto.status,
690
+ amount: dto.amount,
691
+ displayAmount: dto.amount_string,
692
+ asset: Asset.fromDto(dto.asset),
693
+ chain: Blockchain(dto.chain),
694
+ insertedAt: dto.inserted_at ? new Date(dto.inserted_at) : null,
695
+ updatedAt: dto.updated_at ? new Date(dto.updated_at) : null,
696
+ walletAddress: walletAddress ? WalletAddress(walletAddress) : null
697
+ };
698
+ }
699
+ };
700
+ var CreateParticipationParams = {
701
+ /** Maps participation creation params into API DTO payload. */
702
+ toDto: (params) => ({
703
+ offer_id: params.offerId,
704
+ offer_option_id: params.offerOptionId,
705
+ chain: params.chain,
706
+ wallet_address: params.walletAddress,
707
+ amount: params.amount,
708
+ asset_id: params.assetId,
709
+ approval_transaction_hash: params.approvalTransactionHash
710
+ })
711
+ };
712
+
713
+ // src/shared/types/requirement.ts
714
+ var RequirementId = (value) => value;
715
+ var Requirement = {
716
+ fromDto: (dto) => ({
717
+ id: RequirementId(dto.id),
718
+ type: dto.type,
719
+ details: dto.details
720
+ })
721
+ };
722
+ var RequirementStatusInfo = {
723
+ fromStatusesDto: (dto) => Object.entries(dto.statuses).map(([id, status]) => ({
724
+ id: RequirementId(id),
725
+ status
726
+ }))
727
+ };
728
+
651
729
  // src/client/core/coinlist-client.ts
652
730
  var OAUTH_STATE_KEY = "coinlist.oauth_state";
653
731
  var OAUTH_CODE_VERIFIER_KEY = "coinlist.oauth_code_verifier";
@@ -741,10 +819,14 @@ var CoinListClientImpl = class {
741
819
  }
742
820
  async fetchOffersPage(params) {
743
821
  this.ensureAuthenticated();
822
+ const queryParams = PaginationParams.toQueryParams(params);
823
+ if (this._config.sandbox) {
824
+ queryParams.sandbox = true;
825
+ }
744
826
  const pageDto = await this.api.send({
745
827
  method: "GET",
746
828
  url: "/v1/offers",
747
- queryParams: PaginationParams.toQueryParams(params),
829
+ queryParams,
748
830
  attributes: Attributes.protected()
749
831
  });
750
832
  return PaginatedResponse.fromDto(pageDto, Offer.fromDto);
@@ -758,6 +840,67 @@ var CoinListClientImpl = class {
758
840
  });
759
841
  return OfferDetail.fromDto(offerDetailDto);
760
842
  }
843
+ async fetchAllParticipations(offerId) {
844
+ this.ensureAuthenticated();
845
+ return await fetchAllPages(
846
+ this.fetchParticipationsPage.bind(this),
847
+ { offerId }
848
+ );
849
+ }
850
+ async fetchParticipationsPage(params) {
851
+ this.ensureAuthenticated();
852
+ const pageDto = await this.api.send(
853
+ {
854
+ method: "GET",
855
+ url: "/v1/participations",
856
+ queryParams: ParticipationsPaginationParams.toQueryParams(params),
857
+ attributes: Attributes.protected()
858
+ }
859
+ );
860
+ return PaginatedResponse.fromDto(pageDto, Participation.fromDto);
861
+ }
862
+ async fetchParticipation(id) {
863
+ this.ensureAuthenticated();
864
+ const participationDto = await this.api.send({
865
+ method: "GET",
866
+ url: `/v1/participations/${id}`,
867
+ attributes: Attributes.protected()
868
+ });
869
+ return Participation.fromDto(participationDto);
870
+ }
871
+ async createParticipation(params) {
872
+ this.ensureAuthenticated();
873
+ const participationDto = await this.api.send({
874
+ method: "POST",
875
+ url: "/v1/participations",
876
+ body: CreateParticipationParams.toDto(params),
877
+ attributes: Attributes.protected()
878
+ });
879
+ return Participation.fromDto(participationDto);
880
+ }
881
+ async fetchOfferRequirements(offerId) {
882
+ this.ensureAuthenticated();
883
+ const response = await this.api.send({
884
+ method: "GET",
885
+ url: `/v1/offers/${offerId}/requirements`,
886
+ attributes: Attributes.protected()
887
+ });
888
+ return Object.fromEntries(
889
+ Object.entries(response.options).map(([optionId, list]) => [
890
+ optionId,
891
+ list.data.map(Requirement.fromDto)
892
+ ])
893
+ );
894
+ }
895
+ async fetchRequirementStatuses(offerId) {
896
+ this.ensureAuthenticated();
897
+ const response = await this.api.send({
898
+ method: "GET",
899
+ url: `/v1/offers/${offerId}/requirements/statuses`,
900
+ attributes: Attributes.protected()
901
+ });
902
+ return RequirementStatusInfo.fromStatusesDto(response);
903
+ }
761
904
  ensureAuthenticated() {
762
905
  if (this.getAuthState() !== "logged-in") {
763
906
  throw new NotAuthenticatedError();
@@ -797,6 +940,43 @@ function CoinListProvider({ config, children }) {
797
940
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CoinListContext.Provider, { value, children });
798
941
  }
799
942
 
943
+ // src/client/components/requirements/RequirementItem.tsx
944
+ var import_lucide_react = require("lucide-react");
945
+ var import_jsx_runtime2 = require("react/jsx-runtime");
946
+ var RequirementVariant = {
947
+ fromType(type) {
948
+ switch (type) {
949
+ case "external_wallet":
950
+ case "whitelisted_wallet":
951
+ return "wallet";
952
+ default:
953
+ return "verification";
954
+ }
955
+ }
956
+ };
957
+ var RequirementStatus = {
958
+ fromStatusValue(status) {
959
+ switch (status) {
960
+ case "not_started":
961
+ case "action_needed":
962
+ return "required";
963
+ case "in_progress":
964
+ return "pending";
965
+ case "completed":
966
+ return "completed";
967
+ case "rejected":
968
+ return "rejected";
969
+ }
970
+ }
971
+ };
972
+ var ChecklistStatus = {
973
+ derive(statuses) {
974
+ if (statuses.some((s) => s.status === "rejected")) return "ineligible";
975
+ if (statuses.every((s) => s.status === "completed")) return "eligible";
976
+ return "inProgress";
977
+ }
978
+ };
979
+
800
980
  // src/client/hooks/useCoinList.ts
801
981
  var import_react2 = require("react");
802
982
  function useCoinList() {
@@ -816,18 +996,59 @@ var CoinListClientInitializationError = class extends Error {
816
996
  }
817
997
  };
818
998
 
819
- // src/client/hooks/useCompleteCoinListOAuth.ts
999
+ // src/client/hooks/useCoinListRequirements.ts
820
1000
  var import_react3 = require("react");
1001
+ var LOADING_STATE = { type: "LOADING" };
1002
+ function useCoinListRequirements(offerId) {
1003
+ const { coinlist, isReady } = useCoinList();
1004
+ const [requirementsState, setRequirementsState] = (0, import_react3.useState)(LOADING_STATE);
1005
+ const [fetchKey, setFetchKey] = (0, import_react3.useState)(0);
1006
+ const refetch = (0, import_react3.useCallback)(() => setFetchKey((k) => k + 1), []);
1007
+ (0, import_react3.useEffect)(() => {
1008
+ let isCancelled = false;
1009
+ if (!isReady) {
1010
+ setRequirementsState(LOADING_STATE);
1011
+ return () => {
1012
+ isCancelled = true;
1013
+ };
1014
+ }
1015
+ setRequirementsState(LOADING_STATE);
1016
+ Promise.all([
1017
+ coinlist.fetchOfferRequirements(offerId),
1018
+ coinlist.fetchRequirementStatuses(offerId)
1019
+ ]).then(([requirementsByOptionId, statuses]) => {
1020
+ if (!isCancelled) {
1021
+ setRequirementsState({
1022
+ type: "CONTENT",
1023
+ requirementsByOptionId,
1024
+ statuses
1025
+ });
1026
+ }
1027
+ }).catch((error) => {
1028
+ if (!isCancelled) {
1029
+ const reason = error instanceof NotAuthenticatedError ? "not-authenticated" : "generic-error";
1030
+ setRequirementsState({ type: "ERROR", reason });
1031
+ }
1032
+ });
1033
+ return () => {
1034
+ isCancelled = true;
1035
+ };
1036
+ }, [coinlist, isReady, offerId, fetchKey]);
1037
+ return { requirementsState, refetch };
1038
+ }
1039
+
1040
+ // src/client/hooks/useCompleteCoinListOAuth.ts
1041
+ var import_react4 = require("react");
821
1042
  function useCompleteCoinListOAuth(options) {
822
1043
  const { coinlist } = useCoinList();
823
- const postOAuthCompleteRef = (0, import_react3.useRef)(options.postOAuthComplete);
824
- const onFailureRef = (0, import_react3.useRef)(options.onFailure);
825
- const onSuccessRef = (0, import_react3.useRef)(options.onSuccess);
1044
+ const postOAuthCompleteRef = (0, import_react4.useRef)(options.postOAuthComplete);
1045
+ const onFailureRef = (0, import_react4.useRef)(options.onFailure);
1046
+ const onSuccessRef = (0, import_react4.useRef)(options.onSuccess);
826
1047
  postOAuthCompleteRef.current = options.postOAuthComplete;
827
1048
  onFailureRef.current = options.onFailure;
828
1049
  onSuccessRef.current = options.onSuccess;
829
- const hasStartedExchangeRef = (0, import_react3.useRef)(false);
830
- (0, import_react3.useEffect)(() => {
1050
+ const hasStartedExchangeRef = (0, import_react4.useRef)(false);
1051
+ (0, import_react4.useEffect)(() => {
831
1052
  if (typeof window === "undefined") return;
832
1053
  const params = new URLSearchParams(window.location.search);
833
1054
  if (!params.has("code") && !params.has("error")) return;
@@ -897,11 +1118,14 @@ var User = {
897
1118
  // Annotate the CommonJS export names for ESM import in node:
898
1119
  0 && (module.exports = {
899
1120
  AuthorizationCode,
1121
+ Blockchain,
1122
+ ChecklistStatus,
900
1123
  ClientId,
901
1124
  ClientSecret,
902
1125
  CodeChallenge,
903
1126
  CodeVerifier,
904
1127
  CoinListProvider,
1128
+ CreateParticipationParams,
905
1129
  Cursor,
906
1130
  FaqItem,
907
1131
  Link,
@@ -917,14 +1141,24 @@ var User = {
917
1141
  OfferSlug,
918
1142
  PaginatedResponse,
919
1143
  PaginationParams,
1144
+ Participation,
1145
+ ParticipationId,
1146
+ ParticipationsPaginationParams,
920
1147
  RedirectUri,
1148
+ Requirement,
1149
+ RequirementId,
1150
+ RequirementStatus,
1151
+ RequirementStatusInfo,
1152
+ RequirementVariant,
921
1153
  TermItem,
922
1154
  User,
923
1155
  UserEmail,
924
1156
  UserId,
1157
+ WalletAddress,
925
1158
  createCoinListClient,
926
1159
  fetchAllPages,
927
1160
  useCoinList,
1161
+ useCoinListRequirements,
928
1162
  useCompleteCoinListOAuth
929
1163
  });
930
1164
  //# sourceMappingURL=index.cjs.map