@coinbase/cdp-wagmi 0.0.14 → 0.0.15
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/README.md +9 -0
- package/dist/esm/index.js +2 -1
- package/dist/esm/index2.js +46 -40
- package/dist/types/index.d.ts +2 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -94,6 +94,15 @@ ReactDOM.createRoot(document.getElementById('root')!).render(
|
|
|
94
94
|
);
|
|
95
95
|
```
|
|
96
96
|
|
|
97
|
+
### Sign in and connection
|
|
98
|
+
|
|
99
|
+
In order to connect the CDP Embedded Wallet, the end application user must first go through the 2 step sign in flow. As a result, the consumer has 3 options:
|
|
100
|
+
1. Use @coinbase/cdp-core's `signInWithEmail` + `verifyEmailOTP`
|
|
101
|
+
2. Use @coinbase/cdp-hooks' `useSignInWithEmail` + `useVerifyEmailOTP`
|
|
102
|
+
3. Use @coinbase/cdp-react `<SignIn />` component
|
|
103
|
+
|
|
104
|
+
After using any of these methods, the CDP embedded wallet's connector should automatically connect.
|
|
105
|
+
|
|
97
106
|
### Call Wagmi Hooks
|
|
98
107
|
|
|
99
108
|
Now, your application should be able to successfully call Wagmi hooks. For example:
|
package/dist/esm/index.js
CHANGED
package/dist/esm/index2.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { createCDPEmbeddedWallet as
|
|
2
|
-
import { SwitchChainError as
|
|
3
|
-
import { createConnector as
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { createCDPEmbeddedWallet as I, STANDARD_ERROR_CODES as l, EIP1193ProviderError as y, initialize as p } from "@coinbase/cdp-core";
|
|
2
|
+
import { SwitchChainError as f, numberToHex as b, getAddress as D } from "viem";
|
|
3
|
+
import { createConnector as P } from "wagmi";
|
|
4
|
+
const E = "cdp-embedded-wallet";
|
|
5
|
+
function M(u) {
|
|
6
|
+
return P((s) => {
|
|
7
|
+
const C = u.providerConfig?.chains ?? s.chains ?? [];
|
|
8
|
+
let m, r, o, n, c, g;
|
|
9
|
+
async function w() {
|
|
10
|
+
g || (g = p(u.cdpConfig)), await g;
|
|
10
11
|
}
|
|
11
12
|
return {
|
|
12
13
|
/**
|
|
@@ -18,7 +19,7 @@ function Z(d) {
|
|
|
18
19
|
*/
|
|
19
20
|
async setup() {
|
|
20
21
|
const e = await this.getProvider();
|
|
21
|
-
|
|
22
|
+
n || (n = this.onConnect.bind(this), e.on("connect", n));
|
|
22
23
|
},
|
|
23
24
|
/**
|
|
24
25
|
* Connector function called when the user connects their wallet.
|
|
@@ -34,24 +35,28 @@ function Z(d) {
|
|
|
34
35
|
chainId: e,
|
|
35
36
|
isReconnecting: t
|
|
36
37
|
} = {}) {
|
|
37
|
-
let
|
|
38
|
-
|
|
38
|
+
let d = [], i = await this.getChainId();
|
|
39
|
+
const h = await this.getProvider();
|
|
40
|
+
n && (h.removeListener("connect", n), n = void 0), c || (c = this.onAccountsChanged.bind(this), h.on("accountsChanged", c)), r || (r = this.onChainChanged.bind(this), h.on("chainChanged", r)), o || (o = this.onDisconnect.bind(this), h.on("disconnect", o));
|
|
39
41
|
try {
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
if (d = await this.getAccounts(), t)
|
|
43
|
+
return { accounts: d, chainId: i };
|
|
44
|
+
if (!d?.length && !t)
|
|
45
|
+
throw new Error(
|
|
46
|
+
"Please use our hooks / SignIn component to connect your wallet. See the README for more details."
|
|
47
|
+
);
|
|
48
|
+
return e && i !== e && (i = (await this.switchChain({ chainId: e }).catch(
|
|
49
|
+
(a) => {
|
|
50
|
+
if (a.code === l.provider.userRejectedRequest) throw a;
|
|
51
|
+
return { id: i };
|
|
47
52
|
}
|
|
48
|
-
))?.id ??
|
|
49
|
-
} catch (
|
|
50
|
-
const
|
|
51
|
-
throw
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
) :
|
|
53
|
+
))?.id ?? i), { accounts: d, chainId: i };
|
|
54
|
+
} catch (v) {
|
|
55
|
+
const a = v;
|
|
56
|
+
throw a.code === l.provider.userRejectedRequest ? new y(
|
|
57
|
+
l.provider.userRejectedRequest,
|
|
58
|
+
a.message
|
|
59
|
+
) : a;
|
|
55
60
|
}
|
|
56
61
|
},
|
|
57
62
|
/**
|
|
@@ -60,7 +65,7 @@ function Z(d) {
|
|
|
60
65
|
*/
|
|
61
66
|
async disconnect() {
|
|
62
67
|
const e = await this.getProvider();
|
|
63
|
-
await e.request({ method: "wallet_disconnect" }),
|
|
68
|
+
await e.request({ method: "wallet_disconnect" }), o && (e.removeListener("disconnect", o), o = void 0), c && (e.removeListener("accountsChanged", c), c = void 0), r && (e.removeListener("chainChanged", r), r = void 0), n || (n = this.onConnect.bind(this), e.on("connect", n));
|
|
64
69
|
},
|
|
65
70
|
/**
|
|
66
71
|
* Get the accounts of the user
|
|
@@ -87,10 +92,10 @@ function Z(d) {
|
|
|
87
92
|
* @returns {EIP1193Provider} The 1193 provider
|
|
88
93
|
*/
|
|
89
94
|
async getProvider() {
|
|
90
|
-
return await
|
|
91
|
-
chains:
|
|
92
|
-
transports:
|
|
93
|
-
})),
|
|
95
|
+
return await w(), m || (m = I({
|
|
96
|
+
chains: C,
|
|
97
|
+
transports: u.providerConfig.transports
|
|
98
|
+
})), m.provider;
|
|
94
99
|
},
|
|
95
100
|
/**
|
|
96
101
|
* Checks if the user is authorized
|
|
@@ -116,8 +121,8 @@ function Z(d) {
|
|
|
116
121
|
* @param accounts - {readonly string[]} - The accounts of the user (wagmi expects readonly string, not 0xstring)
|
|
117
122
|
*/
|
|
118
123
|
onAccountsChanged(e) {
|
|
119
|
-
|
|
120
|
-
accounts: e.map((t) =>
|
|
124
|
+
s.emitter.emit("change", {
|
|
125
|
+
accounts: e.map((t) => D(t))
|
|
121
126
|
});
|
|
122
127
|
},
|
|
123
128
|
/**
|
|
@@ -127,7 +132,7 @@ function Z(d) {
|
|
|
127
132
|
*/
|
|
128
133
|
onChainChanged(e) {
|
|
129
134
|
const t = Number(e);
|
|
130
|
-
|
|
135
|
+
s.emitter.emit("change", { chainId: t });
|
|
131
136
|
},
|
|
132
137
|
/**
|
|
133
138
|
* Handle connect events ensuring we emit the events to wagmi
|
|
@@ -137,13 +142,13 @@ function Z(d) {
|
|
|
137
142
|
*/
|
|
138
143
|
async onConnect({ chainId: e }) {
|
|
139
144
|
const t = await this.getAccounts();
|
|
140
|
-
t.length !== 0 &&
|
|
145
|
+
t.length !== 0 && s.emitter.emit("connect", { accounts: t, chainId: Number(e) });
|
|
141
146
|
},
|
|
142
147
|
/**
|
|
143
148
|
* Handle disconnect events ensuring we emit the events to wagmi
|
|
144
149
|
*/
|
|
145
150
|
async onDisconnect() {
|
|
146
|
-
|
|
151
|
+
s.emitter.emit("disconnect");
|
|
147
152
|
},
|
|
148
153
|
/**
|
|
149
154
|
* Switches the user to the specified chain
|
|
@@ -153,8 +158,8 @@ function Z(d) {
|
|
|
153
158
|
* @returns {Promise<Chain>} The chain that was switched to
|
|
154
159
|
*/
|
|
155
160
|
async switchChain({ chainId: e }) {
|
|
156
|
-
const t =
|
|
157
|
-
if (!t) throw new
|
|
161
|
+
const t = C.find((i) => i.id === e);
|
|
162
|
+
if (!t) throw new f(new Error("Chain not configured"));
|
|
158
163
|
return await (await this.getProvider()).request({
|
|
159
164
|
method: "wallet_switchEthereumChain",
|
|
160
165
|
params: [{ chainId: b(e) }]
|
|
@@ -162,12 +167,13 @@ function Z(d) {
|
|
|
162
167
|
},
|
|
163
168
|
// Below are temporary values while we dev
|
|
164
169
|
icon: "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTEyIDJMMiA3VjE3TDEyIDIyTDIyIDE3VjdMMTIgMloiIHN0cm9rZT0iY3VycmVudENvbG9yIiBzdHJva2Utd2lkdGg9IjIiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIvPgo8L3N2Zz4K",
|
|
165
|
-
id:
|
|
170
|
+
id: E,
|
|
166
171
|
name: "CDP",
|
|
167
172
|
type: "injected"
|
|
168
173
|
};
|
|
169
174
|
});
|
|
170
175
|
}
|
|
171
176
|
export {
|
|
172
|
-
|
|
177
|
+
E as CDP_CONNECTOR_ID,
|
|
178
|
+
M as createCDPEmbeddedWalletConnector
|
|
173
179
|
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { CDPEmbeddedWalletConfig } from '@coinbase/cdp-core';
|
|
|
2
2
|
import { Config } from '@coinbase/cdp-core';
|
|
3
3
|
import { createConnector } from 'wagmi';
|
|
4
4
|
|
|
5
|
+
export declare const CDP_CONNECTOR_ID = "cdp-embedded-wallet";
|
|
6
|
+
|
|
5
7
|
export declare function createCDPEmbeddedWalletConnector(parameters: {
|
|
6
8
|
cdpConfig: Config;
|
|
7
9
|
providerConfig: CDPEmbeddedWalletConfig;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coinbase/cdp-wagmi",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.15",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist/**",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"react": ">=18.2.0",
|
|
19
19
|
"viem": "^2.33.0",
|
|
20
20
|
"wagmi": "^2.16.0",
|
|
21
|
-
"@coinbase/cdp-core": "^0.0.
|
|
21
|
+
"@coinbase/cdp-core": "^0.0.15"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@tanstack/react-query": "^5.0.0",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"@size-limit/webpack": "^11.2.0",
|
|
35
35
|
"@size-limit/webpack-why": "^11.2.0",
|
|
36
36
|
"size-limit": "^11.2.0",
|
|
37
|
-
"@coinbase/cdp-core": "^0.0.
|
|
37
|
+
"@coinbase/cdp-core": "^0.0.15"
|
|
38
38
|
},
|
|
39
39
|
"size-limit": [
|
|
40
40
|
{
|