@coinbase/cdp-react 0.0.108 → 0.0.110
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/assets/OAuthStatusModal.css +1 -1
- package/dist/assets/SignIn.css +1 -1
- package/dist/assets/SignInImage.css +1 -1
- package/dist/assets/StatusView.css +1 -0
- package/dist/assets/SwitchTransition.css +1 -1
- package/dist/chunks/{CDPReactProvider.CFWIUvzR.js → CDPReactProvider.BWInVuNJ.js} +89 -86
- package/dist/chunks/LinkAuthFlow.0FnIchwa.js +144 -0
- package/dist/chunks/index.Du1vsLh6.js +23 -0
- package/dist/components/CDPReactProvider/index.d.ts +7 -1
- package/dist/components/CDPReactProvider/index.js +11 -7
- package/dist/components/EnrollMfa/index.js +1 -1
- package/dist/components/EnrollMfaModal/index.js +1 -1
- package/dist/components/ExportWallet/index.js +6 -4
- package/dist/components/ExportWalletModal/index.js +1 -1
- package/dist/components/Fund/index.js +1 -1
- package/dist/components/FundModal/index.js +1 -1
- package/dist/components/LinkAuth/LinkAuthFlow.js +9 -5
- package/dist/components/LinkAuth/LinkAuthFlowBackButton.js +2 -2
- package/dist/components/LinkAuth/LinkAuthFlowProvider.d.ts +22 -8
- package/dist/components/LinkAuth/LinkAuthFlowProvider.js +2 -2
- package/dist/components/LinkAuth/LinkAuthItem.js +1 -1
- package/dist/components/LinkAuth/LinkAuthItems.js +35 -28
- package/dist/components/LinkAuth/LinkAuthProvider.js +25 -18
- package/dist/components/LinkAuth/index.d.ts +2 -2
- package/dist/components/LinkAuth/index.js +63 -62
- package/dist/components/LinkAuth/types.d.ts +6 -1
- package/dist/components/LinkAuth/types.js +5 -3
- package/dist/components/LinkAuth/utils.js +3 -3
- package/dist/components/LinkAuthModal/index.d.ts +1 -1
- package/dist/components/LinkAuthModal/index.js +56 -46
- package/dist/components/OAuthStatusModal/index.js +113 -135
- package/dist/components/SignIn/SignInAuthMethodButtons.d.ts +5 -2
- package/dist/components/SignIn/SignInAuthMethodButtons.js +83 -52
- package/dist/components/SignIn/SignInBackButton.js +1 -1
- package/dist/components/SignIn/SignInDescription.js +2 -2
- package/dist/components/SignIn/SignInForm.js +2 -2
- package/dist/components/SignIn/SignInImage.d.ts +12 -3
- package/dist/components/SignIn/SignInImage.js +36 -13
- package/dist/components/SignIn/SignInProvider.js +5 -4
- package/dist/components/SignIn/SignInTitle.js +2 -2
- package/dist/components/SignIn/flows/SignInWithEmail.d.ts +0 -4
- package/dist/components/SignIn/flows/SignInWithEmail.js +73 -74
- package/dist/components/SignIn/flows/SignInWithOAuth.js +1 -1
- package/dist/components/SignIn/flows/SignInWithSiwe.d.ts +27 -0
- package/dist/components/SignIn/flows/SignInWithSiwe.js +63 -0
- package/dist/components/SignIn/flows/SignInWithSms.d.ts +0 -6
- package/dist/components/SignIn/flows/SignInWithSms.js +85 -86
- package/dist/components/SignIn/hooks/useEmailForm.js +13 -13
- package/dist/components/SignIn/hooks/useFlowTransition.d.ts +14 -0
- package/dist/components/SignIn/hooks/useFlowTransition.js +13 -0
- package/dist/components/SignIn/hooks/useOTPForm.js +29 -29
- package/dist/components/SignIn/hooks/usePhoneNumberForm.js +10 -10
- package/dist/components/SignIn/hooks/useStartSiwe.d.ts +10 -0
- package/dist/components/SignIn/hooks/useStartSiwe.js +24 -0
- package/dist/components/SignIn/index.d.ts +2 -2
- package/dist/components/SignIn/index.js +29 -29
- package/dist/components/SignIn/types.d.ts +24 -2
- package/dist/components/SignIn/types.js +5 -1
- package/dist/components/SignIn/useSignInReducer.js +67 -46
- package/dist/components/SignInModal/index.d.ts +1 -1
- package/dist/components/SignInModal/index.js +77 -67
- package/dist/components/SiweStatusView/connectors/baseAccount.d.ts +22 -0
- package/dist/components/SiweStatusView/connectors/baseAccount.js +49 -0
- package/dist/components/SiweStatusView/connectors/siweConnectors.d.ts +6 -0
- package/dist/components/SiweStatusView/connectors/siweConnectors.js +9 -0
- package/dist/components/SiweStatusView/connectors/types.d.ts +45 -0
- package/dist/components/SiweStatusView/connectors/types.js +2 -0
- package/dist/components/SiweStatusView/getSiweErrorMessage.d.ts +13 -0
- package/dist/components/SiweStatusView/getSiweErrorMessage.js +15 -0
- package/dist/components/SiweStatusView/index.d.ts +36 -0
- package/dist/components/SiweStatusView/index.js +71 -0
- package/dist/components/SiweStatusView/toSiweProvider.d.ts +10 -0
- package/dist/components/SiweStatusView/toSiweProvider.js +13 -0
- package/dist/components/SiweStatusView/useSiweFlow.d.ts +37 -0
- package/dist/components/SiweStatusView/useSiweFlow.js +35 -0
- package/dist/components/VerifyMfa/index.js +1 -1
- package/dist/components/VerifyMfaInline/index.js +1 -1
- package/dist/components/VerifyMfaModal/index.js +1 -1
- package/dist/components/ui/StatusView/index.d.ts +35 -0
- package/dist/components/ui/StatusView/index.js +55 -0
- package/dist/components/ui/SwitchFadeTransition/index.d.ts +1 -1
- package/dist/components/ui/SwitchFadeTransition/index.js +8 -12
- package/dist/components/ui/SwitchSlideTransition/index.d.ts +1 -1
- package/dist/components/ui/SwitchSlideTransition/index.js +8 -12
- package/dist/components/ui/SwitchTransition/index.d.ts +10 -3
- package/dist/components/ui/SwitchTransition/index.js +99 -98
- package/dist/hooks/useVerifyMfaModal.js +1 -1
- package/dist/icons/IconBaseColorLogo.d.ts +10 -0
- package/dist/icons/IconBaseColorLogo.js +13 -0
- package/dist/icons/IconBaseLogo.d.ts +24 -0
- package/dist/icons/IconBaseLogo.js +13 -0
- package/dist/icons/index.d.ts +2 -0
- package/dist/icons/index.js +36 -32
- package/dist/index.js +230 -225
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +13 -6
- package/dist/assets/SwitchFadeTransition.css +0 -1
- package/dist/assets/SwitchSlideTransition.css +0 -1
- package/dist/chunks/LinkAuthFlow.S1XbYaG5.js +0 -111
- package/dist/chunks/index.IrJ_irKX.js +0 -17
|
@@ -1,101 +1,119 @@
|
|
|
1
|
-
import { useReducer as
|
|
1
|
+
import { useReducer as o } from "react";
|
|
2
2
|
import "@coinbase/cdp-hooks";
|
|
3
|
-
import "../../chunks/CDPReactProvider.
|
|
4
|
-
function
|
|
5
|
-
|
|
3
|
+
import "../../chunks/CDPReactProvider.BWInVuNJ.js";
|
|
4
|
+
function n(r) {
|
|
5
|
+
const e = r.status === "pending", u = r.status === "success";
|
|
6
|
+
return r.isPending === e && r.isSuccess === u ? r : { ...r, isPending: e, isSuccess: u };
|
|
7
|
+
}
|
|
8
|
+
function l(r, e) {
|
|
9
|
+
switch (e.type) {
|
|
6
10
|
case "SET_AUTH_METHODS":
|
|
7
11
|
return {
|
|
8
|
-
...
|
|
9
|
-
authMethods:
|
|
12
|
+
...r,
|
|
13
|
+
authMethods: e.payload.authMethods
|
|
10
14
|
};
|
|
11
15
|
case "SET_AUTH_METHOD":
|
|
12
16
|
return {
|
|
13
|
-
...
|
|
14
|
-
authMethod:
|
|
17
|
+
...r,
|
|
18
|
+
authMethod: e.payload.authMethod,
|
|
15
19
|
step: "credentials",
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
status: "idle",
|
|
21
|
+
phoneNumber: e.payload.authMethod === "sms" ? "" : r.phoneNumber,
|
|
22
|
+
email: e.payload.authMethod === "email" ? "" : r.email,
|
|
18
23
|
error: null
|
|
19
24
|
};
|
|
20
25
|
case "SET_EMAIL":
|
|
21
|
-
return { ...
|
|
26
|
+
return { ...r, email: e.payload.email, phoneNumber: "", error: null };
|
|
22
27
|
case "SUBMIT_EMAIL":
|
|
23
28
|
return {
|
|
24
|
-
...
|
|
25
|
-
|
|
26
|
-
email:
|
|
29
|
+
...r,
|
|
30
|
+
status: "pending",
|
|
31
|
+
email: e.payload.email,
|
|
27
32
|
phoneNumber: "",
|
|
28
33
|
error: null
|
|
29
34
|
};
|
|
30
35
|
case "SET_PHONE_NUMBER":
|
|
31
|
-
return { ...
|
|
36
|
+
return { ...r, phoneNumber: e.payload.phoneNumber, email: "", error: null };
|
|
32
37
|
case "SUBMIT_PHONE_NUMBER":
|
|
33
38
|
return {
|
|
34
|
-
...
|
|
35
|
-
|
|
36
|
-
phoneNumber:
|
|
39
|
+
...r,
|
|
40
|
+
status: "pending",
|
|
41
|
+
phoneNumber: e.payload.phoneNumber,
|
|
37
42
|
email: "",
|
|
38
43
|
error: null
|
|
39
44
|
};
|
|
40
45
|
case "SUBMIT_EMAIL_SUCCESS":
|
|
41
46
|
case "SUBMIT_PHONE_NUMBER_SUCCESS":
|
|
42
47
|
return {
|
|
43
|
-
...
|
|
48
|
+
...r,
|
|
44
49
|
error: null,
|
|
45
|
-
flowId:
|
|
50
|
+
flowId: e.payload.flowId,
|
|
46
51
|
canResetOTP: !1,
|
|
47
|
-
|
|
52
|
+
status: "idle",
|
|
48
53
|
otp: "",
|
|
49
54
|
step: "verification"
|
|
50
55
|
};
|
|
51
56
|
case "SUBMIT_EMAIL_FAILURE":
|
|
52
57
|
case "SUBMIT_PHONE_NUMBER_FAILURE":
|
|
53
58
|
return {
|
|
54
|
-
...
|
|
55
|
-
error:
|
|
56
|
-
|
|
59
|
+
...r,
|
|
60
|
+
error: e.payload.error,
|
|
61
|
+
status: "error"
|
|
57
62
|
};
|
|
58
63
|
case "SET_OTP":
|
|
59
|
-
return { ...
|
|
64
|
+
return { ...r, error: null, otp: e.payload.otp };
|
|
60
65
|
case "SUBMIT_OTP":
|
|
61
|
-
return { ...
|
|
66
|
+
return { ...r, error: null, status: "pending", otp: e.payload.otp };
|
|
62
67
|
case "SUBMIT_OTP_SUCCESS":
|
|
63
|
-
return { ...
|
|
68
|
+
return { ...r, error: null, status: "success" };
|
|
64
69
|
case "SUBMIT_OTP_FAILURE":
|
|
65
70
|
return {
|
|
66
|
-
...
|
|
67
|
-
error:
|
|
68
|
-
|
|
69
|
-
isSuccess: !1
|
|
71
|
+
...r,
|
|
72
|
+
error: e.payload.error,
|
|
73
|
+
status: "error"
|
|
70
74
|
};
|
|
75
|
+
case "SUBMIT_SIWE":
|
|
76
|
+
return {
|
|
77
|
+
...r,
|
|
78
|
+
error: null,
|
|
79
|
+
status: "pending",
|
|
80
|
+
step: "verification",
|
|
81
|
+
authMethod: e.payload.authMethod
|
|
82
|
+
};
|
|
83
|
+
case "SUBMIT_SIWE_SUCCESS":
|
|
84
|
+
return r.authMethod.startsWith("siwe:") ? { ...r, error: null, status: "success" } : r;
|
|
85
|
+
case "SUBMIT_SIWE_FAILURE":
|
|
86
|
+
return r.authMethod.startsWith("siwe:") ? { ...r, error: e.payload.error, status: "error" } : r;
|
|
71
87
|
case "ALLOW_RESET_OTP":
|
|
72
|
-
return { ...
|
|
88
|
+
return { ...r, canResetOTP: !0 };
|
|
73
89
|
case "RESET_OTP":
|
|
74
|
-
return { ...
|
|
90
|
+
return { ...r, error: null, canResetOTP: !1 };
|
|
75
91
|
case "CLEAR_ERROR":
|
|
76
|
-
return { ...
|
|
92
|
+
return { ...r, error: null };
|
|
77
93
|
case "GO_TO_PREVIOUS_STEP":
|
|
78
94
|
return {
|
|
79
|
-
|
|
80
|
-
|
|
95
|
+
...r,
|
|
96
|
+
// Leaving a SIWE status returns to the default method (its status view has no prior step to
|
|
97
|
+
// step back to); other flows step back within their own method.
|
|
98
|
+
authMethod: r.authMethod.startsWith("siwe:") ? r.authMethods?.[0] ?? r.authMethod : r.authMethod,
|
|
99
|
+
authMethods: r.authMethods,
|
|
81
100
|
canResetOTP: !1,
|
|
82
101
|
error: null,
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
email: e.email,
|
|
102
|
+
status: "idle",
|
|
103
|
+
email: r.email,
|
|
86
104
|
flowId: "",
|
|
87
105
|
otp: "",
|
|
88
|
-
phoneNumber:
|
|
106
|
+
phoneNumber: r.phoneNumber,
|
|
89
107
|
step: "credentials"
|
|
90
108
|
};
|
|
91
109
|
case "RESET_STATE":
|
|
92
110
|
return {
|
|
93
|
-
|
|
94
|
-
|
|
111
|
+
...r,
|
|
112
|
+
authMethod: r.authMethod,
|
|
113
|
+
authMethods: r.authMethods,
|
|
95
114
|
canResetOTP: !1,
|
|
96
115
|
error: null,
|
|
97
|
-
|
|
98
|
-
isSuccess: !1,
|
|
116
|
+
status: "idle",
|
|
99
117
|
email: "",
|
|
100
118
|
flowId: "",
|
|
101
119
|
otp: "",
|
|
@@ -106,7 +124,10 @@ function u(e, r) {
|
|
|
106
124
|
throw new Error("Unknown action type");
|
|
107
125
|
}
|
|
108
126
|
}
|
|
109
|
-
|
|
127
|
+
function s(r, e) {
|
|
128
|
+
return n(l(r, e));
|
|
129
|
+
}
|
|
130
|
+
const t = (r) => o(s, r);
|
|
110
131
|
export {
|
|
111
|
-
|
|
132
|
+
t as useSignInReducer
|
|
112
133
|
};
|
|
@@ -61,7 +61,7 @@ export declare const SignInModalTrigger: ({ children, className, label, ...props
|
|
|
61
61
|
*
|
|
62
62
|
* @group Components
|
|
63
63
|
*/
|
|
64
|
-
export declare const SignInModalContent: (props: SignInModalContentProps) => import("react/jsx-runtime").JSX.Element;
|
|
64
|
+
export declare const SignInModalContent: ({ onInteractOutside, ...props }: SignInModalContentProps) => import("react/jsx-runtime").JSX.Element;
|
|
65
65
|
/**
|
|
66
66
|
* A sign-in modal component that wraps the {@link SignIn} component.
|
|
67
67
|
* In the SignIn modal, the description is hidden on the "credentials" step, and the title is hidden on the "verification" step.
|
|
@@ -1,93 +1,103 @@
|
|
|
1
|
-
import { jsx as n, jsxs as
|
|
1
|
+
import { jsx as n, jsxs as a, Fragment as m } from "react/jsx-runtime";
|
|
2
2
|
import { u as C } from "../../chunks/useSendComponentCallOnce.BI4daEvm.js";
|
|
3
|
-
import { createContext as b, useMemo as x,
|
|
4
|
-
import { c as
|
|
5
|
-
import { u as
|
|
6
|
-
import { SignIn as
|
|
3
|
+
import { createContext as b, useMemo as x, useCallback as v, useContext as N } from "react";
|
|
4
|
+
import { c as w } from "../../chunks/lite.1fxw3LjI.js";
|
|
5
|
+
import { u as D } from "../../chunks/CDPReactProvider.BWInVuNJ.js";
|
|
6
|
+
import { SignIn as k } from "../SignIn/index.js";
|
|
7
7
|
import "@coinbase/cdp-hooks";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
8
|
+
import { isWithinBaseAccountDialog as B } from "../SiweStatusView/connectors/baseAccount.js";
|
|
9
|
+
import { Button as S } from "../ui/Button/index.js";
|
|
10
|
+
import { Modal as T, ModalContent as A, ModalClose as j, ModalTrigger as y, ModalTitle as E, ModalDescription as F } from "../ui/Modal/index.js";
|
|
11
|
+
import { VisuallyHidden as u } from "../ui/VisuallyHidden/index.js";
|
|
12
|
+
import { IconXMark as O } from "../../icons/IconXMark.js";
|
|
13
|
+
import { childrenHasComponent as h } from "../../utils/childrenHasComponent.js";
|
|
13
14
|
import { SignInBackButton as V } from "../SignIn/SignInBackButton.js";
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import { SignInTitle as
|
|
17
|
-
import { SignInDescription as
|
|
18
|
-
import { SignInAuthMethodButtons as
|
|
19
|
-
import { SignInFooter as
|
|
20
|
-
import '../../assets/SignInModal.css';const
|
|
21
|
-
trigger:
|
|
15
|
+
import { SignInForm as z } from "../SignIn/SignInForm.js";
|
|
16
|
+
import { SignInImage as H } from "../SignIn/SignInImage.js";
|
|
17
|
+
import { SignInTitle as f } from "../SignIn/SignInTitle.js";
|
|
18
|
+
import { SignInDescription as p } from "../SignIn/SignInDescription.js";
|
|
19
|
+
import { SignInAuthMethodButtons as J } from "../SignIn/SignInAuthMethodButtons.js";
|
|
20
|
+
import { SignInFooter as W } from "../SignIn/SignInFooter.js";
|
|
21
|
+
import '../../assets/SignInModal.css';const X = "SignInModal-module__trigger___IcJ8x", $ = "SignInModal-module__footer___6qEo2", q = "SignInModal-module__buttons___jhaVn", t = {
|
|
22
|
+
trigger: X,
|
|
22
23
|
"sign-in": "SignInModal-module__sign-in___n05-5",
|
|
23
24
|
"no-footer": "SignInModal-module__no-footer___meSt1",
|
|
24
25
|
"title-desc-wrapper": "SignInModal-module__title-desc-wrapper___--XLa",
|
|
25
26
|
"sign-in-form": "SignInModal-module__sign-in-form___Jzx1-",
|
|
26
27
|
"sign-in-image": "SignInModal-module__sign-in-image___DGg7B",
|
|
27
|
-
footer:
|
|
28
|
-
buttons:
|
|
28
|
+
footer: $,
|
|
29
|
+
buttons: q,
|
|
29
30
|
"back-button": "SignInModal-module__back-button___nMh2-",
|
|
30
31
|
"close-icon": "SignInModal-module__close-icon___b-gMh"
|
|
31
|
-
}, M = b(null),
|
|
32
|
-
const
|
|
33
|
-
if (!
|
|
32
|
+
}, M = b(null), G = () => {
|
|
33
|
+
const e = N(M);
|
|
34
|
+
if (!e)
|
|
34
35
|
throw new Error("useSignInModalContext must be used within a SignInModal");
|
|
35
|
-
return
|
|
36
|
-
},
|
|
37
|
-
children:
|
|
38
|
-
className:
|
|
39
|
-
label:
|
|
40
|
-
...
|
|
41
|
-
}) => /* @__PURE__ */ n(
|
|
42
|
-
const { showCoinbaseFooter:
|
|
43
|
-
|
|
44
|
-
|
|
36
|
+
return e;
|
|
37
|
+
}, I = ({
|
|
38
|
+
children: e,
|
|
39
|
+
className: i = "",
|
|
40
|
+
label: l,
|
|
41
|
+
...d
|
|
42
|
+
}) => /* @__PURE__ */ n(y, { asChild: !0, children: e || /* @__PURE__ */ n(S, { className: w(t.trigger, i), ...d, children: l || "Sign in" }) }), _ = ({ onInteractOutside: e, ...i }) => {
|
|
43
|
+
const { showCoinbaseFooter: l } = D(), { authMethods: d, onSuccess: s } = G(), g = v(
|
|
44
|
+
(o) => {
|
|
45
|
+
if (B(o.detail.originalEvent.target)) {
|
|
46
|
+
o.preventDefault();
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
e?.(o);
|
|
50
|
+
},
|
|
51
|
+
[e]
|
|
52
|
+
);
|
|
53
|
+
return /* @__PURE__ */ n(A, { ...i, onInteractOutside: g, children: /* @__PURE__ */ n(
|
|
54
|
+
k,
|
|
45
55
|
{
|
|
46
|
-
authMethods:
|
|
47
|
-
onSuccess:
|
|
48
|
-
className: `${
|
|
56
|
+
authMethods: d,
|
|
57
|
+
onSuccess: s,
|
|
58
|
+
className: `${t["sign-in"]} ${l ? "" : t["no-footer"]}`,
|
|
49
59
|
...i,
|
|
50
|
-
children: /* @__PURE__ */
|
|
51
|
-
/* @__PURE__ */ n(
|
|
52
|
-
/* @__PURE__ */
|
|
53
|
-
/* @__PURE__ */ n(V, { className:
|
|
54
|
-
/* @__PURE__ */ n(
|
|
60
|
+
children: /* @__PURE__ */ a(m, { children: [
|
|
61
|
+
/* @__PURE__ */ n(L, {}),
|
|
62
|
+
/* @__PURE__ */ a("div", { className: t.buttons, children: [
|
|
63
|
+
/* @__PURE__ */ n(V, { className: t["back-button"] }),
|
|
64
|
+
/* @__PURE__ */ n(j, { asChild: !0, children: /* @__PURE__ */ n(S, { "aria-label": "Close", size: "md", variant: "transparentSecondary", children: /* @__PURE__ */ n(O, { className: t["close-icon"] }) }) })
|
|
55
65
|
] }),
|
|
56
|
-
/* @__PURE__ */ n(
|
|
57
|
-
|
|
58
|
-
/* @__PURE__ */
|
|
59
|
-
|
|
60
|
-
|
|
66
|
+
/* @__PURE__ */ n(z, { onSuccess: s, children: ({ authMethod: o, step: r, Form: c }) => o.startsWith("siwe:") && r === "verification" ? c : /* @__PURE__ */ a(m, { children: [
|
|
67
|
+
/* @__PURE__ */ n("div", { className: t["sign-in-image"], children: /* @__PURE__ */ n(H, { authMethod: o, step: r }) }),
|
|
68
|
+
/* @__PURE__ */ a("div", { className: t["title-desc-wrapper"], children: [
|
|
69
|
+
r === "verification" ? /* @__PURE__ */ n(u, { as: "div", children: /* @__PURE__ */ n(f, {}) }) : /* @__PURE__ */ n(f, {}),
|
|
70
|
+
r === "credentials" ? /* @__PURE__ */ n(u, { as: "div", children: /* @__PURE__ */ n(p, { authMethod: o }) }) : /* @__PURE__ */ n(p, { authMethod: o })
|
|
61
71
|
] }),
|
|
62
|
-
/* @__PURE__ */ n("div", { className:
|
|
63
|
-
|
|
72
|
+
/* @__PURE__ */ n("div", { className: t["sign-in-form"], children: c }),
|
|
73
|
+
r === "credentials" && /* @__PURE__ */ n(J, { activeMethod: o, onSuccess: s })
|
|
64
74
|
] }) }),
|
|
65
|
-
|
|
75
|
+
l && /* @__PURE__ */ n(W, { className: t.footer })
|
|
66
76
|
] })
|
|
67
77
|
}
|
|
68
78
|
) });
|
|
69
|
-
},
|
|
70
|
-
authMethods:
|
|
71
|
-
children:
|
|
72
|
-
open:
|
|
73
|
-
setIsOpen:
|
|
79
|
+
}, un = ({
|
|
80
|
+
authMethods: e,
|
|
81
|
+
children: i,
|
|
82
|
+
open: l,
|
|
83
|
+
setIsOpen: d,
|
|
74
84
|
onSuccess: s
|
|
75
85
|
}) => {
|
|
76
86
|
C("sign_in_modal");
|
|
77
|
-
const
|
|
78
|
-
return /* @__PURE__ */ n(M.Provider, { value:
|
|
79
|
-
/* @__PURE__ */ n(
|
|
80
|
-
/* @__PURE__ */ n(
|
|
81
|
-
] }) : /* @__PURE__ */
|
|
82
|
-
|
|
83
|
-
!
|
|
87
|
+
const g = i ? h(i, I) : !1, o = i ? h(i, _) : !1, r = !g && !o, c = x(() => ({ authMethods: e, onSuccess: s }), [e, s]);
|
|
88
|
+
return /* @__PURE__ */ n(M.Provider, { value: c, children: /* @__PURE__ */ n(T, { open: l, onOpenChange: d, children: r ? /* @__PURE__ */ a(m, { children: [
|
|
89
|
+
/* @__PURE__ */ n(I, { children: i }),
|
|
90
|
+
/* @__PURE__ */ n(_, {})
|
|
91
|
+
] }) : /* @__PURE__ */ a(m, { children: [
|
|
92
|
+
i,
|
|
93
|
+
!o && /* @__PURE__ */ n(_, {})
|
|
84
94
|
] }) }) });
|
|
85
|
-
},
|
|
86
|
-
/* @__PURE__ */ n(
|
|
87
|
-
/* @__PURE__ */ n(
|
|
95
|
+
}, L = () => /* @__PURE__ */ a(u, { children: [
|
|
96
|
+
/* @__PURE__ */ n(E, { asChild: !0, children: /* @__PURE__ */ n(f, { as: "span" }) }),
|
|
97
|
+
/* @__PURE__ */ n(F, { asChild: !0, children: /* @__PURE__ */ n(p, { as: "span" }) })
|
|
88
98
|
] });
|
|
89
99
|
export {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
100
|
+
un as SignInModal,
|
|
101
|
+
_ as SignInModalContent,
|
|
102
|
+
I as SignInModalTrigger
|
|
93
103
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { EvmAddress } from '@coinbase/cdp-core';
|
|
2
|
+
import { Eip1193RequestProvider, SiweConnector } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* The result of connecting to a Base account.
|
|
5
|
+
*/
|
|
6
|
+
export interface BaseAccountConnection {
|
|
7
|
+
/** The connected EIP-1193 provider. */
|
|
8
|
+
provider: Eip1193RequestProvider;
|
|
9
|
+
/** The connected account address. */
|
|
10
|
+
address: EvmAddress;
|
|
11
|
+
/** The EIP-155 chain ID the wallet is currently on. */
|
|
12
|
+
chainId: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Whether the given node is inside the Base Account SDK's own dialog. Used so a surrounding modal
|
|
16
|
+
* (e.g. SignInModal) doesn't treat a click on that dialog as an outside-click and dismiss itself.
|
|
17
|
+
*
|
|
18
|
+
* @param target - The event target to check.
|
|
19
|
+
* @returns {boolean} True if the target is within a Base Account SDK dialog.
|
|
20
|
+
*/
|
|
21
|
+
export declare function isWithinBaseAccountDialog(target: EventTarget | null): boolean;
|
|
22
|
+
export declare const baseAccountConnector: SiweConnector;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import "@coinbase/cdp-core";
|
|
2
|
+
import { IconBaseColorLogo as s } from "../../../icons/IconBaseColorLogo.js";
|
|
3
|
+
import { IconBaseLogo as a } from "../../../icons/IconBaseLogo.js";
|
|
4
|
+
import "react";
|
|
5
|
+
const i = 'Sign in with Base requires the optional "@base-org/account" package. Install it with: npm install @base-org/account';
|
|
6
|
+
let n;
|
|
7
|
+
async function u(o) {
|
|
8
|
+
return n || (n = (async () => {
|
|
9
|
+
let t;
|
|
10
|
+
try {
|
|
11
|
+
({ createBaseAccountSDK: t } = await import("@base-org/account"));
|
|
12
|
+
} catch {
|
|
13
|
+
throw new Error(i);
|
|
14
|
+
}
|
|
15
|
+
return t({ appName: o }).getProvider();
|
|
16
|
+
})().catch((t) => {
|
|
17
|
+
throw n = void 0, t;
|
|
18
|
+
})), n;
|
|
19
|
+
}
|
|
20
|
+
async function l(o) {
|
|
21
|
+
const t = await u(o), [e, r] = await Promise.all([
|
|
22
|
+
t.request({ method: "eth_requestAccounts" }),
|
|
23
|
+
t.request({ method: "eth_chainId" })
|
|
24
|
+
]), c = e?.[0];
|
|
25
|
+
if (!c)
|
|
26
|
+
throw new Error("No account returned from the Base wallet.");
|
|
27
|
+
return { provider: t, address: c, chainId: Number.parseInt(r, 16) };
|
|
28
|
+
}
|
|
29
|
+
async function h(o, t, e) {
|
|
30
|
+
return await o.request({
|
|
31
|
+
method: "personal_sign",
|
|
32
|
+
params: [t, e]
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
const d = "[class*='-base-acc-sdk']";
|
|
36
|
+
function A(o) {
|
|
37
|
+
return o instanceof Element && o.closest(d) !== null;
|
|
38
|
+
}
|
|
39
|
+
const I = {
|
|
40
|
+
label: "Base",
|
|
41
|
+
icon: a,
|
|
42
|
+
colorIcon: s,
|
|
43
|
+
connect: l,
|
|
44
|
+
sign: h
|
|
45
|
+
};
|
|
46
|
+
export {
|
|
47
|
+
I as baseAccountConnector,
|
|
48
|
+
A as isWithinBaseAccountDialog
|
|
49
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { EvmAddress, Hex } from '@coinbase/cdp-core';
|
|
2
|
+
import { ComponentType, SVGProps } from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* The minimal EIP-1193 surface used by the SIWE flow. The Base Account SDK
|
|
5
|
+
* provider satisfies this, as does any injected wallet provider.
|
|
6
|
+
*/
|
|
7
|
+
export interface Eip1193RequestProvider {
|
|
8
|
+
request: (args: {
|
|
9
|
+
method: string;
|
|
10
|
+
params?: unknown[];
|
|
11
|
+
}) => Promise<unknown>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The SIWE providers that can be used as first-party auth methods.
|
|
15
|
+
* Each maps to a `siwe:<provider>` auth method (e.g. `"siwe:base"`).
|
|
16
|
+
*/
|
|
17
|
+
export type SiweProviderType = "base";
|
|
18
|
+
/**
|
|
19
|
+
* A wallet connection produced by a {@link SiweConnector}.
|
|
20
|
+
*/
|
|
21
|
+
export interface SiweConnection {
|
|
22
|
+
/** The connected EIP-1193 provider. */
|
|
23
|
+
provider: Eip1193RequestProvider;
|
|
24
|
+
/** The connected account address. */
|
|
25
|
+
address: EvmAddress;
|
|
26
|
+
/** The EIP-155 chain ID the wallet is currently on. */
|
|
27
|
+
chainId: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Configuration for a SIWE provider: how it connects/signs, plus its display metadata.
|
|
31
|
+
* Adding a new ETH provider only requires implementing this and registering it in
|
|
32
|
+
* {@link siweConnectors}.
|
|
33
|
+
*/
|
|
34
|
+
export interface SiweConnector {
|
|
35
|
+
/** The human-readable provider name (e.g. "Base"). */
|
|
36
|
+
label: string;
|
|
37
|
+
/** The monochrome logo (uses `currentColor`), used on buttons. */
|
|
38
|
+
icon: ComponentType<SVGProps<SVGSVGElement>>;
|
|
39
|
+
/** The colored logo, used in the status graphic. Falls back to `icon` if omitted. */
|
|
40
|
+
colorIcon?: ComponentType<SVGProps<SVGSVGElement>>;
|
|
41
|
+
/** Connects the wallet and returns the provider, address, and chain ID. */
|
|
42
|
+
connect: (appName?: string) => Promise<SiweConnection>;
|
|
43
|
+
/** Signs the SIWE message with the connected wallet. */
|
|
44
|
+
sign: (provider: Eip1193RequestProvider, message: string, address: EvmAddress) => Promise<Hex>;
|
|
45
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a user-facing message for a failed SIWE flow, or `undefined` to fall back to the status
|
|
3
|
+
* view's generic message. Only two cases produce copy worth showing:
|
|
4
|
+
* - HTTP 4xx API errors, which carry actionable, server-authored copy (e.g. "This Ethereum address
|
|
5
|
+
* is already linked to another account.").
|
|
6
|
+
* - A user-rejected wallet request (EIP-1193 code 4001).
|
|
7
|
+
*
|
|
8
|
+
* Everything else is suppressed and the SiweStatusView shows the generic error message.
|
|
9
|
+
*
|
|
10
|
+
* @param error - The caught error from a SIWE flow.
|
|
11
|
+
* @returns {string | undefined} A message to display, or `undefined` to use the generic copy.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getSiweErrorMessage(error: unknown): string | undefined;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { getMessageFromUnknownError as e } from "../../utils/getMessageFromUnknownError.js";
|
|
2
|
+
import { isApiError as n } from "../../utils/isApiError.js";
|
|
3
|
+
import "libphonenumber-js";
|
|
4
|
+
const i = 4001;
|
|
5
|
+
function E(t) {
|
|
6
|
+
if (t) {
|
|
7
|
+
if (n(t) && t.statusCode >= 400 && t.statusCode < 500)
|
|
8
|
+
return e(t, "Something went wrong. Please try again.");
|
|
9
|
+
if (typeof t == "object" && "code" in t && t.code === i)
|
|
10
|
+
return "User cancelled the request. Please try again.";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
E as getSiweErrorMessage
|
|
15
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { StatusViewStatus } from '../ui/StatusView';
|
|
2
|
+
import { siweConnectors, SiweProviderType } from './connectors/siweConnectors';
|
|
3
|
+
/**
|
|
4
|
+
* Props for the SiweStatusView component.
|
|
5
|
+
*/
|
|
6
|
+
export interface SiweStatusViewProps {
|
|
7
|
+
/** The SIWE provider being authenticated. */
|
|
8
|
+
provider: SiweProviderType;
|
|
9
|
+
/** The current status. `"idle"` is ignored (keeps the last status visible while fading out). */
|
|
10
|
+
status: "idle" | StatusViewStatus;
|
|
11
|
+
/** Called when the user clicks the "Try again" button in the error state. */
|
|
12
|
+
onRetry?: () => void;
|
|
13
|
+
/** A contextual message shown in the error state. Falls back to a generic message when omitted. */
|
|
14
|
+
errorMessage?: string;
|
|
15
|
+
/** Whether the status transition animates its height. Defaults to `true`. */
|
|
16
|
+
animateHeight?: boolean;
|
|
17
|
+
/** A contextual message shown in the success state. */
|
|
18
|
+
successMessage?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Renders the SIWE status (pending/success/error) using the shared {@link StatusView}, with
|
|
22
|
+
* provider-specific branding and a "Try again" button on error.
|
|
23
|
+
*
|
|
24
|
+
* Whether the copy reads as sign-in or account-link is derived from `useIsSignedIn` — the same
|
|
25
|
+
* signal {@link useSiweFlow} uses to choose between signing in and linking.
|
|
26
|
+
*
|
|
27
|
+
* @param {SiweStatusViewProps} props - The props for the component.
|
|
28
|
+
* @returns {JSX.Element} The SiweStatusView component.
|
|
29
|
+
*
|
|
30
|
+
* @group Components
|
|
31
|
+
*/
|
|
32
|
+
export declare const SiweStatusView: ({ provider, status, onRetry, errorMessage, successMessage, animateHeight, }: SiweStatusViewProps) => import("react/jsx-runtime").JSX.Element;
|
|
33
|
+
export { siweConnectors, type SiweProviderType };
|
|
34
|
+
export { useSiweFlow } from './useSiweFlow';
|
|
35
|
+
export { toSiweProvider } from './toSiweProvider';
|
|
36
|
+
export { getSiweErrorMessage } from './getSiweErrorMessage';
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { jsx as r, jsxs as v } from "react/jsx-runtime";
|
|
2
|
+
import { useIsSignedIn as C } from "@coinbase/cdp-hooks";
|
|
3
|
+
import { useRef as s, useState as T, useCallback as $, useEffect as x } from "react";
|
|
4
|
+
import { Button as y } from "../ui/Button/index.js";
|
|
5
|
+
import { StatusView as c } from "../ui/StatusView/index.js";
|
|
6
|
+
import { SwitchFadeTransition as A } from "../ui/SwitchFadeTransition/index.js";
|
|
7
|
+
import { siweConnectors as P } from "./connectors/siweConnectors.js";
|
|
8
|
+
import { useSiweFlow as q } from "./useSiweFlow.js";
|
|
9
|
+
import { toSiweProvider as H } from "./toSiweProvider.js";
|
|
10
|
+
import { getSiweErrorMessage as O } from "./getSiweErrorMessage.js";
|
|
11
|
+
const b = ["pending", "success", "error"], D = ({
|
|
12
|
+
provider: p,
|
|
13
|
+
status: t,
|
|
14
|
+
onRetry: u,
|
|
15
|
+
errorMessage: e,
|
|
16
|
+
successMessage: f,
|
|
17
|
+
animateHeight: g = !0
|
|
18
|
+
}) => {
|
|
19
|
+
const { isSignedIn: S } = C(), o = s(S).current, { label: n, icon: w, colorIcon: h } = P[p], k = h ?? w, d = s(null), l = s(t === "idle" ? "pending" : t), [a, E] = T(e);
|
|
20
|
+
t === "error" && e !== a && E(e);
|
|
21
|
+
const m = $((i) => {
|
|
22
|
+
i === "idle" || i === l.current || (l.current = i, d.current?.transition.toggle(i));
|
|
23
|
+
}, []);
|
|
24
|
+
return x(() => {
|
|
25
|
+
m(t);
|
|
26
|
+
}, [t, m]), /* @__PURE__ */ r(
|
|
27
|
+
A,
|
|
28
|
+
{
|
|
29
|
+
animateHeight: g,
|
|
30
|
+
timeout: 250,
|
|
31
|
+
items: b,
|
|
32
|
+
initialEntered: !0,
|
|
33
|
+
transitionRef: d,
|
|
34
|
+
children: ({ itemKey: i, ...I }) => /* @__PURE__ */ v("div", { ...I, children: [
|
|
35
|
+
i === "pending" && /* @__PURE__ */ r(
|
|
36
|
+
c,
|
|
37
|
+
{
|
|
38
|
+
status: "pending",
|
|
39
|
+
icon: /* @__PURE__ */ r(k, { width: "32", height: "32" }),
|
|
40
|
+
title: o ? `Linking your ${n} account` : `Signing in with ${n}`,
|
|
41
|
+
description: "Just a moment..."
|
|
42
|
+
}
|
|
43
|
+
),
|
|
44
|
+
i === "success" && /* @__PURE__ */ r(
|
|
45
|
+
c,
|
|
46
|
+
{
|
|
47
|
+
status: "success",
|
|
48
|
+
title: o ? `${n} account linked` : `Signed in with ${n}`,
|
|
49
|
+
description: f
|
|
50
|
+
}
|
|
51
|
+
),
|
|
52
|
+
i === "error" && /* @__PURE__ */ r(
|
|
53
|
+
c,
|
|
54
|
+
{
|
|
55
|
+
status: "error",
|
|
56
|
+
title: o ? "Account linking failed" : "Sign in failed",
|
|
57
|
+
description: a || "Something went wrong. Please try again.",
|
|
58
|
+
children: !!u && /* @__PURE__ */ r(y, { variant: "secondary", onClick: u, size: "sm", children: "Try again" })
|
|
59
|
+
}
|
|
60
|
+
)
|
|
61
|
+
] })
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
};
|
|
65
|
+
export {
|
|
66
|
+
D as SiweStatusView,
|
|
67
|
+
O as getSiweErrorMessage,
|
|
68
|
+
P as siweConnectors,
|
|
69
|
+
H as toSiweProvider,
|
|
70
|
+
q as useSiweFlow
|
|
71
|
+
};
|