@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.
@@ -2,7 +2,7 @@ import type { Account } from "../../types";
2
2
  import { PROVIDER_ID } from "../../constants";
3
3
  export declare const walletStoreSelector: (state: WalletStore) => {
4
4
  accounts: Account[];
5
- activeAccount: Account | null;
5
+ activeAccount: Account | null | undefined;
6
6
  setActiveAccount: (account: Account) => void;
7
7
  clearActiveAccount: (id: PROVIDER_ID) => void;
8
8
  addAccounts: (accounts: Account[]) => void;
@@ -10,7 +10,7 @@ export declare const walletStoreSelector: (state: WalletStore) => {
10
10
  };
11
11
  export declare type WalletStore = {
12
12
  accounts: Account[];
13
- activeAccount: Account | null;
13
+ activeAccount: Account | null | undefined;
14
14
  setActiveAccount: (account: Account) => void;
15
15
  clearActiveAccount: (id: PROVIDER_ID) => void;
16
16
  addAccounts: (accounts: Account[]) => void;
@@ -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/esm/index.js CHANGED
@@ -886,7 +886,7 @@ const walletStoreSelector = (state) => ({
886
886
  });
887
887
  const emptyState = {
888
888
  accounts: [],
889
- activeAccount: null,
889
+ activeAccount: undefined,
890
890
  setActiveAccount: (account) => { },
891
891
  clearActiveAccount: (id) => { },
892
892
  addAccounts: (accounts) => { },
@@ -2281,6 +2281,27 @@ function useWallet() {
2281
2281
  throw new Error("Client not found for ID");
2282
2282
  return client;
2283
2283
  };
2284
+ const status = useMemo(() => {
2285
+ if (activeAccount === undefined) {
2286
+ return "initializing";
2287
+ }
2288
+ if (activeAccount === null && connectedAccounts.length) {
2289
+ return "connected";
2290
+ }
2291
+ if (activeAccount === null && !connectedAccounts.length) {
2292
+ return "disconnected";
2293
+ }
2294
+ if (activeAccount && activeAccount.address) {
2295
+ return "active";
2296
+ }
2297
+ return "error";
2298
+ }, [activeAccount]);
2299
+ const isActive = useMemo(() => {
2300
+ return status === "active";
2301
+ }, [status]);
2302
+ const isReady = useMemo(() => {
2303
+ return status !== "initializing";
2304
+ }, [status]);
2284
2305
  const selectActiveAccount = async (providerId, address) => {
2285
2306
  try {
2286
2307
  const account = connectedActiveAccounts.find((acct) => acct.address === address && acct.providerId === providerId);
@@ -2394,6 +2415,9 @@ function useWallet() {
2394
2415
  connectedActiveAccounts,
2395
2416
  activeAccount,
2396
2417
  activeAddress: activeAccount?.address,
2418
+ status,
2419
+ isActive,
2420
+ isReady,
2397
2421
  signer,
2398
2422
  signTransactions,
2399
2423
  sendTransactions,
@@ -2,7 +2,7 @@ import type { Account } from "../../types";
2
2
  import { PROVIDER_ID } from "../../constants";
3
3
  export declare const walletStoreSelector: (state: WalletStore) => {
4
4
  accounts: Account[];
5
- activeAccount: Account | null;
5
+ activeAccount: Account | null | undefined;
6
6
  setActiveAccount: (account: Account) => void;
7
7
  clearActiveAccount: (id: PROVIDER_ID) => void;
8
8
  addAccounts: (accounts: Account[]) => void;
@@ -10,7 +10,7 @@ export declare const walletStoreSelector: (state: WalletStore) => {
10
10
  };
11
11
  export declare type WalletStore = {
12
12
  accounts: Account[];
13
- activeAccount: Account | null;
13
+ activeAccount: Account | null | undefined;
14
14
  setActiveAccount: (account: Account) => void;
15
15
  clearActiveAccount: (id: PROVIDER_ID) => void;
16
16
  addAccounts: (accounts: Account[]) => void;
package/dist/index.d.ts CHANGED
@@ -180,8 +180,11 @@ declare function useWallet(): {
180
180
  providers: Provider[] | null;
181
181
  connectedAccounts: Account[];
182
182
  connectedActiveAccounts: Account[];
183
- activeAccount: Account | null;
183
+ activeAccount: Account | null | undefined;
184
184
  activeAddress: string | undefined;
185
+ status: string;
186
+ isActive: boolean;
187
+ isReady: boolean;
185
188
  signer: _algosdk.TransactionSigner;
186
189
  signTransactions: (transactions: Array<Uint8Array>, indexesToSign?: number[], returnGroup?: boolean) => Promise<Uint8Array[]>;
187
190
  sendTransactions: (transactions: Uint8Array[], waitRoundsToConfirm?: number) => Promise<{
package/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "url": "https://github.com/txnlab/use-wallet/issues"
13
13
  },
14
14
  "homepage": "https://txnlab.github.io/use-wallet",
15
- "version": "1.0.5",
15
+ "version": "1.1.5",
16
16
  "description": "React hooks for using Algorand compatible wallets in dApps.",
17
17
  "scripts": {
18
18
  "dev": "yarn storybook",