@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/cjs/index.js CHANGED
@@ -520,9 +520,11 @@ exports.PROVIDER_ID = void 0;
520
520
  PROVIDER_ID["DEFLY"] = "Defly";
521
521
  PROVIDER_ID["EXODUS"] = "Exodus";
522
522
  })(exports.PROVIDER_ID || (exports.PROVIDER_ID = {}));
523
- const NODE_SERVER = "https://mainnet-api.algonode.cloud";
524
- const NODE_TOKEN = "";
525
- const NODE_PORT = "";
523
+ const NODE_SERVER = process.env.REACT_APP_NODE_URL ||
524
+ process.env.NEXT_PUBLIC_NODE_URL ||
525
+ "https://mainnet-api.algonode.cloud";
526
+ const NODE_TOKEN = process.env.REACT_APP_NODE_TOKEN || process.env.NEXT_PUBLIC_NODE_TOKEN || "";
527
+ const NODE_PORT = process.env.REACT_APP_NODE_PORT || process.env.NEXT_PUBLIC_NODE_PORT || "";
526
528
 
527
529
  /*
528
530
  * big.js v6.2.1
@@ -3649,32 +3651,55 @@ function useConnectWallet() {
3649
3651
  }
3650
3652
  };
3651
3653
  const connect = async (id) => {
3652
- await disconnectWCSessions(id);
3653
- const walletClient = await getWalletClient(id);
3654
- const walletInfo = await walletClient.connect(() => disconnect(id));
3655
- if (!walletInfo || !walletInfo.accounts.length) {
3656
- throw new Error("Failed to connect " + id);
3654
+ try {
3655
+ await disconnectWCSessions(id);
3656
+ const walletClient = await getWalletClient(id);
3657
+ const walletInfo = await walletClient.connect(() => disconnect(id));
3658
+ if (!walletInfo || !walletInfo.accounts.length) {
3659
+ throw new Error("Failed to connect " + id);
3660
+ }
3661
+ setActiveAccount(walletInfo.accounts[0]);
3662
+ addAccounts(walletInfo.accounts);
3663
+ }
3664
+ catch (e) {
3665
+ console.error(e);
3657
3666
  }
3658
- setActiveAccount(walletInfo.accounts[0]);
3659
- addAccounts(walletInfo.accounts);
3660
3667
  };
3661
3668
  const setActive = async (id) => {
3662
- await disconnectWCSessions(id);
3663
- const accounts = getAccountsByProvider(id);
3664
- setActiveAccount(accounts[0]);
3669
+ try {
3670
+ await disconnectWCSessions(id);
3671
+ const accounts = getAccountsByProvider(id);
3672
+ setActiveAccount(accounts[0]);
3673
+ }
3674
+ catch (e) {
3675
+ console.error(e);
3676
+ }
3665
3677
  };
3666
3678
  const reconnect = async (id) => {
3667
- const walletClient = await getWalletClient(id);
3668
- const walletInfo = await walletClient?.reconnect(() => disconnect(id));
3669
- if (walletInfo && walletInfo.accounts.length) {
3670
- addAccounts(walletInfo.accounts);
3679
+ try {
3680
+ const walletClient = await getWalletClient(id);
3681
+ const walletInfo = await walletClient?.reconnect(() => disconnect(id));
3682
+ if (walletInfo && walletInfo.accounts.length) {
3683
+ addAccounts(walletInfo.accounts);
3684
+ }
3685
+ }
3686
+ catch (e) {
3687
+ console.error(e);
3688
+ disconnect(id);
3671
3689
  }
3672
3690
  };
3673
3691
  const disconnect = async (id) => {
3674
- const walletClient = await getWalletClient(id);
3675
- walletClient?.disconnect();
3676
- clearActiveAccount(id);
3677
- removeAccounts(id);
3692
+ try {
3693
+ const walletClient = await getWalletClient(id);
3694
+ walletClient?.disconnect();
3695
+ }
3696
+ catch (e) {
3697
+ console.error(e);
3698
+ }
3699
+ finally {
3700
+ clearActiveAccount(id);
3701
+ removeAccounts(id);
3702
+ }
3678
3703
  };
3679
3704
  return {
3680
3705
  providers: providers$1,