@txnlab/use-wallet 2.0.0 → 2.1.1

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
@@ -4,7 +4,7 @@
4
4
 
5
5
  `@txnlab/use-wallet` is a React library that provides a simplified, consistent interface for integrating multiple Algorand wallets into your decentralized applications (dApps).
6
6
 
7
- [![npm version](https://badge.fury.io/js/%40txnlab%2Fuse-wallet.svg)](https://badge.fury.io/js/%40txnlab%2Fuse-wallet)
7
+ [![npm version](https://badge.fury.io/js/@txnlab%2Fuse-wallet.svg)](https://badge.fury.io/js/@txnlab%2Fuse-wallet)
8
8
  ![License](https://img.shields.io/github/license/TxnLab/use-wallet)
9
9
 
10
10
  ## Overview
@@ -43,8 +43,11 @@ Version 2.x introduces [WalletConnect 2.0 support](#walletconnect-20-support).
43
43
  - [Algosdk Static Import](#algosdk-static-import)
44
44
  - [Full Configuration Example](#full-configuration-example)
45
45
  - [WalletConnect 2.0 Support](#walletconnect-20-support)
46
+ - [Defly Wallet (iOS) beta](#defly-wallet-ios-beta)
47
+ - [Pera Wallet (Android) beta](#pera-wallet-android-beta)
46
48
  - [Migration Guide](#migration-guide)
47
49
  - [Local Development](#local-development)
50
+ - [Support](#support)
48
51
  - [Used By](#used-by)
49
52
  - [License](#license)
50
53
 
@@ -91,6 +94,18 @@ In the root of your app, initialize the `WalletProvider` with the `useInitialize
91
94
 
92
95
  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.
93
96
 
97
+ You can initialize your providers in two ways:
98
+
99
+ 1. **Static Import** - This is the standard way of importing modules in JavaScript. In this method, the import statement is at the top of the file and the modules are imported when the file loads. This is done by passing the clientStatic property.
100
+
101
+ 2. **Dynamic Import** - With the dynamic import() syntax, you can load modules on demand by calling a function. This can greatly reduce the initial load time of your app by only loading modules when they are needed. This is done by passing the getDynamicClient property which must be a function that returns a promise that resolves to the client.
102
+
103
+ Note: For each provider, either clientStatic or getDynamicClient must be passed, not both.
104
+
105
+ Here is an example of both:
106
+
107
+ ### Static Import Example
108
+
94
109
  ```jsx
95
110
  import React from 'react'
96
111
  import { WalletProvider, useInitializeProviders, PROVIDER_ID } from '@txnlab/use-wallet'
@@ -99,15 +114,53 @@ import { PeraWalletConnect } from '@perawallet/connect'
99
114
  import { DaffiWalletConnect } from '@daffiwallet/connect'
100
115
 
101
116
  export default function App() {
102
- const providers = useInitializeProviders([
103
- {
104
- providers: [
105
- { id: PROVIDER_ID.DEFLY, clientStatic: DeflyWalletConnect },
106
- { id: PROVIDER_ID.PERA, clientStatic: PeraWalletConnect },
107
- { id: PROVIDER_ID.DAFFI, clientStatic: DaffiWalletConnect }
108
- ]
109
- }
110
- ])
117
+ const providers = useInitializeProviders({
118
+ providers: [
119
+ { id: PROVIDER_ID.DEFLY, clientStatic: DeflyWalletConnect },
120
+ { id: PROVIDER_ID.PERA, clientStatic: PeraWalletConnect },
121
+ { id: PROVIDER_ID.DAFFI, clientStatic: DaffiWalletConnect },
122
+ { id: PROVIDER_ID.EXODUS }
123
+ ]
124
+ })
125
+
126
+ return (
127
+ <WalletProvider value={providers}>
128
+ <div className="App">{/* ... */}</div>
129
+ </WalletProvider>
130
+ )
131
+ }
132
+ ```
133
+
134
+ ### Dynamic Import Example
135
+
136
+ ```jsx
137
+ import React from 'react'
138
+ import { WalletProvider, useInitializeProviders, PROVIDER_ID } from '@txnlab/use-wallet'
139
+
140
+ const getDynamicDeflyWalletConnect = async () => {
141
+ const DeflyWalletConnect = (await import("@blockshake/defly-connect")).DeflyWalletConnect;
142
+ return DeflyWalletConnect;
143
+ };
144
+
145
+ const getDynamicPeraWalletConnect = async () => {
146
+ const PeraWalletConnect = (await import("@perawallet/connect")).PeraWalletConnect;
147
+ return PeraWalletConnect;
148
+ };
149
+
150
+ const getDynamicDaffiWalletConnect = async () => {
151
+ const DaffiWalletConnect = (await import("@daffiwallet/connect")).DaffiWalletConnect;
152
+ return DaffiWalletConnect;
153
+ };
154
+
155
+ export default function App() {
156
+ const providers = useInitializeProviders({
157
+ providers: [
158
+ { id: PROVIDER_ID.DEFLY, getDynamicClient: getDynamicDeflyWalletConnect },
159
+ { id: PROVIDER_ID.PERA, getDynamicClient: getDynamicPeraWalletConnect },
160
+ { id: PROVIDER_ID.DAFFI, getDynamicClient: getDynamicDaffiWalletConnect },
161
+ { id: PROVIDER_ID.EXODUS }
162
+ ]
163
+ })
111
164
 
112
165
  return (
113
166
  <WalletProvider value={providers}>
@@ -117,6 +170,7 @@ export default function App() {
117
170
  }
118
171
  ```
119
172
 
173
+
120
174
  ## The `useWallet` Hook
121
175
 
122
176
  The `useWallet` hook is used to access wallet provider and account state, send unsigned transactions to be signed, and send signed transactions to the node from anywhere in your app. It returns an object with the following properties:
@@ -493,7 +547,8 @@ To configure the Algorand node that providers will use to send transactions, you
493
547
  \* _Refer to each wallet providers' documentation to see which networks they support._
494
548
 
495
549
  ```jsx
496
- const providers = await initializeProviders({
550
+ const providers = useInitializeProviders({
551
+ providers: [...],
497
552
  nodeConfig: {
498
553
  network: 'testnet',
499
554
  nodeServer: 'https://testnet-api.algonode.cloud',
@@ -614,7 +669,17 @@ const providers = useInitializeProviders({
614
669
  })
615
670
  ```
616
671
 
617
- **IMPORTANT:** Only wallets that have been upgraded to support WalletConnect 2.0 will be able to connect to your app with this provider.
672
+ While `projectId` and `metadata` are required, you can also set optional `modalOptions` to customize the appearance of the WalletConnect modal. See the [WalletConnect docs](https://docs.walletconnect.com/2.0/web/walletConnectModal/sign/html/options) for more details.
673
+
674
+ **IMPORTANT:** Wallets must migrate to WalletConnect v2 or they will NOT work with this provider. **The latest versions of Pera Wallet, Defly Wallet, and Daffi Wallet still support WalletConnect v1 ONLY.** Beta versions of these wallets with WalletConnect v2 support are available now:
675
+
676
+ ### Defly Wallet (iOS) beta
677
+
678
+ iOS users can join the [Defly Wallet (iOS) beta program](https://testflight.apple.com/join/S66wwJpq) for testing WalletConnect v2 support. Android beta coming soon.
679
+
680
+ ### Pera Wallet (Android) beta
681
+
682
+ Android users can join the [Pera Wallet (Android) beta program](https://forms.gle/m5TJueyJD9f74ieL8) for testing WalletConnect v2 support. Fill out the form and wait for an email with instructions. Form submissions will be checked periodically and added in bulk.
618
683
 
619
684
  ### "Module not found" errors in Next.js 13
620
685
 
@@ -768,12 +833,25 @@ In the root of the `use-wallet` directory, run:
768
833
  yarn link react react-dom
769
834
  ```
770
835
 
836
+ ## Support
837
+
838
+ For questions or technical support, you can reach us in the #use-wallet channel on NFD's Discord: https://discord.gg/w6vSwG5bFK
839
+
840
+ To report bugs/issues or make a feature request here on GitHub:
841
+
842
+ - [Create an issue](https://github.com/TxnLab/use-wallet/issues/new)
843
+ - [Create a discussion](https://github.com/TxnLab/use-wallet/discussions/new/choose)
844
+
771
845
  ## Used By
772
846
 
773
- Are you using `@txnlab/use-wallet`? We'd love to include your project here. Let us know! [Twitter](https://twitter.com/NFDomains) | [Discord](https://discord.gg/7XcuMTfeZP) | [Email](mailto:admin@txnlab.dev)
847
+ Are you using `@txnlab/use-wallet`? We'd love to include your project here. Let us know! [Twitter](https://twitter.com/NFDomains) | [Discord](https://discord.gg/w6vSwG5bFK) | [Email](mailto:admin@txnlab.dev)
774
848
 
775
849
  - [@algoscan/use-wallet-ui](https://github.com/algoscan/use-wallet-ui)
776
850
  - [@algoworldnft/algoworld-swapper](https://github.com/algoworldnft/algoworld-swapper)
851
+ - [Algogator](https://algogator.finance/)
852
+ - [Notiboy](https://notiboy.com/)
853
+ - [Rand Drops](https://drops.randgallery.com/drops)
854
+ - [Vestige](https://vestige.fi/)
777
855
 
778
856
  Full list of [Dependents](https://github.com/TxnLab/use-wallet/network/dependents)
779
857
 
package/dist/cjs/index.js CHANGED
@@ -198,7 +198,7 @@ const createStoreImpl = (createState) => {
198
198
  return () => listeners.delete(listener);
199
199
  };
200
200
  const destroy = () => {
201
- if ((undefined && undefined.MODE) !== "production") {
201
+ if ((undefined ? undefined.MODE : void 0) !== "production") {
202
202
  console.warn(
203
203
  "[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."
204
204
  );
@@ -730,7 +730,7 @@ function useStore(api, selector = api.getState, equalityFn) {
730
730
  return slice;
731
731
  }
732
732
  const createImpl = (createState) => {
733
- if ((undefined && undefined.MODE) !== "production" && typeof createState !== "function") {
733
+ if ((undefined ? undefined.MODE : void 0) !== "production" && typeof createState !== "function") {
734
734
  console.warn(
735
735
  "[DEPRECATED] Passing a vanilla store will be unsupported in a future version. Instead use `import { useStore } from 'zustand'`."
736
736
  );
@@ -773,11 +773,11 @@ const devtoolsImpl = (fn, devtoolsOptions = {}) => (set, get, api) => {
773
773
  const { enabled, anonymousActionType, store, ...options } = devtoolsOptions;
774
774
  let extensionConnector;
775
775
  try {
776
- extensionConnector = (enabled != null ? enabled : (undefined && undefined.MODE) !== "production") && window.__REDUX_DEVTOOLS_EXTENSION__;
776
+ extensionConnector = (enabled != null ? enabled : (undefined ? undefined.MODE : void 0) !== "production") && window.__REDUX_DEVTOOLS_EXTENSION__;
777
777
  } catch (e) {
778
778
  }
779
779
  if (!extensionConnector) {
780
- if ((undefined && undefined.MODE) !== "production" && enabled) {
780
+ if ((undefined ? undefined.MODE : void 0) !== "production" && enabled) {
781
781
  console.warn(
782
782
  "[zustand devtools middleware] Please install/enable Redux devtools extension"
783
783
  );
@@ -831,7 +831,7 @@ const devtoolsImpl = (fn, devtoolsOptions = {}) => (set, get, api) => {
831
831
  let didWarnAboutReservedActionType = false;
832
832
  const originalDispatch = api.dispatch;
833
833
  api.dispatch = (...a) => {
834
- if ((undefined && undefined.MODE) !== "production" && a[0].type === "__setState" && !didWarnAboutReservedActionType) {
834
+ if ((undefined ? undefined.MODE : void 0) !== "production" && a[0].type === "__setState" && !didWarnAboutReservedActionType) {
835
835
  console.warn(
836
836
  '[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'
837
837
  );
@@ -1276,7 +1276,7 @@ const newImpl = (config, baseOptions) => (set, get, api) => {
1276
1276
  };
1277
1277
  const persistImpl = (config, baseOptions) => {
1278
1278
  if ("getStorage" in baseOptions || "serialize" in baseOptions || "deserialize" in baseOptions) {
1279
- if ((undefined && undefined.MODE) !== "production") {
1279
+ if ((undefined ? undefined.MODE : void 0) !== "production") {
1280
1280
  console.warn(
1281
1281
  "[DEPRECATED] `getStorage`, `serialize` and `deserialize` options are deprecated. Use `storage` option instead."
1282
1282
  );
@@ -1407,13 +1407,19 @@ class PeraWalletClient extends BaseClient {
1407
1407
  icon: ICON$8,
1408
1408
  isWalletConnect: true
1409
1409
  };
1410
- static async init({ clientOptions, algodOptions, clientStatic, algosdkStatic, network = DEFAULT_NETWORK }) {
1410
+ static async init({ clientOptions, algodOptions, clientStatic, getDynamicClient, algosdkStatic, network = DEFAULT_NETWORK }) {
1411
1411
  try {
1412
1412
  debugLog(`${exports.PROVIDER_ID.PERA.toUpperCase()} initializing...`);
1413
- if (!clientStatic) {
1414
- throw new Error('Pera Wallet provider missing required property: clientStatic');
1413
+ let PeraWalletConnect;
1414
+ if (clientStatic) {
1415
+ PeraWalletConnect = clientStatic;
1416
+ }
1417
+ else if (getDynamicClient) {
1418
+ PeraWalletConnect = await getDynamicClient();
1419
+ }
1420
+ else {
1421
+ throw new Error('Pera Wallet provider missing required property: clientStatic or getDynamicClient');
1415
1422
  }
1416
- const PeraWalletConnect = clientStatic;
1417
1423
  const algosdk = algosdkStatic || (await Algod.init(algodOptions)).algosdk;
1418
1424
  const algodClient = getAlgodClient(algosdk, algodOptions);
1419
1425
  const peraWallet = new PeraWalletConnect({
@@ -1564,13 +1570,19 @@ class DaffiWalletClient extends BaseClient {
1564
1570
  icon: ICON$7,
1565
1571
  isWalletConnect: true
1566
1572
  };
1567
- static async init({ clientOptions, algodOptions, clientStatic, algosdkStatic, network = DEFAULT_NETWORK }) {
1573
+ static async init({ clientOptions, algodOptions, clientStatic, getDynamicClient, algosdkStatic, network = DEFAULT_NETWORK }) {
1568
1574
  try {
1569
1575
  debugLog(`${exports.PROVIDER_ID.DAFFI.toUpperCase()} initializing...`);
1570
- if (!clientStatic) {
1571
- throw new Error('Daffi Wallet provider missing required property: clientStatic');
1576
+ let DaffiWalletConnect;
1577
+ if (clientStatic) {
1578
+ DaffiWalletConnect = clientStatic;
1579
+ }
1580
+ else if (getDynamicClient) {
1581
+ DaffiWalletConnect = await getDynamicClient();
1582
+ }
1583
+ else {
1584
+ throw new Error('Daffi Wallet provider missing required property: clientStatic or getDynamicClient');
1572
1585
  }
1573
- const DaffiWalletConnect = clientStatic;
1574
1586
  const algosdk = algosdkStatic || (await Algod.init(algodOptions)).algosdk;
1575
1587
  const algodClient = getAlgodClient(algosdk, algodOptions);
1576
1588
  const daffiWallet = new DaffiWalletConnect({
@@ -1722,13 +1734,19 @@ class MyAlgoWalletClient extends BaseClient {
1722
1734
  icon: ICON$6,
1723
1735
  isWalletConnect: false
1724
1736
  };
1725
- static async init({ clientOptions, algodOptions, clientStatic, algosdkStatic, network = DEFAULT_NETWORK }) {
1737
+ static async init({ clientOptions, algodOptions, clientStatic, getDynamicClient, algosdkStatic, network = DEFAULT_NETWORK }) {
1726
1738
  try {
1727
1739
  debugLog(`${exports.PROVIDER_ID.MYALGO.toUpperCase()} initializing...`);
1728
- if (!clientStatic) {
1729
- throw new Error('MyAlgo Wallet provider missing required property: clientStatic');
1740
+ let MyAlgoConnect;
1741
+ if (clientStatic) {
1742
+ MyAlgoConnect = clientStatic;
1743
+ }
1744
+ else if (getDynamicClient) {
1745
+ MyAlgoConnect = await getDynamicClient();
1746
+ }
1747
+ else {
1748
+ throw new Error('MyAlgo Wallet provider missing required property: clientStatic or getDynamicClient');
1730
1749
  }
1731
- const MyAlgoConnect = clientStatic;
1732
1750
  const algosdk = algosdkStatic || (await Algod.init(algodOptions)).algosdk;
1733
1751
  const algodClient = getAlgodClient(algosdk, algodOptions);
1734
1752
  const myAlgo = new MyAlgoConnect({
@@ -1834,13 +1852,19 @@ class DeflyWalletClient extends BaseClient {
1834
1852
  icon: ICON$5,
1835
1853
  isWalletConnect: true
1836
1854
  };
1837
- static async init({ clientOptions, algodOptions, clientStatic, algosdkStatic, network = DEFAULT_NETWORK }) {
1855
+ static async init({ clientOptions, algodOptions, clientStatic, getDynamicClient, algosdkStatic, network = DEFAULT_NETWORK }) {
1838
1856
  try {
1839
1857
  debugLog(`${exports.PROVIDER_ID.DEFLY.toUpperCase()} initializing...`);
1840
- if (!clientStatic) {
1841
- throw new Error('Defly Wallet provider missing required property: clientStatic');
1858
+ let DeflyWalletConnect;
1859
+ if (clientStatic) {
1860
+ DeflyWalletConnect = clientStatic;
1861
+ }
1862
+ else if (getDynamicClient) {
1863
+ DeflyWalletConnect = await getDynamicClient();
1864
+ }
1865
+ else {
1866
+ throw new Error('Defly Wallet provider missing required property: clientStatic or getDynamicClient');
1842
1867
  }
1843
- const DeflyWalletConnect = clientStatic;
1844
1868
  const algosdk = algosdkStatic || (await Algod.init(algodOptions)).algosdk;
1845
1869
  const algodClient = getAlgodClient(algosdk, algodOptions);
1846
1870
  const deflyWallet = new DeflyWalletConnect({
@@ -2294,11 +2318,18 @@ class WalletConnectClient extends BaseClient {
2294
2318
  icon: ICON$2,
2295
2319
  isWalletConnect: true
2296
2320
  };
2297
- static async init({ clientOptions, algodOptions, clientStatic, algosdkStatic, network = DEFAULT_NETWORK }) {
2321
+ static async init({ clientOptions, algodOptions, clientStatic, getDynamicClient, algosdkStatic, network = DEFAULT_NETWORK }) {
2298
2322
  try {
2299
2323
  debugLog(`${exports.PROVIDER_ID.WALLETCONNECT.toUpperCase()} initializing...`);
2300
- if (!clientStatic) {
2301
- throw new Error('WalletConnect provider missing required property: clientStatic');
2324
+ let Client;
2325
+ if (clientStatic) {
2326
+ Client = clientStatic;
2327
+ }
2328
+ else if (getDynamicClient) {
2329
+ Client = await getDynamicClient();
2330
+ }
2331
+ else {
2332
+ throw new Error('WalletConnect provider missing required property: clientStatic or getDynamicClient');
2302
2333
  }
2303
2334
  if (!clientOptions) {
2304
2335
  throw new Error('WalletConnect provider missing required property: clientOptions');
@@ -2307,7 +2338,6 @@ class WalletConnectClient extends BaseClient {
2307
2338
  throw new Error(`WalletConnect only supports Algorand mainnet, testnet, and betanet. "${network}" is not supported.`);
2308
2339
  }
2309
2340
  const chain = ALGORAND_CHAINS[network];
2310
- const Client = clientStatic;
2311
2341
  // Initialize client
2312
2342
  const client = new Client({
2313
2343
  ...clientOptions,
@@ -2869,7 +2899,7 @@ function shallow(objA, objB) {
2869
2899
  return true;
2870
2900
  }
2871
2901
  var shallow$1 = (objA, objB) => {
2872
- if ((undefined && undefined.MODE) !== "production") {
2902
+ if ((undefined ? undefined.MODE : void 0) !== "production") {
2873
2903
  console.warn(
2874
2904
  "[DEPRECATED] Default export is deprecated. Instead use `import { shallow } from 'zustand/shallow'`."
2875
2905
  );