@coinbase/cdp-react 0.0.86 → 0.0.87
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/CDPReactProvider.css +1 -1
- package/dist/assets/EnrollMfaFlow.css +1 -1
- package/dist/assets/VerifyMfaFlow.css +1 -1
- package/dist/assets/VerifyMfaFlowBackButton.css +1 -0
- package/dist/assets/VerifyMfaInline.css +1 -1
- package/dist/assets/VerifyMfaItem.css +1 -0
- package/dist/assets/VerifyMfaItems.css +1 -0
- package/dist/assets/sms.css +1 -0
- package/dist/chunks/CDPReactProvider.C38bKQ2x.js +337 -0
- package/dist/chunks/{LinkAuthFlow.BaUSMzGH.js → LinkAuthFlow.CLubKoY0.js} +13 -13
- package/dist/chunks/{index.C_DV0Ud7.js → index.BN39qScu.js} +1 -1
- package/dist/chunks/index.BX4k-ruQ.js +12 -0
- package/dist/chunks/index.Bgx0-QLY.js +12 -0
- package/dist/components/CDPReactProvider/index.js +1 -1
- package/dist/components/EnrollMfa/EnrollMfaDescription.js +4 -3
- package/dist/components/EnrollMfa/EnrollMfaFlow.js +27 -26
- package/dist/components/EnrollMfa/EnrollMfaFlowBackButton.js +7 -6
- package/dist/components/EnrollMfa/EnrollMfaFlowProvider.d.ts +1 -1
- package/dist/components/EnrollMfa/EnrollMfaFlowProvider.js +5 -4
- package/dist/components/EnrollMfa/EnrollMfaImage.js +7 -6
- package/dist/components/EnrollMfa/EnrollMfaItem.js +7 -6
- package/dist/components/EnrollMfa/EnrollMfaItems.js +28 -25
- package/dist/components/EnrollMfa/EnrollMfaProvider.js +22 -17
- package/dist/components/EnrollMfa/EnrollMfaTitle.js +8 -7
- package/dist/components/EnrollMfa/index.js +134 -128
- package/dist/components/EnrollMfa/methods/sms.d.ts +6 -0
- package/dist/components/EnrollMfa/methods/sms.js +148 -0
- package/dist/components/EnrollMfa/methods/totp.js +24 -19
- package/dist/components/EnrollMfa/types.d.ts +17 -5
- package/dist/components/EnrollMfa/types.js +1 -0
- package/dist/components/EnrollMfa/useEnrollMfaReducer.js +51 -38
- package/dist/components/EnrollMfaModal/index.js +1 -1
- package/dist/components/ExportWallet/index.js +109 -101
- 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 +2 -2
- package/dist/components/LinkAuth/LinkAuthFlowBackButton.js +2 -2
- package/dist/components/LinkAuth/LinkAuthFlowProvider.js +2 -2
- package/dist/components/LinkAuth/LinkAuthItem.js +1 -1
- package/dist/components/LinkAuth/LinkAuthItems.js +1 -1
- package/dist/components/LinkAuth/LinkAuthProvider.js +1 -1
- package/dist/components/LinkAuth/index.js +3 -3
- package/dist/components/LinkAuth/types.js +1 -1
- package/dist/components/LinkAuth/utils.js +1 -1
- package/dist/components/LinkAuthModal/index.js +2 -2
- package/dist/components/OAuthStatusModal/index.js +1 -1
- package/dist/components/SignIn/SignInAuthMethodButtons.js +1 -1
- package/dist/components/SignIn/SignInBackButton.js +12 -12
- package/dist/components/SignIn/SignInDescription.js +2 -2
- package/dist/components/SignIn/SignInForm.js +2 -2
- package/dist/components/SignIn/SignInImage.js +1 -1
- package/dist/components/SignIn/SignInProvider.js +1 -1
- package/dist/components/SignIn/SignInTitle.js +2 -2
- package/dist/components/SignIn/flows/SignInWithEmail.js +1 -1
- package/dist/components/SignIn/flows/SignInWithOAuth.js +1 -1
- package/dist/components/SignIn/flows/SignInWithSms.js +74 -84
- package/dist/components/SignIn/index.js +1 -1
- package/dist/components/SignIn/types.d.ts +2 -0
- package/dist/components/SignIn/types.js +1 -1
- package/dist/components/SignIn/useSignInReducer.js +20 -6
- package/dist/components/SignInModal/index.js +1 -1
- package/dist/components/VerifyMfa/VerifyMfaDescription.d.ts +1 -1
- package/dist/components/VerifyMfa/VerifyMfaDescription.js +24 -14
- package/dist/components/VerifyMfa/VerifyMfaFlow.d.ts +5 -4
- package/dist/components/VerifyMfa/VerifyMfaFlow.js +52 -13
- package/dist/components/VerifyMfa/VerifyMfaFlowBackButton.d.ts +9 -0
- package/dist/components/VerifyMfa/VerifyMfaFlowBackButton.js +40 -0
- package/dist/components/VerifyMfa/VerifyMfaFlowProvider.d.ts +23 -0
- package/dist/components/VerifyMfa/VerifyMfaFlowProvider.js +37 -0
- package/dist/components/VerifyMfa/VerifyMfaImage.d.ts +1 -1
- package/dist/components/VerifyMfa/VerifyMfaImage.js +25 -13
- package/dist/components/VerifyMfa/VerifyMfaItem.d.ts +10 -0
- package/dist/components/VerifyMfa/VerifyMfaItem.js +27 -0
- package/dist/components/VerifyMfa/VerifyMfaItems.d.ts +9 -0
- package/dist/components/VerifyMfa/VerifyMfaItems.js +31 -0
- package/dist/components/VerifyMfa/VerifyMfaProvider.js +27 -14
- package/dist/components/VerifyMfa/VerifyMfaTitle.d.ts +1 -1
- package/dist/components/VerifyMfa/VerifyMfaTitle.js +23 -13
- package/dist/components/VerifyMfa/index.d.ts +6 -2
- package/dist/components/VerifyMfa/index.js +23 -14
- package/dist/components/VerifyMfa/methods/sms.d.ts +6 -0
- package/dist/components/VerifyMfa/methods/sms.js +90 -0
- package/dist/components/VerifyMfa/methods/totp.js +40 -39
- package/dist/components/VerifyMfa/types.d.ts +21 -2
- package/dist/components/VerifyMfa/types.js +1 -0
- package/dist/components/VerifyMfa/useVerifyMfaReducer.d.ts +2 -1
- package/dist/components/VerifyMfa/useVerifyMfaReducer.js +29 -4
- package/dist/components/VerifyMfaInline/index.d.ts +1 -1
- package/dist/components/VerifyMfaInline/index.js +133 -116
- package/dist/components/VerifyMfaModal/index.js +7 -5
- package/dist/components/ui/SwitchTransition/index.js +3 -3
- package/dist/hooks/usePhoneNumberState.d.ts +15 -0
- package/dist/hooks/usePhoneNumberState.js +39 -0
- package/dist/hooks/useTransitionMap.js +24 -22
- package/dist/hooks/useVerifyMfaModal.js +1 -1
- package/dist/index.js +59 -51
- package/dist/utils/transition.d.ts +3 -3
- package/dist/utils/transition.js +21 -20
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +6 -6
- package/dist/chunks/CDPReactProvider.CIQm4C4z.js +0 -299
- package/dist/chunks/index.CKQKBoX2.js +0 -9
- package/dist/chunks/index.Dp-lIxM1.js +0 -9
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { jsx as t, Fragment as a, jsxs as D } from "react/jsx-runtime";
|
|
2
|
+
import { useState as M, useCallback as i, useEffect as E, useMemo as w } from "react";
|
|
3
|
+
import { OTPForm as x } from "../../forms/OTPForm/index.js";
|
|
4
|
+
import { PhoneNumberForm as F } from "../../forms/PhoneNumberForm/index.js";
|
|
5
|
+
import { Badge as U } from "../../ui/Badge/index.js";
|
|
6
|
+
import { usePhoneNumberState as j } from "../../../hooks/usePhoneNumberState.js";
|
|
7
|
+
import { useTimer as I } from "../../../hooks/useTimer.js";
|
|
8
|
+
import { IconPhone as W } from "../../../icons/IconPhone.js";
|
|
9
|
+
import { formatPhoneNumber as k } from "../../../utils/formatPhoneNumber.js";
|
|
10
|
+
import { useEnrollMfaFlow as A } from "../EnrollMfaFlowProvider.js";
|
|
11
|
+
import { useEnrollMfaContext as _ } from "../EnrollMfaProvider.js";
|
|
12
|
+
import "@coinbase/cdp-core";
|
|
13
|
+
import "@coinbase/cdp-hooks";
|
|
14
|
+
import '../../../assets/sms.css';const L = "sms-module__form___G393d", B = "sms-module__credentials___jMUzc", f = {
|
|
15
|
+
form: L,
|
|
16
|
+
"otp-form": "sms-module__otp-form___yNrQa",
|
|
17
|
+
credentials: B
|
|
18
|
+
}, q = ({
|
|
19
|
+
autoFocus: e = !0,
|
|
20
|
+
step: o,
|
|
21
|
+
onSubmit: m,
|
|
22
|
+
children: h
|
|
23
|
+
}) => {
|
|
24
|
+
const { state: r, dispatch: n } = _(), { startEnrollment: c } = A(), {
|
|
25
|
+
timeRemaining: l,
|
|
26
|
+
start: u,
|
|
27
|
+
reset: N
|
|
28
|
+
} = I(), [p, C] = M(!1), b = i(
|
|
29
|
+
(s) => {
|
|
30
|
+
n({ type: "SET_PHONE_NUMBER", payload: { phoneNumber: s } });
|
|
31
|
+
},
|
|
32
|
+
[n]
|
|
33
|
+
), { phoneNumberObject: S, countryCode: g, handlePhoneNumberChange: O, handleCountryCodeChange: P } = j({
|
|
34
|
+
phoneNumber: r.phoneNumber,
|
|
35
|
+
onPhoneNumberChange: b
|
|
36
|
+
}), v = i(
|
|
37
|
+
(s) => {
|
|
38
|
+
n({ type: "SET_MFA_CODE", payload: { mfaCode: s } });
|
|
39
|
+
},
|
|
40
|
+
[n]
|
|
41
|
+
), y = i(() => {
|
|
42
|
+
n({ type: "CLEAR_ERROR" });
|
|
43
|
+
}, [n]), R = i(
|
|
44
|
+
(s) => {
|
|
45
|
+
s.preventDefault(), c("sms");
|
|
46
|
+
},
|
|
47
|
+
[c]
|
|
48
|
+
), T = i(async () => {
|
|
49
|
+
n({ type: "SET_MFA_CODE", payload: { mfaCode: "" } }), C(!1), u(60), c("sms");
|
|
50
|
+
}, [n, c, u]);
|
|
51
|
+
E(() => {
|
|
52
|
+
o === "setup-verification" && u(60);
|
|
53
|
+
}, [o, u]), E(() => {
|
|
54
|
+
l === 0 && !p && (C(!0), N());
|
|
55
|
+
}, [l, p, N]);
|
|
56
|
+
let d;
|
|
57
|
+
switch (o) {
|
|
58
|
+
case "setup":
|
|
59
|
+
d = /* @__PURE__ */ t(
|
|
60
|
+
F,
|
|
61
|
+
{
|
|
62
|
+
className: f.form,
|
|
63
|
+
autoFocus: e,
|
|
64
|
+
phoneNumber: S,
|
|
65
|
+
countryCode: g,
|
|
66
|
+
onPhoneNumberChange: O,
|
|
67
|
+
onCountryCodeChange: P,
|
|
68
|
+
error: r.error && r.step === "setup" ? r.error : void 0,
|
|
69
|
+
isPending: r.isPending,
|
|
70
|
+
onClearServerErrors: y,
|
|
71
|
+
onSubmit: R,
|
|
72
|
+
submitLabel: "Continue"
|
|
73
|
+
}
|
|
74
|
+
);
|
|
75
|
+
break;
|
|
76
|
+
case "setup-verification":
|
|
77
|
+
d = /* @__PURE__ */ t(
|
|
78
|
+
x,
|
|
79
|
+
{
|
|
80
|
+
className: f["otp-form"],
|
|
81
|
+
autoFocus: e,
|
|
82
|
+
otp: r.mfaCode,
|
|
83
|
+
error: r.error && r.step === "setup-verification" ? r.error : void 0,
|
|
84
|
+
isPending: r.isPending,
|
|
85
|
+
onOTPChange: v,
|
|
86
|
+
onResendOTP: T,
|
|
87
|
+
onSubmit: m,
|
|
88
|
+
passwordLength: 6,
|
|
89
|
+
canResetOTP: p,
|
|
90
|
+
resendCountdown: l,
|
|
91
|
+
successMessage: r.isSuccess ? "Enrolled!" : void 0
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
return h ? /* @__PURE__ */ t(a, { children: h({ step: o, Content: d }) }) : d;
|
|
97
|
+
}, z = ({ step: e }) => {
|
|
98
|
+
switch (e) {
|
|
99
|
+
case "setup":
|
|
100
|
+
return /* @__PURE__ */ t(a, { children: "Enter phone number" });
|
|
101
|
+
case "setup-verification":
|
|
102
|
+
return /* @__PURE__ */ t(a, { children: "Enter verification code" });
|
|
103
|
+
default:
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
}, G = ({ step: e }) => {
|
|
107
|
+
const { state: o } = _(), m = w(
|
|
108
|
+
() => e === "setup-verification" ? k(o.phoneNumber) : "",
|
|
109
|
+
[o.phoneNumber, e]
|
|
110
|
+
);
|
|
111
|
+
switch (e) {
|
|
112
|
+
case "setup":
|
|
113
|
+
return /* @__PURE__ */ t(a, { children: "We'll send you a verification code via text." });
|
|
114
|
+
case "setup-verification":
|
|
115
|
+
return /* @__PURE__ */ D(a, { children: [
|
|
116
|
+
"Enter the 6 digit code sent to",
|
|
117
|
+
" ",
|
|
118
|
+
m ? /* @__PURE__ */ t("span", { className: f.credentials, children: m }) : "your phone number"
|
|
119
|
+
] });
|
|
120
|
+
default:
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
}, H = ({ step: e }) => {
|
|
124
|
+
switch (e) {
|
|
125
|
+
case "setup":
|
|
126
|
+
case "setup-verification":
|
|
127
|
+
return /* @__PURE__ */ t(U, { variant: "secondary", children: /* @__PURE__ */ t(W, {}) });
|
|
128
|
+
default:
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
}, ie = {
|
|
132
|
+
content: q,
|
|
133
|
+
description: G,
|
|
134
|
+
getInitiateOptions: (e) => ({
|
|
135
|
+
mfaMethod: "sms",
|
|
136
|
+
phoneNumber: e.phoneNumber
|
|
137
|
+
}),
|
|
138
|
+
image: H,
|
|
139
|
+
requiresInput: !0,
|
|
140
|
+
title: z
|
|
141
|
+
};
|
|
142
|
+
export {
|
|
143
|
+
q as SmsContent,
|
|
144
|
+
G as SmsDescription,
|
|
145
|
+
H as SmsImage,
|
|
146
|
+
z as SmsTitle,
|
|
147
|
+
ie as smsMethodConfig
|
|
148
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as t, jsxs as l, Fragment as i } from "react/jsx-runtime";
|
|
2
2
|
import { c as u } from "../../../chunks/lite.1fxw3LjI.js";
|
|
3
|
-
import { useCallback as
|
|
3
|
+
import { useCallback as c } from "react";
|
|
4
4
|
import { OTPForm as E } from "../../forms/OTPForm/index.js";
|
|
5
5
|
import { Badge as C } from "../../ui/Badge/index.js";
|
|
6
6
|
import { Button as m } from "../../ui/Button/index.js";
|
|
@@ -8,8 +8,10 @@ import { CopyTextField as T } from "../../ui/CopyTextField/index.js";
|
|
|
8
8
|
import { Error as f } from "../../ui/Error/index.js";
|
|
9
9
|
import { QRCode as v } from "../../ui/QRCode/index.js";
|
|
10
10
|
import { IconSmartPhone as k } from "../../../icons/IconSmartPhone.js";
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
11
|
+
import { isApiError as S } from "../../../utils/isApiError.js";
|
|
12
|
+
import { useEnrollMfaFlow as w } from "../EnrollMfaFlowProvider.js";
|
|
13
|
+
import { useEnrollMfaContext as M } from "../EnrollMfaProvider.js";
|
|
14
|
+
import "@coinbase/cdp-core";
|
|
13
15
|
import "@coinbase/cdp-hooks";
|
|
14
16
|
import '../../../assets/totp.css';const P = "totp-module__expired___SKiyj", F = "totp-module__container___1aL5H", o = {
|
|
15
17
|
"qr-code": "totp-module__qr-code___qyK1k",
|
|
@@ -17,24 +19,24 @@ import '../../../assets/totp.css';const P = "totp-module__expired___SKiyj", F =
|
|
|
17
19
|
container: F,
|
|
18
20
|
"copy-key": "totp-module__copy-key___iwzZf",
|
|
19
21
|
"otp-form": "totp-module__otp-form___OzooV"
|
|
20
|
-
},
|
|
22
|
+
}, b = ({
|
|
21
23
|
autoFocus: r = !0,
|
|
22
|
-
step:
|
|
24
|
+
step: a,
|
|
23
25
|
onSubmit: h,
|
|
24
26
|
children: p
|
|
25
27
|
}) => {
|
|
26
|
-
const { state: e, dispatch: n } =
|
|
28
|
+
const { state: e, dispatch: n } = M(), { startEnrollment: d } = w(), _ = c(() => {
|
|
27
29
|
d(e.method);
|
|
28
|
-
}, [d, e.method]), y =
|
|
30
|
+
}, [d, e.method]), y = c(() => {
|
|
29
31
|
n({ type: "SET_STEP", payload: { step: "setup-verification", flowDirection: "left" } });
|
|
30
|
-
}, [n]), g =
|
|
32
|
+
}, [n]), g = c(
|
|
31
33
|
(x) => {
|
|
32
34
|
n({ type: "SET_MFA_CODE", payload: { mfaCode: x } });
|
|
33
35
|
},
|
|
34
36
|
[n]
|
|
35
37
|
);
|
|
36
38
|
let s;
|
|
37
|
-
switch (
|
|
39
|
+
switch (a) {
|
|
38
40
|
case "setup":
|
|
39
41
|
s = /* @__PURE__ */ l("div", { className: o.container, children: [
|
|
40
42
|
/* @__PURE__ */ t("div", { className: u(o["qr-code"], e.isExpired ? o.expired : ""), children: /* @__PURE__ */ t(v, { value: e.authUrl || "", size: 128, ecl: "L" }) }),
|
|
@@ -48,7 +50,7 @@ import '../../../assets/totp.css';const P = "totp-module__expired___SKiyj", F =
|
|
|
48
50
|
}
|
|
49
51
|
),
|
|
50
52
|
e.isExpired && /* @__PURE__ */ t(f, { children: "Verification timed out. For your security, try again." }),
|
|
51
|
-
!e.isExpired && !!e.error && e.step === "setup" && /* @__PURE__ */ t(f, { children:
|
|
53
|
+
!e.isExpired && !!e.error && e.step === "setup" && /* @__PURE__ */ t(f, { children: S(e.error) ? e.error.message : e.error })
|
|
52
54
|
] }),
|
|
53
55
|
e.isExpired ? /* @__PURE__ */ t(
|
|
54
56
|
m,
|
|
@@ -79,8 +81,8 @@ import '../../../assets/totp.css';const P = "totp-module__expired___SKiyj", F =
|
|
|
79
81
|
);
|
|
80
82
|
break;
|
|
81
83
|
}
|
|
82
|
-
return p ? /* @__PURE__ */ t(i, { children: p({ step:
|
|
83
|
-
},
|
|
84
|
+
return p ? /* @__PURE__ */ t(i, { children: p({ step: a, Content: s }) }) : s;
|
|
85
|
+
}, O = ({ step: r }) => {
|
|
84
86
|
switch (r) {
|
|
85
87
|
case "setup":
|
|
86
88
|
return /* @__PURE__ */ t(i, { children: "Set up authenticator" });
|
|
@@ -105,16 +107,19 @@ import '../../../assets/totp.css';const P = "totp-module__expired___SKiyj", F =
|
|
|
105
107
|
default:
|
|
106
108
|
return null;
|
|
107
109
|
}
|
|
108
|
-
},
|
|
109
|
-
content:
|
|
110
|
-
title:
|
|
110
|
+
}, G = {
|
|
111
|
+
content: b,
|
|
112
|
+
title: O,
|
|
111
113
|
description: q,
|
|
112
|
-
image: A
|
|
114
|
+
image: A,
|
|
115
|
+
getInitiateOptions: () => ({
|
|
116
|
+
mfaMethod: "totp"
|
|
117
|
+
})
|
|
113
118
|
};
|
|
114
119
|
export {
|
|
115
|
-
|
|
120
|
+
b as TotpContent,
|
|
116
121
|
q as TotpDescription,
|
|
117
122
|
A as TotpImage,
|
|
118
|
-
|
|
119
|
-
|
|
123
|
+
O as TotpTitle,
|
|
124
|
+
G as totpMethodConfig
|
|
120
125
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { InitiateMfaEnrollmentResult, InitiateMfaOptions } from '@coinbase/cdp-core';
|
|
1
2
|
import { APIError } from '@coinbase/cdp-hooks';
|
|
2
3
|
import { FC, FormEvent, ReactNode } from 'react';
|
|
3
|
-
export type MfaMethod = "
|
|
4
|
+
export type MfaMethod = InitiateMfaOptions["mfaMethod"];
|
|
4
5
|
export type EnrollMfaStep = "list" | "setup" | "setup-verification";
|
|
5
6
|
export type EnrollMfaMethodStep = Exclude<EnrollMfaStep, "list">;
|
|
6
7
|
export interface EnrollMfaMethodComponentProps {
|
|
@@ -15,6 +16,7 @@ export interface EnrollMfaState {
|
|
|
15
16
|
mfaCode: string;
|
|
16
17
|
authUrl: string | null;
|
|
17
18
|
secret: string | null;
|
|
19
|
+
phoneNumber: string;
|
|
18
20
|
initiatedAt: number | null;
|
|
19
21
|
isExpired: boolean;
|
|
20
22
|
error: string | APIError | null;
|
|
@@ -26,12 +28,18 @@ export type EnrollMfaAction = {
|
|
|
26
28
|
payload: {
|
|
27
29
|
step: EnrollMfaStep;
|
|
28
30
|
flowDirection?: "left" | "right";
|
|
31
|
+
method?: MfaMethod;
|
|
29
32
|
};
|
|
30
33
|
} | {
|
|
31
34
|
type: "SET_MFA_CODE";
|
|
32
35
|
payload: {
|
|
33
36
|
mfaCode: string;
|
|
34
37
|
};
|
|
38
|
+
} | {
|
|
39
|
+
type: "SET_PHONE_NUMBER";
|
|
40
|
+
payload: {
|
|
41
|
+
phoneNumber: string;
|
|
42
|
+
};
|
|
35
43
|
} | {
|
|
36
44
|
type: "INITIATE_ENROLLMENT";
|
|
37
45
|
payload: {
|
|
@@ -39,10 +47,7 @@ export type EnrollMfaAction = {
|
|
|
39
47
|
};
|
|
40
48
|
} | {
|
|
41
49
|
type: "INITIATE_ENROLLMENT_SUCCESS";
|
|
42
|
-
payload:
|
|
43
|
-
authUrl: string;
|
|
44
|
-
secret: string;
|
|
45
|
-
};
|
|
50
|
+
payload: InitiateMfaEnrollmentResult;
|
|
46
51
|
} | {
|
|
47
52
|
type: "INITIATE_ENROLLMENT_FAILURE";
|
|
48
53
|
payload: {
|
|
@@ -59,6 +64,11 @@ export type EnrollMfaAction = {
|
|
|
59
64
|
payload: {
|
|
60
65
|
error: string | APIError;
|
|
61
66
|
};
|
|
67
|
+
} | {
|
|
68
|
+
type: "SET_METHODS";
|
|
69
|
+
payload: {
|
|
70
|
+
methods: MfaMethod[];
|
|
71
|
+
};
|
|
62
72
|
} | {
|
|
63
73
|
type: "CLEAR_ERROR";
|
|
64
74
|
} | {
|
|
@@ -78,6 +88,8 @@ export interface EnrollMfaMethodContentProps {
|
|
|
78
88
|
export interface EnrollMfaMethodConfig {
|
|
79
89
|
content: FC<EnrollMfaMethodContentProps>;
|
|
80
90
|
description: FC<EnrollMfaMethodComponentProps>;
|
|
91
|
+
getInitiateOptions: (state: EnrollMfaState) => InitiateMfaOptions;
|
|
81
92
|
image: FC<EnrollMfaMethodComponentProps>;
|
|
93
|
+
requiresInput?: boolean;
|
|
82
94
|
title: FC<EnrollMfaMethodComponentProps>;
|
|
83
95
|
}
|
|
@@ -1,111 +1,124 @@
|
|
|
1
|
-
import { useReducer as
|
|
1
|
+
import { useReducer as d } from "react";
|
|
2
2
|
import "@coinbase/cdp-hooks";
|
|
3
|
-
import { isApiError as
|
|
3
|
+
import { isApiError as i } from "../../utils/isApiError.js";
|
|
4
4
|
import "libphonenumber-js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
import "@coinbase/cdp-core";
|
|
6
|
+
const l = ["list", "setup", "setup-verification"], s = (e) => ({
|
|
7
|
+
method: e[0] || "totp",
|
|
8
|
+
methods: e,
|
|
8
9
|
step: "list",
|
|
9
10
|
flowDirection: "left",
|
|
10
11
|
mfaCode: "",
|
|
11
12
|
authUrl: null,
|
|
12
13
|
secret: null,
|
|
14
|
+
phoneNumber: "",
|
|
13
15
|
initiatedAt: null,
|
|
14
16
|
isExpired: !1,
|
|
15
17
|
error: null,
|
|
16
18
|
isPending: !1,
|
|
17
19
|
isSuccess: !1
|
|
18
|
-
}), u = (
|
|
19
|
-
switch (
|
|
20
|
+
}), u = (e, r) => {
|
|
21
|
+
switch (r.type) {
|
|
20
22
|
case "SET_STEP":
|
|
21
23
|
return {
|
|
22
|
-
...
|
|
23
|
-
step:
|
|
24
|
-
flowDirection:
|
|
24
|
+
...e,
|
|
25
|
+
step: r.payload.step,
|
|
26
|
+
flowDirection: r.payload.flowDirection || e.flowDirection,
|
|
27
|
+
method: r.payload.method || e.method,
|
|
25
28
|
error: null
|
|
26
29
|
};
|
|
27
30
|
case "SET_MFA_CODE":
|
|
28
31
|
return {
|
|
29
|
-
...
|
|
30
|
-
mfaCode:
|
|
32
|
+
...e,
|
|
33
|
+
mfaCode: r.payload.mfaCode,
|
|
34
|
+
error: null
|
|
35
|
+
};
|
|
36
|
+
case "SET_PHONE_NUMBER":
|
|
37
|
+
return {
|
|
38
|
+
...e,
|
|
39
|
+
phoneNumber: r.payload.phoneNumber,
|
|
31
40
|
error: null
|
|
32
41
|
};
|
|
33
42
|
case "INITIATE_ENROLLMENT":
|
|
34
43
|
return {
|
|
35
|
-
...
|
|
36
|
-
method:
|
|
44
|
+
...e,
|
|
45
|
+
method: r.payload.method,
|
|
37
46
|
isPending: !0,
|
|
38
47
|
error: null,
|
|
39
48
|
flowDirection: "left"
|
|
40
49
|
};
|
|
41
|
-
case "INITIATE_ENROLLMENT_SUCCESS":
|
|
50
|
+
case "INITIATE_ENROLLMENT_SUCCESS": {
|
|
51
|
+
const o = l.indexOf(e.step), n = o < l.length - 1 ? l[o + 1] : e.step;
|
|
42
52
|
return {
|
|
43
|
-
...
|
|
53
|
+
...e,
|
|
44
54
|
isPending: !1,
|
|
45
|
-
authUrl:
|
|
46
|
-
secret:
|
|
55
|
+
authUrl: "authUrl" in r.payload ? r.payload.authUrl : null,
|
|
56
|
+
secret: "secret" in r.payload ? r.payload.secret : null,
|
|
47
57
|
initiatedAt: Date.now(),
|
|
48
58
|
isExpired: !1,
|
|
49
|
-
step:
|
|
59
|
+
step: n
|
|
50
60
|
};
|
|
61
|
+
}
|
|
51
62
|
case "INITIATE_ENROLLMENT_FAILURE":
|
|
52
63
|
return {
|
|
53
|
-
...
|
|
64
|
+
...e,
|
|
54
65
|
isPending: !1,
|
|
55
|
-
error:
|
|
56
|
-
step: "list",
|
|
57
|
-
flowDirection: "right"
|
|
66
|
+
error: r.payload.error
|
|
58
67
|
};
|
|
59
68
|
case "ENROLLMENT_SESSION_EXPIRED":
|
|
60
69
|
return {
|
|
61
|
-
...
|
|
70
|
+
...e,
|
|
62
71
|
mfaCode: "",
|
|
63
72
|
isExpired: !0
|
|
64
73
|
};
|
|
65
74
|
case "SUBMIT_ENROLLMENT":
|
|
66
75
|
return {
|
|
67
|
-
...
|
|
76
|
+
...e,
|
|
68
77
|
isPending: !0,
|
|
69
78
|
error: null,
|
|
70
79
|
flowDirection: "left"
|
|
71
80
|
};
|
|
72
81
|
case "SUBMIT_ENROLLMENT_SUCCESS":
|
|
73
82
|
return {
|
|
74
|
-
...
|
|
83
|
+
...e,
|
|
75
84
|
isPending: !1,
|
|
76
85
|
isSuccess: !0
|
|
77
86
|
};
|
|
78
87
|
case "SUBMIT_ENROLLMENT_FAILURE":
|
|
79
88
|
return {
|
|
80
|
-
...
|
|
89
|
+
...e,
|
|
81
90
|
isPending: !1,
|
|
82
|
-
error:
|
|
83
|
-
isExpired:
|
|
91
|
+
error: r.payload.error,
|
|
92
|
+
isExpired: i(r.payload.error) ? r.payload.error.errorType === "mfa_flow_expired" : r.payload.error.toLowerCase().startsWith("mfa flow not found or expired")
|
|
93
|
+
};
|
|
94
|
+
case "SET_METHODS":
|
|
95
|
+
return {
|
|
96
|
+
...e,
|
|
97
|
+
methods: r.payload.methods
|
|
84
98
|
};
|
|
85
99
|
case "CLEAR_ERROR":
|
|
86
100
|
return {
|
|
87
|
-
...
|
|
101
|
+
...e,
|
|
88
102
|
error: null
|
|
89
103
|
};
|
|
90
104
|
case "GO_TO_PREVIOUS_STEP": {
|
|
91
|
-
const o = l.indexOf(
|
|
105
|
+
const o = l.indexOf(e.step), n = o > 0 ? l[o - 1] : e.step;
|
|
92
106
|
return {
|
|
93
|
-
...
|
|
107
|
+
...e,
|
|
94
108
|
flowDirection: "right",
|
|
95
|
-
step:
|
|
109
|
+
step: n,
|
|
96
110
|
error: null,
|
|
97
111
|
isExpired: !1,
|
|
98
112
|
mfaCode: ""
|
|
99
|
-
// Clear MFA code when going back
|
|
100
113
|
};
|
|
101
114
|
}
|
|
102
115
|
case "RESET_STATE":
|
|
103
|
-
return
|
|
116
|
+
return s(e.methods);
|
|
104
117
|
default:
|
|
105
|
-
return
|
|
118
|
+
return e;
|
|
106
119
|
}
|
|
107
|
-
},
|
|
120
|
+
}, S = (e = ["totp"]) => d(u, e, s);
|
|
108
121
|
export {
|
|
109
122
|
l as STEPS,
|
|
110
|
-
|
|
123
|
+
S as useEnrollMfaReducer
|
|
111
124
|
};
|
|
@@ -2,7 +2,7 @@ import { jsx as o, jsxs as r, Fragment as s } from "react/jsx-runtime";
|
|
|
2
2
|
import { u as v } from "../../chunks/useSendComponentCallOnce.BHZMuo6E.js";
|
|
3
3
|
import { createContext as b, useMemo as w, useContext as y } from "react";
|
|
4
4
|
import { c as p } from "../../chunks/lite.1fxw3LjI.js";
|
|
5
|
-
import { u as F } from "../../chunks/CDPReactProvider.
|
|
5
|
+
import { u as F } from "../../chunks/CDPReactProvider.C38bKQ2x.js";
|
|
6
6
|
import { EnrollMfa as T, EnrollMfaError as B } from "../EnrollMfa/index.js";
|
|
7
7
|
import { Button as h } from "../ui/Button/index.js";
|
|
8
8
|
import { Modal as A, ModalContent as O, ModalTitle as S, ModalDescription as $, ModalClose as E, ModalTrigger as D } from "../ui/Modal/index.js";
|