@txnlab/use-wallet 0.1.23 → 1.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 (122) hide show
  1. package/README.md +252 -94
  2. package/dist/cjs/algod/index.d.ts +3 -2
  3. package/dist/cjs/clients/algosigner/client.d.ts +35 -0
  4. package/dist/cjs/clients/algosigner/constants.d.ts +2 -0
  5. package/dist/cjs/clients/algosigner/index.d.ts +2 -0
  6. package/dist/cjs/clients/algosigner/types.d.ts +40 -0
  7. package/dist/{esm/clients → cjs/clients/base}/base.d.ts +12 -25
  8. package/dist/cjs/clients/base/index.d.ts +2 -0
  9. package/dist/cjs/clients/defly/client.d.ts +37 -0
  10. package/dist/cjs/clients/defly/constants.d.ts +1 -0
  11. package/dist/cjs/clients/defly/index.d.ts +2 -0
  12. package/dist/cjs/clients/defly/types.d.ts +36 -0
  13. package/dist/cjs/clients/exodus/client.d.ts +33 -0
  14. package/dist/cjs/clients/exodus/constants.d.ts +1 -0
  15. package/dist/cjs/clients/exodus/index.d.ts +2 -0
  16. package/dist/cjs/clients/exodus/types.d.ts +40 -0
  17. package/dist/cjs/clients/index.d.ts +11 -15
  18. package/dist/cjs/clients/kmd/client.d.ts +29 -0
  19. package/dist/cjs/clients/kmd/constants.d.ts +1 -0
  20. package/dist/cjs/clients/kmd/index.d.ts +2 -0
  21. package/dist/cjs/clients/kmd/types.d.ts +38 -0
  22. package/dist/cjs/clients/{myalgowallet.d.ts → myalgo/client.d.ts} +14 -17
  23. package/dist/cjs/clients/myalgo/constants.d.ts +1 -0
  24. package/dist/cjs/clients/myalgo/index.d.ts +2 -0
  25. package/dist/cjs/clients/myalgo/types.d.ts +23 -0
  26. package/dist/cjs/clients/pera/client.d.ts +35 -0
  27. package/dist/cjs/clients/pera/constants.d.ts +1 -0
  28. package/dist/cjs/clients/pera/index.d.ts +2 -0
  29. package/dist/cjs/clients/pera/types.d.ts +36 -0
  30. package/dist/cjs/clients/walletconnect/client.d.ts +37 -0
  31. package/dist/cjs/clients/walletconnect/constants.d.ts +2 -0
  32. package/dist/cjs/clients/walletconnect/index.d.ts +2 -0
  33. package/dist/cjs/clients/walletconnect/types.d.ts +54 -0
  34. package/dist/cjs/constants/constants.d.ts +12 -16
  35. package/dist/cjs/hooks/index.d.ts +0 -1
  36. package/dist/cjs/hooks/useWallet.d.ts +140 -8
  37. package/dist/cjs/index.d.ts +4 -2
  38. package/dist/cjs/index.js +736 -739
  39. package/dist/cjs/index.js.map +1 -1
  40. package/dist/cjs/store/index.d.ts +1 -0
  41. package/dist/cjs/store/state/clientStore.d.ts +22 -0
  42. package/dist/cjs/types/node.d.ts +3 -0
  43. package/dist/cjs/types/wallet.d.ts +2 -2
  44. package/dist/cjs/utils/index.d.ts +2 -2
  45. package/dist/cjs/utils/initializeProviders.d.ts +13 -0
  46. package/dist/cjs/utils/reconnectProviders.d.ts +6 -0
  47. package/dist/esm/algod/index.d.ts +3 -2
  48. package/dist/esm/clients/algosigner/client.d.ts +35 -0
  49. package/dist/esm/clients/algosigner/constants.d.ts +2 -0
  50. package/dist/esm/clients/algosigner/index.d.ts +2 -0
  51. package/dist/esm/clients/algosigner/types.d.ts +40 -0
  52. package/dist/{cjs/clients → esm/clients/base}/base.d.ts +12 -25
  53. package/dist/esm/clients/base/index.d.ts +2 -0
  54. package/dist/esm/clients/defly/client.d.ts +37 -0
  55. package/dist/esm/clients/defly/constants.d.ts +1 -0
  56. package/dist/esm/clients/defly/index.d.ts +2 -0
  57. package/dist/esm/clients/defly/types.d.ts +36 -0
  58. package/dist/esm/clients/exodus/client.d.ts +33 -0
  59. package/dist/esm/clients/exodus/constants.d.ts +1 -0
  60. package/dist/esm/clients/exodus/index.d.ts +2 -0
  61. package/dist/esm/clients/exodus/types.d.ts +40 -0
  62. package/dist/esm/clients/index.d.ts +11 -15
  63. package/dist/esm/clients/kmd/client.d.ts +29 -0
  64. package/dist/esm/clients/kmd/constants.d.ts +1 -0
  65. package/dist/esm/clients/kmd/index.d.ts +2 -0
  66. package/dist/esm/clients/kmd/types.d.ts +38 -0
  67. package/dist/esm/clients/{myalgowallet.d.ts → myalgo/client.d.ts} +14 -17
  68. package/dist/esm/clients/myalgo/constants.d.ts +1 -0
  69. package/dist/esm/clients/myalgo/index.d.ts +2 -0
  70. package/dist/esm/clients/myalgo/types.d.ts +23 -0
  71. package/dist/esm/clients/pera/client.d.ts +35 -0
  72. package/dist/esm/clients/pera/constants.d.ts +1 -0
  73. package/dist/esm/clients/pera/index.d.ts +2 -0
  74. package/dist/esm/clients/pera/types.d.ts +36 -0
  75. package/dist/esm/clients/walletconnect/client.d.ts +37 -0
  76. package/dist/esm/clients/walletconnect/constants.d.ts +2 -0
  77. package/dist/esm/clients/walletconnect/index.d.ts +2 -0
  78. package/dist/esm/clients/walletconnect/types.d.ts +54 -0
  79. package/dist/esm/constants/constants.d.ts +12 -16
  80. package/dist/esm/hooks/index.d.ts +0 -1
  81. package/dist/esm/hooks/useWallet.d.ts +140 -8
  82. package/dist/esm/index.d.ts +4 -2
  83. package/dist/esm/index.js +724 -730
  84. package/dist/esm/store/index.d.ts +1 -0
  85. package/dist/esm/store/state/clientStore.d.ts +22 -0
  86. package/dist/esm/types/node.d.ts +3 -0
  87. package/dist/esm/types/wallet.d.ts +2 -2
  88. package/dist/esm/utils/index.d.ts +2 -2
  89. package/dist/esm/utils/initializeProviders.d.ts +13 -0
  90. package/dist/esm/utils/reconnectProviders.d.ts +6 -0
  91. package/dist/index.d.ts +669 -66
  92. package/package.json +2 -2
  93. package/dist/cjs/clients/algosigner.d.ts +0 -62
  94. package/dist/cjs/clients/defly.d.ts +0 -51
  95. package/dist/cjs/clients/exodus.d.ts +0 -52
  96. package/dist/cjs/clients/kmd.d.ts +0 -31
  97. package/dist/cjs/clients/perawallet.d.ts +0 -47
  98. package/dist/cjs/clients/walletconnect.d.ts +0 -47
  99. package/dist/cjs/hooks/useConnectWallet.d.ts +0 -30
  100. package/dist/cjs/providers/algosigner.d.ts +0 -2
  101. package/dist/cjs/providers/defly.d.ts +0 -2
  102. package/dist/cjs/providers/exodus.d.ts +0 -2
  103. package/dist/cjs/providers/index.d.ts +0 -9
  104. package/dist/cjs/providers/kmd.d.ts +0 -2
  105. package/dist/cjs/providers/myalgowallet.d.ts +0 -2
  106. package/dist/cjs/providers/perawallet.d.ts +0 -2
  107. package/dist/cjs/providers/walletconnect.d.ts +0 -2
  108. package/dist/esm/clients/algosigner.d.ts +0 -62
  109. package/dist/esm/clients/defly.d.ts +0 -51
  110. package/dist/esm/clients/exodus.d.ts +0 -52
  111. package/dist/esm/clients/kmd.d.ts +0 -31
  112. package/dist/esm/clients/perawallet.d.ts +0 -47
  113. package/dist/esm/clients/walletconnect.d.ts +0 -47
  114. package/dist/esm/hooks/useConnectWallet.d.ts +0 -30
  115. package/dist/esm/providers/algosigner.d.ts +0 -2
  116. package/dist/esm/providers/defly.d.ts +0 -2
  117. package/dist/esm/providers/exodus.d.ts +0 -2
  118. package/dist/esm/providers/index.d.ts +0 -9
  119. package/dist/esm/providers/kmd.d.ts +0 -2
  120. package/dist/esm/providers/myalgowallet.d.ts +0 -2
  121. package/dist/esm/providers/perawallet.d.ts +0 -2
  122. package/dist/esm/providers/walletconnect.d.ts +0 -2
package/README.md CHANGED
@@ -12,7 +12,6 @@ React hooks for using Algorand compatible wallets with web applications.
12
12
  - [WalletConnect](https://walletconnect.com)
13
13
  - [KMD](https://developer.algorand.org/docs/rest-apis/kmd)
14
14
 
15
-
16
15
  ## Demo
17
16
 
18
17
  Preview a basic implementation in [Storybook](https://txnlab.github.io/use-wallet) or check out [this example](https://github.com/gabrielkuettel/use-wallet-example).
@@ -45,64 +44,106 @@ Install peer dependencies (if needed)
45
44
  npm install algosdk @blockshake/defly-connect @perawallet/connect @randlabs/myalgo-connect @walletconnect/client algorand-walletconnect-qrcode-modal @json-rpc-tools/utils
46
45
  ```
47
46
 
48
- ### Set up the wallet providers
47
+ ### Set up the Wallet Provider
48
+
49
+ In `app.js`, initialize the Wallet Provider so that the `useWallet` hook can be used in the child components, and use the `reconnectProviders` function to restore sessions for users returning to the app.
50
+
49
51
 
50
52
  ```jsx
51
53
  import React from "react";
52
- import { useConnectWallet } from "@txnlab/use-wallet";
54
+ import {
55
+ reconnectProviders,
56
+ initializeProviders,
57
+ WalletProvider,
58
+ } from "@txnlab/use-wallet";
53
59
 
54
- function App() {
55
- const { providers, reconnectProviders, accounts, activeAccount } = useConnectWallet();
60
+ const walletProviders = initializeProviders();
56
61
 
62
+ export default function App() {
57
63
  // Reconnect the session when the user returns to the dApp
58
64
  React.useEffect(() => {
59
- reconnectProviders();
65
+ reconnectProviders(walletProviders);
60
66
  }, []);
61
67
 
62
- // Use these properties to display connected accounts to users.
63
- // They are reactive and presisted to local storage.
64
- React.useEffect(() => {
65
- console.log("connected accounts", accounts);
66
- console.log("active account", activeAccount);
67
- });
68
+ return (
69
+ <WalletProvider value={walletProviders}>
70
+ ...
71
+ </WalletProvider>);
72
+ }
73
+ ```
74
+
75
+ The `reconnectProviders` function is used to restore session states of wallets that rely on the `WalletConnect` protocol.
76
+
77
+ By default, all of the supported providers except for `KMD` are returned by `useConnectWallet`. An array can be passed to `initializeProviders` to determine which providers your dApp supports, as shown below.
78
+
79
+ ```jsx
80
+ import { initializeProviders, PROVIDER_ID } from "@txnlab/use-wallet";
81
+
82
+ const walletProviders = initializeProviders([
83
+ PROVIDER_ID.KMD_WALLET,
84
+ PROVIDER_ID.WALLET_CONNECT,
85
+ ]);
86
+ ```
87
+
88
+ For more configuration options, see [Provider Configuration](#provider-configuration).
89
+
90
+ ### Connect
91
+
92
+ Map through the `providers` object to list the providers and enable users to connect.
93
+
94
+ ```jsx
95
+ import React from "react";
96
+ import { useWallet } from "@txnlab/use-wallet";
97
+
98
+ export default function Connect() {
99
+ const { providers, activeAccount } = useWallet();
68
100
 
69
101
  // Map through the providers.
70
102
  // Render account information and "connect", "set active", and "disconnect" buttons.
71
103
  // Finally, map through the `accounts` property to render a dropdown for each connected account.
72
104
  return (
73
105
  <div>
74
- {providers.map((provider) => (
75
- <div key={"provider-" + provider.id}>
106
+ {providers?.map((provider) => (
107
+ <div key={"provider-" + provider.metadata.id}>
76
108
  <h4>
77
- <img width={30} height={30} src={provider.icon} />
78
- {provider.name} {provider.isActive && "[active]"}
109
+ <img width={30} height={30} alt="" src={provider.metadata.icon} />
110
+ {provider.metadata.name} {provider.isActive && "[active]"}
79
111
  </h4>
80
112
  <div>
81
113
  <button onClick={provider.connect} disabled={provider.isConnected}>
82
114
  Connect
83
115
  </button>
84
- <button onClick={provider.disconnect} disabled={!provider.isConnected}>
85
- Disonnect
116
+ <button
117
+ onClick={provider.disconnect}
118
+ disabled={!provider.isConnected}
119
+ >
120
+ Disconnect
86
121
  </button>
87
- <button onClick={provider.setActive} disabled={!provider.isConnected || provider.isActive}>
122
+ <button
123
+ onClick={provider.setActiveProvider}
124
+ disabled={!provider.isConnected || provider.isActive}
125
+ >
88
126
  Set Active
89
127
  </button>
90
- {provider.isActive && provider.accounts.length && (
91
- <select
92
- value={provider.activeAccount?.address}
93
- onChange={(e) => provider.selectAccount(e.target.value)}
94
- >
95
- {provider.accounts.map((account) => (
96
- <option value={account.address}>{account.address}</option>
97
- ))}
98
- </select>
99
- )}
128
+ <div>
129
+ {provider.isActive && provider.accounts.length && (
130
+ <select
131
+ value={activeAccount?.address}
132
+ onChange={(e) => provider.setActiveAccount(e.target.value)}
133
+ >
134
+ {provider.accounts.map((account) => (
135
+ <option key={account.address} value={account.address}>{account.address}</option>
136
+ ))}
137
+ </select>
138
+ )}
139
+ </div>
100
140
  </div>
101
141
  </div>
102
142
  ))}
103
143
  </div>
104
144
  );
105
145
  }
146
+
106
147
  ```
107
148
 
108
149
  Each provider has two connection states: `isConnected` and `isActive`.
@@ -111,30 +152,30 @@ Each provider has two connection states: `isConnected` and `isActive`.
111
152
 
112
153
  `isActive` indicates that the provider is currently active and will be used to sign and send transactions when using the `useWallet` hook.
113
154
 
114
- By default, all of the supported providers except for `KMD` are returned by `useConnectWallet`. A configuration object can be passed to determine which providers your dApp suports, as shown below.
115
-
116
- ```jsx
117
- import { useConnectWallet, PROVIDER_ID } from "@txnlab/use-wallet";
118
-
119
- ...
120
-
121
- const { providers } = useConnectWallet({
122
- providers: [
123
- PROVIDER_ID.MYALGO_WALLET,
124
- PROVIDER_ID.PERA_WALLET,
125
- PROVIDER_ID.KMD_WALLET,
126
- ],
127
- });
128
- ```
155
+ The `activeAccount` is the primary account that is currently active and will be used to sign and send transactions.
129
156
 
130
157
  ### Sign and send transactions
131
158
 
159
+ Construct a transaction using `algosdk`, and sign and send the transaction using the `signTransactions` and `sendTransactions` functions provided by the `useWallet` hook.
160
+
132
161
  ```jsx
133
162
  import React from "react";
134
- import { useWallet } from "@txnlab/use-wallet";
135
-
136
- function Wallet() {
137
- const { activeAccount, signTransactions, sendTransactions } = useWallet();
163
+ import {
164
+ useWallet,
165
+ DEFAULT_NODE_BASEURL,
166
+ DEFAULT_NODE_TOKEN,
167
+ DEFAULT_NODE_PORT,
168
+ } from "@txnlab/use-wallet";
169
+ import algosdk from "algosdk";
170
+
171
+ const algodClient = new algosdk.Algodv2(
172
+ DEFAULT_NODE_TOKEN,
173
+ DEFAULT_NODE_BASEURL,
174
+ DEFAULT_NODE_PORT
175
+ );
176
+
177
+ export default function Transact() {
178
+ const { activeAddress, signTransactions, sendTransactions } = useWallet();
138
179
 
139
180
  const sendTransaction = async (
140
181
  from?: string,
@@ -145,91 +186,180 @@ function Wallet() {
145
186
  throw new Error("Missing transaction params.");
146
187
  }
147
188
 
148
- const params = await algodClient.getTransactionParams().do();
189
+ const suggestedParams = await algodClient.getTransactionParams().do();
149
190
 
150
- // Construct a transaction to be signed and sent.
151
191
  const transaction = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
152
192
  from,
153
193
  to,
154
194
  amount,
155
- suggestedParams: params,
195
+ suggestedParams,
156
196
  });
157
197
 
158
- // Encode the transactions into a byte array.
159
198
  const encodedTransaction = algosdk.encodeUnsignedTransaction(transaction);
160
199
 
161
- // Sign the transactions.
162
200
  const signedTransactions = await signTransactions([encodedTransaction]);
163
201
 
164
- // Send the transactions.
165
- const { id } = await sendTransactions(signedTransactions);
202
+ const waitRoundsToConfirm = 4;
203
+
204
+ const { id } = await sendTransactions(
205
+ signedTransactions,
206
+ waitRoundsToConfirm
207
+ );
166
208
 
167
209
  console.log("Successfully sent transaction. Transaction ID: ", id);
168
210
  };
169
211
 
170
- if (!activeAccount) {
212
+ if (!activeAddress) {
171
213
  return <p>Connect an account first.</p>;
172
214
  }
173
215
 
174
216
  return (
175
217
  <div>
176
- {
177
- <button
178
- onClick={() =>
179
- sendTransaction(
180
- activeAccount?.address,
181
- activeAccount?.address,
182
- 1000
183
- )
184
- }
185
- className="button"
186
- >
187
- Sign and send transactions
188
- </button>
189
- }
218
+ <button
219
+ onClick={() => sendTransaction(activeAddress, activeAddress, 1000)}
220
+ className="button"
221
+ >
222
+ Sign and send transactions
223
+ </button>
190
224
  </div>
191
225
  );
192
- };
226
+ }
193
227
  ```
194
228
 
195
- ## Environment Variables
229
+ ### Display account details
196
230
 
197
- By default, wallets will connect to Algorand [MainNet](https://developer.algorand.org/docs/get-details/algorand-networks/mainnet). You can change this behavior by setting the following environment variables:
231
+ The `activeAccount` object can be used to display details for the currently active account. For convenience, the `activeAddress` property shows the currently active address.
198
232
 
199
- * `NODE_NETWORK` (defaults to `mainnet`, and can be set to `testnet`, `betanet`, or the name of a local network running in dev mode)
200
-
201
- * `NODE_SERVER`
202
-
203
- * `NODE_TOKEN`
233
+ ```jsx
234
+ import React from "react";
235
+ import { useWallet } from "@txnlab/use-wallet";
204
236
 
205
- * `NODE_PORT`
237
+ export default function Account() {
238
+ const { activeAccount } = useWallet();
206
239
 
207
- Example `.env` file:
240
+ if (!activeAccount) {
241
+ return <p>No account active.</p>;
242
+ }
208
243
 
244
+ return (
245
+ <div>
246
+ <h4>Active Account</h4>
247
+ <p>
248
+ Name: <span>{activeAccount.name}</span>
249
+ </p>
250
+ <p>
251
+ Address: <span>{activeAccount.address}</span>
252
+ </p>
253
+ <p>
254
+ Provider: <span>{activeAccount.providerId}</span>
255
+ </p>
256
+ </div>
257
+ );
258
+ }
209
259
  ```
210
- NODE_NETWORK=devmodenet
211
- NODE_SERVER=http://algod
212
- NODE_TOKEN=xxxxxxxxx
213
- NODE_PORT=8080
260
+
261
+ ## Provider Configuration
262
+
263
+ The `initializeProviders` functon accepts a configuration object that can be used to configure the nodes that the providers use to send transactions, as shown below.
264
+
265
+ ```jsx
266
+ const walletProviders = initializeProviders([], {
267
+ network: "devmodenet",
268
+ nodeServer: "http://algod",
269
+ nodeToken: "xxxxxxxxx",
270
+ nodePort: "8080",
271
+ });
214
272
  ```
215
273
 
216
- ### Create React App and Next.js
274
+ Passing an empty array as the first argument enables all of the default providers. The `network` property should be specified as `betanet`, `testnet`, `mainnet` or the name of your local development network.
275
+
276
+ For more custom configuration options, the providers can be configured individually by creating an object and passing it to the `WalletProvider` where the key contains the provider ID, and the value calls the `init` function of the provider client. See below for an example:
217
277
 
218
- In Create React App and Next.js projects, you'll need to add a prefix to these environment variables to expose them to the browser.
278
+ ```jsx
279
+ ...
219
280
 
220
- * `REACT_APP_` in [Create React App](https://create-react-app.dev/docs/adding-custom-environment-variables/)
281
+ import {
282
+ PROVIDER_ID,
283
+ pera,
284
+ myalgo,
285
+ } from "@txnlab/use-wallet";
221
286
 
222
- * `NEXT_PUBLIC_` in [Next.js](https://nextjs.org/docs/basic-features/environment-variables#exposing-environment-variables-to-the-browser)
287
+ const walletProviders = {
288
+ [PROVIDER_ID.PERA]: pera.init({
289
+ clientOptions: {
290
+ shouldShowSignTxnToast: true,
291
+ },
292
+ }),
293
+ [PROVIDER_ID.MYALGO]: myalgo.init({
294
+ network: "devmodenet",
295
+ algodOptions: ["xxxxxxxxx", "http://algod", "8080"],
296
+ clientOptions: { disableLedgerNano: true },
297
+ }),
298
+ };
223
299
 
224
- Example `.env` file in Create React App:
300
+ ...
225
301
 
302
+ <WalletProvider value={walletProviders}>
303
+ ...
304
+ </WalletProvider>
226
305
  ```
227
- REACT_APP_NODE_NETWORK=devmodenet
228
- REACT_APP_NODE_SERVER=http://algod
229
- REACT_APP_NODE_TOKEN=xxxxxxxxx
230
- REACT_APP_NODE_PORT=8080
306
+
307
+ ## Static Imports
308
+
309
+ By default, `use-wallet` dynamically imports all of the dependencies for the providiers, as well as `algosdk`, to reduce bundle size.
310
+
311
+ Some React frameworks, like [Remix](https://remix.run/), do not support dynamic imports. To get around this, those dependencies can be imported in your application and passed to the `useWallet` provider. See below for an example.
312
+
313
+ ```jsx
314
+ ...
315
+
316
+ import algosdk from "algosdk";
317
+ import MyAlgoConnect from "@randlabs/myalgo-connect";
318
+ import { PeraWalletConnect } from "@perawallet/connect";
319
+ import { DeflyWalletConnect } from "@blockshake/defly-connect";
320
+ import WalletConnect from "@walletconnect/client";
321
+ import QRCodeModal from "algorand-walletconnect-qrcode-modal";
322
+
323
+ const walletProviders = {
324
+ [PROVIDER_ID.PERA]: pera.init({
325
+ algosdkStatic: algosdk,
326
+ clientStatic: PeraWalletConnect,
327
+ }),
328
+ [PROVIDER_ID.MYALGO]: myalgo.init({
329
+ algosdkStatic: algosdk,
330
+ clientStatic: MyAlgoConnect,
331
+ }),
332
+ [PROVIDER_ID.DEFLY]: defly.init({
333
+ algosdkStatic: algosdk,
334
+ clientStatic: DeflyWalletConnect,
335
+ }),
336
+ [PROVIDER_ID.EXODUS]: exodus.init({
337
+ algosdkStatic: algosdk,
338
+ }),
339
+ [PROVIDER_ID.ALGOSIGNER]: algosigner.init({
340
+ algosdkStatic: algosdk,
341
+ }),
342
+ [PROVIDER_ID.WALLETCONNECT]: walletconnect.init({
343
+ algosdkStatic: algosdk,
344
+ clientStatic: WalletConnect,
345
+ modalStatic: QRCodeModal,
346
+ }),
347
+ };
348
+
349
+ export default function App() {
350
+ ...
351
+
352
+ return (
353
+ <WalletProvider value={walletProviders}>
354
+ ...
355
+ </WalletProvider>
356
+ );
357
+ }
358
+
231
359
  ```
232
360
 
361
+ Note that some of the providers do not require static imports to be provided. This is usually the case of providers that are browser extensions.
362
+
233
363
  ## Webpack 5
234
364
 
235
365
  1. Install `react-app-rewired` and the missing polyfills.
@@ -287,16 +417,44 @@ yarn install
287
417
  ### Demo in Storybook
288
418
 
289
419
  ```bash
290
- yarn storybook
420
+ yarn dev
291
421
 
292
422
  ```
293
423
 
424
+ To develop against a local version of `use-wallet` in your application, do the following:
425
+
294
426
  ### Build the library
295
427
 
296
428
  ```bash
297
429
  yarn build
298
430
  ```
299
431
 
432
+ ### Symlink the library
433
+
434
+ In the root of `use-wallet` directory, run:
435
+
436
+ ```bash
437
+ yarn link
438
+ ```
439
+
440
+ In the root of your application, run:
441
+ ```bash
442
+ yarn link @txnlab/use-wallet
443
+ ```
444
+
445
+ ### Symlink React
446
+
447
+ In the root of your application, run:
448
+ ```bash
449
+ cd node_modules/react
450
+ yarn link
451
+ ```
452
+
453
+ In the root of `use-wallet` directory, run:
454
+ ```bash
455
+ yarn link react
456
+ ```
457
+
300
458
  ## License
301
459
 
302
460
  See the [LICENSE](https://github.com/TxnLab/use-wallet/blob/main/LICENSE.md) file for license rights and limitations (MIT)
@@ -1,9 +1,10 @@
1
1
  import type _algosdk from "algosdk";
2
+ import type { AlgodClientOptions } from "../types";
2
3
  export declare const getAlgosdk: () => Promise<typeof _algosdk>;
3
- export declare const getAlgodClient: (algosdk: typeof _algosdk) => Promise<_algosdk.Algodv2>;
4
+ export declare const getAlgodClient: (algosdk: typeof _algosdk, algodClientOptions?: AlgodClientOptions) => Promise<_algosdk.Algodv2>;
4
5
  export default class Algod {
5
6
  algosdk: typeof _algosdk;
6
7
  algodClient: _algosdk.Algodv2;
7
8
  constructor(algosdk: typeof _algosdk, algodClient: _algosdk.Algodv2);
8
- static init(): Promise<Algod>;
9
+ static init(algodOptions?: AlgodClientOptions): Promise<Algod>;
9
10
  }
@@ -0,0 +1,35 @@
1
+ import BaseWallet from "../base";
2
+ import { PROVIDER_ID } from "../../constants";
3
+ import type { TransactionsArray, Network } from "../../types";
4
+ import type { AlgoSignerTransaction, AlgoSignerClientConstructor, InitParams } from "./types";
5
+ declare class AlgoSignerClient extends BaseWallet {
6
+ #private;
7
+ network: Network;
8
+ constructor({ client, algosdk, algodClient, network, }: AlgoSignerClientConstructor);
9
+ static metadata: {
10
+ id: PROVIDER_ID;
11
+ name: string;
12
+ icon: string;
13
+ isWalletConnect: boolean;
14
+ };
15
+ static init({ algodOptions, algosdkStatic, network, }: InitParams): Promise<AlgoSignerClient | null>;
16
+ connect(): Promise<{
17
+ accounts: {
18
+ name: string;
19
+ address: string;
20
+ providerId: PROVIDER_ID;
21
+ }[];
22
+ id: PROVIDER_ID;
23
+ name: string;
24
+ icon: string;
25
+ isWalletConnect: boolean;
26
+ }>;
27
+ reconnect(onDisconnect: () => void): Promise<null>;
28
+ disconnect(): Promise<void>;
29
+ signTransactions(connectedAccounts: string[], transactions: Uint8Array[]): Promise<Uint8Array[]>;
30
+ /** @deprecated */
31
+ formatTransactionsArray(transactions: TransactionsArray): AlgoSignerTransaction[];
32
+ /** @deprecated */
33
+ signEncodedTransactions(transactions: TransactionsArray): Promise<Uint8Array[]>;
34
+ }
35
+ export default AlgoSignerClient;
@@ -0,0 +1,2 @@
1
+ export declare const ICON: string;
2
+ export declare const DEFAULT_NETWORK = "MainNet";
@@ -0,0 +1,2 @@
1
+ import algosigner from "./client";
2
+ export default algosigner;
@@ -0,0 +1,40 @@
1
+ import type _algosdk from "algosdk";
2
+ import { PROVIDER_ID } from "../../constants";
3
+ import type { AlgodClientOptions, Network } from "../../types";
4
+ export declare type WindowExtended = {
5
+ AlgoSigner: AlgoSigner;
6
+ } & Window & typeof globalThis;
7
+ export declare type AlgoSignerTransaction = {
8
+ txn: string;
9
+ signers?: [];
10
+ multisig?: string;
11
+ };
12
+ export declare type SupportedLedgers = "MainNet" | "TestNet" | "BetaNet" | string;
13
+ export declare type AlgoSigner = {
14
+ connect: () => Promise<Record<string, never>>;
15
+ accounts: (ledger: {
16
+ ledger: SupportedLedgers;
17
+ }) => Promise<{
18
+ address: string;
19
+ }[]>;
20
+ signTxn: (transactions: AlgoSignerTransaction[]) => Promise<{
21
+ txID: string;
22
+ blob: string;
23
+ }[]>;
24
+ encoding: {
25
+ msgpackToBase64(transaction: Uint8Array): string;
26
+ byteArrayToString(transaction: Uint8Array): string;
27
+ };
28
+ };
29
+ export declare type AlgoSignerClientConstructor = {
30
+ client: AlgoSigner;
31
+ id: PROVIDER_ID;
32
+ algosdk: typeof _algosdk;
33
+ algodClient: _algosdk.Algodv2;
34
+ network: SupportedLedgers;
35
+ };
36
+ export declare type InitParams = {
37
+ algodOptions?: AlgodClientOptions;
38
+ algosdkStatic?: typeof _algosdk;
39
+ network?: Network;
40
+ };
@@ -1,29 +1,16 @@
1
1
  import type _algosdk from "algosdk";
2
- import { PROVIDER_ID } from "../constants";
3
- import type { WalletProvider, Asset, Wallet, AccountInfo, ConfirmedTxn, TransactionsArray, TxnInfo } from "../types";
4
- export interface BaseWalletInterface {
5
- connect(onDisconnect: () => void): Promise<Wallet>;
6
- healthCheck(): Promise<Record<string, never>>;
7
- disconnect(): Promise<void>;
8
- reconnect(onDisconnect: () => void): Promise<Wallet | null>;
9
- decodeTransaction(txn: string, isSigned: boolean): _algosdk.Transaction;
10
- logEncodedTransaction(txn: string, isSigned: boolean): void;
11
- groupTransactionsBySender(transactions: TransactionsArray): Record<string, TxnInfo[]>;
12
- signTransactions(connectedAccounts: string[], transactions: Array<Uint8Array>): Promise<Uint8Array[]>;
13
- signEncodedTransactions(transactions: TransactionsArray): Promise<Uint8Array[]>;
14
- sendRawTransactions(transactions: Uint8Array[], waitRoundsToConfirm?: number): Promise<ConfirmedTxn & {
15
- id: string;
16
- }>;
17
- getAccountInfo(address: string): Promise<AccountInfo>;
18
- getAssets(address: string): Promise<Asset[]>;
19
- waitForConfirmation(txId: string, timeout?: number): Promise<ConfirmedTxn>;
20
- }
21
- declare abstract class BaseWallet implements BaseWalletInterface {
2
+ import { PROVIDER_ID } from "../../constants";
3
+ import type { Asset, Wallet, AccountInfo, TransactionsArray } from "../../types";
4
+ declare abstract class BaseClient {
22
5
  algosdk: typeof _algosdk;
23
6
  algodClient: _algosdk.Algodv2;
24
7
  keepWCAlive: HTMLAudioElement;
25
- protected abstract id: PROVIDER_ID;
26
- protected abstract provider: WalletProvider;
8
+ static metadata: {
9
+ id: PROVIDER_ID;
10
+ name: string;
11
+ icon: string;
12
+ isWalletConnect: boolean;
13
+ };
27
14
  abstract connect(onDisconnect: () => void): Promise<Wallet>;
28
15
  abstract disconnect(): Promise<void>;
29
16
  abstract reconnect(onDisconnect: () => void): Promise<Wallet | null>;
@@ -39,7 +26,7 @@ declare abstract class BaseWallet implements BaseWalletInterface {
39
26
  "pool-error": string;
40
27
  txn: {
41
28
  sig: Uint8Array;
42
- txn: import("../types").Txn;
29
+ txn: import("../../types").Txn;
43
30
  };
44
31
  txId: string;
45
32
  }>;
@@ -52,7 +39,7 @@ declare abstract class BaseWallet implements BaseWalletInterface {
52
39
  "pool-error": string;
53
40
  txn: {
54
41
  sig: Uint8Array;
55
- txn: import("../types").Txn;
42
+ txn: import("../../types").Txn;
56
43
  };
57
44
  txId: string;
58
45
  id: any;
@@ -60,4 +47,4 @@ declare abstract class BaseWallet implements BaseWalletInterface {
60
47
  keepWCAliveStart(): void;
61
48
  keepWCAliveStop(): void;
62
49
  }
63
- export default BaseWallet;
50
+ export default BaseClient;
@@ -0,0 +1,2 @@
1
+ import baseClient from "./base";
2
+ export default baseClient;
@@ -0,0 +1,37 @@
1
+ import type { Wallet } from "../../types";
2
+ import { PROVIDER_ID } from "../../constants";
3
+ import BaseWallet from "../base";
4
+ import { TransactionsArray } from "../../types";
5
+ import type { Network } from "../../types";
6
+ import { DeflyTransaction, InitParams, DeflyWalletClientConstructor } from "./types";
7
+ declare class DeflyWalletClient extends BaseWallet {
8
+ #private;
9
+ network: Network;
10
+ constructor({ client, algosdk, algodClient, network, }: DeflyWalletClientConstructor);
11
+ static metadata: {
12
+ id: PROVIDER_ID;
13
+ name: string;
14
+ icon: string;
15
+ isWalletConnect: boolean;
16
+ };
17
+ static init({ clientOptions, algodOptions, clientStatic, algosdkStatic, network, }: InitParams): Promise<DeflyWalletClient | null>;
18
+ connect(onDisconnect: () => void): Promise<Wallet>;
19
+ reconnect(onDisconnect: () => void): Promise<{
20
+ accounts: {
21
+ name: string;
22
+ address: string;
23
+ providerId: PROVIDER_ID;
24
+ }[];
25
+ id: PROVIDER_ID;
26
+ name: string;
27
+ icon: string;
28
+ isWalletConnect: boolean;
29
+ } | null>;
30
+ disconnect(): Promise<void>;
31
+ signTransactions(connectedAccounts: string[], transactions: Uint8Array[]): Promise<Uint8Array[]>;
32
+ /** @deprecated */
33
+ signEncodedTransactions(transactions: TransactionsArray): Promise<Uint8Array[]>;
34
+ /** @deprecated */
35
+ formatTransactionsArray(transactions: TransactionsArray): DeflyTransaction[];
36
+ }
37
+ export default DeflyWalletClient;
@@ -0,0 +1 @@
1
+ export declare const ICON: string;
@@ -0,0 +1,2 @@
1
+ import defly from "./client";
2
+ export default defly;