@txnlab/use-wallet 1.0.5 → 1.1.6

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
@@ -258,6 +258,26 @@ export default function Account() {
258
258
  }
259
259
  ```
260
260
 
261
+ ### Check connection status
262
+
263
+ The `isActive` and `isReady` properties can be used to check the status of the wallets. The `isActive` property determines whether or not an account is currently active. The `isReady` property shows if `use-wallet` has mounted and successfully read the connection status from the providers. These properties are useful when setting up client side access restrictions, for example, by redirecting a user if no wallet is active, as shown below.
264
+
265
+ ```jsx
266
+ const { isActive, isReady } = useWallet()
267
+
268
+ useEffect(() => {
269
+ if (isReady && isActive) {
270
+ allowAccess()
271
+ }
272
+
273
+ if (isReady && !isActive) {
274
+ denyAccess()
275
+ }
276
+ })
277
+
278
+ ```
279
+
280
+
261
281
  ## Provider Configuration
262
282
 
263
283
  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.
@@ -462,6 +482,7 @@ yarn link react
462
482
  Are you using `@txnlab/use-wallet`? We'd love to include you here. Let us know! [Twitter](https://twitter.com/NFDomains) | [Discord](https://discord.gg/7XcuMTfeZP) | [Email](mailto:admin@txnlab.dev)
463
483
 
464
484
  * [@algoscan/use-wallet-ui](https://github.com/algoscan/use-wallet-ui)
485
+ * [@algoworldnft/algoworld-swapper](https://github.com/algoworldnft/algoworld-swapper)
465
486
 
466
487
  ## License
467
488
 
@@ -14,8 +14,11 @@ export default function useWallet(): {
14
14
  providers: Provider[] | null;
15
15
  connectedAccounts: import("../types").Account[];
16
16
  connectedActiveAccounts: import("../types").Account[];
17
- activeAccount: import("../types").Account | null;
17
+ activeAccount: import("../types").Account | null | undefined;
18
18
  activeAddress: string | undefined;
19
+ status: string;
20
+ isActive: boolean;
21
+ isReady: boolean;
19
22
  signer: algosdk.TransactionSigner;
20
23
  signTransactions: (transactions: Array<Uint8Array>, indexesToSign?: number[], returnGroup?: boolean) => Promise<Uint8Array[]>;
21
24
  sendTransactions: (transactions: Uint8Array[], waitRoundsToConfirm?: number) => Promise<{
package/dist/cjs/index.js CHANGED
@@ -888,7 +888,7 @@ const walletStoreSelector = (state) => ({
888
888
  });
889
889
  const emptyState = {
890
890
  accounts: [],
891
- activeAccount: null,
891
+ activeAccount: undefined,
892
892
  setActiveAccount: (account) => { },
893
893
  clearActiveAccount: (id) => { },
894
894
  addAccounts: (accounts) => { },
@@ -1582,7 +1582,8 @@ class ExodusClient extends BaseClient {
1582
1582
  });
1583
1583
  }
1584
1584
  catch (e) {
1585
- console.error("Error initializing...", e);
1585
+ console.warn(e);
1586
+ console.warn(`Error initializing ${ExodusClient.metadata.name}.`, "Do you have the extension installed?", "https://www.exodus.com/web3-wallet");
1586
1587
  return null;
1587
1588
  }
1588
1589
  }
@@ -1731,7 +1732,8 @@ class AlgoSignerClient extends BaseClient {
1731
1732
  });
1732
1733
  }
1733
1734
  catch (e) {
1734
- console.error("Error initializing...", e);
1735
+ console.warn(e);
1736
+ console.warn(`Error initializing ${AlgoSignerClient.metadata.name}.`, "Do you have the extension installed?", "https://www.purestake.com/technology/algosigner");
1735
1737
  return null;
1736
1738
  }
1737
1739
  }
@@ -2283,6 +2285,27 @@ function useWallet() {
2283
2285
  throw new Error("Client not found for ID");
2284
2286
  return client;
2285
2287
  };
2288
+ const status = require$$0.useMemo(() => {
2289
+ if (activeAccount === undefined) {
2290
+ return "initializing";
2291
+ }
2292
+ if (activeAccount === null && connectedAccounts.length) {
2293
+ return "connected";
2294
+ }
2295
+ if (activeAccount === null && !connectedAccounts.length) {
2296
+ return "disconnected";
2297
+ }
2298
+ if (activeAccount && activeAccount.address) {
2299
+ return "active";
2300
+ }
2301
+ return "error";
2302
+ }, [activeAccount]);
2303
+ const isActive = require$$0.useMemo(() => {
2304
+ return status === "active";
2305
+ }, [status]);
2306
+ const isReady = require$$0.useMemo(() => {
2307
+ return status !== "initializing";
2308
+ }, [status]);
2286
2309
  const selectActiveAccount = async (providerId, address) => {
2287
2310
  try {
2288
2311
  const account = connectedActiveAccounts.find((acct) => acct.address === address && acct.providerId === providerId);
@@ -2396,6 +2419,9 @@ function useWallet() {
2396
2419
  connectedActiveAccounts,
2397
2420
  activeAccount,
2398
2421
  activeAddress: activeAccount?.address,
2422
+ status,
2423
+ isActive,
2424
+ isReady,
2399
2425
  signer,
2400
2426
  signTransactions,
2401
2427
  sendTransactions,