btc-wallet 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
package/esm/index.js CHANGED
@@ -84,6 +84,7 @@ 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);
87
88
  return accounts;
88
89
  });
89
90
  }
@@ -649,6 +650,7 @@ var WalletClientProvider = class {
649
650
  }
650
651
  }
651
652
  if (method === "personal_sign" /* personalSign */) {
653
+ console.log("personal_sign ---- ", arg);
652
654
  return new Promise((resolve, reject) => {
653
655
  eventUtils_default.emit("personalSign" /* personalSign */, arg);
654
656
  eventUtils_default.once("personalSignResult" /* personalSignResult */, ({ result, error }) => {
@@ -954,6 +956,7 @@ var ConnectModal = ({ open, onClose }) => {
954
956
  yield connect(connector.metadata.id);
955
957
  closeConnectModal();
956
958
  } catch (error) {
959
+ console.error("onConnect error", error);
957
960
  if (error.code === 4001) {
958
961
  setRetryVisible(true);
959
962
  }
@@ -1496,10 +1499,13 @@ var SignModal = ({ open, onClose, onOpen }) => {
1496
1499
  }), [userOpBundle, smartAccount, accountContract]);
1497
1500
  useEffect4(() => {
1498
1501
  if (userOpBundle && open) {
1502
+ console.log("deserializeUserOp start");
1499
1503
  setDeserializeLoading(true);
1500
1504
  deserializeUserOp().then((result) => {
1505
+ console.log("\u{1F680} ~ deserializeUserOp ~ result:", result);
1501
1506
  setDeserializeResult(result);
1502
1507
  }).catch((error) => {
1508
+ console.log("\u{1F680} ~ deserializeUserOp ~ error:", error);
1503
1509
  eventUtils_default.emit("sendUserOpResult" /* sendUserOpResult */, {
1504
1510
  error
1505
1511
  });
@@ -1510,6 +1516,7 @@ var SignModal = ({ open, onClose, onOpen }) => {
1510
1516
  useEffect4(() => {
1511
1517
  if (open && publicClient && evmAccount && userOpBundle) {
1512
1518
  publicClient.getBalance({ address: evmAccount }).then((result) => setNativeBalance(result)).catch((error) => {
1519
+ console.log("\u{1F680} ~ getBalance ~ error:", error);
1513
1520
  eventUtils_default.emit("sendUserOpResult" /* sendUserOpResult */, {
1514
1521
  error
1515
1522
  });
@@ -1682,6 +1689,7 @@ var AASignerProvider = class {
1682
1689
  this.getPublicClient = () => {
1683
1690
  var _a, _b;
1684
1691
  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);
1685
1693
  return createPublicClient({
1686
1694
  transport: http(rpcUrl)
1687
1695
  });
@@ -1716,8 +1724,10 @@ var AASignerProvider = class {
1716
1724
  return `0x${this.chainId.toString(16)}`;
1717
1725
  } else if (arg.method === "personal_sign" /* personalSign */) {
1718
1726
  let message = (_a = arg.params) == null ? void 0 : _a[0];
1727
+ console.log("personal_sign message:", message);
1719
1728
  if (message.length !== 66) {
1720
1729
  const hash = hashMessage({ raw: message });
1730
+ console.log("personal_sign hash:", hash);
1721
1731
  message = hash;
1722
1732
  }
1723
1733
  const result = yield this.personalSign(message || "");
@@ -1725,15 +1735,19 @@ var AASignerProvider = class {
1725
1735
  if (!convertResult) {
1726
1736
  throw new Error("sign error");
1727
1737
  }
1738
+ console.log(`personal_sign result(${convertResult.length}): `, convertResult);
1728
1739
  return convertResult;
1729
1740
  } else if (arg.method === "eth_signTypedData" || arg.method === "eth_signTypedData_v4") {
1730
1741
  const typedData = (_b = arg.params) == null ? void 0 : _b[1];
1742
+ console.log("signTypedData typedData", typedData);
1731
1743
  const hash = hashTypedData(typeof typedData === "string" ? JSON.parse(typedData) : typedData);
1744
+ console.log("signTypedData hash", hash);
1732
1745
  const result = yield this.personalSign(hash || "");
1733
1746
  const convertResult = convertSignature(result);
1734
1747
  if (!convertResult) {
1735
1748
  throw new Error("sign error");
1736
1749
  }
1750
+ console.log(`eth_signTypedData result(${convertResult.length}): `, convertResult);
1737
1751
  return convertResult;
1738
1752
  } else if (arg.method === "wallet_switchEthereumChain") {
1739
1753
  if (arg.params && arg.params instanceof Array && arg.params[0] && arg.params[0].chainId) {
@@ -1905,6 +1919,7 @@ var ConnectProvider = ({
1905
1919
  setEVMAccount(res);
1906
1920
  }).catch((e) => {
1907
1921
  setEVMAccount(void 0);
1922
+ console.error("smartAccount getAddress error", e);
1908
1923
  });
1909
1924
  } else {
1910
1925
  setEVMAccount(void 0);
@@ -1926,6 +1941,7 @@ var ConnectProvider = ({
1926
1941
  const requestAccount = useCallback7(
1927
1942
  (connector2) => __async(void 0, null, function* () {
1928
1943
  let accounts2 = yield connector2.getAccounts();
1944
+ console.log("requestAccount start, autoConnect", accounts2, autoConnect);
1929
1945
  if (accounts2.length === 0 && autoConnect) {
1930
1946
  accounts2 = yield connector2.requestAccounts();
1931
1947
  }
@@ -1935,7 +1951,9 @@ var ConnectProvider = ({
1935
1951
  );
1936
1952
  const requestDirectAccount = useCallback7(
1937
1953
  (connector2) => __async(void 0, null, function* () {
1954
+ console.log(111);
1938
1955
  let accounts2 = yield connector2.getAccounts();
1956
+ console.log("requestAccount start, autoConnect", accounts2, autoConnect);
1939
1957
  if (accounts2.length === 0) {
1940
1958
  accounts2 = yield connector2.requestAccounts();
1941
1959
  }
@@ -1947,6 +1965,7 @@ var ConnectProvider = ({
1947
1965
  useEffect5(() => {
1948
1966
  if (connector) {
1949
1967
  requestAccount(connector).catch((e) => {
1968
+ console.log("get account error", e);
1950
1969
  setAccounts([]);
1951
1970
  });
1952
1971
  } else {
@@ -2002,6 +2021,7 @@ var ConnectProvider = ({
2002
2021
  })
2003
2022
  })
2004
2023
  );
2024
+ console.log("walletEntryPlugin init");
2005
2025
  }
2006
2026
  }, [options, evmSupportChainIds, accountContract]);
2007
2027
  useEffect5(() => {
@@ -2010,6 +2030,7 @@ var ConnectProvider = ({
2010
2030
  walletEntryPlugin.setWalletCore({
2011
2031
  ethereum: smartAccount.provider
2012
2032
  });
2033
+ console.log("walletEntryPlugin setWalletCore");
2013
2034
  }
2014
2035
  }, [smartAccount, options]);
2015
2036
  useEffect5(() => {
@@ -2017,8 +2038,10 @@ var ConnectProvider = ({
2017
2038
  if (((_a2 = options.walletOptions) == null ? void 0 : _a2.visible) !== false) {
2018
2039
  if (evmAccount) {
2019
2040
  walletEntryPlugin.walletEntryCreate();
2041
+ console.log("walletEntryPlugin walletEntryCreate");
2020
2042
  } else {
2021
2043
  walletEntryPlugin.walletEntryDestroy();
2044
+ console.log("walletEntryPlugin walletEntryDestroy");
2022
2045
  }
2023
2046
  }
2024
2047
  }, [evmAccount, smartAccount, options]);
@@ -2317,6 +2340,7 @@ import { sha256 } from "js-sha256";
2317
2340
 
2318
2341
  // src/utils/initWalletButton.ts
2319
2342
  function setupWalletButton(network, wallet, originalWallet) {
2343
+ console.log("setupWalletButton");
2320
2344
  if (document.getElementById("satoshi-wallet-button")) {
2321
2345
  return;
2322
2346
  }
@@ -2363,6 +2387,9 @@ function createFloatingButtonWithIframe({
2363
2387
  iframe.style.display = isCurrentlyVisible ? "none" : "block";
2364
2388
  button.src = isCurrentlyVisible ? openImageUrl : closeImageUrl;
2365
2389
  localStorage.setItem("iframeVisible", String(!isCurrentlyVisible));
2390
+ setTimeout(() => {
2391
+ iframe.focus();
2392
+ }, 0);
2366
2393
  };
2367
2394
  return button;
2368
2395
  }
@@ -2374,9 +2401,6 @@ function createIframe({
2374
2401
  iframe.id = "satoshi-wallet-iframe";
2375
2402
  iframe.allow = "clipboard-read; clipboard-write";
2376
2403
  iframe.src = iframeUrl;
2377
- iframe.onclick = () => {
2378
- iframe.focus();
2379
- };
2380
2404
  Object.assign(iframe.style, __spreadValues({
2381
2405
  position: "fixed",
2382
2406
  bottom: "90px",
@@ -2395,20 +2419,24 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
2395
2419
  const accountId = (_a = yield wallet == null ? void 0 : wallet.getAccounts()) == null ? void 0 : _a[0].accountId;
2396
2420
  const originalAccountId = originalWallet.account;
2397
2421
  const originalPublicKey = yield originalWallet.getPublicKey();
2422
+ console.log({ accountId, originalAccountId, originalPublicKey });
2398
2423
  const iframeSrc = new URL(iframe.src);
2399
2424
  iframeSrc.searchParams.set("origin", window.location.origin);
2400
2425
  accountId && iframeSrc.searchParams.set("accountId", accountId);
2401
2426
  originalAccountId && iframeSrc.searchParams.set("originalAccountId", originalAccountId);
2402
2427
  originalPublicKey && iframeSrc.searchParams.set("originalPublicKey", originalPublicKey);
2403
2428
  iframe.src = iframeSrc.toString();
2429
+ console.log("iframe src", iframe.src);
2404
2430
  window.addEventListener("message", (event) => __async(this, null, function* () {
2405
2431
  var _a2, _b;
2406
2432
  if (event.origin !== iframeSrc.origin)
2407
2433
  return;
2408
2434
  const { action, requestId, data } = event.data;
2409
2435
  if (action === "signAndSendTransaction") {
2436
+ console.log("signAndSendTransaction message", event.data);
2410
2437
  try {
2411
2438
  const result = yield wallet.signAndSendTransaction(data);
2439
+ console.log("signAndSendTransaction result", result);
2412
2440
  (_a2 = event.source) == null ? void 0 : _a2.postMessage(
2413
2441
  {
2414
2442
  requestId,
@@ -2418,6 +2446,7 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
2418
2446
  { targetOrigin: event.origin }
2419
2447
  );
2420
2448
  } catch (error) {
2449
+ console.error("signAndSendTransaction error", error);
2421
2450
  (_b = event.source) == null ? void 0 : _b.postMessage(
2422
2451
  {
2423
2452
  requestId,
@@ -2509,6 +2538,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2509
2538
  signAndSendTransaction,
2510
2539
  signAndSendTransactions
2511
2540
  };
2541
+ initWalletButton(options.network.networkId, wallet);
2512
2542
  if (!inter) {
2513
2543
  inter = setInterval(() => __async(void 0, null, function* () {
2514
2544
  const btcContext = window.btcContext;
@@ -2517,6 +2547,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2517
2547
  const context = btcContext.getContext();
2518
2548
  context.on("updatePublicKey", (btcPublicKey) => __async(void 0, null, function* () {
2519
2549
  const { nearTempAddress } = yield getNearAccountByBtcPublicKey(btcPublicKey);
2550
+ console.info("accountsChanged:", nearTempAddress, btcContext.account);
2520
2551
  emitter.emit("accountsChanged", {
2521
2552
  accounts: [
2522
2553
  {
@@ -2530,6 +2561,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2530
2561
  accounts: []
2531
2562
  });
2532
2563
  }));
2564
+ console.log("metadata.autoConnect:", metadata);
2533
2565
  if ("autoConnect" in metadata && metadata.autoConnect && localStorage.getItem("near-wallet-selector:selectedWalletId") === '"btc-wallet"') {
2534
2566
  yield btcContext.autoConnect();
2535
2567
  }
@@ -2537,7 +2569,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2537
2569
  }
2538
2570
  }), 500);
2539
2571
  }
2540
- initWalletButton(options.network.networkId, state.getAccount(), wallet);
2541
2572
  function viewMethod(_02) {
2542
2573
  return __async(this, arguments, function* ({ method, args = {} }) {
2543
2574
  const res = yield provider.query({
@@ -2563,7 +2594,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2563
2594
  state.saveAccount(nearTempAddress);
2564
2595
  state.savePublicKey(nearTempPublicKey);
2565
2596
  state.saveBtcPublicKey(btcPublicKey);
2566
- initWalletButton(options.network.networkId, nearTempAddress, wallet);
2567
2597
  return {
2568
2598
  nearTempAddress,
2569
2599
  nearTempPublicKey
@@ -2572,6 +2602,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2572
2602
  }
2573
2603
  function signIn(_02) {
2574
2604
  return __async(this, arguments, function* ({ contractId, methodNames }) {
2605
+ console.log(provider);
2575
2606
  const accountId = state.getAccount();
2576
2607
  const publicKey = state.getPublicKey();
2577
2608
  const btcContext = window.btcContext;
@@ -2677,6 +2708,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2677
2708
  txBytes,
2678
2709
  (byte) => ("0" + (byte & 255).toString(16)).slice(-2)
2679
2710
  ).join("");
2711
+ console.log("txHex:", txHex);
2680
2712
  const hash = bs58.encode(new Uint8Array(sha256.array(txBytes)));
2681
2713
  return { txBytes, txHex, hash };
2682
2714
  });
@@ -2701,8 +2733,10 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2701
2733
  btcPubKey: state.getBtcPublicKey(),
2702
2734
  data: toHex(strIntention)
2703
2735
  });
2736
+ console.log("result:", result);
2704
2737
  if (result.result_code === 0) {
2705
2738
  const hash = newTransactions.map((t) => t.hash);
2739
+ console.log("txHash:", hash);
2706
2740
  const result2 = yield pollTransactionStatuses(options.network.networkId, hash);
2707
2741
  return result2;
2708
2742
  } else {
@@ -2710,6 +2744,26 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2710
2744
  }
2711
2745
  });
2712
2746
  }
2747
+ function initWalletButton(network, wallet2) {
2748
+ return __async(this, null, function* () {
2749
+ console.log("initWalletButton:", network, wallet2);
2750
+ const checkAndSetupWalletButton = () => {
2751
+ const accountId = state.getAccount();
2752
+ const btcContext = window.btcContext;
2753
+ console.log("checkAndSetupWalletButton:", accountId, btcContext.account);
2754
+ if (accountId && btcContext.account) {
2755
+ setupWalletButton(network, wallet2, btcContext);
2756
+ } else {
2757
+ removeWalletButton();
2758
+ !btcContext.account && setTimeout(() => {
2759
+ checkAndSetupWalletButton();
2760
+ }, 5e3);
2761
+ }
2762
+ };
2763
+ yield delay(1e3);
2764
+ checkAndSetupWalletButton();
2765
+ });
2766
+ }
2713
2767
  return wallet;
2714
2768
  });
2715
2769
  function getNonceFromApi(network, accountId) {
@@ -2768,22 +2822,6 @@ function toHex(originalString) {
2768
2822
  hexString = hexString.replace(/(^0+)/g, "");
2769
2823
  return hexString;
2770
2824
  }
2771
- function initWalletButton(network, accountId, wallet) {
2772
- return __async(this, null, function* () {
2773
- yield delay(1e3);
2774
- const checkAndSetupWalletButton = () => {
2775
- if (accountId && window.btcContext.account) {
2776
- setupWalletButton(network, wallet, window.btcContext);
2777
- } else {
2778
- removeWalletButton();
2779
- !window.btcContext.account && setTimeout(() => {
2780
- checkAndSetupWalletButton();
2781
- }, 5e3);
2782
- }
2783
- };
2784
- checkAndSetupWalletButton();
2785
- });
2786
- }
2787
2825
  var rcpUrls = {
2788
2826
  mainnet: [
2789
2827
  "https://near.lava.build",
@@ -2812,14 +2850,17 @@ function pollTransactionStatuses(network, hashes) {
2812
2850
  try {
2813
2851
  const result = yield provider.txStatus(hash, "unused", "FINAL");
2814
2852
  if (result && result.status) {
2853
+ console.log(`Transaction ${hash} result:`, result);
2815
2854
  return result;
2816
2855
  }
2817
2856
  } catch (error) {
2857
+ console.error(`Failed to fetch transaction status for ${hash}: ${error.message}`);
2818
2858
  }
2819
2859
  if (attempt === maxAttempts) {
2820
2860
  throw new Error(`Transaction not found after max attempts: ${hash}`);
2821
2861
  }
2822
2862
  yield delay(1e4);
2863
+ console.log(`RPC request failed for ${hash}, retrying ${maxAttempts - attempt} more times`);
2823
2864
  }
2824
2865
  });
2825
2866
  const results = yield Promise.all(hashes.map((hash) => pollStatus(hash)));
@@ -2829,7 +2870,7 @@ function pollTransactionStatuses(network, hashes) {
2829
2870
 
2830
2871
  // src/index.ts
2831
2872
  var getVersion = () => {
2832
- return "0.1.2";
2873
+ return "0.1.3";
2833
2874
  };
2834
2875
  if (typeof window !== "undefined") {
2835
2876
  window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();