btc-wallet 0.5.31-beta → 0.5.33-beta

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,10 +5,10 @@ export declare function BtcWalletSelectorContextProvider({ children, }: {
5
5
  }): import("react/jsx-runtime").JSX.Element;
6
6
  export declare function useBtcWalletSelector(): {
7
7
  login: () => Promise<string | null>;
8
- autoConnect: () => Promise<void>;
8
+ autoConnect: () => Promise<any>;
9
9
  logout: () => void;
10
10
  account: string;
11
- getPublicKey: () => any;
11
+ getPublicKey: () => Promise<string | undefined>;
12
12
  signMessage: (msg: string) => any;
13
13
  getContext: () => any;
14
14
  getNetwork: () => Promise<"livenet" | "testnet">;
package/dist/index.js CHANGED
@@ -2792,7 +2792,8 @@ function useBtcWalletSelector() {
2792
2792
  }, [signMessage]);
2793
2793
  (0, import_react11.useEffect)(() => {
2794
2794
  const fn = (account) => {
2795
- if (account) {
2795
+ console.log("accountsChanged account", account);
2796
+ if (account == null ? void 0 : account.length) {
2796
2797
  getPublicKey().then((res) => {
2797
2798
  publicKey.current = res;
2798
2799
  context.emit("updatePublicKey", res);
@@ -2841,7 +2842,7 @@ function useBtcWalletSelector() {
2841
2842
  return account;
2842
2843
  }),
2843
2844
  autoConnect: () => __async(this, null, function* () {
2844
- requestDirectAccount(connectorRef.current).catch((e) => {
2845
+ return requestDirectAccount(connectorRef.current).catch((e) => {
2845
2846
  console.error("btcLoginError", e);
2846
2847
  context.emit("btcLoginError");
2847
2848
  });
@@ -2854,9 +2855,21 @@ function useBtcWalletSelector() {
2854
2855
  context.emit("btcLogOut");
2855
2856
  },
2856
2857
  account: accounts == null ? void 0 : accounts[0],
2857
- getPublicKey: () => {
2858
- return publicKey.current;
2859
- },
2858
+ getPublicKey: () => __async(this, null, function* () {
2859
+ const publicKey2 = yield getPublicKey();
2860
+ if (publicKey2)
2861
+ return publicKey2;
2862
+ if (connectModalOpen)
2863
+ return;
2864
+ try {
2865
+ yield requestDirectAccount(connectorRef.current);
2866
+ return yield getPublicKey();
2867
+ } catch (error) {
2868
+ console.error("btcLoginError", error);
2869
+ context.emit("btcLoginError");
2870
+ return;
2871
+ }
2872
+ }),
2860
2873
  signMessage: (msg) => {
2861
2874
  return signMessageFn.current(msg);
2862
2875
  },
@@ -2872,10 +2885,12 @@ function useBtcWalletSelector() {
2872
2885
  getNetwork2,
2873
2886
  switchNetwork,
2874
2887
  sendBitcoin2,
2888
+ connectModalOpen,
2875
2889
  openConnectModal,
2876
- requestDirectAccount,
2877
2890
  context,
2878
- disconnect
2891
+ requestDirectAccount,
2892
+ disconnect,
2893
+ getPublicKey
2879
2894
  ]);
2880
2895
  return hook;
2881
2896
  }
@@ -4183,7 +4198,14 @@ function getWithdrawTransaction(_0) {
4183
4198
  env = "mainnet"
4184
4199
  }) {
4185
4200
  const config = getWalletConfig(env);
4186
- const _btcAddress = btcAddress || getBtcProvider().account;
4201
+ let _btcAddress = btcAddress || getBtcProvider().account;
4202
+ if (!_btcAddress) {
4203
+ yield getBtcProvider().autoConnect();
4204
+ _btcAddress = getBtcProvider().account;
4205
+ if (!_btcAddress) {
4206
+ throw new Error("BTC Account is not available.");
4207
+ }
4208
+ }
4187
4209
  const _csna = csna || (yield getCsnaAccountId(env));
4188
4210
  const { inputs, outputs, isError, errorMsg, fromAmount, gasFee } = yield calculateWithdraw({
4189
4211
  amount,
@@ -4606,7 +4628,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
4606
4628
  });
4607
4629
  const context = window.btcContext.getContext();
4608
4630
  context.on("updatePublicKey", (btcPublicKey) => __async(this, null, function* () {
4609
- console.log("updatePublicKey");
4610
4631
  state_default.clear();
4611
4632
  console.log("updatePublicKey clear");
4612
4633
  try {
@@ -4905,7 +4926,7 @@ function getGroup(state) {
4905
4926
 
4906
4927
  // src/index.ts
4907
4928
  var getVersion = () => {
4908
- return "0.5.31-beta";
4929
+ return "0.5.33-beta";
4909
4930
  };
4910
4931
  if (typeof window !== "undefined") {
4911
4932
  window.__BTC_WALLET_VERSION = getVersion();