btc-wallet 0.1.2 → 0.1.4

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/dist/index.js CHANGED
@@ -133,6 +133,7 @@ var InjectedConnector = class extends BaseConnector {
133
133
  requestAccounts() {
134
134
  return __async(this, null, function* () {
135
135
  const accounts = yield this.getProviderOrThrow().requestAccounts();
136
+ console.log("\u{1F680} ~ InjectedConnector ~ requestAccounts ~ accounts:", accounts);
136
137
  return accounts;
137
138
  });
138
139
  }
@@ -698,6 +699,7 @@ var WalletClientProvider = class {
698
699
  }
699
700
  }
700
701
  if (method === "personal_sign" /* personalSign */) {
702
+ console.log("personal_sign ---- ", arg);
701
703
  return new Promise((resolve, reject) => {
702
704
  eventUtils_default.emit("personalSign" /* personalSign */, arg);
703
705
  eventUtils_default.once("personalSignResult" /* personalSignResult */, ({ result, error }) => {
@@ -1003,6 +1005,7 @@ var ConnectModal = ({ open, onClose }) => {
1003
1005
  yield connect(connector.metadata.id);
1004
1006
  closeConnectModal();
1005
1007
  } catch (error) {
1008
+ console.error("onConnect error", error);
1006
1009
  if (error.code === 4001) {
1007
1010
  setRetryVisible(true);
1008
1011
  }
@@ -1545,10 +1548,13 @@ var SignModal = ({ open, onClose, onOpen }) => {
1545
1548
  }), [userOpBundle, smartAccount, accountContract]);
1546
1549
  (0, import_react8.useEffect)(() => {
1547
1550
  if (userOpBundle && open) {
1551
+ console.log("deserializeUserOp start");
1548
1552
  setDeserializeLoading(true);
1549
1553
  deserializeUserOp().then((result) => {
1554
+ console.log("\u{1F680} ~ deserializeUserOp ~ result:", result);
1550
1555
  setDeserializeResult(result);
1551
1556
  }).catch((error) => {
1557
+ console.log("\u{1F680} ~ deserializeUserOp ~ error:", error);
1552
1558
  eventUtils_default.emit("sendUserOpResult" /* sendUserOpResult */, {
1553
1559
  error
1554
1560
  });
@@ -1559,6 +1565,7 @@ var SignModal = ({ open, onClose, onOpen }) => {
1559
1565
  (0, import_react8.useEffect)(() => {
1560
1566
  if (open && publicClient && evmAccount && userOpBundle) {
1561
1567
  publicClient.getBalance({ address: evmAccount }).then((result) => setNativeBalance(result)).catch((error) => {
1568
+ console.log("\u{1F680} ~ getBalance ~ error:", error);
1562
1569
  eventUtils_default.emit("sendUserOpResult" /* sendUserOpResult */, {
1563
1570
  error
1564
1571
  });
@@ -1723,6 +1730,7 @@ var AASignerProvider = class {
1723
1730
  this.getPublicClient = () => {
1724
1731
  var _a, _b;
1725
1732
  const rpcUrl = ((_a = this == null ? void 0 : this.rpcUrls) == null ? void 0 : _a[this.chainId]) || ((_b = import_chains3.chains.getEVMChainInfoById(this.chainId || 1)) == null ? void 0 : _b.rpcUrl);
1733
+ console.log("rpcUrl", rpcUrl);
1726
1734
  return (0, import_viem4.createPublicClient)({
1727
1735
  transport: (0, import_viem4.http)(rpcUrl)
1728
1736
  });
@@ -1757,8 +1765,10 @@ var AASignerProvider = class {
1757
1765
  return `0x${this.chainId.toString(16)}`;
1758
1766
  } else if (arg.method === "personal_sign" /* personalSign */) {
1759
1767
  let message = (_a = arg.params) == null ? void 0 : _a[0];
1768
+ console.log("personal_sign message:", message);
1760
1769
  if (message.length !== 66) {
1761
1770
  const hash = (0, import_viem4.hashMessage)({ raw: message });
1771
+ console.log("personal_sign hash:", hash);
1762
1772
  message = hash;
1763
1773
  }
1764
1774
  const result = yield this.personalSign(message || "");
@@ -1766,15 +1776,19 @@ var AASignerProvider = class {
1766
1776
  if (!convertResult) {
1767
1777
  throw new Error("sign error");
1768
1778
  }
1779
+ console.log(`personal_sign result(${convertResult.length}): `, convertResult);
1769
1780
  return convertResult;
1770
1781
  } else if (arg.method === "eth_signTypedData" || arg.method === "eth_signTypedData_v4") {
1771
1782
  const typedData = (_b = arg.params) == null ? void 0 : _b[1];
1783
+ console.log("signTypedData typedData", typedData);
1772
1784
  const hash = (0, import_viem4.hashTypedData)(typeof typedData === "string" ? JSON.parse(typedData) : typedData);
1785
+ console.log("signTypedData hash", hash);
1773
1786
  const result = yield this.personalSign(hash || "");
1774
1787
  const convertResult = convertSignature(result);
1775
1788
  if (!convertResult) {
1776
1789
  throw new Error("sign error");
1777
1790
  }
1791
+ console.log(`eth_signTypedData result(${convertResult.length}): `, convertResult);
1778
1792
  return convertResult;
1779
1793
  } else if (arg.method === "wallet_switchEthereumChain") {
1780
1794
  if (arg.params && arg.params instanceof Array && arg.params[0] && arg.params[0].chainId) {
@@ -1946,6 +1960,7 @@ var ConnectProvider = ({
1946
1960
  setEVMAccount(res);
1947
1961
  }).catch((e) => {
1948
1962
  setEVMAccount(void 0);
1963
+ console.error("smartAccount getAddress error", e);
1949
1964
  });
1950
1965
  } else {
1951
1966
  setEVMAccount(void 0);
@@ -1967,6 +1982,7 @@ var ConnectProvider = ({
1967
1982
  const requestAccount = (0, import_react10.useCallback)(
1968
1983
  (connector2) => __async(void 0, null, function* () {
1969
1984
  let accounts2 = yield connector2.getAccounts();
1985
+ console.log("requestAccount start, autoConnect", accounts2, autoConnect);
1970
1986
  if (accounts2.length === 0 && autoConnect) {
1971
1987
  accounts2 = yield connector2.requestAccounts();
1972
1988
  }
@@ -1976,7 +1992,9 @@ var ConnectProvider = ({
1976
1992
  );
1977
1993
  const requestDirectAccount = (0, import_react10.useCallback)(
1978
1994
  (connector2) => __async(void 0, null, function* () {
1995
+ console.log(111);
1979
1996
  let accounts2 = yield connector2.getAccounts();
1997
+ console.log("requestAccount start, autoConnect", accounts2, autoConnect);
1980
1998
  if (accounts2.length === 0) {
1981
1999
  accounts2 = yield connector2.requestAccounts();
1982
2000
  }
@@ -1988,6 +2006,7 @@ var ConnectProvider = ({
1988
2006
  (0, import_react10.useEffect)(() => {
1989
2007
  if (connector) {
1990
2008
  requestAccount(connector).catch((e) => {
2009
+ console.log("get account error", e);
1991
2010
  setAccounts([]);
1992
2011
  });
1993
2012
  } else {
@@ -2043,6 +2062,7 @@ var ConnectProvider = ({
2043
2062
  })
2044
2063
  })
2045
2064
  );
2065
+ console.log("walletEntryPlugin init");
2046
2066
  }
2047
2067
  }, [options, evmSupportChainIds, accountContract]);
2048
2068
  (0, import_react10.useEffect)(() => {
@@ -2051,6 +2071,7 @@ var ConnectProvider = ({
2051
2071
  import_wallet.walletEntryPlugin.setWalletCore({
2052
2072
  ethereum: smartAccount.provider
2053
2073
  });
2074
+ console.log("walletEntryPlugin setWalletCore");
2054
2075
  }
2055
2076
  }, [smartAccount, options]);
2056
2077
  (0, import_react10.useEffect)(() => {
@@ -2058,8 +2079,10 @@ var ConnectProvider = ({
2058
2079
  if (((_a2 = options.walletOptions) == null ? void 0 : _a2.visible) !== false) {
2059
2080
  if (evmAccount) {
2060
2081
  import_wallet.walletEntryPlugin.walletEntryCreate();
2082
+ console.log("walletEntryPlugin walletEntryCreate");
2061
2083
  } else {
2062
2084
  import_wallet.walletEntryPlugin.walletEntryDestroy();
2085
+ console.log("walletEntryPlugin walletEntryDestroy");
2063
2086
  }
2064
2087
  }
2065
2088
  }, [evmAccount, smartAccount, options]);
@@ -2358,6 +2381,7 @@ var import_js_sha256 = require("js-sha256");
2358
2381
 
2359
2382
  // src/utils/initWalletButton.ts
2360
2383
  function setupWalletButton(network, wallet, originalWallet) {
2384
+ console.log("setupWalletButton");
2361
2385
  if (document.getElementById("satoshi-wallet-button")) {
2362
2386
  return;
2363
2387
  }
@@ -2365,6 +2389,13 @@ function setupWalletButton(network, wallet, originalWallet) {
2365
2389
  iframeUrl: network === "testnet" ? "https://wallet-dev.satoshibridge.top" : "https://wallet.satoshibridge.top",
2366
2390
  iframeStyle: { width: "400px", height: "650px" }
2367
2391
  });
2392
+ iframe.addEventListener("mouseenter", () => {
2393
+ var _a;
2394
+ (_a = document.activeElement) == null ? void 0 : _a.setAttribute("tabindex", "null");
2395
+ setTimeout(() => {
2396
+ iframe.focus();
2397
+ }, 0);
2398
+ });
2368
2399
  const button = createFloatingButtonWithIframe({
2369
2400
  openImageUrl: "https://assets.deltatrade.ai/wallet-assets/wallet-btn.png",
2370
2401
  closeImageUrl: "https://assets.deltatrade.ai/wallet-assets/wallet-btn-active.png",
@@ -2404,6 +2435,9 @@ function createFloatingButtonWithIframe({
2404
2435
  iframe.style.display = isCurrentlyVisible ? "none" : "block";
2405
2436
  button.src = isCurrentlyVisible ? openImageUrl : closeImageUrl;
2406
2437
  localStorage.setItem("iframeVisible", String(!isCurrentlyVisible));
2438
+ setTimeout(() => {
2439
+ iframe.focus();
2440
+ }, 0);
2407
2441
  };
2408
2442
  return button;
2409
2443
  }
@@ -2415,9 +2449,6 @@ function createIframe({
2415
2449
  iframe.id = "satoshi-wallet-iframe";
2416
2450
  iframe.allow = "clipboard-read; clipboard-write";
2417
2451
  iframe.src = iframeUrl;
2418
- iframe.onclick = () => {
2419
- iframe.focus();
2420
- };
2421
2452
  Object.assign(iframe.style, __spreadValues({
2422
2453
  position: "fixed",
2423
2454
  bottom: "90px",
@@ -2436,20 +2467,24 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
2436
2467
  const accountId = (_a = yield wallet == null ? void 0 : wallet.getAccounts()) == null ? void 0 : _a[0].accountId;
2437
2468
  const originalAccountId = originalWallet.account;
2438
2469
  const originalPublicKey = yield originalWallet.getPublicKey();
2470
+ console.log({ accountId, originalAccountId, originalPublicKey });
2439
2471
  const iframeSrc = new URL(iframe.src);
2440
2472
  iframeSrc.searchParams.set("origin", window.location.origin);
2441
2473
  accountId && iframeSrc.searchParams.set("accountId", accountId);
2442
2474
  originalAccountId && iframeSrc.searchParams.set("originalAccountId", originalAccountId);
2443
2475
  originalPublicKey && iframeSrc.searchParams.set("originalPublicKey", originalPublicKey);
2444
2476
  iframe.src = iframeSrc.toString();
2477
+ console.log("iframe src", iframe.src);
2445
2478
  window.addEventListener("message", (event) => __async(this, null, function* () {
2446
2479
  var _a2, _b;
2447
2480
  if (event.origin !== iframeSrc.origin)
2448
2481
  return;
2449
2482
  const { action, requestId, data } = event.data;
2450
2483
  if (action === "signAndSendTransaction") {
2484
+ console.log("signAndSendTransaction message", event.data);
2451
2485
  try {
2452
2486
  const result = yield wallet.signAndSendTransaction(data);
2487
+ console.log("signAndSendTransaction result", result);
2453
2488
  (_a2 = event.source) == null ? void 0 : _a2.postMessage(
2454
2489
  {
2455
2490
  requestId,
@@ -2459,6 +2494,7 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
2459
2494
  { targetOrigin: event.origin }
2460
2495
  );
2461
2496
  } catch (error) {
2497
+ console.error("signAndSendTransaction error", error);
2462
2498
  (_b = event.source) == null ? void 0 : _b.postMessage(
2463
2499
  {
2464
2500
  requestId,
@@ -2550,6 +2586,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2550
2586
  signAndSendTransaction,
2551
2587
  signAndSendTransactions
2552
2588
  };
2589
+ initWalletButton(options.network.networkId, wallet);
2553
2590
  if (!inter) {
2554
2591
  inter = setInterval(() => __async(void 0, null, function* () {
2555
2592
  const btcContext = window.btcContext;
@@ -2558,6 +2595,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2558
2595
  const context = btcContext.getContext();
2559
2596
  context.on("updatePublicKey", (btcPublicKey) => __async(void 0, null, function* () {
2560
2597
  const { nearTempAddress } = yield getNearAccountByBtcPublicKey(btcPublicKey);
2598
+ console.info("accountsChanged:", nearTempAddress, btcContext.account);
2561
2599
  emitter.emit("accountsChanged", {
2562
2600
  accounts: [
2563
2601
  {
@@ -2571,6 +2609,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2571
2609
  accounts: []
2572
2610
  });
2573
2611
  }));
2612
+ console.log("metadata.autoConnect:", metadata);
2574
2613
  if ("autoConnect" in metadata && metadata.autoConnect && localStorage.getItem("near-wallet-selector:selectedWalletId") === '"btc-wallet"') {
2575
2614
  yield btcContext.autoConnect();
2576
2615
  }
@@ -2578,7 +2617,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2578
2617
  }
2579
2618
  }), 500);
2580
2619
  }
2581
- initWalletButton(options.network.networkId, state.getAccount(), wallet);
2582
2620
  function viewMethod(_02) {
2583
2621
  return __async(this, arguments, function* ({ method, args = {} }) {
2584
2622
  const res = yield provider.query({
@@ -2604,7 +2642,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2604
2642
  state.saveAccount(nearTempAddress);
2605
2643
  state.savePublicKey(nearTempPublicKey);
2606
2644
  state.saveBtcPublicKey(btcPublicKey);
2607
- initWalletButton(options.network.networkId, nearTempAddress, wallet);
2608
2645
  return {
2609
2646
  nearTempAddress,
2610
2647
  nearTempPublicKey
@@ -2613,6 +2650,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2613
2650
  }
2614
2651
  function signIn(_02) {
2615
2652
  return __async(this, arguments, function* ({ contractId, methodNames }) {
2653
+ console.log(provider);
2616
2654
  const accountId = state.getAccount();
2617
2655
  const publicKey = state.getPublicKey();
2618
2656
  const btcContext = window.btcContext;
@@ -2718,6 +2756,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2718
2756
  txBytes,
2719
2757
  (byte) => ("0" + (byte & 255).toString(16)).slice(-2)
2720
2758
  ).join("");
2759
+ console.log("txHex:", txHex);
2721
2760
  const hash = import_bs58.default.encode(new Uint8Array(import_js_sha256.sha256.array(txBytes)));
2722
2761
  return { txBytes, txHex, hash };
2723
2762
  });
@@ -2742,8 +2781,10 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2742
2781
  btcPubKey: state.getBtcPublicKey(),
2743
2782
  data: toHex(strIntention)
2744
2783
  });
2784
+ console.log("result:", result);
2745
2785
  if (result.result_code === 0) {
2746
2786
  const hash = newTransactions.map((t) => t.hash);
2787
+ console.log("txHash:", hash);
2747
2788
  const result2 = yield pollTransactionStatuses(options.network.networkId, hash);
2748
2789
  return result2;
2749
2790
  } else {
@@ -2751,6 +2792,26 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2751
2792
  }
2752
2793
  });
2753
2794
  }
2795
+ function initWalletButton(network, wallet2) {
2796
+ return __async(this, null, function* () {
2797
+ console.log("initWalletButton:", network, wallet2);
2798
+ const checkAndSetupWalletButton = () => {
2799
+ const accountId = state.getAccount();
2800
+ const btcContext = window.btcContext;
2801
+ console.log("checkAndSetupWalletButton:", accountId, btcContext.account);
2802
+ if (accountId && btcContext.account) {
2803
+ setupWalletButton(network, wallet2, btcContext);
2804
+ } else {
2805
+ removeWalletButton();
2806
+ !btcContext.account && setTimeout(() => {
2807
+ checkAndSetupWalletButton();
2808
+ }, 5e3);
2809
+ }
2810
+ };
2811
+ yield delay(1e3);
2812
+ checkAndSetupWalletButton();
2813
+ });
2814
+ }
2754
2815
  return wallet;
2755
2816
  });
2756
2817
  function getNonceFromApi(network, accountId) {
@@ -2809,22 +2870,6 @@ function toHex(originalString) {
2809
2870
  hexString = hexString.replace(/(^0+)/g, "");
2810
2871
  return hexString;
2811
2872
  }
2812
- function initWalletButton(network, accountId, wallet) {
2813
- return __async(this, null, function* () {
2814
- yield delay(1e3);
2815
- const checkAndSetupWalletButton = () => {
2816
- if (accountId && window.btcContext.account) {
2817
- setupWalletButton(network, wallet, window.btcContext);
2818
- } else {
2819
- removeWalletButton();
2820
- !window.btcContext.account && setTimeout(() => {
2821
- checkAndSetupWalletButton();
2822
- }, 5e3);
2823
- }
2824
- };
2825
- checkAndSetupWalletButton();
2826
- });
2827
- }
2828
2873
  var rcpUrls = {
2829
2874
  mainnet: [
2830
2875
  "https://near.lava.build",
@@ -2853,14 +2898,17 @@ function pollTransactionStatuses(network, hashes) {
2853
2898
  try {
2854
2899
  const result = yield provider.txStatus(hash, "unused", "FINAL");
2855
2900
  if (result && result.status) {
2901
+ console.log(`Transaction ${hash} result:`, result);
2856
2902
  return result;
2857
2903
  }
2858
2904
  } catch (error) {
2905
+ console.error(`Failed to fetch transaction status for ${hash}: ${error.message}`);
2859
2906
  }
2860
2907
  if (attempt === maxAttempts) {
2861
2908
  throw new Error(`Transaction not found after max attempts: ${hash}`);
2862
2909
  }
2863
2910
  yield delay(1e4);
2911
+ console.log(`RPC request failed for ${hash}, retrying ${maxAttempts - attempt} more times`);
2864
2912
  }
2865
2913
  });
2866
2914
  const results = yield Promise.all(hashes.map((hash) => pollStatus(hash)));
@@ -2870,7 +2918,7 @@ function pollTransactionStatuses(network, hashes) {
2870
2918
 
2871
2919
  // src/index.ts
2872
2920
  var getVersion = () => {
2873
- return "0.1.2";
2921
+ return "0.1.4";
2874
2922
  };
2875
2923
  if (typeof window !== "undefined") {
2876
2924
  window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();