@coinbase/cdp-hooks 0.0.38 → 0.0.41
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/esm/index3.js +44 -45
- package/dist/types/index.d.ts +4 -0
- package/package.json +3 -3
package/dist/esm/index3.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getAccessToken as A, sendUserOperation as y, signInWithEmail as O, signInWithSms as
|
|
1
|
+
import { getAccessToken as A, sendUserOperation as y, signInWithEmail as O, signInWithSms as U, verifyEmailOTP as I, verifySmsOTP as P, signOut as x, signEvmHash as M, signEvmTransaction as k, sendEvmTransaction as C, signEvmMessage as W, signSolanaMessage as H, signEvmTypedData as b, exportEvmAccount as D, exportSolanaAccount as V, signSolanaTransaction as F, sendSolanaTransaction as z, getUserOperation as G } from "@coinbase/cdp-core";
|
|
2
2
|
import { useState as u, useEffect as f, useMemo as j, useCallback as h } from "react";
|
|
3
3
|
import { useCDP as p } from "./index2.js";
|
|
4
4
|
import { useAutoPolling as q } from "./index4.js";
|
|
@@ -9,13 +9,13 @@ const Y = () => {
|
|
|
9
9
|
}, Z = () => {
|
|
10
10
|
const { isInitialized: n } = p();
|
|
11
11
|
return { isInitialized: n };
|
|
12
|
-
}, _ = () => ({ signInWithEmail: g(O) }), $ = () => ({ signInWithSms: g(
|
|
12
|
+
}, _ = () => ({ signInWithEmail: g(O) }), $ = () => ({ signInWithSms: g(U) }), R = () => ({ verifyEmailOTP: g(I) }), nn = () => ({ verifySmsOTP: g(P) }), en = () => {
|
|
13
13
|
const { isSignedIn: n } = p();
|
|
14
14
|
return { isSignedIn: n };
|
|
15
15
|
}, w = () => {
|
|
16
16
|
const { currentUser: n } = p();
|
|
17
17
|
return { currentUser: n };
|
|
18
|
-
}, tn = () => ({ signOut:
|
|
18
|
+
}, tn = () => ({ signOut: i(x) }), rn = () => ({ getAccessToken: A }), sn = () => {
|
|
19
19
|
const { currentUser: n } = w();
|
|
20
20
|
return {
|
|
21
21
|
evmAddress: n?.evmSmartAccounts?.[0] ?? n?.evmAccounts?.[0] ?? null
|
|
@@ -25,11 +25,11 @@ const Y = () => {
|
|
|
25
25
|
return {
|
|
26
26
|
solanaAddress: n?.solanaAccounts?.[0] ?? null
|
|
27
27
|
};
|
|
28
|
-
}, on = () => ({ signEvmHash:
|
|
29
|
-
const [n, e] = u(null), [
|
|
28
|
+
}, on = () => ({ signEvmHash: i(M) }), cn = () => ({ signEvmTransaction: i(k) }), un = () => {
|
|
29
|
+
const [n, e] = u(null), [s, r] = u(null), [c, S] = u(null), { config: a } = p(), d = i(
|
|
30
30
|
async (m) => {
|
|
31
|
-
const
|
|
32
|
-
return e({ hash:
|
|
31
|
+
const o = await C(m);
|
|
32
|
+
return e({ hash: o.transactionHash, network: m.network }), S(null), r(null), o;
|
|
33
33
|
}
|
|
34
34
|
);
|
|
35
35
|
f(() => {
|
|
@@ -39,43 +39,43 @@ const Y = () => {
|
|
|
39
39
|
const E = await B(n.network, a).waitForTransactionReceipt({
|
|
40
40
|
hash: n.hash
|
|
41
41
|
});
|
|
42
|
-
|
|
43
|
-
} catch (
|
|
44
|
-
S(
|
|
42
|
+
r(E);
|
|
43
|
+
} catch (o) {
|
|
44
|
+
S(o instanceof Error ? o : new Error(String(o)));
|
|
45
45
|
}
|
|
46
46
|
})();
|
|
47
47
|
}, [n]);
|
|
48
|
-
const l = j(() => n ?
|
|
48
|
+
const l = j(() => n ? s ? { status: "success", receipt: s } : c ? { status: "error", error: c } : { status: "pending", hash: n.hash } : { status: "idle" }, [n, s, c]);
|
|
49
49
|
return {
|
|
50
50
|
sendEvmTransaction: d,
|
|
51
51
|
data: l
|
|
52
52
|
};
|
|
53
|
-
}, pn = () => ({ signEvmMessage:
|
|
54
|
-
sendSolanaTransaction:
|
|
55
|
-
}),
|
|
53
|
+
}, pn = () => ({ signEvmMessage: i(W) }), dn = () => ({ signSolanaMessage: i(H) }), ln = () => ({ signEvmTypedData: i(b) }), Sn = () => ({ exportEvmAccount: i(D) }), mn = () => ({ exportSolanaAccount: i(V) }), gn = () => ({ signSolanaTransaction: i(F) }), En = () => ({
|
|
54
|
+
sendSolanaTransaction: i(z)
|
|
55
|
+
}), i = (n) => {
|
|
56
56
|
const { isSignedIn: e } = p();
|
|
57
57
|
return h(
|
|
58
|
-
async (...
|
|
58
|
+
async (...r) => {
|
|
59
59
|
if (!e)
|
|
60
60
|
throw new Error("User is not authenticated");
|
|
61
|
-
return n(...
|
|
61
|
+
return n(...r);
|
|
62
62
|
},
|
|
63
63
|
[e, n]
|
|
64
64
|
);
|
|
65
65
|
}, g = (n) => {
|
|
66
66
|
const { isSignedIn: e } = p();
|
|
67
67
|
return h(
|
|
68
|
-
async (...
|
|
68
|
+
async (...r) => {
|
|
69
69
|
if (e)
|
|
70
70
|
throw new Error("User is already authenticated. Please sign out first.");
|
|
71
|
-
return n(...
|
|
71
|
+
return n(...r);
|
|
72
72
|
},
|
|
73
73
|
[e, n]
|
|
74
74
|
);
|
|
75
75
|
}, wn = () => {
|
|
76
|
-
const [n, e] = u(void 0), { status:
|
|
76
|
+
const [n, e] = u(void 0), { status: s, data: r, error: c } = J(n);
|
|
77
77
|
return {
|
|
78
|
-
sendUserOperation:
|
|
78
|
+
sendUserOperation: i(
|
|
79
79
|
async (a) => {
|
|
80
80
|
const d = await y(a);
|
|
81
81
|
return e({
|
|
@@ -85,42 +85,41 @@ const Y = () => {
|
|
|
85
85
|
}), d;
|
|
86
86
|
}
|
|
87
87
|
),
|
|
88
|
-
data:
|
|
88
|
+
data: r,
|
|
89
89
|
error: c,
|
|
90
|
-
status:
|
|
90
|
+
status: s
|
|
91
91
|
};
|
|
92
92
|
}, J = (n = {}) => {
|
|
93
|
-
const { userOperationHash: e, evmSmartAccount:
|
|
93
|
+
const { userOperationHash: e, evmSmartAccount: s, network: r, enabled: c } = n, [S, a] = u("idle"), [d, l] = u(void 0), [m, o] = u(void 0), { currentUser: E } = w();
|
|
94
94
|
f(() => {
|
|
95
|
-
e &&
|
|
96
|
-
}, [e,
|
|
97
|
-
const v = c !== !1 && !!(e &&
|
|
95
|
+
e && s && r && (a(c !== !1 ? "pending" : "idle"), l(void 0), o(void 0));
|
|
96
|
+
}, [e, s, r, c]);
|
|
97
|
+
const v = c !== !1 && !!(e && s && r && E);
|
|
98
98
|
return q(
|
|
99
99
|
{
|
|
100
100
|
pollFn: async () => {
|
|
101
|
-
const
|
|
101
|
+
const t = await G({
|
|
102
102
|
userOperationHash: e,
|
|
103
|
-
evmSmartAccount:
|
|
104
|
-
network:
|
|
103
|
+
evmSmartAccount: s,
|
|
104
|
+
network: r
|
|
105
105
|
});
|
|
106
|
-
return l(
|
|
106
|
+
return l(t), t;
|
|
107
107
|
},
|
|
108
|
-
shouldStop: (
|
|
108
|
+
shouldStop: (t) => t.status === "complete" || t.status === "dropped" || t.status === "failed",
|
|
109
109
|
enabled: v,
|
|
110
|
-
onSuccess: (
|
|
111
|
-
if (
|
|
112
|
-
l(
|
|
113
|
-
else if (
|
|
114
|
-
const T =
|
|
115
|
-
|
|
116
|
-
} else
|
|
117
|
-
l(s), a("error");
|
|
110
|
+
onSuccess: (t) => {
|
|
111
|
+
if (t.status === "complete")
|
|
112
|
+
l(t), a("success");
|
|
113
|
+
else if (t.status === "failed") {
|
|
114
|
+
const T = t.receipts?.[0]?.revert?.message || "User operation failed";
|
|
115
|
+
o(new Error(T)), a("error");
|
|
116
|
+
} else t.status === "dropped" ? (o(new Error('User operation failed with status: "dropped"')), a("error")) : (l(t), a("error"));
|
|
118
117
|
},
|
|
119
|
-
onError: (
|
|
120
|
-
|
|
118
|
+
onError: (t) => {
|
|
119
|
+
o(t), a("error");
|
|
121
120
|
}
|
|
122
121
|
},
|
|
123
|
-
[e,
|
|
122
|
+
[e, s, r, v]
|
|
124
123
|
), {
|
|
125
124
|
status: S,
|
|
126
125
|
data: d,
|
|
@@ -130,12 +129,12 @@ const Y = () => {
|
|
|
130
129
|
export {
|
|
131
130
|
Y as useConfig,
|
|
132
131
|
w as useCurrentUser,
|
|
133
|
-
|
|
132
|
+
i as useEnforceAuthenticated,
|
|
134
133
|
g as useEnforceUnauthenticated,
|
|
135
|
-
|
|
134
|
+
sn as useEvmAddress,
|
|
136
135
|
Sn as useExportEvmAccount,
|
|
137
136
|
mn as useExportSolanaAccount,
|
|
138
|
-
|
|
137
|
+
rn as useGetAccessToken,
|
|
139
138
|
Z as useIsInitialized,
|
|
140
139
|
en as useIsSignedIn,
|
|
141
140
|
un as useSendEvmTransaction,
|
package/dist/types/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coinbase/cdp-hooks",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.41",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist/**",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
"peerDependencies": {
|
|
16
16
|
"react": ">=18.2.0",
|
|
17
|
-
"@coinbase/cdp-core": "^0.0.
|
|
17
|
+
"@coinbase/cdp-core": "^0.0.41"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@testing-library/jest-dom": "^6.6.3",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"@size-limit/webpack": "^11.2.0",
|
|
30
30
|
"@size-limit/webpack-why": "^11.2.0",
|
|
31
31
|
"size-limit": "^11.2.0",
|
|
32
|
-
"@coinbase/cdp-core": "^0.0.
|
|
32
|
+
"@coinbase/cdp-core": "^0.0.41"
|
|
33
33
|
},
|
|
34
34
|
"size-limit": [
|
|
35
35
|
{
|