btc-wallet 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,7 +12,7 @@ interface GlobalState {
12
12
  accounts: string[];
13
13
  provider: any;
14
14
  disconnect: () => void;
15
- requestDirectAccount: (connector: BaseConnector) => void;
15
+ requestDirectAccount: (connector: BaseConnector) => any;
16
16
  getPublicKey: () => Promise<string>;
17
17
  signMessage: (message: string) => Promise<string>;
18
18
  evmAccount?: string;
@@ -1,5 +1,5 @@
1
1
  export declare const useConnectModal: () => {
2
2
  openConnectModal: () => void;
3
3
  disconnect: () => void;
4
- requestDirectAccount: (connector: import("..").BaseConnector) => void;
4
+ requestDirectAccount: (connector: import("..").BaseConnector) => any;
5
5
  };
package/dist/index.js CHANGED
@@ -1980,6 +1980,7 @@ var ConnectProvider = ({
1980
1980
  accounts2 = yield connector2.requestAccounts();
1981
1981
  }
1982
1982
  setAccounts(accounts2);
1983
+ return accounts2;
1983
1984
  }),
1984
1985
  []
1985
1986
  );
@@ -2235,7 +2236,7 @@ function BtcWalletSelectorContextProvider({ children, autoConnect = false }) {
2235
2236
  visible: true
2236
2237
  }
2237
2238
  },
2238
- autoConnect,
2239
+ autoConnect: false,
2239
2240
  connectors: [new UnisatConnector()],
2240
2241
  children: [
2241
2242
  children,
@@ -2268,17 +2269,23 @@ function useBtcWalletSelector() {
2268
2269
  signMessageFn.current = signMessage;
2269
2270
  }, [signMessage]);
2270
2271
  (0, import_react12.useEffect)(() => {
2272
+ const fn = (account) => {
2273
+ if (account) {
2274
+ getPublicKey().then((res) => {
2275
+ publicKey.current = res;
2276
+ context.emit("updatePublicKey", res);
2277
+ });
2278
+ }
2279
+ };
2271
2280
  if (connector) {
2272
- connector.on("accountsChanged", (account) => {
2273
- if (account) {
2274
- getPublicKey().then((res) => {
2275
- publicKey.current = res;
2276
- context.emit("updatePublicKey", res);
2277
- });
2278
- }
2279
- });
2281
+ connector.on("accountsChanged", fn);
2280
2282
  }
2281
2283
  connectorRef.current = connector;
2284
+ return () => {
2285
+ if (connector) {
2286
+ connector.removeListener("accountsChanged", fn);
2287
+ }
2288
+ };
2282
2289
  }, [connector]);
2283
2290
  return {
2284
2291
  login: () => __async(this, null, function* () {
@@ -2296,7 +2303,9 @@ function useBtcWalletSelector() {
2296
2303
  return null;
2297
2304
  }
2298
2305
  }
2299
- yield requestDirectAccount(connectorRef.current);
2306
+ requestDirectAccount(connectorRef.current).catch((e) => {
2307
+ context.emit("btcLoginError");
2308
+ });
2300
2309
  }),
2301
2310
  logout: () => {
2302
2311
  disconnect && disconnect();
@@ -2402,6 +2411,7 @@ function createIframe({
2402
2411
  }) {
2403
2412
  const iframe = document.createElement("iframe");
2404
2413
  iframe.id = "satoshi-wallet-iframe";
2414
+ iframe.allow = "clipboard-read; clipboard-write";
2405
2415
  iframe.src = iframeUrl;
2406
2416
  Object.assign(iframe.style, __spreadValues({
2407
2417
  position: "fixed",
@@ -2555,7 +2565,13 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2555
2565
  ]
2556
2566
  });
2557
2567
  }));
2568
+ context.on("btcLoginError", (e) => __async(void 0, null, function* () {
2569
+ emitter.emit("accountsChanged", {
2570
+ accounts: []
2571
+ });
2572
+ }));
2558
2573
  if ("autoConnect" in metadata && metadata.autoConnect && localStorage.getItem("near-wallet-selector:selectedWalletId") === '"btc-wallet"') {
2574
+ btcContext.autoConnect();
2559
2575
  }
2560
2576
  clearInterval(inter);
2561
2577
  }
@@ -2711,7 +2727,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2711
2727
  const intention = {
2712
2728
  chain_id: "397",
2713
2729
  csna: accountId,
2714
- near_transactions: newTransactions.map((t) => Array.from(t.txBytes)),
2730
+ near_transactions: newTransactions.map((t) => Array.from(t.txHex)),
2715
2731
  gas_token: token,
2716
2732
  gas_limit: "3000",
2717
2733
  nonce: Number(nonce).toString()
@@ -2854,7 +2870,7 @@ function pollTransactionStatuses(network, hashes) {
2854
2870
 
2855
2871
  // src/index.ts
2856
2872
  var getVersion = () => {
2857
- return "0.0.3";
2873
+ return "0.0.5";
2858
2874
  };
2859
2875
  if (typeof window !== "undefined") {
2860
2876
  window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();