@coinlist-co/react 0.2.0 → 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.
- package/dist/RequirementItem-BpkJQep8.d.ts +37 -0
- package/dist/RequirementItem-BvwsFu9e.d.cts +37 -0
- package/dist/{chunk-G3B4RLXP.js → chunk-IADBIDY6.js} +3 -3
- package/dist/chunk-IDCROXPS.js +412 -0
- package/dist/chunk-IDCROXPS.js.map +1 -0
- package/dist/{chunk-Z5RFQOMS.js → chunk-P4DTIPEX.js} +71 -8
- package/dist/chunk-P4DTIPEX.js.map +1 -0
- package/dist/{chunk-32GOUV3L.js → chunk-V5M7SA3C.js} +47 -4
- package/dist/chunk-V5M7SA3C.js.map +1 -0
- package/dist/client/components/index.cjs +467 -5
- package/dist/client/components/index.cjs.map +1 -1
- package/dist/client/components/index.d.cts +61 -11
- package/dist/client/components/index.d.ts +61 -11
- package/dist/client/components/index.js +268 -240
- package/dist/client/components/index.js.map +1 -1
- package/dist/client/core/index.cjs +68 -7
- package/dist/client/core/index.cjs.map +1 -1
- package/dist/client/core/index.d.cts +2 -2
- package/dist/client/core/index.d.ts +2 -2
- package/dist/client/core/index.js +3 -1
- package/dist/client/hooks/index.cjs +49 -6
- package/dist/client/hooks/index.cjs.map +1 -1
- package/dist/client/hooks/index.d.cts +6 -5
- package/dist/client/hooks/index.d.ts +6 -5
- package/dist/client/hooks/index.js +5 -3
- package/dist/client/index.cjs +166 -13
- package/dist/client/index.cjs.map +1 -1
- package/dist/client/index.d.cts +6 -4
- package/dist/client/index.d.ts +6 -4
- package/dist/client/index.js +20 -2
- package/dist/client/styles.css +1 -1
- package/dist/{coinlist-client-20v7fJSW.d.ts → coinlist-client-B_dJkbwB.d.ts} +33 -144
- package/dist/{coinlist-client-Ds86ycAg.d.cts → coinlist-client-DBKa6j3f.d.cts} +33 -144
- package/dist/requirement-CxbdY8l4.d.cts +202 -0
- package/dist/requirement-fJsQ3f9_.d.ts +202 -0
- package/dist/{useCoinListOffers-DIdOb5hB.d.ts → useCoinListOffers-C5lBlzcC.d.ts} +1 -1
- package/dist/{useCoinListOffers-DvJxu6qj.d.cts → useCoinListOffers-CguwXaCX.d.cts} +1 -1
- package/dist/useCoinListRequirements-BECx1cIw.d.ts +31 -0
- package/dist/useCoinListRequirements-CX2gV9gJ.d.cts +31 -0
- package/dist/{useCompleteCoinListOAuth-C359mp_k.d.cts → useCompleteCoinListOAuth-BRhAqD4_.d.cts} +1 -1
- package/dist/{useCompleteCoinListOAuth-wZX3o8r2.d.ts → useCompleteCoinListOAuth-DEZpHjd6.d.ts} +1 -1
- package/package.json +4 -4
- package/dist/chunk-32GOUV3L.js.map +0 -1
- package/dist/chunk-Z5RFQOMS.js.map +0 -1
- package/dist/offer-D6p_Ijme.d.cts +0 -30
- package/dist/offer-DnFEFJw9.d.ts +0 -30
- /package/dist/{chunk-G3B4RLXP.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-
|
|
2
|
-
import { a as OfferId } from '../../
|
|
3
|
-
|
|
4
|
-
export { u as
|
|
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-
|
|
4
|
+
} from "../../chunk-IADBIDY6.js";
|
|
5
5
|
import {
|
|
6
6
|
useCoinList,
|
|
7
|
+
useCoinListRequirements,
|
|
7
8
|
useCompleteCoinListOAuth
|
|
8
|
-
} from "../../chunk-
|
|
9
|
-
import "../../chunk-
|
|
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
|
package/dist/client/index.cjs
CHANGED
|
@@ -22,6 +22,7 @@ var client_exports = {};
|
|
|
22
22
|
__export(client_exports, {
|
|
23
23
|
AuthorizationCode: () => AuthorizationCode,
|
|
24
24
|
Blockchain: () => Blockchain,
|
|
25
|
+
ChecklistStatus: () => ChecklistStatus,
|
|
25
26
|
ClientId: () => ClientId,
|
|
26
27
|
ClientSecret: () => ClientSecret,
|
|
27
28
|
CodeChallenge: () => CodeChallenge,
|
|
@@ -45,7 +46,13 @@ __export(client_exports, {
|
|
|
45
46
|
PaginationParams: () => PaginationParams,
|
|
46
47
|
Participation: () => Participation,
|
|
47
48
|
ParticipationId: () => ParticipationId,
|
|
49
|
+
ParticipationsPaginationParams: () => ParticipationsPaginationParams,
|
|
48
50
|
RedirectUri: () => RedirectUri,
|
|
51
|
+
Requirement: () => Requirement,
|
|
52
|
+
RequirementId: () => RequirementId,
|
|
53
|
+
RequirementStatus: () => RequirementStatus,
|
|
54
|
+
RequirementStatusInfo: () => RequirementStatusInfo,
|
|
55
|
+
RequirementVariant: () => RequirementVariant,
|
|
49
56
|
TermItem: () => TermItem,
|
|
50
57
|
User: () => User,
|
|
51
58
|
UserEmail: () => UserEmail,
|
|
@@ -54,6 +61,7 @@ __export(client_exports, {
|
|
|
54
61
|
createCoinListClient: () => createCoinListClient,
|
|
55
62
|
fetchAllPages: () => fetchAllPages,
|
|
56
63
|
useCoinList: () => useCoinList,
|
|
64
|
+
useCoinListRequirements: () => useCoinListRequirements,
|
|
57
65
|
useCompleteCoinListOAuth: () => useCompleteCoinListOAuth
|
|
58
66
|
});
|
|
59
67
|
module.exports = __toCommonJS(client_exports);
|
|
@@ -493,13 +501,15 @@ var ApiClient = class {
|
|
|
493
501
|
|
|
494
502
|
// src/shared/api/pagination.ts
|
|
495
503
|
var Cursor = (value) => value;
|
|
496
|
-
async function fetchAllPages(fetchPage) {
|
|
504
|
+
async function fetchAllPages(fetchPage, baseParams) {
|
|
497
505
|
const items = [];
|
|
498
506
|
let cursor = null;
|
|
499
507
|
do {
|
|
500
|
-
const
|
|
508
|
+
const params = {
|
|
509
|
+
...baseParams ?? {},
|
|
501
510
|
after: cursor ?? void 0
|
|
502
|
-
}
|
|
511
|
+
};
|
|
512
|
+
const page = await fetchPage(params);
|
|
503
513
|
items.push(...page.data);
|
|
504
514
|
cursor = page.startingAfter;
|
|
505
515
|
} while (cursor);
|
|
@@ -657,6 +667,17 @@ var Milestone = {
|
|
|
657
667
|
var ParticipationId = (value) => value;
|
|
658
668
|
var Blockchain = (value) => value;
|
|
659
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
|
+
};
|
|
660
681
|
var Participation = {
|
|
661
682
|
/** Maps API DTO shape into the SDK participation domain model. */
|
|
662
683
|
fromDto: (dto) => {
|
|
@@ -689,6 +710,22 @@ var CreateParticipationParams = {
|
|
|
689
710
|
})
|
|
690
711
|
};
|
|
691
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
|
+
|
|
692
729
|
// src/client/core/coinlist-client.ts
|
|
693
730
|
var OAUTH_STATE_KEY = "coinlist.oauth_state";
|
|
694
731
|
var OAUTH_CODE_VERIFIER_KEY = "coinlist.oauth_code_verifier";
|
|
@@ -782,10 +819,14 @@ var CoinListClientImpl = class {
|
|
|
782
819
|
}
|
|
783
820
|
async fetchOffersPage(params) {
|
|
784
821
|
this.ensureAuthenticated();
|
|
822
|
+
const queryParams = PaginationParams.toQueryParams(params);
|
|
823
|
+
if (this._config.sandbox) {
|
|
824
|
+
queryParams.sandbox = true;
|
|
825
|
+
}
|
|
785
826
|
const pageDto = await this.api.send({
|
|
786
827
|
method: "GET",
|
|
787
828
|
url: "/v1/offers",
|
|
788
|
-
queryParams
|
|
829
|
+
queryParams,
|
|
789
830
|
attributes: Attributes.protected()
|
|
790
831
|
});
|
|
791
832
|
return PaginatedResponse.fromDto(pageDto, Offer.fromDto);
|
|
@@ -799,9 +840,12 @@ var CoinListClientImpl = class {
|
|
|
799
840
|
});
|
|
800
841
|
return OfferDetail.fromDto(offerDetailDto);
|
|
801
842
|
}
|
|
802
|
-
async fetchAllParticipations() {
|
|
843
|
+
async fetchAllParticipations(offerId) {
|
|
803
844
|
this.ensureAuthenticated();
|
|
804
|
-
return await fetchAllPages(
|
|
845
|
+
return await fetchAllPages(
|
|
846
|
+
this.fetchParticipationsPage.bind(this),
|
|
847
|
+
{ offerId }
|
|
848
|
+
);
|
|
805
849
|
}
|
|
806
850
|
async fetchParticipationsPage(params) {
|
|
807
851
|
this.ensureAuthenticated();
|
|
@@ -809,7 +853,7 @@ var CoinListClientImpl = class {
|
|
|
809
853
|
{
|
|
810
854
|
method: "GET",
|
|
811
855
|
url: "/v1/participations",
|
|
812
|
-
queryParams:
|
|
856
|
+
queryParams: ParticipationsPaginationParams.toQueryParams(params),
|
|
813
857
|
attributes: Attributes.protected()
|
|
814
858
|
}
|
|
815
859
|
);
|
|
@@ -834,6 +878,29 @@ var CoinListClientImpl = class {
|
|
|
834
878
|
});
|
|
835
879
|
return Participation.fromDto(participationDto);
|
|
836
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
|
+
}
|
|
837
904
|
ensureAuthenticated() {
|
|
838
905
|
if (this.getAuthState() !== "logged-in") {
|
|
839
906
|
throw new NotAuthenticatedError();
|
|
@@ -873,6 +940,43 @@ function CoinListProvider({ config, children }) {
|
|
|
873
940
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CoinListContext.Provider, { value, children });
|
|
874
941
|
}
|
|
875
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
|
+
|
|
876
980
|
// src/client/hooks/useCoinList.ts
|
|
877
981
|
var import_react2 = require("react");
|
|
878
982
|
function useCoinList() {
|
|
@@ -892,18 +996,59 @@ var CoinListClientInitializationError = class extends Error {
|
|
|
892
996
|
}
|
|
893
997
|
};
|
|
894
998
|
|
|
895
|
-
// src/client/hooks/
|
|
999
|
+
// src/client/hooks/useCoinListRequirements.ts
|
|
896
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");
|
|
897
1042
|
function useCompleteCoinListOAuth(options) {
|
|
898
1043
|
const { coinlist } = useCoinList();
|
|
899
|
-
const postOAuthCompleteRef = (0,
|
|
900
|
-
const onFailureRef = (0,
|
|
901
|
-
const onSuccessRef = (0,
|
|
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);
|
|
902
1047
|
postOAuthCompleteRef.current = options.postOAuthComplete;
|
|
903
1048
|
onFailureRef.current = options.onFailure;
|
|
904
1049
|
onSuccessRef.current = options.onSuccess;
|
|
905
|
-
const hasStartedExchangeRef = (0,
|
|
906
|
-
(0,
|
|
1050
|
+
const hasStartedExchangeRef = (0, import_react4.useRef)(false);
|
|
1051
|
+
(0, import_react4.useEffect)(() => {
|
|
907
1052
|
if (typeof window === "undefined") return;
|
|
908
1053
|
const params = new URLSearchParams(window.location.search);
|
|
909
1054
|
if (!params.has("code") && !params.has("error")) return;
|
|
@@ -974,6 +1119,7 @@ var User = {
|
|
|
974
1119
|
0 && (module.exports = {
|
|
975
1120
|
AuthorizationCode,
|
|
976
1121
|
Blockchain,
|
|
1122
|
+
ChecklistStatus,
|
|
977
1123
|
ClientId,
|
|
978
1124
|
ClientSecret,
|
|
979
1125
|
CodeChallenge,
|
|
@@ -997,7 +1143,13 @@ var User = {
|
|
|
997
1143
|
PaginationParams,
|
|
998
1144
|
Participation,
|
|
999
1145
|
ParticipationId,
|
|
1146
|
+
ParticipationsPaginationParams,
|
|
1000
1147
|
RedirectUri,
|
|
1148
|
+
Requirement,
|
|
1149
|
+
RequirementId,
|
|
1150
|
+
RequirementStatus,
|
|
1151
|
+
RequirementStatusInfo,
|
|
1152
|
+
RequirementVariant,
|
|
1001
1153
|
TermItem,
|
|
1002
1154
|
User,
|
|
1003
1155
|
UserEmail,
|
|
@@ -1006,6 +1158,7 @@ var User = {
|
|
|
1006
1158
|
createCoinListClient,
|
|
1007
1159
|
fetchAllPages,
|
|
1008
1160
|
useCoinList,
|
|
1161
|
+
useCoinListRequirements,
|
|
1009
1162
|
useCompleteCoinListOAuth
|
|
1010
1163
|
});
|
|
1011
1164
|
//# sourceMappingURL=index.cjs.map
|