@crossmint/client-sdk-react-ui 0.0.8-alpha.4 → 0.1.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 (136) hide show
  1. package/README.md +18 -12
  2. package/lib/cjs/CrossmintPayButton.d.ts +3 -0
  3. package/lib/cjs/CrossmintPayButton.js +91 -0
  4. package/lib/cjs/CrossmintPayButton.js.map +1 -0
  5. package/lib/cjs/CrossmintStatusButton.d.ts +3 -0
  6. package/lib/cjs/CrossmintStatusButton.js +75 -0
  7. package/lib/cjs/CrossmintStatusButton.js.map +1 -0
  8. package/lib/cjs/hooks/useCrossmintModal.d.ts +12 -0
  9. package/lib/cjs/hooks/useCrossmintModal.js +90 -0
  10. package/lib/cjs/hooks/useCrossmintModal.js.map +1 -0
  11. package/lib/cjs/{useCrossMintStatus.d.ts → hooks/useCrossmintStatus.d.ts} +6 -3
  12. package/lib/cjs/hooks/useCrossmintStatus.js +75 -0
  13. package/lib/cjs/hooks/useCrossmintStatus.js.map +1 -0
  14. package/lib/cjs/index.d.ts +2 -7
  15. package/lib/cjs/index.js +7 -8
  16. package/lib/cjs/index.js.map +1 -1
  17. package/lib/cjs/package.json +3 -1
  18. package/lib/cjs/styles/index.d.ts +9 -0
  19. package/lib/cjs/styles/index.js +45 -0
  20. package/lib/cjs/styles/index.js.map +1 -0
  21. package/lib/cjs/types.d.ts +48 -0
  22. package/lib/cjs/types.js +29 -0
  23. package/lib/cjs/types.js.map +1 -0
  24. package/lib/cjs/utils.d.ts +1 -0
  25. package/lib/cjs/utils.js +5 -0
  26. package/lib/cjs/utils.js.map +1 -0
  27. package/lib/cjs/version.d.ts +1 -0
  28. package/lib/cjs/version.js +5 -0
  29. package/lib/cjs/version.js.map +1 -0
  30. package/lib/esm/CrossmintPayButton.d.ts +3 -0
  31. package/lib/esm/CrossmintPayButton.js +49 -0
  32. package/lib/esm/CrossmintPayButton.js.map +1 -0
  33. package/lib/esm/CrossmintStatusButton.d.ts +3 -0
  34. package/lib/esm/CrossmintStatusButton.js +36 -0
  35. package/lib/esm/CrossmintStatusButton.js.map +1 -0
  36. package/lib/esm/hooks/useCrossmintModal.d.ts +12 -0
  37. package/lib/esm/hooks/useCrossmintModal.js +87 -0
  38. package/lib/esm/hooks/useCrossmintModal.js.map +1 -0
  39. package/lib/esm/{useCrossMintStatus.d.ts → hooks/useCrossmintStatus.d.ts} +6 -3
  40. package/lib/esm/hooks/useCrossmintStatus.js +60 -0
  41. package/lib/esm/hooks/useCrossmintStatus.js.map +1 -0
  42. package/lib/esm/index.d.ts +2 -7
  43. package/lib/esm/index.js +2 -7
  44. package/lib/esm/index.js.map +1 -1
  45. package/lib/esm/package.json +3 -0
  46. package/lib/esm/styles/index.d.ts +9 -0
  47. package/lib/esm/styles/index.js +41 -0
  48. package/lib/esm/styles/index.js.map +1 -0
  49. package/lib/esm/types.d.ts +48 -0
  50. package/lib/esm/types.js +26 -0
  51. package/lib/esm/types.js.map +1 -0
  52. package/lib/esm/utils.d.ts +1 -0
  53. package/lib/esm/utils.js +2 -0
  54. package/lib/esm/utils.js.map +1 -0
  55. package/lib/esm/version.d.ts +1 -0
  56. package/lib/esm/version.js +2 -0
  57. package/lib/esm/version.js.map +1 -0
  58. package/package.json +21 -11
  59. package/src/CrossmintPayButton.tsx +108 -0
  60. package/src/CrossmintStatusButton.tsx +77 -0
  61. package/src/hooks/useCrossmintModal.ts +142 -0
  62. package/src/hooks/useCrossmintStatus.ts +85 -0
  63. package/src/index.ts +2 -7
  64. package/src/styles/index.ts +50 -0
  65. package/src/types.ts +56 -0
  66. package/src/utils.ts +1 -0
  67. package/src/version.ts +1 -0
  68. package/lib/cjs/CrossMintButton.d.ts +0 -16
  69. package/lib/cjs/CrossMintButton.js +0 -60
  70. package/lib/cjs/CrossMintButton.js.map +0 -1
  71. package/lib/cjs/CrossMintModal.d.ts +0 -6
  72. package/lib/cjs/CrossMintModal.js +0 -55
  73. package/lib/cjs/CrossMintModal.js.map +0 -1
  74. package/lib/cjs/CrossMintModalProvider.d.ts +0 -6
  75. package/lib/cjs/CrossMintModalProvider.js +0 -48
  76. package/lib/cjs/CrossMintModalProvider.js.map +0 -1
  77. package/lib/cjs/CrossMintPopupProvider.d.ts +0 -6
  78. package/lib/cjs/CrossMintPopupProvider.js +0 -70
  79. package/lib/cjs/CrossMintPopupProvider.js.map +0 -1
  80. package/lib/cjs/CrossMintProvider.d.ts +0 -10
  81. package/lib/cjs/CrossMintProvider.js +0 -52
  82. package/lib/cjs/CrossMintProvider.js.map +0 -1
  83. package/lib/cjs/CrossMintStatusButton.d.ts +0 -10
  84. package/lib/cjs/CrossMintStatusButton.js +0 -66
  85. package/lib/cjs/CrossMintStatusButton.js.map +0 -1
  86. package/lib/cjs/CrossMintStatusProvider.d.ts +0 -8
  87. package/lib/cjs/CrossMintStatusProvider.js +0 -70
  88. package/lib/cjs/CrossMintStatusProvider.js.map +0 -1
  89. package/lib/cjs/useCrossMintModal.d.ts +0 -7
  90. package/lib/cjs/useCrossMintModal.js +0 -10
  91. package/lib/cjs/useCrossMintModal.js.map +0 -1
  92. package/lib/cjs/useCrossMintPopup.d.ts +0 -8
  93. package/lib/cjs/useCrossMintPopup.js +0 -10
  94. package/lib/cjs/useCrossMintPopup.js.map +0 -1
  95. package/lib/cjs/useCrossMintStatus.js +0 -18
  96. package/lib/cjs/useCrossMintStatus.js.map +0 -1
  97. package/lib/esm/CrossMintButton.d.ts +0 -16
  98. package/lib/esm/CrossMintButton.js +0 -25
  99. package/lib/esm/CrossMintButton.js.map +0 -1
  100. package/lib/esm/CrossMintModal.d.ts +0 -6
  101. package/lib/esm/CrossMintModal.js +0 -32
  102. package/lib/esm/CrossMintModal.js.map +0 -1
  103. package/lib/esm/CrossMintModalProvider.d.ts +0 -6
  104. package/lib/esm/CrossMintModalProvider.js +0 -13
  105. package/lib/esm/CrossMintModalProvider.js.map +0 -1
  106. package/lib/esm/CrossMintPopupProvider.d.ts +0 -6
  107. package/lib/esm/CrossMintPopupProvider.js +0 -47
  108. package/lib/esm/CrossMintPopupProvider.js.map +0 -1
  109. package/lib/esm/CrossMintProvider.d.ts +0 -10
  110. package/lib/esm/CrossMintProvider.js +0 -17
  111. package/lib/esm/CrossMintProvider.js.map +0 -1
  112. package/lib/esm/CrossMintStatusButton.d.ts +0 -10
  113. package/lib/esm/CrossMintStatusButton.js +0 -31
  114. package/lib/esm/CrossMintStatusButton.js.map +0 -1
  115. package/lib/esm/CrossMintStatusProvider.d.ts +0 -8
  116. package/lib/esm/CrossMintStatusProvider.js +0 -36
  117. package/lib/esm/CrossMintStatusProvider.js.map +0 -1
  118. package/lib/esm/useCrossMintModal.d.ts +0 -7
  119. package/lib/esm/useCrossMintModal.js +0 -6
  120. package/lib/esm/useCrossMintModal.js.map +0 -1
  121. package/lib/esm/useCrossMintPopup.d.ts +0 -8
  122. package/lib/esm/useCrossMintPopup.js +0 -6
  123. package/lib/esm/useCrossMintPopup.js.map +0 -1
  124. package/lib/esm/useCrossMintStatus.js +0 -14
  125. package/lib/esm/useCrossMintStatus.js.map +0 -1
  126. package/src/CrossMintButton.tsx +0 -75
  127. package/src/CrossMintModal.tsx +0 -54
  128. package/src/CrossMintModalProvider.tsx +0 -23
  129. package/src/CrossMintPopupProvider.tsx +0 -94
  130. package/src/CrossMintProvider.tsx +0 -44
  131. package/src/CrossMintStatusButton.tsx +0 -73
  132. package/src/CrossMintStatusProvider.tsx +0 -63
  133. package/src/useCrossMintModal.tsx +0 -12
  134. package/src/useCrossMintPopup.tsx +0 -21
  135. package/src/useCrossMintStatus.tsx +0 -22
  136. package/styles.css +0 -119
@@ -0,0 +1,108 @@
1
+ import React, { FC, MouseEventHandler, useMemo, useCallback, useState } from "react";
2
+ import useCrossmintStatus, { OnboardingRequestStatusResponse } from "./hooks/useCrossmintStatus";
3
+ import useCrossmintModal from "./hooks/useCrossmintModal";
4
+ import { useStyles, formatProps } from "./styles";
5
+ import { isClientSide } from "./utils";
6
+ import { CrossmintPayButtonProps, mintingContractTypes } from "./types";
7
+
8
+ const defaultMintConfig: any = {
9
+ type: mintingContractTypes.CANDY_MACHINE,
10
+ };
11
+
12
+ export const CrossmintPayButton: FC<CrossmintPayButtonProps> = ({
13
+ className,
14
+ disabled,
15
+ onClick,
16
+ style,
17
+ tabIndex,
18
+ theme = "dark",
19
+ collectionTitle,
20
+ collectionDescription,
21
+ collectionPhoto,
22
+ mintTo,
23
+ emailTo,
24
+ listingId,
25
+ clientId,
26
+ development = false,
27
+ auctionId,
28
+ hideMintOnInactiveClient = false,
29
+ showOverlay = true,
30
+ mintConfig = defaultMintConfig,
31
+ ...props
32
+ }) => {
33
+ const status = useCrossmintStatus({ clientId, development });
34
+ const { connecting, connect } = useCrossmintModal({
35
+ clientId,
36
+ development,
37
+ showOverlay,
38
+ });
39
+
40
+ if (collectionTitle === "<TITLE_FOR_YOUR_COLLECTION>") {
41
+ console.warn("No collection title specified. Please add a collection title to your <CrossmintPayButton />");
42
+ collectionTitle = "";
43
+ }
44
+
45
+ if (collectionDescription === "<DESCRIPTION_OF_YOUR_COLLECTION>") {
46
+ console.warn(
47
+ "No collection description specified. Please add a collection description to your <CrossmintPayButton />"
48
+ );
49
+ collectionDescription = "";
50
+ }
51
+
52
+ if (collectionPhoto === "<OPT_URL_TO_PHOTO_COVER>") {
53
+ console.warn("No collection photo specified. Please add a collection photo to your <CrossmintPayButton />");
54
+ collectionPhoto = "";
55
+ }
56
+
57
+ const handleClick: MouseEventHandler<HTMLButtonElement> = useCallback(
58
+ (event) => {
59
+ if (onClick) onClick(event);
60
+
61
+ if (!event.defaultPrevented) {
62
+ connect(
63
+ mintConfig,
64
+ collectionTitle,
65
+ collectionDescription,
66
+ collectionPhoto,
67
+ mintTo,
68
+ emailTo,
69
+ listingId
70
+ );
71
+ }
72
+ },
73
+ [onClick]
74
+ );
75
+
76
+ const classes = useStyles(formatProps(theme));
77
+
78
+ const content = useMemo(() => {
79
+ if (connecting) return <p className={classes.crossmintParagraph}>Connecting ...</p>;
80
+ return <p className={classes.crossmintParagraph}>Buy with credit card</p>;
81
+ }, [connecting]);
82
+
83
+ if (hideMintOnInactiveClient && status !== OnboardingRequestStatusResponse.ACCEPTED) {
84
+ return null;
85
+ }
86
+
87
+ return (
88
+ <>
89
+ {isClientSide && (
90
+ <button
91
+ className={`${classes.crossmintButton} ${className}`}
92
+ disabled={disabled}
93
+ onClick={handleClick}
94
+ style={{ ...style }}
95
+ tabIndex={tabIndex}
96
+ {...props}
97
+ >
98
+ <img
99
+ className={classes.crossmintImg}
100
+ src="https://www.crossmint.io/assets/crossmint/logo.png"
101
+ alt="Crossmint logo"
102
+ />
103
+ {content}
104
+ </button>
105
+ )}
106
+ </>
107
+ );
108
+ };
@@ -0,0 +1,77 @@
1
+ import React, { FC, MouseEventHandler, useMemo, useCallback } from "react";
2
+ import useCrossmintStatus, { OnboardingRequestStatusResponse } from "./hooks/useCrossmintStatus";
3
+ import { useStyles, formatProps } from "./styles";
4
+ import { baseUrls, BaseButtonProps } from "./types";
5
+ import { isClientSide } from "./utils";
6
+
7
+ export const CrossmintStatusButton: FC<BaseButtonProps> = ({
8
+ className,
9
+ disabled,
10
+ onClick,
11
+ style,
12
+ tabIndex,
13
+ theme = "dark",
14
+ clientId,
15
+ auctionId,
16
+ development = false,
17
+ ...props
18
+ }) => {
19
+ const status = useCrossmintStatus({ clientId, development });
20
+
21
+ const handleClick: MouseEventHandler<HTMLButtonElement> = useCallback(
22
+ (event) => {
23
+ if (onClick) onClick(event);
24
+
25
+ if (status === OnboardingRequestStatusResponse.WAITING_SUBMISSION) {
26
+ const baseUrl = development ? baseUrls.dev : baseUrls.prod;
27
+ window.open(
28
+ `${baseUrl}/developers/onboarding${clientId ? `?clientId=${clientId}` : ""}${
29
+ auctionId ? `&auctionId=${auctionId}` : ""
30
+ }`,
31
+ "_blank"
32
+ );
33
+ return;
34
+ }
35
+ },
36
+ [status]
37
+ );
38
+
39
+ const classes = useStyles(formatProps(theme));
40
+
41
+ const content = useMemo(() => {
42
+ switch (status) {
43
+ case OnboardingRequestStatusResponse.INVALID:
44
+ return <p className={classes.crossmintParagraph}>Invalid clientId</p>;
45
+ case OnboardingRequestStatusResponse.WAITING_SUBMISSION:
46
+ return <p className={classes.crossmintParagraph}>Click here to setup CrossMint</p>;
47
+ case OnboardingRequestStatusResponse.PENDING:
48
+ return <p className={classes.crossmintParagraph}>Your application is under review</p>;
49
+ case OnboardingRequestStatusResponse.ACCEPTED:
50
+ return <p className={classes.crossmintParagraph}>You're good to go!</p>;
51
+ case OnboardingRequestStatusResponse.REJECTED:
52
+ return <p className={classes.crossmintParagraph}>Your application was rejected</p>;
53
+ }
54
+ }, [status]);
55
+
56
+ return (
57
+ <>
58
+ {isClientSide && (
59
+ <button
60
+ className={`${classes.crossmintButton} ${className}`}
61
+ disabled={status !== OnboardingRequestStatusResponse.WAITING_SUBMISSION}
62
+ onClick={handleClick}
63
+ style={{ ...style }}
64
+ tabIndex={tabIndex}
65
+ {...props}
66
+ >
67
+ <img
68
+ className={classes.crossmintImg}
69
+ src={`${baseUrls.prod}/assets/crossmint/logo.png`}
70
+ alt="Crossmint logo"
71
+ />
72
+ {content}
73
+ </button>
74
+ )}
75
+ </>
76
+ );
77
+ };
@@ -0,0 +1,142 @@
1
+ import { useState } from "react";
2
+ import { LIB_VERSION } from "../version";
3
+ import { baseUrls, clientNames, PayButtonConfig } from "../types";
4
+
5
+ function createPopupString() {
6
+ return `height=750,width=400,left=${window.innerWidth / 2 - 200},top=${
7
+ window.innerHeight / 2 - 375
8
+ },resizable=yes,scrollbars=yes,toolbar=yes,menubar=true,location=no,directories=no, status=yes`;
9
+ }
10
+
11
+ interface IProps {
12
+ development: boolean;
13
+ clientId: string;
14
+ showOverlay: boolean;
15
+ }
16
+
17
+ interface IReturn {
18
+ connecting: boolean;
19
+ connect: (
20
+ mintConfig: PayButtonConfig,
21
+ collectionTitle?: string,
22
+ collectionDescription?: string,
23
+ collectionPhoto?: string,
24
+ mintTo?: string,
25
+ emailTo?: string,
26
+ listingId?: string
27
+ ) => void;
28
+ }
29
+
30
+ type MintQueryParams = {
31
+ clientId: string;
32
+ closeOnSuccess: string;
33
+ collectionTitle?: string;
34
+ collectionDescription?: string;
35
+ collectionPhoto?: string;
36
+ mintTo?: string;
37
+ emailTo?: string;
38
+ listingId?: string;
39
+ clientName: string;
40
+ clientVersion: string;
41
+ mintConfig: string;
42
+ };
43
+
44
+ const overlayId = "__crossmint-overlay__";
45
+
46
+ const addLoadingOverlay = (): void => {
47
+ const overlayEl = document.createElement("div");
48
+ overlayEl.setAttribute("id", overlayId);
49
+ const overlayStyles = {
50
+ width: "100vw",
51
+ height: "100vh",
52
+ "background-color": "rgba(0, 0, 0, 0.5)",
53
+ position: "fixed",
54
+ "z-index": "99999999",
55
+ top: "0",
56
+ left: "0",
57
+ };
58
+ Object.assign(overlayEl.style, overlayStyles);
59
+ document.body.appendChild(overlayEl);
60
+ };
61
+
62
+ const removeLoadingOverlay = (): void => {
63
+ const overlayEl = document.getElementById(overlayId);
64
+ if (overlayEl) overlayEl.remove();
65
+ };
66
+
67
+ export default function useCrossMintModal({ development, clientId, showOverlay }: IProps): IReturn {
68
+ const [connecting, setConnecting] = useState(false);
69
+
70
+ const createPopup = (
71
+ mintConfig: PayButtonConfig,
72
+ collectionTitle?: string,
73
+ collectionDescription?: string,
74
+ collectionPhoto?: string,
75
+ mintTo?: string,
76
+ emailTo?: string,
77
+ listingId?: string
78
+ ) => {
79
+ const urlOrigin = development ? baseUrls.dev : baseUrls.prod;
80
+ const getMintQueryParams = (): string => {
81
+ const mintQueryParams: MintQueryParams = {
82
+ clientId: clientId,
83
+ closeOnSuccess: "false",
84
+ clientName: clientNames.reactUi,
85
+ clientVersion: LIB_VERSION,
86
+ mintConfig: JSON.stringify(mintConfig),
87
+ };
88
+
89
+ if (collectionTitle) mintQueryParams.collectionTitle = collectionTitle;
90
+ if (collectionDescription) mintQueryParams.collectionDescription = collectionDescription;
91
+ if (collectionPhoto) mintQueryParams.collectionPhoto = collectionPhoto;
92
+ if (mintTo) mintQueryParams.mintTo = mintTo;
93
+ if (emailTo) mintQueryParams.emailTo = emailTo;
94
+ if (listingId) mintQueryParams.listingId = listingId;
95
+
96
+ return new URLSearchParams(mintQueryParams).toString();
97
+ };
98
+ const callbackUrl = encodeURIComponent(`${urlOrigin}/checkout/mint?${getMintQueryParams()}`);
99
+ const url = `${urlOrigin}/signin?callbackUrl=${callbackUrl}`;
100
+
101
+ const pop = window.open(url, "popUpWindow", createPopupString());
102
+ if (pop) {
103
+ registerListeners(pop);
104
+ if (showOverlay) {
105
+ addLoadingOverlay();
106
+ }
107
+ } else {
108
+ setConnecting(false);
109
+ console.error("Failed to open popup window");
110
+ }
111
+ };
112
+
113
+ const connect = (
114
+ mintConfig: PayButtonConfig,
115
+ collectionTitle?: string,
116
+ collectionDescription?: string,
117
+ collectionPhoto?: string,
118
+ mintTo?: string,
119
+ emailTo?: string,
120
+ listingId?: string
121
+ ) => {
122
+ if (connecting) return;
123
+
124
+ setConnecting(true);
125
+
126
+ createPopup(mintConfig, collectionTitle, collectionDescription, collectionPhoto, mintTo, emailTo, listingId);
127
+ };
128
+
129
+ function registerListeners(pop: Window) {
130
+ const timer = setInterval(function () {
131
+ if (pop.closed) {
132
+ clearInterval(timer);
133
+ setConnecting(false);
134
+ if (showOverlay) {
135
+ removeLoadingOverlay();
136
+ }
137
+ }
138
+ }, 500);
139
+ }
140
+
141
+ return { connecting, connect };
142
+ }
@@ -0,0 +1,85 @@
1
+ import { useState, useEffect } from "react";
2
+ import { validate } from "uuid";
3
+ import { LIB_VERSION } from "../version";
4
+ import { clientNames, baseUrls, customHeaders } from "../types";
5
+
6
+ export enum OnboardingRequestStatusResponse {
7
+ WAITING_SUBMISSION = "waiting-submission",
8
+ PENDING = "pending",
9
+ REJECTED = "rejected",
10
+ ACCEPTED = "accepted",
11
+ INVALID = "invalid",
12
+ }
13
+
14
+ export interface CrossMintStatusContextState {
15
+ status: OnboardingRequestStatusResponse;
16
+ clientId: string;
17
+ auctionId?: string;
18
+ hideMintOnInactiveClient: boolean;
19
+ }
20
+
21
+ interface IProps {
22
+ clientId: string;
23
+ development: boolean;
24
+ }
25
+
26
+ const validateClientId = (clientId: string): boolean => {
27
+ try {
28
+ const isValid = validate(clientId);
29
+ return !!isValid;
30
+ } catch (e) {
31
+ console.error(e);
32
+ return false;
33
+ }
34
+ };
35
+
36
+ export default function useCrossMintStatus({ clientId, development }: IProps) {
37
+ const [status, setStatus] = useState<OnboardingRequestStatusResponse>(
38
+ OnboardingRequestStatusResponse.WAITING_SUBMISSION
39
+ );
40
+
41
+ async function fetchClientIntegration() {
42
+ if (!clientId || clientId === "" || clientId === "<YOUR_CLIENT_ID>") {
43
+ console.error("You must enter your own Crossmint client ID in <CrossmintPayButton clientId=XXX>");
44
+ return;
45
+ }
46
+
47
+ if (!validateClientId(clientId)) {
48
+ console.error(
49
+ "The clientId passed to is invalid. Make sure to pass the clientId obtained from the crossmint team, with format XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX"
50
+ );
51
+ return;
52
+ }
53
+
54
+ const baseUrl = development ? baseUrls.dev : baseUrls.prod;
55
+
56
+ const res = await fetch(`${baseUrl}/api/crossmint/onboardingRequests/${clientId}/status`, {
57
+ headers: {
58
+ [customHeaders.clientVersion]: LIB_VERSION,
59
+ [customHeaders.clientName]: clientNames.reactUi,
60
+ },
61
+ });
62
+
63
+ if (res.status === 200) {
64
+ const resData: { clientId: string; status: OnboardingRequestStatusResponse } = await res.json();
65
+
66
+ setStatus(resData.status);
67
+ } else {
68
+ if (status !== OnboardingRequestStatusResponse.INVALID) {
69
+ setStatus(OnboardingRequestStatusResponse.INVALID);
70
+ }
71
+ }
72
+ }
73
+
74
+ useEffect(() => {
75
+ fetchClientIntegration();
76
+
77
+ const interval = setInterval(() => {
78
+ fetchClientIntegration();
79
+ }, 60 * 1000);
80
+
81
+ return () => clearInterval(interval);
82
+ }, []);
83
+
84
+ return status;
85
+ }
package/src/index.ts CHANGED
@@ -1,7 +1,2 @@
1
- export * from "./CrossMintButton";
2
- export * from "./CrossMintModal";
3
- export * from "./useCrossMintModal";
4
- export * from "./useCrossMintPopup";
5
- export * from "./CrossMintProvider";
6
- export * from "./useCrossMintStatus";
7
- export * from "./CrossMintStatusButton";
1
+ export * from "./CrossmintPayButton";
2
+ export * from "./CrossmintStatusButton";
@@ -0,0 +1,50 @@
1
+ import { createUseStyles } from "react-jss";
2
+
3
+ const DARK_BG = "#1e1e1e";
4
+
5
+ interface CustomStylingProps {
6
+ buttonBgColor?: string;
7
+ paragraphColor?: string;
8
+ }
9
+
10
+ const themeIsLight = (theme: string) => theme === "light";
11
+ export const formatProps = (theme: string): CustomStylingProps => ({
12
+ buttonBgColor: themeIsLight(theme) ? "white" : DARK_BG,
13
+ paragraphColor: themeIsLight(theme) ? "black" : "white",
14
+ });
15
+
16
+ export const useStyles = createUseStyles({
17
+ "@global": {
18
+ "@import":
19
+ "url('https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900&display=swap')",
20
+ },
21
+ crossmintButton: {
22
+ display: "flex",
23
+ "flex-direction": "row",
24
+ "align-items": "center",
25
+ padding: "0.875rem 0.875rem",
26
+ "font-weight": "900",
27
+ transition: "opacity ease-in-out 0.25s",
28
+ "border-radius": "0.5rem",
29
+ "font-family": `"Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif`,
30
+ outline: "none",
31
+ border: "none",
32
+ "box-shadow": "0px 8px 15px rgba(0, 0, 0, 0.1)",
33
+ "justify-content": "center",
34
+ background: ({ buttonBgColor }: CustomStylingProps) => buttonBgColor,
35
+
36
+ "&:hover:enabled": {
37
+ opacity: "0.6",
38
+ cursor: "pointer",
39
+ },
40
+ },
41
+ crossmintImg: {
42
+ width: "21px",
43
+ height: "21px",
44
+ "margin-right": "0.875rem",
45
+ },
46
+ crossmintParagraph: {
47
+ color: ({ paragraphColor }: CustomStylingProps) => paragraphColor,
48
+ margin: "0",
49
+ },
50
+ });
package/src/types.ts ADDED
@@ -0,0 +1,56 @@
1
+ import { CSSProperties, MouseEvent } from "react";
2
+
3
+ export enum clientNames {
4
+ reactUi = "client-sdk-react-ui",
5
+ }
6
+
7
+ export enum baseUrls {
8
+ prod = "https://www.crossmint.io",
9
+ dev = "http://localhost:3001",
10
+ }
11
+
12
+ export enum customHeaders {
13
+ clientVersion = "X-Client-Version",
14
+ clientName = "X-Client-Name",
15
+ }
16
+
17
+ enum theme {
18
+ light = "light",
19
+ dark = "dark",
20
+ }
21
+
22
+ export enum mintingContractTypes {
23
+ CANDY_MACHINE = "candy-machine",
24
+ SOLANA_AUCTION = "solana-auction",
25
+ ERC_721 = "erc-721",
26
+ }
27
+
28
+ export interface PayButtonConfig {
29
+ type: string;
30
+
31
+ [propName: string]: any;
32
+ }
33
+
34
+ export interface BaseButtonProps {
35
+ className?: string;
36
+ disabled?: boolean;
37
+ onClick?: (e: MouseEvent<HTMLButtonElement>) => void;
38
+ style?: CSSProperties;
39
+ tabIndex?: number;
40
+ clientId: string;
41
+ auctionId?: string;
42
+ theme?: theme;
43
+ development?: boolean;
44
+ }
45
+
46
+ export interface CrossmintPayButtonProps extends BaseButtonProps {
47
+ collectionTitle?: string;
48
+ collectionDescription?: string;
49
+ collectionPhoto?: string;
50
+ mintTo?: string;
51
+ emailTo?: string;
52
+ listingId?: string;
53
+ showOverlay?: boolean;
54
+ hideMintOnInactiveClient?: boolean;
55
+ mintConfig?: PayButtonConfig;
56
+ }
package/src/utils.ts ADDED
@@ -0,0 +1 @@
1
+ export const isClientSide = typeof window !== "undefined";
package/src/version.ts ADDED
@@ -0,0 +1 @@
1
+ export const LIB_VERSION = "0.1.1";
@@ -1,16 +0,0 @@
1
- import { CSSProperties, FC, MouseEvent } from "react";
2
- export interface ButtonProps {
3
- className?: string;
4
- disabled?: boolean;
5
- onClick?: (e: MouseEvent<HTMLButtonElement>) => void;
6
- style?: CSSProperties;
7
- tabIndex?: number;
8
- theme?: "light" | "dark";
9
- collectionTitle?: string;
10
- collectionDescription?: string;
11
- collectionPhoto?: string;
12
- mintTo?: string;
13
- emailTo?: string;
14
- listingId?: string;
15
- }
16
- export declare const CrossMintButton: FC<ButtonProps>;
@@ -1,60 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __rest = (this && this.__rest) || function (s, e) {
22
- var t = {};
23
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
24
- t[p] = s[p];
25
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
26
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
27
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
28
- t[p[i]] = s[p[i]];
29
- }
30
- return t;
31
- };
32
- Object.defineProperty(exports, "__esModule", { value: true });
33
- exports.CrossMintButton = void 0;
34
- const react_1 = __importStar(require("react"));
35
- const _1 = require(".");
36
- const useCrossMintPopup_1 = require("./useCrossMintPopup");
37
- const CrossMintButton = (_a) => {
38
- var { className, disabled, onClick, style, tabIndex, theme = "dark", collectionTitle, collectionDescription, collectionPhoto, mintTo, emailTo, listingId } = _a, props = __rest(_a, ["className", "disabled", "onClick", "style", "tabIndex", "theme", "collectionTitle", "collectionDescription", "collectionPhoto", "mintTo", "emailTo", "listingId"]);
39
- const { hideMintOnInactiveClient, status } = (0, _1.useCrossMintStatus)();
40
- const { connecting, connect } = (0, useCrossMintPopup_1.useCrossMintPopup)();
41
- const handleClick = (0, react_1.useCallback)((event) => {
42
- if (onClick)
43
- onClick(event);
44
- if (!event.defaultPrevented)
45
- connect(collectionTitle, collectionDescription, collectionPhoto, mintTo, emailTo, listingId);
46
- }, [onClick]);
47
- const content = (0, react_1.useMemo)(() => {
48
- if (connecting)
49
- return react_1.default.createElement("p", null, "Connecting ...");
50
- return react_1.default.createElement("p", null, "Buy with credit card");
51
- }, [connecting]);
52
- if (hideMintOnInactiveClient && status !== _1.OnboardingRequestStatusResponse.ACCEPTED) {
53
- return null;
54
- }
55
- return (react_1.default.createElement("button", Object.assign({ className: `client-sdk-button-trigger client-sdk-button-trigger-${theme}`, disabled: disabled, onClick: handleClick, style: Object.assign({}, style), tabIndex: tabIndex }, props),
56
- react_1.default.createElement("img", { className: "client-sdk-button-icon", src: "https://www.crossmint.io/assets/crossmint/logo.png", alt: "Crossmint logo" }),
57
- content));
58
- };
59
- exports.CrossMintButton = CrossMintButton;
60
- //# sourceMappingURL=CrossMintButton.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CrossMintButton.js","sourceRoot":"","sources":["../../src/CrossMintButton.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAsG;AACtG,wBAAwE;AACxE,2DAAwD;AAiBjD,MAAM,eAAe,GAAoB,CAAC,EAchD,EAAE,EAAE;QAd4C,EAC7C,SAAS,EACT,QAAQ,EACR,OAAO,EACP,KAAK,EACL,QAAQ,EACR,KAAK,GAAG,MAAM,EACd,eAAe,EACf,qBAAqB,EACrB,eAAe,EACf,MAAM,EACN,OAAO,EACP,SAAS,OAEZ,EADM,KAAK,cAbqC,mKAchD,CADW;IAER,MAAM,EAAE,wBAAwB,EAAE,MAAM,EAAE,GAAG,IAAA,qBAAkB,GAAE,CAAC;IAElE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,IAAA,qCAAiB,GAAE,CAAC;IAEpD,MAAM,WAAW,GAAyC,IAAA,mBAAW,EACjE,CAAC,KAAK,EAAE,EAAE;QACN,IAAI,OAAO;YAAE,OAAO,CAAC,KAAK,CAAC,CAAC;QAE5B,IAAI,CAAC,KAAK,CAAC,gBAAgB;YACvB,OAAO,CAAC,eAAe,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IACrG,CAAC,EACD,CAAC,OAAO,CAAC,CACZ,CAAC;IAEF,MAAM,OAAO,GAAG,IAAA,eAAO,EAAC,GAAG,EAAE;QACzB,IAAI,UAAU;YAAE,OAAO,0DAAqB,CAAC;QAC7C,OAAO,gEAA2B,CAAC;IACvC,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;IAEjB,IAAI,wBAAwB,IAAI,MAAM,KAAK,kCAA+B,CAAC,QAAQ,EAAE;QACjF,OAAO,IAAI,CAAC;KACf;IAED,OAAO,CACH,wDACI,SAAS,EAAE,uDAAuD,KAAK,EAAE,EACzE,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,WAAW,EACpB,KAAK,oBAAO,KAAK,GACjB,QAAQ,EAAE,QAAQ,IACd,KAAK;QAET,uCACI,SAAS,EAAC,wBAAwB,EAClC,GAAG,EAAC,oDAAoD,EACxD,GAAG,EAAC,gBAAgB,GACtB;QACD,OAAO,CACH,CACZ,CAAC;AACN,CAAC,CAAC;AAvDW,QAAA,eAAe,mBAuD1B"}
@@ -1,6 +0,0 @@
1
- import { FC } from "react";
2
- export interface CrossMintModalProps {
3
- className?: string;
4
- container?: string;
5
- }
6
- export declare const CrossMintModal: FC<CrossMintModalProps>;
@@ -1,55 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.CrossMintModal = void 0;
23
- const react_1 = __importStar(require("react"));
24
- const react_dom_1 = require("react-dom");
25
- const useCrossMintModal_1 = require("./useCrossMintModal");
26
- const CrossMintModal = ({ className = "", container = "body" }) => {
27
- const ref = (0, react_1.useRef)(null);
28
- const { setVisible } = (0, useCrossMintModal_1.useCrossMintModal)();
29
- const [fadeIn, setFadeIn] = (0, react_1.useState)(false);
30
- const [portal, setPortal] = (0, react_1.useState)(null);
31
- const hideModal = (0, react_1.useCallback)(() => {
32
- setFadeIn(false);
33
- setTimeout(() => setVisible(false), 150);
34
- }, [setFadeIn, setVisible]);
35
- (0, react_1.useLayoutEffect)(() => {
36
- // Get original overflow
37
- const { overflow } = window.getComputedStyle(document.body);
38
- // Hack to enable fade in animation after mount
39
- setTimeout(() => setFadeIn(true), 0);
40
- // Prevent scrolling on mount
41
- document.body.style.overflow = "hidden";
42
- return () => {
43
- // Re-enable scrolling when component unmounts
44
- document.body.style.overflow = overflow;
45
- };
46
- }, [hideModal]);
47
- (0, react_1.useLayoutEffect)(() => setPortal(document.querySelector(container)), [setPortal, container]);
48
- return (portal &&
49
- (0, react_dom_1.createPortal)(react_1.default.createElement("div", { "aria-modal": "true", className: `client-sdk-modal ${fadeIn ? "client-sdk-modal-fade-in" : ""} ${className}`, ref: ref },
50
- react_1.default.createElement("div", { className: "client-sdk-modal-container" },
51
- react_1.default.createElement("span", { className: "client-sdk-modal-loader" })),
52
- react_1.default.createElement("div", { className: "client-sdk-modal-overlay" })), portal));
53
- };
54
- exports.CrossMintModal = CrossMintModal;
55
- //# sourceMappingURL=CrossMintModal.js.map