@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 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
@@ -1,4 +1,5 @@
1
- import { createCDPEmbeddedWalletConnector as r } from "./index2.js";
1
+ import { CDP_CONNECTOR_ID as o, createCDPEmbeddedWalletConnector as r } from "./index2.js";
2
2
  export {
3
+ o as CDP_CONNECTOR_ID,
3
4
  r as createCDPEmbeddedWalletConnector
4
5
  };
@@ -1,12 +1,13 @@
1
- import { createCDPEmbeddedWallet as w, STANDARD_ERROR_CODES as g, EIP1193ProviderError as I, initialize as p } from "@coinbase/cdp-core";
2
- import { SwitchChainError as y, numberToHex as b, getAddress as f } from "viem";
3
- import { createConnector as D } from "wagmi";
4
- function Z(d) {
5
- return D((a) => {
6
- const v = d.providerConfig?.chains ?? a.chains ?? [];
7
- let h, i, r, u, c, m;
8
- async function C() {
9
- m || (m = p(d.cdpConfig)), await m;
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
- r || (r = this.onDisconnect.bind(this), e.on("disconnect", r)), c || (c = this.onAccountsChanged.bind(this), e.on("accountsChanged", c)), i || (i = this.onChainChanged.bind(this), e.on("chainChanged", i)), u || (u = this.onConnect.bind(this), e.on("connect", u));
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 o = [];
38
- t && (o = await this.getAccounts());
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 (!o?.length && !t && (o = await (await this.getProvider()).request({ method: "eth_requestAccounts" }), o.length === 0))
41
- throw new Error("User has no evm addresses available or is not authenticated");
42
- let n = await this.getChainId();
43
- return e && n !== e && (n = (await this.switchChain({ chainId: e }).catch(
44
- (l) => {
45
- if (l.code === g.provider.userRejectedRequest) throw l;
46
- return { id: n };
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 ?? n), { accounts: o, chainId: n };
49
- } catch (n) {
50
- const s = n;
51
- throw s.code === g.provider.userRejectedRequest ? new I(
52
- g.provider.userRejectedRequest,
53
- s.message
54
- ) : s;
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" }), r && (e.removeListener("disconnect", r), r = void 0), c && (e.removeListener("accountsChanged", c), c = void 0), i && (e.removeListener("chainChanged", i), i = void 0);
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 C(), h || (h = w({
91
- chains: v,
92
- transports: d.providerConfig.transports
93
- })), h.provider;
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
- a.emitter.emit("change", {
120
- accounts: e.map((t) => f(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
- a.emitter.emit("change", { chainId: t });
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 && a.emitter.emit("connect", { accounts: t, chainId: Number(e) });
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
- a.emitter.emit("disconnect");
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 = v.find((n) => n.id === e);
157
- if (!t) throw new y(new Error("Chain not configured"));
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: "cdp",
170
+ id: E,
166
171
  name: "CDP",
167
172
  type: "injected"
168
173
  };
169
174
  });
170
175
  }
171
176
  export {
172
- Z as createCDPEmbeddedWalletConnector
177
+ E as CDP_CONNECTOR_ID,
178
+ M as createCDPEmbeddedWalletConnector
173
179
  };
@@ -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.14",
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.14"
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.14"
37
+ "@coinbase/cdp-core": "^0.0.15"
38
38
  },
39
39
  "size-limit": [
40
40
  {