btc-wallet 0.0.4 → 0.0.6

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.
@@ -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
  }
@@ -2698,7 +2714,8 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2698
2714
  (0, import_utils5.baseDecode)(header.hash)
2699
2715
  );
2700
2716
  const txBytes = (0, import_transaction.encodeTransaction)(_transaction);
2701
- const txHex = toHex(txBytes.toString());
2717
+ const txHex = Array.from(txBytes, (byte) => ("0" + (byte & 255).toString(16)).slice(-2)).join("");
2718
+ ;
2702
2719
  const hash = import_bs58.default.encode(new Uint8Array(import_js_sha256.sha256.array(txBytes)));
2703
2720
  return { txBytes, txHex, hash };
2704
2721
  });
@@ -2711,7 +2728,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2711
2728
  const intention = {
2712
2729
  chain_id: "397",
2713
2730
  csna: accountId,
2714
- near_transactions: newTransactions.map((t) => Array.from(t.txHex)),
2731
+ near_transactions: newTransactions.map((t) => t.txHex),
2715
2732
  gas_token: token,
2716
2733
  gas_limit: "3000",
2717
2734
  nonce: Number(nonce).toString()
@@ -2854,7 +2871,7 @@ function pollTransactionStatuses(network, hashes) {
2854
2871
 
2855
2872
  // src/index.ts
2856
2873
  var getVersion = () => {
2857
- return "0.0.4";
2874
+ return "0.0.6";
2858
2875
  };
2859
2876
  if (typeof window !== "undefined") {
2860
2877
  window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();