@tonconnect/ui 0.0.7 → 0.0.9
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 +268 -2
- package/dist/tonconnect-ui.min.js +467 -0
- package/dist/tonconnect-ui.min.js.map +1 -0
- package/lib/index.d.ts +122 -43
- package/lib/index.js +767 -461
- package/lib/index.js.map +1 -1
- package/lib/index.umd.js +768 -462
- package/lib/index.umd.js.map +1 -1
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -16,6 +16,28 @@ You can find more details and the protocol specification in the [docs](https://g
|
|
|
16
16
|
|
|
17
17
|
# Getting started
|
|
18
18
|
|
|
19
|
+
## Installation with cdn
|
|
20
|
+
Add the script to your HTML file:
|
|
21
|
+
```html
|
|
22
|
+
<script src="https://unpkg.com/@tonconnect/ui@latest/dist/tonconnect-ui.min.js"></script>
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
ℹ️ If you don't want auto-update the library, pass concrete version instead of `latest`, e.g.
|
|
26
|
+
```html
|
|
27
|
+
<script src="https://unpkg.com/@tonconnect/ui@0.0.9/dist/tonconnect-ui.min.js"></script>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
You can find `TonConnectUI` in global variable `TON_CONNECT_UI`, e.g.
|
|
31
|
+
```html
|
|
32
|
+
<script>
|
|
33
|
+
const tonConnectUI = new TON_CONNECT_UI.TonConnectUI({
|
|
34
|
+
manifestUrl: 'https://<YOUR_APP_URL>/tonconnect-manifest.json',
|
|
35
|
+
buttonRootId: '<YOUR_CONNECT_BUTTON_ANCHOR_ID>'
|
|
36
|
+
});
|
|
37
|
+
</script>
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
|
|
19
41
|
## Installation with npm
|
|
20
42
|
`npm i @tonconnect/ui`
|
|
21
43
|
|
|
@@ -41,7 +63,9 @@ See all available options:
|
|
|
41
63
|
```ts
|
|
42
64
|
tonConnectUI.uiOptions = {
|
|
43
65
|
language: 'ru',
|
|
44
|
-
|
|
66
|
+
uiPreferences: {
|
|
67
|
+
theme: THEME.DARK
|
|
68
|
+
}
|
|
45
69
|
};
|
|
46
70
|
```
|
|
47
71
|
|
|
@@ -50,7 +74,7 @@ Passed options will be merged with current UI options. Note, that you have to pa
|
|
|
50
74
|
|
|
51
75
|
DON'T do this:
|
|
52
76
|
```ts
|
|
53
|
-
tonConnectUI.uiOptions.language = 'ru';
|
|
77
|
+
/* WRONG, WILL NOT WORK */ tonConnectUI.uiOptions.language = 'ru';
|
|
54
78
|
```
|
|
55
79
|
|
|
56
80
|
[See all available options](https://ton-connect.github.io/sdk/interfaces/_tonconnect_ui.TonConnectUiOptions.html)
|
|
@@ -168,3 +192,245 @@ const defaultBehaviour = {
|
|
|
168
192
|
notifications: ['before', 'success', 'error']
|
|
169
193
|
}
|
|
170
194
|
```
|
|
195
|
+
|
|
196
|
+
## UI customisation
|
|
197
|
+
TonConnect UI provides an interface that should be familiar and recognizable to the user when using various apps.
|
|
198
|
+
However, the app developer can make changes to this interface to keep it consistent with the app interface.
|
|
199
|
+
|
|
200
|
+
### Customise UI using tonconnectUI.uiOptions
|
|
201
|
+
All such updates are reactive -- change `tonconnectUI.uiOptions` and changes will be applied immediately.
|
|
202
|
+
|
|
203
|
+
[See all available options](https://ton-connect.github.io/sdk/interfaces/_tonconnect_ui.UIPreferences.html)
|
|
204
|
+
|
|
205
|
+
#### Change border radius
|
|
206
|
+
There are three border-radius modes: `'m'`, `'s'` and `'none'`. Default is `'m'`. You can change it via tonconnectUI.uiOptions, or set on tonConnectUI creating:
|
|
207
|
+
|
|
208
|
+
```ts
|
|
209
|
+
/* Pass to the constructor */
|
|
210
|
+
const tonConnectUI = new TonConnectUI({
|
|
211
|
+
manifestUrl: 'https://<YOUR_APP_URL>/tonconnect-manifest.json',
|
|
212
|
+
uiPreferences: {
|
|
213
|
+
borderRadius: 's'
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
/* Or update dynamically */
|
|
219
|
+
tonConnectUI.uiOptions = {
|
|
220
|
+
uiPreferences: {
|
|
221
|
+
borderRadius: 's'
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Note, that `uiOptions` is a setter which will merge new options with previous ones. So you doesn't need to merge it explicitly. Just pass changed options.
|
|
227
|
+
```ts
|
|
228
|
+
/* DON'T DO THIS. SEE DESCRIPTION ABOVE */
|
|
229
|
+
tonConnectUI.uiOptions = {
|
|
230
|
+
...previousUIOptions,
|
|
231
|
+
uiPreferences: {
|
|
232
|
+
borderRadius: 's'
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
/* Just pass changed property */
|
|
237
|
+
tonConnectUI.uiOptions = {
|
|
238
|
+
uiPreferences: {
|
|
239
|
+
borderRadius: 's'
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
#### Change theme
|
|
245
|
+
You can set fixed theme: `'THEME.LIGHT'` or `'THEME.DARK'`, or use system theme. Default theme is system.
|
|
246
|
+
|
|
247
|
+
```ts
|
|
248
|
+
import { THEME } from '@tonconnect/ui';
|
|
249
|
+
|
|
250
|
+
tonConnectUI.uiOptions = {
|
|
251
|
+
uiPreferences: {
|
|
252
|
+
theme: THEME.DARK
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
You also can set `'SYSTEM'` theme:
|
|
258
|
+
```ts
|
|
259
|
+
tonConnectUI.uiOptions = {
|
|
260
|
+
uiPreferences: {
|
|
261
|
+
theme: 'SYSTEM'
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
You can set theme in the constructor if needed:
|
|
267
|
+
```ts
|
|
268
|
+
import { THEME } from '@tonconnect/ui';
|
|
269
|
+
|
|
270
|
+
const tonConnectUI = new TonConnectUI({
|
|
271
|
+
manifestUrl: 'https://<YOUR_APP_URL>/tonconnect-manifest.json',
|
|
272
|
+
uiPreferences: {
|
|
273
|
+
theme: THEME.DARK
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
#### Change colors scheme
|
|
279
|
+
You can redefine all colors scheme for each theme or change some colors. Just pass colors that you want to change.
|
|
280
|
+
|
|
281
|
+
```ts
|
|
282
|
+
tonConnectUI.uiOptions = {
|
|
283
|
+
uiPreferences: {
|
|
284
|
+
colorsSet: {
|
|
285
|
+
[THEME.DARK]: {
|
|
286
|
+
connectButton: {
|
|
287
|
+
background: '#29CC6A'
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
You can change colors for both themes at the same time:
|
|
296
|
+
|
|
297
|
+
```ts
|
|
298
|
+
tonConnectUI.uiOptions = {
|
|
299
|
+
uiPreferences: {
|
|
300
|
+
colorsSet: {
|
|
301
|
+
[THEME.DARK]: {
|
|
302
|
+
connectButton: {
|
|
303
|
+
background: '#29CC6A'
|
|
304
|
+
}
|
|
305
|
+
},
|
|
306
|
+
[THEME.LIGHT]: {
|
|
307
|
+
text: {
|
|
308
|
+
primary: '#FF0000'
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
You can set colors scheme in the constructor if needed:
|
|
318
|
+
```ts
|
|
319
|
+
import { THEME } from '@tonconnect/ui';
|
|
320
|
+
|
|
321
|
+
const tonConnectUI = new TonConnectUI({
|
|
322
|
+
manifestUrl: 'https://<YOUR_APP_URL>/tonconnect-manifest.json',
|
|
323
|
+
uiPreferences: {
|
|
324
|
+
colorsSet: {
|
|
325
|
+
[THEME.DARK]: {
|
|
326
|
+
connectButton: {
|
|
327
|
+
background: '#29CC6A'
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
[See all available options](https://ton-connect.github.io/sdk/interfaces/_tonconnect_ui.PartialColorsSet.html)
|
|
336
|
+
|
|
337
|
+
#### Combine options
|
|
338
|
+
It is possible to change all required options at the same time:
|
|
339
|
+
|
|
340
|
+
```ts
|
|
341
|
+
tonConnectUI.uiOptions = {
|
|
342
|
+
uiPreferences: {
|
|
343
|
+
theme: THEME.DARK,
|
|
344
|
+
borderRadius: 's',
|
|
345
|
+
colorsSet: {
|
|
346
|
+
[THEME.DARK]: {
|
|
347
|
+
connectButton: {
|
|
348
|
+
background: '#29CC6A'
|
|
349
|
+
}
|
|
350
|
+
},
|
|
351
|
+
[THEME.LIGHT]: {
|
|
352
|
+
text: {
|
|
353
|
+
primary: '#FF0000'
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
### Direct css customisation
|
|
363
|
+
It is not recommended to customise TonConnect UI elements via css as it may confuse the user when looking for known and familiar UI elements such as connect button/modals.
|
|
364
|
+
However, it is possible if needed. You can add css styles to the specified selectors of the UI element. See list of selectors in the table below:
|
|
365
|
+
|
|
366
|
+
| Element | Selector | Element description |
|
|
367
|
+
|--------------------------------------|----------------------------------|---------------------------------------------------------------------------------------------------|
|
|
368
|
+
| Connect wallet modal container | `#tc-wallets-modal-container` | Container of the modal window that opens when you click on the "connect wallet" button. |
|
|
369
|
+
| Select wallet modal content | `#tc-wallets-modal` | Content of the modal window with wallet selection. |
|
|
370
|
+
| QR-code modal content | `#tc-qr-modal` | Content of the modal window with QR-code. |
|
|
371
|
+
| Action modal container | `#tc-actions-modal-container` | Container of the modal window that opens when you call `sendTransaction` or other action. |
|
|
372
|
+
| Confirm action modal content | `#tc-confirm-modal` | Content of the modal window asking for confirmation of the action in the wallet. |
|
|
373
|
+
| "Transaction sent" modal content | `#tc-transaction-sent-modal` | Content of the modal window informing that the transaction was successfully sent. |
|
|
374
|
+
| "Transaction canceled" modal content | `#tc-transaction-canceled-modal` | Content of the modal window informing that the transaction was not sent. |
|
|
375
|
+
| "Connect Wallet" button | `#tc-connect-button` | "Connect Wallet" button element. |
|
|
376
|
+
| Wallet menu dropdown button | `#tc-dropdown-button` | Wallet menu button -- host of the dropdown wallet menu (copy address/disconnect). |
|
|
377
|
+
| Wallet menu dropdown container | `#tc-dropdown-container` | Container of the dropdown that opens when you click on the "wallet menu" button with ton address. |
|
|
378
|
+
| Wallet menu dropdown content | `#tc-dropdown` | Content of the dropdown that opens when you click on the "wallet menu" button with ton address. |
|
|
379
|
+
| Notifications container | `#tc-notifications` | Container of the actions notifications. |
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
## Customize the list of displayed wallets
|
|
383
|
+
You can customize the list of displayed wallets: change order, exclude wallets or add custom wallets.
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
### Redefine wallets list
|
|
387
|
+
Pass an array of the wallet's names and custom wallets. Array items order will be applied to the wallets in modal window.
|
|
388
|
+
|
|
389
|
+
You can define custom wallet with `jsBridgeKey` (wallet = browser extension or there is a wallet dapp browser) or with `bridgeUrl` and `universalLink` pair (for http-connection compatible wallets), or pass all of these properties.
|
|
390
|
+
```ts
|
|
391
|
+
import { UIWallet } from '@tonconnect/ui';
|
|
392
|
+
|
|
393
|
+
const customWallet: UIWallet = {
|
|
394
|
+
name: '<CUSTOM_WALLET_NAME>',
|
|
395
|
+
imageUrl: '<CUSTOM_WALLET_IMAGE_URL>',
|
|
396
|
+
aboutUrl: '<CUSTOM_WALLET_ABOUT_URL>',
|
|
397
|
+
jsBridgeKey: '<CUSTOM_WALLET_JS_BRIDGE_KEY>',
|
|
398
|
+
bridgeUrl: '<CUSTOM_WALLET_HTTP_BRIDGE_URL>',
|
|
399
|
+
universalLink: '<CUSTOM_WALLET_UNIVERSAL_LINK>'
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
tonConnectUI.uiOptions = {
|
|
403
|
+
walletsList: {
|
|
404
|
+
wallets: ['tonkeeper', 'openmask', customWallet]
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
### Modify default wallets list
|
|
410
|
+
Exclude some wallets with `excludeWallets` property.
|
|
411
|
+
Include custom wallets with `includeWallets` property.
|
|
412
|
+
Setup place where custom wallets will appear in the all wallets list with `includeWalletsOrder`. Default value id `'end''`.
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
```ts
|
|
416
|
+
import { UIWallet } from '@tonconnect/ui';
|
|
417
|
+
|
|
418
|
+
const customWallet: UIWallet = {
|
|
419
|
+
name: '<CUSTOM_WALLET_NAME>',
|
|
420
|
+
imageUrl: '<CUSTOM_WALLET_IMAGE_URL>',
|
|
421
|
+
aboutUrl: '<CUSTOM_WALLET_ABOUT_URL>',
|
|
422
|
+
jsBridgeKey: '<CUSTOM_WALLET_JS_BRIDGE_KEY>',
|
|
423
|
+
bridgeUrl: '<CUSTOM_WALLET_HTTP_BRIDGE_URL>',
|
|
424
|
+
universalLink: '<CUSTOM_WALLET_UNIVERSAL_LINK>'
|
|
425
|
+
};
|
|
426
|
+
|
|
427
|
+
tonConnectUI.uiOptions = {
|
|
428
|
+
walletsList: {
|
|
429
|
+
excludeWallets: ['openmask'],
|
|
430
|
+
includeWallets: [customWallet],
|
|
431
|
+
includeWalletsOrder: 'start'
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
[See all available options](https://ton-connect.github.io/sdk/types/_tonconnect_ui.WalletsListConfiguration.html)
|