@txnlab/use-wallet 2.0.0-alpha.5 → 2.0.0

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.
Files changed (74) hide show
  1. package/README.md +35 -29
  2. package/dist/cjs/index.js +597 -269
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/jest.config.d.ts +1 -1
  5. package/dist/cjs/src/clients/algosigner/client.d.ts +4 -3
  6. package/dist/cjs/src/clients/algosigner/types.d.ts +12 -12
  7. package/dist/cjs/src/clients/base/base.d.ts +4 -3
  8. package/dist/cjs/src/clients/daffi/client.d.ts +6 -4
  9. package/dist/cjs/src/clients/daffi/types.d.ts +7 -10
  10. package/dist/cjs/src/clients/defly/client.d.ts +6 -5
  11. package/dist/cjs/src/clients/defly/types.d.ts +8 -11
  12. package/dist/cjs/src/clients/exodus/client.d.ts +4 -3
  13. package/dist/cjs/src/clients/exodus/types.d.ts +10 -12
  14. package/dist/cjs/src/clients/kmd/client.d.ts +5 -3
  15. package/dist/cjs/src/clients/kmd/types.d.ts +8 -10
  16. package/dist/cjs/src/clients/mnemonic/client.d.ts +5 -3
  17. package/dist/cjs/src/clients/mnemonic/types.d.ts +7 -7
  18. package/dist/cjs/src/clients/myalgo/client.d.ts +4 -7
  19. package/dist/cjs/src/clients/myalgo/types.d.ts +7 -10
  20. package/dist/cjs/src/clients/pera/client.d.ts +6 -4
  21. package/dist/cjs/src/clients/pera/types.d.ts +7 -10
  22. package/dist/cjs/src/clients/walletconnect2/client.d.ts +7 -5
  23. package/dist/cjs/src/clients/walletconnect2/constants.d.ts +0 -1
  24. package/dist/cjs/src/clients/walletconnect2/types.d.ts +8 -11
  25. package/dist/cjs/src/constants/constants.d.ts +1 -1
  26. package/dist/cjs/src/hooks/useInitializeProviders.d.ts +1 -1
  27. package/dist/cjs/src/index.d.ts +1 -1
  28. package/dist/cjs/src/store/state/debugStore.d.ts +1 -1
  29. package/dist/cjs/src/store/state/walletStore.d.ts +3 -3
  30. package/dist/cjs/src/testUtils/mockClients.d.ts +1 -1
  31. package/dist/cjs/src/types/api.d.ts +3 -3
  32. package/dist/cjs/src/types/node.d.ts +8 -8
  33. package/dist/cjs/src/types/providers.d.ts +27 -15
  34. package/dist/cjs/src/types/utilities.d.ts +1 -1
  35. package/dist/cjs/src/types/wallet.d.ts +9 -12
  36. package/dist/cjs/src/utils/encodeNFDTransactionsArray.d.ts +1 -1
  37. package/dist/cjs/src/utils/reconnectProviders.d.ts +1 -1
  38. package/dist/esm/index.js +597 -269
  39. package/dist/esm/jest.config.d.ts +1 -1
  40. package/dist/esm/src/clients/algosigner/client.d.ts +4 -3
  41. package/dist/esm/src/clients/algosigner/types.d.ts +12 -12
  42. package/dist/esm/src/clients/base/base.d.ts +4 -3
  43. package/dist/esm/src/clients/daffi/client.d.ts +6 -4
  44. package/dist/esm/src/clients/daffi/types.d.ts +7 -10
  45. package/dist/esm/src/clients/defly/client.d.ts +6 -5
  46. package/dist/esm/src/clients/defly/types.d.ts +8 -11
  47. package/dist/esm/src/clients/exodus/client.d.ts +4 -3
  48. package/dist/esm/src/clients/exodus/types.d.ts +10 -12
  49. package/dist/esm/src/clients/kmd/client.d.ts +5 -3
  50. package/dist/esm/src/clients/kmd/types.d.ts +8 -10
  51. package/dist/esm/src/clients/mnemonic/client.d.ts +5 -3
  52. package/dist/esm/src/clients/mnemonic/types.d.ts +7 -7
  53. package/dist/esm/src/clients/myalgo/client.d.ts +4 -7
  54. package/dist/esm/src/clients/myalgo/types.d.ts +7 -10
  55. package/dist/esm/src/clients/pera/client.d.ts +6 -4
  56. package/dist/esm/src/clients/pera/types.d.ts +7 -10
  57. package/dist/esm/src/clients/walletconnect2/client.d.ts +7 -5
  58. package/dist/esm/src/clients/walletconnect2/constants.d.ts +0 -1
  59. package/dist/esm/src/clients/walletconnect2/types.d.ts +8 -11
  60. package/dist/esm/src/constants/constants.d.ts +1 -1
  61. package/dist/esm/src/hooks/useInitializeProviders.d.ts +1 -1
  62. package/dist/esm/src/index.d.ts +1 -1
  63. package/dist/esm/src/store/state/debugStore.d.ts +1 -1
  64. package/dist/esm/src/store/state/walletStore.d.ts +3 -3
  65. package/dist/esm/src/testUtils/mockClients.d.ts +1 -1
  66. package/dist/esm/src/types/api.d.ts +3 -3
  67. package/dist/esm/src/types/node.d.ts +8 -8
  68. package/dist/esm/src/types/providers.d.ts +27 -15
  69. package/dist/esm/src/types/utilities.d.ts +1 -1
  70. package/dist/esm/src/types/wallet.d.ts +9 -12
  71. package/dist/esm/src/utils/encodeNFDTransactionsArray.d.ts +1 -1
  72. package/dist/esm/src/utils/reconnectProviders.d.ts +1 -1
  73. package/dist/index.d.ts +180 -200
  74. package/package.json +16 -20
package/README.md CHANGED
@@ -1,10 +1,15 @@
1
- # @txnlab/use-wallet
1
+ ![](use-wallet-banner.png)
2
+
3
+ # UseWallet v2
2
4
 
3
5
  `@txnlab/use-wallet` is a React library that provides a simplified, consistent interface for integrating multiple Algorand wallets into your decentralized applications (dApps).
4
6
 
7
+ [![npm version](https://badge.fury.io/js/%40txnlab%2Fuse-wallet.svg)](https://badge.fury.io/js/%40txnlab%2Fuse-wallet)
8
+ ![License](https://img.shields.io/github/license/TxnLab/use-wallet)
9
+
5
10
  ## Overview
6
11
 
7
- With the `use-wallet`'s hooks and utility functions, you can:
12
+ With UseWallet's hooks and utility functions, you can:
8
13
 
9
14
  - Easily add or remove wallet support with a few lines of code
10
15
  - Configure each wallet provider as needed for your application
@@ -14,7 +19,7 @@ With the `use-wallet`'s hooks and utility functions, you can:
14
19
 
15
20
  It provides an abstraction layer that unifies the initialization, connection, and transaction signing logic, eliminating the need to interact with each wallet's individual API.
16
21
 
17
- This library supports most Algorand wallet providers, including Defly, Pera, Daffi, and Exodus (see [Supported Wallet Providers](#supported-wallet-providers) for the full list).
22
+ UseWallet supports most Algorand wallet providers, including Defly, Pera, Daffi, and Exodus (see [Supported Wallet Providers](#supported-wallet-providers) for the full list).
18
23
 
19
24
  Version 2.x introduces [WalletConnect 2.0 support](#walletconnect-20-support).
20
25
 
@@ -84,7 +89,7 @@ npm install @blockshake/defly-connect @perawallet/connect @daffiwallet/connect
84
89
 
85
90
  In the root of your app, initialize the `WalletProvider` with the `useInitializeProviders` hook.
86
91
 
87
- This example initializes `useWallet` with Defly, Pera, Daffi and Exodus wallet providers. The default node configuration (mainnet via [AlgoNode](https://algonode.io/api/)) is used. See [Provider Configuration](#provider-configuration) for more options.
92
+ This example initializes Defly, Pera, Daffi and Exodus wallet providers. The default node configuration (mainnet via [AlgoNode](https://algonode.io/api/)) is used. See [Provider Configuration](#provider-configuration) for more options.
88
93
 
89
94
  ```jsx
90
95
  import React from 'react'
@@ -363,7 +368,7 @@ The promise will resolve to an object containing the transaction `id` and the [`
363
368
 
364
369
  ## Checking Connection Status
365
370
 
366
- The `isActive` and `isReady` properties can be used to check the status of the wallet providers. The `isActive` property determines whether or not an account is currently active. The `isReady` property indicates whether `use-wallet` has mounted and successfully read the connection status from the providers.
371
+ The `isActive` and `isReady` properties can be used to check the status of the wallet providers. The `isActive` property determines whether or not an account is currently active. The `isReady` property indicates whether client has mounted and successfully read the connection status from the wallet providers.
367
372
 
368
373
  These properties are useful when setting up client side access restrictions, for example, by redirecting a user if no wallet provider `isActive`, as shown below.
369
374
 
@@ -411,7 +416,7 @@ useEffect(() => {
411
416
  - Documentation - https://docs.walletconnect.com/
412
417
  - WalletConnect Cloud - https://cloud.walletconnect.com/
413
418
  - Web3Modal - https://web3modal.com/
414
- - Install dependency - `npm install @web3modal/sign-html`
419
+ - Install dependency - `npm install @walletconnect/modal-sign-html`
415
420
 
416
421
  ### Exodus Wallet
417
422
 
@@ -441,15 +446,15 @@ Support for these wallets will be removed in a future release.
441
446
 
442
447
  The `useInitializeProviders` hook accepts a configuration object with the following properties:
443
448
 
444
- | Key | Type | Default Value |
445
- | ---------------------- | ------------------------------------- | -------------------------------------- |
446
- | providers | `Array<ProviderDef>` | _required_ |
447
- | nodeConfig.network | `string \| undefined` | `'mainnet'` |
448
- | nodeConfig.nodeServer | `string \| undefined` | `'https://mainnet-api.algonode.cloud'` |
449
- | nodeConfig.nodeToken | `string \| undefined` | `''` |
450
- | nodeConfig.nodePort | `string \| number \| undefined` | `443` |
451
- | nodeConfig.nodeHeaders | `Record<string, string> \| undefined` | |
452
- | algosdkStatic | `typeof algosdk \| undefined` | |
449
+ | Key | Type | Default Value |
450
+ | ---------------------- | -------------------------------------------------------------------------------------------------------- | -------------------------------------- |
451
+ | providers | `Array<ProviderDef>` | _required_ |
452
+ | nodeConfig.network | `string \| undefined` | `'mainnet'` |
453
+ | nodeConfig.nodeServer | `string \| undefined` | `'https://mainnet-api.algonode.cloud'` |
454
+ | nodeConfig.nodeToken | `string \| algosdk.AlgodTokenHeader \| algosdk.CustomTokenHeader \| algosdk.BaseHTTPClient \| undefined` | `''` |
455
+ | nodeConfig.nodePort | `string \| number \| undefined` | `443` |
456
+ | nodeConfig.nodeHeaders | `Record<string, string> \| undefined` | |
457
+ | algosdkStatic | `typeof algosdk \| undefined` | |
453
458
 
454
459
  ### Provider Definitions
455
460
 
@@ -500,7 +505,7 @@ const providers = await initializeProviders({
500
505
 
501
506
  ### Algosdk Static Import
502
507
 
503
- By default, `use-wallet` dynamically imports the `algosdk` peer dependency installed in your app, to reduce bundle size.
508
+ By default, the providers dynamically import the `algosdk` peer dependency installed in your app, to reduce bundle size.
504
509
 
505
510
  Some React frameworks, like [Remix](https://remix.run/), do not support dynamic imports. To get around this, you can set the optional `algosdkStatic` root property to the imported `algosdk` module.
506
511
 
@@ -533,7 +538,7 @@ import { PROVIDER_ID, WalletProvider, useInitializeProviders } from '@txnlab/use
533
538
  import { DeflyWalletConnect } from '@blockshake/defly-connect'
534
539
  import { PeraWalletConnect } from '@perawallet/connect'
535
540
  import { DaffiWalletConnect } from '@daffiwallet/connect'
536
- import { Web3ModalSign } from '@web3modal/sign-html'
541
+ import { WalletConnectModalSign } from '@walletconnect/modal-sign-html'
537
542
 
538
543
  export default function App() {
539
544
  const providers = useInitializeProviders({
@@ -543,7 +548,7 @@ export default function App() {
543
548
  { id: PROVIDER_ID.DAFFI, clientStatic: DaffiWalletConnect },
544
549
  {
545
550
  id: PROVIDER_ID.WALLETCONNECT,
546
- clientStatic: Web3ModalSign,
551
+ clientStatic: WalletConnectModalSign,
547
552
  clientOptions: {
548
553
  projectId: '<YOUR_PROJECT_ID>',
549
554
  metadata: {
@@ -553,7 +558,7 @@ export default function App() {
553
558
  icons: ['https://walletconnect.com/walletconnect-logo.png']
554
559
  },
555
560
  modalOptions: {
556
- theme: 'dark'
561
+ themeMode: 'dark'
557
562
  }
558
563
  }
559
564
  },
@@ -578,13 +583,13 @@ export default function App() {
578
583
 
579
584
  ## WalletConnect 2.0 Support
580
585
 
581
- `use-wallet` v2 introduces support for WalletConnect 2.0. This is a major upgrade to the WalletConnect protocol, and introduces a number of breaking changes for app developers.
586
+ UseWallet v2 introduces support for WalletConnect 2.0. This is a major upgrade to the WalletConnect protocol, and introduces a number of breaking changes for app developers.
582
587
 
583
- However, Algorand apps with `use-wallet` will be able to support the new protocol with minimal effort:
588
+ However, Algorand apps with UseWallet will be able to support the new protocol with minimal effort:
584
589
 
585
590
  1. **Obtain a project ID** - You will need to obtain a project ID from [WalletConnect Cloud](https://cloud.walletconnect.com/). This is a simple process, and there is no waiting period. Every app will need its own unique project ID.
586
591
 
587
- 2. **Install client library** - Install `@web3modal/sign-html` and set `clientStatic` to the imported `Web3ModalSign` module.
592
+ 2. **Install client library** - Install `@walletconnect/modal-sign-html` and set `clientStatic` to the imported `WalletConnectModalSign` module.
588
593
 
589
594
  3. **Required options** - Set the required `clientOptions` as shown below
590
595
 
@@ -593,7 +598,7 @@ const providers = useInitializeProviders({
593
598
  providers: [
594
599
  {
595
600
  id: PROVIDER_ID.WALLETCONNECT,
596
- clientStatic: Web3ModalSign,
601
+ clientStatic: WalletConnectModalSign,
597
602
  clientOptions: {
598
603
  projectId: '<YOUR_PROJECT_ID>',
599
604
  metadata: {
@@ -679,15 +684,16 @@ See [Provider Configuration](#provider-configuration) for more details.
679
684
 
680
685
  ### shouldShowSignTxnToast
681
686
 
682
- Pera Connect and Defly Connect both have a `shouldShowSignTxnToast` option that is set to `true` by default. `use-wallet` v1 set this to `false` by default, and required setting the option back to `true` to achieve the libraries' default behavior.
687
+ Pera Connect, Defly Connect and Daffi Connect share a `shouldShowSignTxnToast` option that is set to `true` by default. UseWallet v1 set these to `false` by default, and required setting the option back to `true` to achieve the libraries' default behavior.
683
688
 
684
- In v2 this option is set to `true` by default. If your app has this option explicitly set you can remove it from your configuration. If you wish to disable the toast(s), you must now explicitly set the option to `false`.
689
+ In v2 this option is set to `true` by default. If your app has this option set to `true` you can remove it from your configuration. If you wish to disable the toast(s), you must now explicitly set the option to `false`.
685
690
 
686
691
  ```jsx
687
692
  const providers = useInitializeProviders({
688
693
  providers: [
689
694
  { id: PROVIDER_ID.DEFLY, clientOptions: { shouldShowSignTxnToast: false } },
690
- { id: PROVIDER_ID.PERA, clientOptions: { shouldShowSignTxnToast: false } }
695
+ { id: PROVIDER_ID.PERA, clientOptions: { shouldShowSignTxnToast: false } },
696
+ { id: PROVIDER_ID.DAFFI, clientOptions: { shouldShowSignTxnToast: false } }
691
697
  // other providers...
692
698
  ]
693
699
  })
@@ -695,10 +701,10 @@ const providers = useInitializeProviders({
695
701
 
696
702
  ### WalletConnect peer dependencies
697
703
 
698
- The WalletConnect provider now supports WalletConnect 2.0. To continue supporting this provider, or to add support to your application, you must install the `@web3modal/sign-html` package.
704
+ The WalletConnect provider now supports WalletConnect 2.0. To continue supporting this provider, or to add support to your application, you must install the `@walletconnect/modal-sign-html` package.
699
705
 
700
706
  ```bash
701
- npm install @web3modal/sign-html
707
+ npm install @walletconnect/modal-sign-html
702
708
  ```
703
709
 
704
710
  The peer dependencies for WalletConnect 1.x should be uninstalled.
@@ -723,7 +729,7 @@ yarn install
723
729
  yarn dev
724
730
  ```
725
731
 
726
- To develop against a local version of `use-wallet` in your application, do the following:
732
+ To develop against a local version of `@txnlab/use-wallet` in your application, do the following:
727
733
 
728
734
  ### Build the library
729
735