btc-wallet 0.1.8 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
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,
@@ -2547,15 +2518,16 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2547
2518
  signAndSendTransaction,
2548
2519
  signAndSendTransactions
2549
2520
  };
2521
+ initWalletButton(options.network.networkId, wallet);
2550
2522
  if (!inter) {
2551
2523
  inter = setInterval(() => __async(void 0, null, function* () {
2552
2524
  const btcContext = window.btcContext;
2553
- console.log("inter btcContext:", btcContext);
2554
2525
  if (btcContext) {
2555
2526
  clearInterval(inter);
2556
2527
  const context = btcContext.getContext();
2557
2528
  context.on("updatePublicKey", (btcPublicKey) => __async(void 0, null, function* () {
2558
2529
  const { nearTempAddress } = yield getNearAccountByBtcPublicKey(btcPublicKey);
2530
+ removeWalletButton();
2559
2531
  initWalletButton(options.network.networkId, wallet);
2560
2532
  emitter.emit("accountsChanged", {
2561
2533
  accounts: [
@@ -2570,7 +2542,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2570
2542
  accounts: []
2571
2543
  });
2572
2544
  }));
2573
- console.log("metadata.autoConnect:", metadata);
2574
2545
  if ("autoConnect" in metadata && metadata.autoConnect && localStorage.getItem("near-wallet-selector:selectedWalletId") === '"btc-wallet"') {
2575
2546
  yield btcContext.autoConnect();
2576
2547
  }
@@ -2611,7 +2582,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2611
2582
  }
2612
2583
  function signIn(_02) {
2613
2584
  return __async(this, arguments, function* ({ contractId, methodNames }) {
2614
- console.log(provider);
2615
2585
  const accountId = state.getAccount();
2616
2586
  const publicKey = state.getPublicKey();
2617
2587
  const btcContext = window.btcContext;
@@ -2718,7 +2688,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2718
2688
  txBytes,
2719
2689
  (byte) => ("0" + (byte & 255).toString(16)).slice(-2)
2720
2690
  ).join("");
2721
- console.log("txHex:", txHex);
2722
2691
  const hash = bs58.encode(new Uint8Array(sha256.array(txBytes)));
2723
2692
  return { txBytes, txHex, hash };
2724
2693
  });
@@ -2743,10 +2712,8 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2743
2712
  btcPubKey: state.getBtcPublicKey(),
2744
2713
  data: toHex(strIntention)
2745
2714
  });
2746
- console.log("result:", result);
2747
2715
  if (result.result_code === 0) {
2748
2716
  const hash = newTransactions.map((t) => t.hash);
2749
- console.log("txHash:", hash);
2750
2717
  const result2 = yield pollTransactionStatuses(options.network.networkId, hash);
2751
2718
  return result2;
2752
2719
  } else {
@@ -2756,11 +2723,9 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2756
2723
  }
2757
2724
  function initWalletButton(network, wallet2) {
2758
2725
  return __async(this, null, function* () {
2759
- console.log("initWalletButton:", network, wallet2);
2760
2726
  const checkAndSetupWalletButton = () => {
2761
2727
  const accountId = state.getAccount();
2762
2728
  const btcContext = window.btcContext;
2763
- console.log("checkAndSetupWalletButton:", accountId, btcContext.account);
2764
2729
  if (accountId && btcContext.account) {
2765
2730
  setupWalletButton(network, wallet2, btcContext);
2766
2731
  } else {
@@ -2860,17 +2825,14 @@ function pollTransactionStatuses(network, hashes) {
2860
2825
  try {
2861
2826
  const result = yield provider.txStatus(hash, "unused", "FINAL");
2862
2827
  if (result && result.status) {
2863
- console.log(`Transaction ${hash} result:`, result);
2864
2828
  return result;
2865
2829
  }
2866
2830
  } catch (error) {
2867
- console.error(`Failed to fetch transaction status for ${hash}: ${error.message}`);
2868
2831
  }
2869
2832
  if (attempt === maxAttempts) {
2870
2833
  throw new Error(`Transaction not found after max attempts: ${hash}`);
2871
2834
  }
2872
2835
  yield delay(1e4);
2873
- console.log(`RPC request failed for ${hash}, retrying ${maxAttempts - attempt} more times`);
2874
2836
  }
2875
2837
  });
2876
2838
  const results = yield Promise.all(hashes.map((hash) => pollStatus(hash)));
@@ -2880,7 +2842,7 @@ function pollTransactionStatuses(network, hashes) {
2880
2842
 
2881
2843
  // src/index.ts
2882
2844
  var getVersion = () => {
2883
- return "0.1.8";
2845
+ return "0.2.0";
2884
2846
  };
2885
2847
  if (typeof window !== "undefined") {
2886
2848
  window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();