cosmos-connect-react 0.1.0 → 0.1.2
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 +75 -0
- package/dist/hooks.d.ts +6 -6
- package/dist/styles.css +329 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# cosmos-connect-react
|
|
2
|
+
|
|
3
|
+
React hooks and context provider for Cosmos wallet management. Built on top of `cosmos-connect-core`.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install cosmos-connect-react cosmos-connect-core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Setup Provider
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { CosmosProvider } from 'cosmos-connect-react';
|
|
17
|
+
import { KeplrWallet, LeapWallet } from 'cosmos-connect-core';
|
|
18
|
+
|
|
19
|
+
const terraClassic = {
|
|
20
|
+
chainId: 'columbus-5',
|
|
21
|
+
rpc: 'https://terra-classic-rpc.publicnode.com',
|
|
22
|
+
rest: 'https://terra-classic-lcd.publicnode.com',
|
|
23
|
+
bech32Prefix: 'terra',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const config = {
|
|
27
|
+
chains: [terraClassic],
|
|
28
|
+
wallets: [new KeplrWallet(), new LeapWallet()],
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
function App() {
|
|
32
|
+
return (
|
|
33
|
+
<CosmosProvider config={config}>
|
|
34
|
+
<YourApp />
|
|
35
|
+
</CosmosProvider>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Use Hooks
|
|
41
|
+
|
|
42
|
+
```tsx
|
|
43
|
+
import { useAccount, useConnect, useClient } from 'cosmos-connect-react';
|
|
44
|
+
|
|
45
|
+
function WalletButton() {
|
|
46
|
+
const { address, isConnected } = useAccount();
|
|
47
|
+
const { connect } = useConnect();
|
|
48
|
+
const { client } = useClient();
|
|
49
|
+
|
|
50
|
+
if (isConnected) {
|
|
51
|
+
return <div>Connected: {address}</div>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<button onClick={() => connect(client.getWallets()[0])}>
|
|
56
|
+
Connect Wallet
|
|
57
|
+
</button>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Available Hooks
|
|
63
|
+
|
|
64
|
+
- `useAccount()` - Get current account address and connection status
|
|
65
|
+
- `useConnect()` - Connect/disconnect wallet functions
|
|
66
|
+
- `useClient()` - Access wallet client instance
|
|
67
|
+
- `useCosmos()` - Access full Cosmos context
|
|
68
|
+
|
|
69
|
+
## License
|
|
70
|
+
|
|
71
|
+
BSD-2-Clause
|
|
72
|
+
|
|
73
|
+
## Author
|
|
74
|
+
|
|
75
|
+
[@0xzahh](https://github.com/0xzahh)
|
package/dist/hooks.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
export declare const useAccount: () => {
|
|
2
|
-
address:
|
|
3
|
-
status:
|
|
2
|
+
address: string | undefined;
|
|
3
|
+
status: import("cosmos-connect-core").ClientStatus;
|
|
4
4
|
isConnected: boolean;
|
|
5
5
|
isConnecting: boolean;
|
|
6
6
|
isDisconnected: boolean;
|
|
7
|
-
account:
|
|
7
|
+
account: import("cosmos-connect-core").Account | null;
|
|
8
8
|
};
|
|
9
9
|
export declare const useConnect: () => {
|
|
10
|
-
connect: (walletId: string, chainId: string) => Promise<
|
|
10
|
+
connect: (walletId: string, chainId: string) => Promise<void>;
|
|
11
11
|
};
|
|
12
12
|
export declare const useDisconnect: () => {
|
|
13
|
-
disconnect: () => Promise<
|
|
13
|
+
disconnect: () => Promise<void>;
|
|
14
14
|
};
|
|
15
|
-
export declare const useClient: () => Client;
|
|
15
|
+
export declare const useClient: () => import("cosmos-connect-core").Client;
|
|
16
16
|
export declare const useBalance: () => {
|
|
17
17
|
balance: {
|
|
18
18
|
amount: string;
|
package/dist/styles.css
ADDED
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
/* Official ConnectKit Tokens Refined */
|
|
3
|
+
--ck-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
|
4
|
+
--ck-border-radius: 20px;
|
|
5
|
+
--ck-secondary-button-border-radius: 16px;
|
|
6
|
+
|
|
7
|
+
--ck-body-background: #ffffff;
|
|
8
|
+
--ck-body-color: #373737;
|
|
9
|
+
--ck-body-color-muted: #999999;
|
|
10
|
+
--ck-body-background-secondary: #f6f7f9;
|
|
11
|
+
--ck-body-background-tertiary: #F3F4F7;
|
|
12
|
+
--ck-body-divider: #f7f6f8;
|
|
13
|
+
|
|
14
|
+
--ck-accent-color: #3b82f6;
|
|
15
|
+
--ck-overlay-background: rgba(71, 88, 107, 0.24);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
[data-theme='dark'] {
|
|
19
|
+
--ck-body-background: #2B2B2B;
|
|
20
|
+
--ck-body-color: #ffffff;
|
|
21
|
+
--ck-body-color-muted: rgba(255, 255, 255, 0.4);
|
|
22
|
+
--ck-body-background-secondary: #333333;
|
|
23
|
+
--ck-body-background-tertiary: #333333;
|
|
24
|
+
--ck-body-divider: #383838;
|
|
25
|
+
--ck-overlay-background: rgba(0,0,0,0.4);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.cc-modal-overlay {
|
|
29
|
+
position: fixed;
|
|
30
|
+
top: 0;
|
|
31
|
+
left: 0;
|
|
32
|
+
right: 0;
|
|
33
|
+
bottom: 0;
|
|
34
|
+
background: var(--ck-overlay-background);
|
|
35
|
+
display: flex;
|
|
36
|
+
align-items: center;
|
|
37
|
+
justify-content: center;
|
|
38
|
+
z-index: 1000;
|
|
39
|
+
backdrop-filter: blur(10px);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.cc-modal-content {
|
|
43
|
+
background: var(--ck-body-background);
|
|
44
|
+
color: var(--ck-body-color);
|
|
45
|
+
width: 100%;
|
|
46
|
+
max-width: 400px;
|
|
47
|
+
border-radius: var(--ck-border-radius);
|
|
48
|
+
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.02), 0 20px 25px -5px rgba(0, 0, 0, 0.08);
|
|
49
|
+
padding: 1.5rem;
|
|
50
|
+
position: relative;
|
|
51
|
+
font-family: var(--ck-font-family);
|
|
52
|
+
overflow: hidden;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.cc-modal-header {
|
|
56
|
+
display: flex;
|
|
57
|
+
align-items: center;
|
|
58
|
+
justify-content: space-between;
|
|
59
|
+
margin-bottom: 1.5rem;
|
|
60
|
+
min-height: 32px;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.cc-help-btn, .cc-back-btn {
|
|
64
|
+
background: none;
|
|
65
|
+
border: 1px solid var(--ck-body-divider);
|
|
66
|
+
color: var(--ck-body-color-muted);
|
|
67
|
+
width: 28px;
|
|
68
|
+
height: 28px;
|
|
69
|
+
border-radius: 50%;
|
|
70
|
+
cursor: pointer;
|
|
71
|
+
display: flex;
|
|
72
|
+
align-items: center;
|
|
73
|
+
justify-content: center;
|
|
74
|
+
font-size: 0.875rem;
|
|
75
|
+
transition: all 0.2s;
|
|
76
|
+
z-index: 1;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.cc-help-btn:hover, .cc-back-btn:hover {
|
|
80
|
+
background: var(--ck-body-background-secondary);
|
|
81
|
+
color: var(--ck-body-color);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.cc-modal-title {
|
|
85
|
+
position: absolute;
|
|
86
|
+
left: 50%;
|
|
87
|
+
transform: translateX(-50%);
|
|
88
|
+
font-size: 1rem;
|
|
89
|
+
font-weight: 700;
|
|
90
|
+
letter-spacing: -0.01em;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.cc-close-btn {
|
|
94
|
+
background: var(--ck-body-background-secondary);
|
|
95
|
+
border: none;
|
|
96
|
+
color: var(--ck-body-color-muted);
|
|
97
|
+
width: 32px;
|
|
98
|
+
height: 32px;
|
|
99
|
+
border-radius: 50%;
|
|
100
|
+
cursor: pointer;
|
|
101
|
+
display: flex;
|
|
102
|
+
align-items: center;
|
|
103
|
+
justify-content: center;
|
|
104
|
+
font-size: 1.25rem;
|
|
105
|
+
transition: all 0.2s;
|
|
106
|
+
z-index: 1;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/* Page Containers */
|
|
110
|
+
.cc-modal-body {
|
|
111
|
+
position: relative;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/* Wallet List */
|
|
115
|
+
.cc-wallet-list {
|
|
116
|
+
display: flex;
|
|
117
|
+
flex-direction: column;
|
|
118
|
+
gap: 0.5rem;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.cc-wallet-item {
|
|
122
|
+
display: flex;
|
|
123
|
+
align-items: center;
|
|
124
|
+
justify-content: space-between;
|
|
125
|
+
padding: 0.875rem 1.25rem;
|
|
126
|
+
background: var(--ck-body-background-secondary);
|
|
127
|
+
border: none;
|
|
128
|
+
border-radius: var(--ck-secondary-button-border-radius);
|
|
129
|
+
cursor: pointer;
|
|
130
|
+
width: 100%;
|
|
131
|
+
transition: all 0.2s ease;
|
|
132
|
+
color: var(--ck-body-color);
|
|
133
|
+
font-weight: 600;
|
|
134
|
+
font-size: 1rem;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.cc-wallet-item:hover {
|
|
138
|
+
background: var(--ck-body-background-tertiary);
|
|
139
|
+
transform: scale(1.01);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.cc-wallet-icon {
|
|
143
|
+
width: 32px;
|
|
144
|
+
height: 32px;
|
|
145
|
+
border-radius: 8px;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/* About View */
|
|
149
|
+
.cc-about-steps {
|
|
150
|
+
display: flex;
|
|
151
|
+
flex-direction: column;
|
|
152
|
+
gap: 1.25rem;
|
|
153
|
+
margin-bottom: 2rem;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.cc-about-step {
|
|
157
|
+
display: flex;
|
|
158
|
+
gap: 1rem;
|
|
159
|
+
align-items: flex-start;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
.cc-step-num {
|
|
163
|
+
background: var(--ck-body-background-secondary);
|
|
164
|
+
color: var(--ck-body-color);
|
|
165
|
+
width: 24px;
|
|
166
|
+
height: 24px;
|
|
167
|
+
border-radius: 6px;
|
|
168
|
+
display: flex;
|
|
169
|
+
align-items: center;
|
|
170
|
+
justify-content: center;
|
|
171
|
+
font-size: 0.75rem;
|
|
172
|
+
font-weight: 800;
|
|
173
|
+
flex-shrink: 0;
|
|
174
|
+
margin-top: 2px;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
.cc-step-content h4 {
|
|
178
|
+
margin: 0 0 0.25rem 0;
|
|
179
|
+
font-size: 0.9375rem;
|
|
180
|
+
font-weight: 700;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
.cc-step-content p {
|
|
184
|
+
margin: 0;
|
|
185
|
+
font-size: 0.8125rem;
|
|
186
|
+
color: var(--ck-body-color-muted);
|
|
187
|
+
line-height: 1.4;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/* Profile View */
|
|
191
|
+
.cc-profile-view {
|
|
192
|
+
display: flex;
|
|
193
|
+
flex-direction: column;
|
|
194
|
+
align-items: center;
|
|
195
|
+
text-align: center;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
.cc-profile-avatar {
|
|
199
|
+
margin-bottom: 1.5rem;
|
|
200
|
+
box-shadow: 0 0 0 8px rgba(59, 130, 246, 0.05);
|
|
201
|
+
border-radius: 50%;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
.cc-profile-address {
|
|
205
|
+
font-size: 1.25rem;
|
|
206
|
+
font-weight: 800;
|
|
207
|
+
letter-spacing: -0.02em;
|
|
208
|
+
margin-bottom: 0.25rem;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
.cc-profile-balance {
|
|
212
|
+
font-size: 1rem;
|
|
213
|
+
font-weight: 600;
|
|
214
|
+
color: var(--ck-body-color-muted);
|
|
215
|
+
margin-bottom: 2rem;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
.cc-profile-actions {
|
|
219
|
+
display: grid;
|
|
220
|
+
grid-template-columns: 1fr 1fr;
|
|
221
|
+
gap: 0.75rem;
|
|
222
|
+
width: 100%;
|
|
223
|
+
margin-bottom: 1.5rem;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
.cc-util-btn {
|
|
227
|
+
padding: 0.75rem;
|
|
228
|
+
background: var(--ck-body-background-secondary);
|
|
229
|
+
border: none;
|
|
230
|
+
border-radius: 12px;
|
|
231
|
+
font-weight: 600;
|
|
232
|
+
font-size: 0.875rem;
|
|
233
|
+
color: var(--ck-body-color);
|
|
234
|
+
cursor: pointer;
|
|
235
|
+
transition: all 0.2s;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
.cc-util-btn:hover {
|
|
239
|
+
background: var(--ck-body-background-tertiary);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/* General Utilities */
|
|
243
|
+
.cc-primary-btn {
|
|
244
|
+
background: var(--ck-accent-color);
|
|
245
|
+
color: white;
|
|
246
|
+
width: 100%;
|
|
247
|
+
padding: 0.875rem;
|
|
248
|
+
border-radius: var(--ck-secondary-button-border-radius);
|
|
249
|
+
border: none;
|
|
250
|
+
font-weight: 700;
|
|
251
|
+
font-size: 0.9375rem;
|
|
252
|
+
cursor: pointer;
|
|
253
|
+
transition: all 0.2s;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
.cc-primary-btn:hover {
|
|
257
|
+
filter: brightness(1.1);
|
|
258
|
+
transform: translateY(-1px);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
.cc-footer-btn {
|
|
262
|
+
margin-top: 1.5rem;
|
|
263
|
+
padding-top: 1.5rem;
|
|
264
|
+
border-top: 1px solid var(--ck-body-divider);
|
|
265
|
+
background: none;
|
|
266
|
+
border: none;
|
|
267
|
+
width: 100%;
|
|
268
|
+
display: flex;
|
|
269
|
+
align-items: center;
|
|
270
|
+
justify-content: center;
|
|
271
|
+
gap: 0.5rem;
|
|
272
|
+
color: var(--ck-body-color-muted);
|
|
273
|
+
font-size: 0.875rem;
|
|
274
|
+
font-weight: 500;
|
|
275
|
+
cursor: pointer;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
.cc-footer-btn:hover {
|
|
279
|
+
color: var(--ck-body-color);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/* Spinner */
|
|
283
|
+
.cc-spinner-container {
|
|
284
|
+
position: relative;
|
|
285
|
+
width: 80px;
|
|
286
|
+
height: 80px;
|
|
287
|
+
margin: 0 auto 2rem auto;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
.cc-spinner {
|
|
291
|
+
width: 100%;
|
|
292
|
+
height: 100%;
|
|
293
|
+
border: 4px solid var(--ck-body-background-secondary);
|
|
294
|
+
border-top-color: var(--ck-accent-color);
|
|
295
|
+
border-radius: 50%;
|
|
296
|
+
animation: cc-spin 1s linear infinite;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
.cc-spinner-icon {
|
|
300
|
+
position: absolute;
|
|
301
|
+
top: 50%;
|
|
302
|
+
left: 50%;
|
|
303
|
+
transform: translate(-50%, -50%);
|
|
304
|
+
width: 40px;
|
|
305
|
+
height: 40px;
|
|
306
|
+
border-radius: 10px;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
@keyframes cc-spin { to { transform: rotate(360deg); } }
|
|
310
|
+
|
|
311
|
+
/* Pill */
|
|
312
|
+
.cc-pill {
|
|
313
|
+
display: inline-flex;
|
|
314
|
+
align-items: center;
|
|
315
|
+
gap: 0.75rem;
|
|
316
|
+
padding: 4px 12px 4px 4px;
|
|
317
|
+
background: var(--ck-body-background);
|
|
318
|
+
border: 1px solid var(--ck-body-divider);
|
|
319
|
+
border-radius: 99px;
|
|
320
|
+
cursor: pointer;
|
|
321
|
+
font-weight: 600;
|
|
322
|
+
color: var(--ck-body-color);
|
|
323
|
+
transition: all 0.2s;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
.cc-pill:hover {
|
|
327
|
+
border-color: var(--ck-accent-color);
|
|
328
|
+
box-shadow: 0 4px 12px rgba(0,0,0,0.05);
|
|
329
|
+
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cosmos-connect-react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"build": "tsc"
|
|
8
|
+
"build": "tsc && cp src/styles.css dist/"
|
|
9
9
|
},
|
|
10
10
|
"peerDependencies": {
|
|
11
11
|
"cosmos-connect-core": "*",
|