btc-wallet 0.1.6 → 0.1.7

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
  }
@@ -2404,20 +2428,24 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
2404
2428
  const accountId = (_a = yield wallet == null ? void 0 : wallet.getAccounts()) == null ? void 0 : _a[0].accountId;
2405
2429
  const originalAccountId = originalWallet.account;
2406
2430
  const originalPublicKey = yield originalWallet.getPublicKey();
2431
+ console.log({ accountId, originalAccountId, originalPublicKey });
2407
2432
  const iframeSrc = new URL(iframe.src);
2408
2433
  iframeSrc.searchParams.set("origin", window.location.origin);
2409
2434
  accountId && iframeSrc.searchParams.set("accountId", accountId);
2410
2435
  originalAccountId && iframeSrc.searchParams.set("originalAccountId", originalAccountId);
2411
2436
  originalPublicKey && iframeSrc.searchParams.set("originalPublicKey", originalPublicKey);
2412
2437
  iframe.src = iframeSrc.toString();
2438
+ console.log("iframe src", iframe.src);
2413
2439
  window.addEventListener("message", (event) => __async(this, null, function* () {
2414
2440
  var _a2, _b;
2415
2441
  if (event.origin !== iframeSrc.origin)
2416
2442
  return;
2417
2443
  const { action, requestId, data } = event.data;
2418
2444
  if (action === "signAndSendTransaction") {
2445
+ console.log("signAndSendTransaction message", event.data);
2419
2446
  try {
2420
2447
  const result = yield wallet.signAndSendTransaction(data);
2448
+ console.log("signAndSendTransaction result", result);
2421
2449
  (_a2 = event.source) == null ? void 0 : _a2.postMessage(
2422
2450
  {
2423
2451
  requestId,
@@ -2427,6 +2455,7 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
2427
2455
  { targetOrigin: event.origin }
2428
2456
  );
2429
2457
  } catch (error) {
2458
+ console.error("signAndSendTransaction error", error);
2430
2459
  (_b = event.source) == null ? void 0 : _b.postMessage(
2431
2460
  {
2432
2461
  requestId,
@@ -2522,11 +2551,13 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2522
2551
  if (!inter) {
2523
2552
  inter = setInterval(() => __async(void 0, null, function* () {
2524
2553
  const btcContext = window.btcContext;
2554
+ console.log("inter btcContext:", btcContext);
2525
2555
  if (btcContext) {
2526
2556
  clearInterval(inter);
2527
2557
  const context = btcContext.getContext();
2528
2558
  context.on("updatePublicKey", (btcPublicKey) => __async(void 0, null, function* () {
2529
2559
  const { nearTempAddress } = yield getNearAccountByBtcPublicKey(btcPublicKey);
2560
+ console.info("accountsChanged:", nearTempAddress, btcContext.account);
2530
2561
  emitter.emit("accountsChanged", {
2531
2562
  accounts: [
2532
2563
  {
@@ -2540,6 +2571,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2540
2571
  accounts: []
2541
2572
  });
2542
2573
  }));
2574
+ console.log("metadata.autoConnect:", metadata);
2543
2575
  if ("autoConnect" in metadata && metadata.autoConnect && localStorage.getItem("near-wallet-selector:selectedWalletId") === '"btc-wallet"') {
2544
2576
  yield btcContext.autoConnect();
2545
2577
  }
@@ -2580,6 +2612,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2580
2612
  }
2581
2613
  function signIn(_02) {
2582
2614
  return __async(this, arguments, function* ({ contractId, methodNames }) {
2615
+ console.log(provider);
2583
2616
  const accountId = state.getAccount();
2584
2617
  const publicKey = state.getPublicKey();
2585
2618
  const btcContext = window.btcContext;
@@ -2608,7 +2641,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2608
2641
  btcContext.logout();
2609
2642
  state.clear();
2610
2643
  window.localStorage.removeItem("near-wallet-selector:selectedWalletId");
2611
- initWalletButton(options.network.networkId, wallet);
2644
+ removeWalletButton();
2612
2645
  });
2613
2646
  }
2614
2647
  function getAccounts() {
@@ -2685,6 +2718,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2685
2718
  txBytes,
2686
2719
  (byte) => ("0" + (byte & 255).toString(16)).slice(-2)
2687
2720
  ).join("");
2721
+ console.log("txHex:", txHex);
2688
2722
  const hash = bs58.encode(new Uint8Array(sha256.array(txBytes)));
2689
2723
  return { txBytes, txHex, hash };
2690
2724
  });
@@ -2709,8 +2743,10 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2709
2743
  btcPubKey: state.getBtcPublicKey(),
2710
2744
  data: toHex(strIntention)
2711
2745
  });
2746
+ console.log("result:", result);
2712
2747
  if (result.result_code === 0) {
2713
2748
  const hash = newTransactions.map((t) => t.hash);
2749
+ console.log("txHash:", hash);
2714
2750
  const result2 = yield pollTransactionStatuses(options.network.networkId, hash);
2715
2751
  return result2;
2716
2752
  } else {
@@ -2720,9 +2756,11 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2720
2756
  }
2721
2757
  function initWalletButton(network, wallet2) {
2722
2758
  return __async(this, null, function* () {
2759
+ console.log("initWalletButton:", network, wallet2);
2723
2760
  const checkAndSetupWalletButton = () => {
2724
2761
  const accountId = state.getAccount();
2725
2762
  const btcContext = window.btcContext;
2763
+ console.log("checkAndSetupWalletButton:", accountId, btcContext.account);
2726
2764
  if (accountId && btcContext.account) {
2727
2765
  setupWalletButton(network, wallet2, btcContext);
2728
2766
  } else {
@@ -2822,14 +2860,17 @@ function pollTransactionStatuses(network, hashes) {
2822
2860
  try {
2823
2861
  const result = yield provider.txStatus(hash, "unused", "FINAL");
2824
2862
  if (result && result.status) {
2863
+ console.log(`Transaction ${hash} result:`, result);
2825
2864
  return result;
2826
2865
  }
2827
2866
  } catch (error) {
2867
+ console.error(`Failed to fetch transaction status for ${hash}: ${error.message}`);
2828
2868
  }
2829
2869
  if (attempt === maxAttempts) {
2830
2870
  throw new Error(`Transaction not found after max attempts: ${hash}`);
2831
2871
  }
2832
2872
  yield delay(1e4);
2873
+ console.log(`RPC request failed for ${hash}, retrying ${maxAttempts - attempt} more times`);
2833
2874
  }
2834
2875
  });
2835
2876
  const results = yield Promise.all(hashes.map((hash) => pollStatus(hash)));
@@ -2839,7 +2880,7 @@ function pollTransactionStatuses(network, hashes) {
2839
2880
 
2840
2881
  // src/index.ts
2841
2882
  var getVersion = () => {
2842
- return "0.1.6";
2883
+ return "0.1.7";
2843
2884
  };
2844
2885
  if (typeof window !== "undefined") {
2845
2886
  window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();