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.
@@ -1,8 +1,8 @@
1
1
  import type { Wallet } from '@near-wallet-selector/core';
2
2
  import { type ENV } from '../config';
3
3
  interface OriginalWallet {
4
- account: string | null;
5
- getPublicKey: () => Promise<string>;
4
+ account: string | undefined;
5
+ getPublicKey: () => Promise<string | undefined>;
6
6
  }
7
7
  export declare function setupWalletButton(env: ENV, wallet: Wallet, originalWallet: OriginalWallet): void;
8
8
  export declare function removeWalletButton(): void;
package/esm/index.js CHANGED
@@ -2723,7 +2723,8 @@ function useBtcWalletSelector() {
2723
2723
  }, [signMessage]);
2724
2724
  useEffect6(() => {
2725
2725
  const fn = (account) => {
2726
- if (account) {
2726
+ console.log("accountsChanged account", account);
2727
+ if (account == null ? void 0 : account.length) {
2727
2728
  getPublicKey().then((res) => {
2728
2729
  publicKey.current = res;
2729
2730
  context.emit("updatePublicKey", res);
@@ -2772,7 +2773,7 @@ function useBtcWalletSelector() {
2772
2773
  return account;
2773
2774
  }),
2774
2775
  autoConnect: () => __async(this, null, function* () {
2775
- requestDirectAccount(connectorRef.current).catch((e) => {
2776
+ return requestDirectAccount(connectorRef.current).catch((e) => {
2776
2777
  console.error("btcLoginError", e);
2777
2778
  context.emit("btcLoginError");
2778
2779
  });
@@ -2785,9 +2786,21 @@ function useBtcWalletSelector() {
2785
2786
  context.emit("btcLogOut");
2786
2787
  },
2787
2788
  account: accounts == null ? void 0 : accounts[0],
2788
- getPublicKey: () => {
2789
- return publicKey.current;
2790
- },
2789
+ getPublicKey: () => __async(this, null, function* () {
2790
+ const publicKey2 = yield getPublicKey();
2791
+ if (publicKey2)
2792
+ return publicKey2;
2793
+ if (connectModalOpen)
2794
+ return;
2795
+ try {
2796
+ yield requestDirectAccount(connectorRef.current);
2797
+ return yield getPublicKey();
2798
+ } catch (error) {
2799
+ console.error("btcLoginError", error);
2800
+ context.emit("btcLoginError");
2801
+ return;
2802
+ }
2803
+ }),
2791
2804
  signMessage: (msg) => {
2792
2805
  return signMessageFn.current(msg);
2793
2806
  },
@@ -2803,10 +2816,12 @@ function useBtcWalletSelector() {
2803
2816
  getNetwork2,
2804
2817
  switchNetwork,
2805
2818
  sendBitcoin2,
2819
+ connectModalOpen,
2806
2820
  openConnectModal,
2807
- requestDirectAccount,
2808
2821
  context,
2809
- disconnect
2822
+ requestDirectAccount,
2823
+ disconnect,
2824
+ getPublicKey
2810
2825
  ]);
2811
2826
  return hook;
2812
2827
  }
@@ -4114,7 +4129,14 @@ function getWithdrawTransaction(_0) {
4114
4129
  env = "mainnet"
4115
4130
  }) {
4116
4131
  const config = getWalletConfig(env);
4117
- const _btcAddress = btcAddress || getBtcProvider().account;
4132
+ let _btcAddress = btcAddress || getBtcProvider().account;
4133
+ if (!_btcAddress) {
4134
+ yield getBtcProvider().autoConnect();
4135
+ _btcAddress = getBtcProvider().account;
4136
+ if (!_btcAddress) {
4137
+ throw new Error("BTC Account is not available.");
4138
+ }
4139
+ }
4118
4140
  const _csna = csna || (yield getCsnaAccountId(env));
4119
4141
  const { inputs, outputs, isError, errorMsg, fromAmount, gasFee } = yield calculateWithdraw({
4120
4142
  amount,
@@ -4537,7 +4559,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
4537
4559
  });
4538
4560
  const context = window.btcContext.getContext();
4539
4561
  context.on("updatePublicKey", (btcPublicKey) => __async(this, null, function* () {
4540
- console.log("updatePublicKey");
4541
4562
  state_default.clear();
4542
4563
  console.log("updatePublicKey clear");
4543
4564
  try {
@@ -4838,7 +4859,7 @@ function getGroup(state) {
4838
4859
 
4839
4860
  // src/index.ts
4840
4861
  var getVersion = () => {
4841
- return "0.5.31-beta";
4862
+ return "0.5.33-beta";
4842
4863
  };
4843
4864
  if (typeof window !== "undefined") {
4844
4865
  window.__BTC_WALLET_VERSION = getVersion();