btc-wallet 0.1.7 → 0.1.9

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.
package/esm/index.js CHANGED
@@ -84,7 +84,6 @@ var InjectedConnector = class extends BaseConnector {
84
84
  requestAccounts() {
85
85
  return __async(this, null, function* () {
86
86
  const accounts = yield this.getProviderOrThrow().requestAccounts();
87
- console.log("\u{1F680} ~ InjectedConnector ~ requestAccounts ~ accounts:", accounts);
88
87
  return accounts;
89
88
  });
90
89
  }
@@ -650,7 +649,6 @@ var WalletClientProvider = class {
650
649
  }
651
650
  }
652
651
  if (method === "personal_sign" /* personalSign */) {
653
- console.log("personal_sign ---- ", arg);
654
652
  return new Promise((resolve, reject) => {
655
653
  eventUtils_default.emit("personalSign" /* personalSign */, arg);
656
654
  eventUtils_default.once("personalSignResult" /* personalSignResult */, ({ result, error }) => {
@@ -956,7 +954,6 @@ var ConnectModal = ({ open, onClose }) => {
956
954
  yield connect(connector.metadata.id);
957
955
  closeConnectModal();
958
956
  } catch (error) {
959
- console.error("onConnect error", error);
960
957
  if (error.code === 4001) {
961
958
  setRetryVisible(true);
962
959
  }
@@ -1499,13 +1496,10 @@ var SignModal = ({ open, onClose, onOpen }) => {
1499
1496
  }), [userOpBundle, smartAccount, accountContract]);
1500
1497
  useEffect4(() => {
1501
1498
  if (userOpBundle && open) {
1502
- console.log("deserializeUserOp start");
1503
1499
  setDeserializeLoading(true);
1504
1500
  deserializeUserOp().then((result) => {
1505
- console.log("\u{1F680} ~ deserializeUserOp ~ result:", result);
1506
1501
  setDeserializeResult(result);
1507
1502
  }).catch((error) => {
1508
- console.log("\u{1F680} ~ deserializeUserOp ~ error:", error);
1509
1503
  eventUtils_default.emit("sendUserOpResult" /* sendUserOpResult */, {
1510
1504
  error
1511
1505
  });
@@ -1516,7 +1510,6 @@ var SignModal = ({ open, onClose, onOpen }) => {
1516
1510
  useEffect4(() => {
1517
1511
  if (open && publicClient && evmAccount && userOpBundle) {
1518
1512
  publicClient.getBalance({ address: evmAccount }).then((result) => setNativeBalance(result)).catch((error) => {
1519
- console.log("\u{1F680} ~ getBalance ~ error:", error);
1520
1513
  eventUtils_default.emit("sendUserOpResult" /* sendUserOpResult */, {
1521
1514
  error
1522
1515
  });
@@ -1689,7 +1682,6 @@ var AASignerProvider = class {
1689
1682
  this.getPublicClient = () => {
1690
1683
  var _a, _b;
1691
1684
  const rpcUrl = ((_a = this == null ? void 0 : this.rpcUrls) == null ? void 0 : _a[this.chainId]) || ((_b = chains3.getEVMChainInfoById(this.chainId || 1)) == null ? void 0 : _b.rpcUrl);
1692
- console.log("rpcUrl", rpcUrl);
1693
1685
  return createPublicClient({
1694
1686
  transport: http(rpcUrl)
1695
1687
  });
@@ -1724,10 +1716,8 @@ var AASignerProvider = class {
1724
1716
  return `0x${this.chainId.toString(16)}`;
1725
1717
  } else if (arg.method === "personal_sign" /* personalSign */) {
1726
1718
  let message = (_a = arg.params) == null ? void 0 : _a[0];
1727
- console.log("personal_sign message:", message);
1728
1719
  if (message.length !== 66) {
1729
1720
  const hash = hashMessage({ raw: message });
1730
- console.log("personal_sign hash:", hash);
1731
1721
  message = hash;
1732
1722
  }
1733
1723
  const result = yield this.personalSign(message || "");
@@ -1735,19 +1725,15 @@ var AASignerProvider = class {
1735
1725
  if (!convertResult) {
1736
1726
  throw new Error("sign error");
1737
1727
  }
1738
- console.log(`personal_sign result(${convertResult.length}): `, convertResult);
1739
1728
  return convertResult;
1740
1729
  } else if (arg.method === "eth_signTypedData" || arg.method === "eth_signTypedData_v4") {
1741
1730
  const typedData = (_b = arg.params) == null ? void 0 : _b[1];
1742
- console.log("signTypedData typedData", typedData);
1743
1731
  const hash = hashTypedData(typeof typedData === "string" ? JSON.parse(typedData) : typedData);
1744
- console.log("signTypedData hash", hash);
1745
1732
  const result = yield this.personalSign(hash || "");
1746
1733
  const convertResult = convertSignature(result);
1747
1734
  if (!convertResult) {
1748
1735
  throw new Error("sign error");
1749
1736
  }
1750
- console.log(`eth_signTypedData result(${convertResult.length}): `, convertResult);
1751
1737
  return convertResult;
1752
1738
  } else if (arg.method === "wallet_switchEthereumChain") {
1753
1739
  if (arg.params && arg.params instanceof Array && arg.params[0] && arg.params[0].chainId) {
@@ -1919,7 +1905,6 @@ var ConnectProvider = ({
1919
1905
  setEVMAccount(res);
1920
1906
  }).catch((e) => {
1921
1907
  setEVMAccount(void 0);
1922
- console.error("smartAccount getAddress error", e);
1923
1908
  });
1924
1909
  } else {
1925
1910
  setEVMAccount(void 0);
@@ -1941,7 +1926,6 @@ var ConnectProvider = ({
1941
1926
  const requestAccount = useCallback7(
1942
1927
  (connector2) => __async(void 0, null, function* () {
1943
1928
  let accounts2 = yield connector2.getAccounts();
1944
- console.log("requestAccount start, autoConnect", accounts2, autoConnect);
1945
1929
  if (accounts2.length === 0 && autoConnect) {
1946
1930
  accounts2 = yield connector2.requestAccounts();
1947
1931
  }
@@ -1951,9 +1935,7 @@ var ConnectProvider = ({
1951
1935
  );
1952
1936
  const requestDirectAccount = useCallback7(
1953
1937
  (connector2) => __async(void 0, null, function* () {
1954
- console.log(111);
1955
1938
  let accounts2 = yield connector2.getAccounts();
1956
- console.log("requestAccount start, autoConnect", accounts2, autoConnect);
1957
1939
  if (accounts2.length === 0) {
1958
1940
  accounts2 = yield connector2.requestAccounts();
1959
1941
  }
@@ -1965,7 +1947,6 @@ var ConnectProvider = ({
1965
1947
  useEffect5(() => {
1966
1948
  if (connector) {
1967
1949
  requestAccount(connector).catch((e) => {
1968
- console.log("get account error", e);
1969
1950
  setAccounts([]);
1970
1951
  });
1971
1952
  } else {
@@ -2021,7 +2002,6 @@ var ConnectProvider = ({
2021
2002
  })
2022
2003
  })
2023
2004
  );
2024
- console.log("walletEntryPlugin init");
2025
2005
  }
2026
2006
  }, [options, evmSupportChainIds, accountContract]);
2027
2007
  useEffect5(() => {
@@ -2030,7 +2010,6 @@ var ConnectProvider = ({
2030
2010
  walletEntryPlugin.setWalletCore({
2031
2011
  ethereum: smartAccount.provider
2032
2012
  });
2033
- console.log("walletEntryPlugin setWalletCore");
2034
2013
  }
2035
2014
  }, [smartAccount, options]);
2036
2015
  useEffect5(() => {
@@ -2038,10 +2017,8 @@ var ConnectProvider = ({
2038
2017
  if (((_a2 = options.walletOptions) == null ? void 0 : _a2.visible) !== false) {
2039
2018
  if (evmAccount) {
2040
2019
  walletEntryPlugin.walletEntryCreate();
2041
- console.log("walletEntryPlugin walletEntryCreate");
2042
2020
  } else {
2043
2021
  walletEntryPlugin.walletEntryDestroy();
2044
- console.log("walletEntryPlugin walletEntryDestroy");
2045
2022
  }
2046
2023
  }
2047
2024
  }, [evmAccount, smartAccount, options]);
@@ -2340,7 +2317,6 @@ import { sha256 } from "js-sha256";
2340
2317
 
2341
2318
  // src/utils/initWalletButton.ts
2342
2319
  function setupWalletButton(network, wallet, originalWallet) {
2343
- console.log("setupWalletButton");
2344
2320
  if (document.getElementById("satoshi-wallet-button")) {
2345
2321
  return;
2346
2322
  }
@@ -2428,24 +2404,20 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
2428
2404
  const accountId = (_a = yield wallet == null ? void 0 : wallet.getAccounts()) == null ? void 0 : _a[0].accountId;
2429
2405
  const originalAccountId = originalWallet.account;
2430
2406
  const originalPublicKey = yield originalWallet.getPublicKey();
2431
- console.log({ accountId, originalAccountId, originalPublicKey });
2432
2407
  const iframeSrc = new URL(iframe.src);
2433
2408
  iframeSrc.searchParams.set("origin", window.location.origin);
2434
2409
  accountId && iframeSrc.searchParams.set("accountId", accountId);
2435
2410
  originalAccountId && iframeSrc.searchParams.set("originalAccountId", originalAccountId);
2436
2411
  originalPublicKey && iframeSrc.searchParams.set("originalPublicKey", originalPublicKey);
2437
2412
  iframe.src = iframeSrc.toString();
2438
- console.log("iframe src", iframe.src);
2439
2413
  window.addEventListener("message", (event) => __async(this, null, function* () {
2440
2414
  var _a2, _b;
2441
2415
  if (event.origin !== iframeSrc.origin)
2442
2416
  return;
2443
2417
  const { action, requestId, data } = event.data;
2444
2418
  if (action === "signAndSendTransaction") {
2445
- console.log("signAndSendTransaction message", event.data);
2446
2419
  try {
2447
2420
  const result = yield wallet.signAndSendTransaction(data);
2448
- console.log("signAndSendTransaction result", result);
2449
2421
  (_a2 = event.source) == null ? void 0 : _a2.postMessage(
2450
2422
  {
2451
2423
  requestId,
@@ -2455,7 +2427,6 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
2455
2427
  { targetOrigin: event.origin }
2456
2428
  );
2457
2429
  } catch (error) {
2458
- console.error("signAndSendTransaction error", error);
2459
2430
  (_b = event.source) == null ? void 0 : _b.postMessage(
2460
2431
  {
2461
2432
  requestId,
@@ -2551,13 +2522,12 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2551
2522
  if (!inter) {
2552
2523
  inter = setInterval(() => __async(void 0, null, function* () {
2553
2524
  const btcContext = window.btcContext;
2554
- console.log("inter btcContext:", btcContext);
2555
2525
  if (btcContext) {
2556
2526
  clearInterval(inter);
2557
2527
  const context = btcContext.getContext();
2558
2528
  context.on("updatePublicKey", (btcPublicKey) => __async(void 0, null, function* () {
2559
2529
  const { nearTempAddress } = yield getNearAccountByBtcPublicKey(btcPublicKey);
2560
- console.info("accountsChanged:", nearTempAddress, btcContext.account);
2530
+ initWalletButton(options.network.networkId, wallet);
2561
2531
  emitter.emit("accountsChanged", {
2562
2532
  accounts: [
2563
2533
  {
@@ -2571,7 +2541,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2571
2541
  accounts: []
2572
2542
  });
2573
2543
  }));
2574
- console.log("metadata.autoConnect:", metadata);
2575
2544
  if ("autoConnect" in metadata && metadata.autoConnect && localStorage.getItem("near-wallet-selector:selectedWalletId") === '"btc-wallet"') {
2576
2545
  yield btcContext.autoConnect();
2577
2546
  }
@@ -2612,10 +2581,10 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2612
2581
  }
2613
2582
  function signIn(_02) {
2614
2583
  return __async(this, arguments, function* ({ contractId, methodNames }) {
2615
- console.log(provider);
2616
2584
  const accountId = state.getAccount();
2617
2585
  const publicKey = state.getPublicKey();
2618
2586
  const btcContext = window.btcContext;
2587
+ initWalletButton(options.network.networkId, wallet);
2619
2588
  if (accountId && publicKey) {
2620
2589
  return [
2621
2590
  {
@@ -2718,7 +2687,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2718
2687
  txBytes,
2719
2688
  (byte) => ("0" + (byte & 255).toString(16)).slice(-2)
2720
2689
  ).join("");
2721
- console.log("txHex:", txHex);
2722
2690
  const hash = bs58.encode(new Uint8Array(sha256.array(txBytes)));
2723
2691
  return { txBytes, txHex, hash };
2724
2692
  });
@@ -2743,10 +2711,8 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2743
2711
  btcPubKey: state.getBtcPublicKey(),
2744
2712
  data: toHex(strIntention)
2745
2713
  });
2746
- console.log("result:", result);
2747
2714
  if (result.result_code === 0) {
2748
2715
  const hash = newTransactions.map((t) => t.hash);
2749
- console.log("txHash:", hash);
2750
2716
  const result2 = yield pollTransactionStatuses(options.network.networkId, hash);
2751
2717
  return result2;
2752
2718
  } else {
@@ -2756,16 +2722,14 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2756
2722
  }
2757
2723
  function initWalletButton(network, wallet2) {
2758
2724
  return __async(this, null, function* () {
2759
- console.log("initWalletButton:", network, wallet2);
2760
2725
  const checkAndSetupWalletButton = () => {
2761
2726
  const accountId = state.getAccount();
2762
2727
  const btcContext = window.btcContext;
2763
- console.log("checkAndSetupWalletButton:", accountId, btcContext.account);
2764
2728
  if (accountId && btcContext.account) {
2765
2729
  setupWalletButton(network, wallet2, btcContext);
2766
2730
  } else {
2767
2731
  removeWalletButton();
2768
- !btcContext.account && setTimeout(() => {
2732
+ setTimeout(() => {
2769
2733
  checkAndSetupWalletButton();
2770
2734
  }, 5e3);
2771
2735
  }
@@ -2860,17 +2824,14 @@ function pollTransactionStatuses(network, hashes) {
2860
2824
  try {
2861
2825
  const result = yield provider.txStatus(hash, "unused", "FINAL");
2862
2826
  if (result && result.status) {
2863
- console.log(`Transaction ${hash} result:`, result);
2864
2827
  return result;
2865
2828
  }
2866
2829
  } catch (error) {
2867
- console.error(`Failed to fetch transaction status for ${hash}: ${error.message}`);
2868
2830
  }
2869
2831
  if (attempt === maxAttempts) {
2870
2832
  throw new Error(`Transaction not found after max attempts: ${hash}`);
2871
2833
  }
2872
2834
  yield delay(1e4);
2873
- console.log(`RPC request failed for ${hash}, retrying ${maxAttempts - attempt} more times`);
2874
2835
  }
2875
2836
  });
2876
2837
  const results = yield Promise.all(hashes.map((hash) => pollStatus(hash)));
@@ -2880,7 +2841,7 @@ function pollTransactionStatuses(network, hashes) {
2880
2841
 
2881
2842
  // src/index.ts
2882
2843
  var getVersion = () => {
2883
- return "0.1.7";
2844
+ return "0.1.9";
2884
2845
  };
2885
2846
  if (typeof window !== "undefined") {
2886
2847
  window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();