@txnlab/use-wallet 1.0.5 → 1.1.5

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) => { },
@@ -2283,6 +2283,27 @@ function useWallet() {
2283
2283
  throw new Error("Client not found for ID");
2284
2284
  return client;
2285
2285
  };
2286
+ const status = require$$0.useMemo(() => {
2287
+ if (activeAccount === undefined) {
2288
+ return "initializing";
2289
+ }
2290
+ if (activeAccount === null && connectedAccounts.length) {
2291
+ return "connected";
2292
+ }
2293
+ if (activeAccount === null && !connectedAccounts.length) {
2294
+ return "disconnected";
2295
+ }
2296
+ if (activeAccount && activeAccount.address) {
2297
+ return "active";
2298
+ }
2299
+ return "error";
2300
+ }, [activeAccount]);
2301
+ const isActive = require$$0.useMemo(() => {
2302
+ return status === "active";
2303
+ }, [status]);
2304
+ const isReady = require$$0.useMemo(() => {
2305
+ return status !== "initializing";
2306
+ }, [status]);
2286
2307
  const selectActiveAccount = async (providerId, address) => {
2287
2308
  try {
2288
2309
  const account = connectedActiveAccounts.find((acct) => acct.address === address && acct.providerId === providerId);
@@ -2396,6 +2417,9 @@ function useWallet() {
2396
2417
  connectedActiveAccounts,
2397
2418
  activeAccount,
2398
2419
  activeAddress: activeAccount?.address,
2420
+ status,
2421
+ isActive,
2422
+ isReady,
2399
2423
  signer,
2400
2424
  signTransactions,
2401
2425
  sendTransactions,