@txnlab/use-wallet 0.0.9 → 0.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.
@@ -5,6 +5,6 @@ export declare enum PROVIDER_ID {
5
5
  DEFLY = "Defly",
6
6
  EXODUS = "Exodus"
7
7
  }
8
- export declare const NODE_SERVER = "https://mainnet-api.algonode.cloud";
9
- export declare const NODE_TOKEN = "";
10
- export declare const NODE_PORT = "";
8
+ export declare const NODE_SERVER: string;
9
+ export declare const NODE_TOKEN: string;
10
+ export declare const NODE_PORT: string;
package/dist/esm/index.js CHANGED
@@ -494,9 +494,11 @@ var PROVIDER_ID;
494
494
  PROVIDER_ID["DEFLY"] = "Defly";
495
495
  PROVIDER_ID["EXODUS"] = "Exodus";
496
496
  })(PROVIDER_ID || (PROVIDER_ID = {}));
497
- const NODE_SERVER = "https://mainnet-api.algonode.cloud";
498
- const NODE_TOKEN = "";
499
- const NODE_PORT = "";
497
+ const NODE_SERVER = process.env.REACT_APP_NODE_URL ||
498
+ process.env.NEXT_PUBLIC_NODE_URL ||
499
+ "https://mainnet-api.algonode.cloud";
500
+ const NODE_TOKEN = process.env.REACT_APP_NODE_TOKEN || process.env.NEXT_PUBLIC_NODE_TOKEN || "";
501
+ const NODE_PORT = process.env.REACT_APP_NODE_PORT || process.env.NEXT_PUBLIC_NODE_PORT || "";
500
502
 
501
503
  /*
502
504
  * big.js v6.2.1
@@ -3623,32 +3625,55 @@ function useConnectWallet() {
3623
3625
  }
3624
3626
  };
3625
3627
  const connect = async (id) => {
3626
- await disconnectWCSessions(id);
3627
- const walletClient = await getWalletClient(id);
3628
- const walletInfo = await walletClient.connect(() => disconnect(id));
3629
- if (!walletInfo || !walletInfo.accounts.length) {
3630
- throw new Error("Failed to connect " + id);
3628
+ try {
3629
+ await disconnectWCSessions(id);
3630
+ const walletClient = await getWalletClient(id);
3631
+ const walletInfo = await walletClient.connect(() => disconnect(id));
3632
+ if (!walletInfo || !walletInfo.accounts.length) {
3633
+ throw new Error("Failed to connect " + id);
3634
+ }
3635
+ setActiveAccount(walletInfo.accounts[0]);
3636
+ addAccounts(walletInfo.accounts);
3637
+ }
3638
+ catch (e) {
3639
+ console.error(e);
3631
3640
  }
3632
- setActiveAccount(walletInfo.accounts[0]);
3633
- addAccounts(walletInfo.accounts);
3634
3641
  };
3635
3642
  const setActive = async (id) => {
3636
- await disconnectWCSessions(id);
3637
- const accounts = getAccountsByProvider(id);
3638
- setActiveAccount(accounts[0]);
3643
+ try {
3644
+ await disconnectWCSessions(id);
3645
+ const accounts = getAccountsByProvider(id);
3646
+ setActiveAccount(accounts[0]);
3647
+ }
3648
+ catch (e) {
3649
+ console.error(e);
3650
+ }
3639
3651
  };
3640
3652
  const reconnect = async (id) => {
3641
- const walletClient = await getWalletClient(id);
3642
- const walletInfo = await walletClient?.reconnect(() => disconnect(id));
3643
- if (walletInfo && walletInfo.accounts.length) {
3644
- addAccounts(walletInfo.accounts);
3653
+ try {
3654
+ const walletClient = await getWalletClient(id);
3655
+ const walletInfo = await walletClient?.reconnect(() => disconnect(id));
3656
+ if (walletInfo && walletInfo.accounts.length) {
3657
+ addAccounts(walletInfo.accounts);
3658
+ }
3659
+ }
3660
+ catch (e) {
3661
+ console.error(e);
3662
+ disconnect(id);
3645
3663
  }
3646
3664
  };
3647
3665
  const disconnect = async (id) => {
3648
- const walletClient = await getWalletClient(id);
3649
- walletClient?.disconnect();
3650
- clearActiveAccount(id);
3651
- removeAccounts(id);
3666
+ try {
3667
+ const walletClient = await getWalletClient(id);
3668
+ walletClient?.disconnect();
3669
+ }
3670
+ catch (e) {
3671
+ console.error(e);
3672
+ }
3673
+ finally {
3674
+ clearActiveAccount(id);
3675
+ removeAccounts(id);
3676
+ }
3652
3677
  };
3653
3678
  return {
3654
3679
  providers: providers$1,