btc-wallet 0.2.6 → 0.2.7

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.
@@ -1,7 +1,4 @@
1
- import type { SmartAccount, UserOp } from '@particle-network/aa';
2
- import type { AccountInfo } from '../types/accountInfo';
1
+ import type { UserOp } from '@particle-network/aa';
3
2
  export declare const pubKeyToEVMAddress: (pubKey: string) => `0x${string}`;
4
3
  export declare const convertSignature: (signature: string) => string;
5
4
  export declare function caculateNativeFee(userOp: UserOp): bigint;
6
- export declare const getBTCAAAddress: (smartAccount: SmartAccount, btcAddress: string, name: string, version: string) => Promise<string>;
7
- export declare const getBTCAccountInfo: (smartAccount: SmartAccount, btcAddress: string, name: string, version: string) => Promise<AccountInfo>;
@@ -1,10 +1,5 @@
1
1
  import type { AAOptions } from '@particle-network/aa';
2
2
  export declare function shortString(str: any): string;
3
- /**
4
- * 复制到剪贴板
5
- * @param {string} text
6
- * @returns {Promise<void>}
7
- */
8
3
  export declare function copyToClipboard(text: string): Promise<unknown>;
9
4
  export declare const defaultTokenIcon = "https://static.particle.network/token-list/defaultToken/default.png";
10
5
  export declare const ipfsToSrc: (ipfs: string) => string;
package/esm/index.js CHANGED
@@ -681,7 +681,7 @@ var WalletClientProvider = class {
681
681
 
682
682
  // src/hooks/useETHProvider.ts
683
683
  var useETHProvider = () => {
684
- const { evmAccount, smartAccount, getSmartAccountInfo } = useConnectProvider();
684
+ const { evmAccount, smartAccount } = useConnectProvider();
685
685
  const [chainId, setChainId] = useState();
686
686
  useEffect(() => {
687
687
  if (smartAccount) {
@@ -775,7 +775,11 @@ var useETHProvider = () => {
775
775
  return (smartAccount == null ? void 0 : smartAccount.provider).publicClient;
776
776
  }, [smartAccount, chainId]);
777
777
  const provider = useMemo(() => {
778
- const ethereumProvider = new EthereumProvider(sendUserOp, smartAccount == null ? void 0 : smartAccount.provider, evmAccount);
778
+ const ethereumProvider = new EthereumProvider(
779
+ sendUserOp,
780
+ smartAccount == null ? void 0 : smartAccount.provider,
781
+ evmAccount
782
+ );
779
783
  return ethereumProvider;
780
784
  }, [evmAccount, sendUserOp, smartAccount == null ? void 0 : smartAccount.provider]);
781
785
  const walletClient = useMemo(() => {
@@ -787,7 +791,6 @@ var useETHProvider = () => {
787
791
  provider,
788
792
  evmAccount,
789
793
  account: evmAccount,
790
- getSmartAccountInfo,
791
794
  switchChain,
792
795
  chainId,
793
796
  getFeeQuotes,
@@ -1085,7 +1088,13 @@ var checkBTCVersion = (accountContracts, accountContractKey, version) => {
1085
1088
  var delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
1086
1089
 
1087
1090
  // src/utils/ethereumUtils.ts
1088
- import { bytesToHex, publicToAddress, toBytes, toChecksumAddress, toRpcSig } from "@ethereumjs/util";
1091
+ import {
1092
+ bytesToHex,
1093
+ publicToAddress,
1094
+ toBytes,
1095
+ toChecksumAddress,
1096
+ toRpcSig
1097
+ } from "@ethereumjs/util";
1089
1098
  import bitcore from "bitcore-lib";
1090
1099
  var pubKeyToEVMAddress = (pubKey) => {
1091
1100
  const address = toChecksumAddress(bytesToHex(publicToAddress(toBytes(`0x${pubKey}`), true)));
@@ -1100,57 +1109,6 @@ var convertSignature = (signature) => {
1100
1109
  function caculateNativeFee(userOp) {
1101
1110
  return (BigInt(userOp.callGasLimit) + BigInt(userOp.verificationGasLimit) + BigInt(userOp.preVerificationGas)) * BigInt(userOp.maxFeePerGas);
1102
1111
  }
1103
- var getBTCAAAddress = (smartAccount, btcAddress, name, version) => __async(void 0, null, function* () {
1104
- var _a;
1105
- const addresses = yield smartAccount.provider.request({ method: "eth_accounts" });
1106
- const owner = addresses[0];
1107
- const localKey = `particle_${name}_${version}_${owner}`;
1108
- if (typeof window !== "undefined" && localStorage) {
1109
- const localAA = localStorage.getItem(localKey);
1110
- if (localAA) {
1111
- return localAA;
1112
- }
1113
- }
1114
- const btcPublicKey = yield smartAccount.provider.getPublicKey();
1115
- const accountInfo = yield smartAccount.sendRpc({
1116
- method: "particle_aa_getBTCAccount",
1117
- params: [
1118
- {
1119
- name,
1120
- version,
1121
- btcPublicKey,
1122
- btcAddress
1123
- }
1124
- ]
1125
- });
1126
- const address = (_a = accountInfo == null ? void 0 : accountInfo[0]) == null ? void 0 : _a.smartAccountAddress;
1127
- if (typeof window !== "undefined" && localStorage && address) {
1128
- localStorage.setItem(localKey, address);
1129
- }
1130
- return address;
1131
- });
1132
- var getBTCAccountInfo = (smartAccount, btcAddress, name, version) => __async(void 0, null, function* () {
1133
- const btcPublicKey = yield smartAccount.provider.getPublicKey();
1134
- const [accountInfo] = yield smartAccount.sendRpc({
1135
- method: "particle_aa_getBTCAccount",
1136
- params: [
1137
- {
1138
- name,
1139
- version,
1140
- btcPublicKey,
1141
- btcAddress
1142
- }
1143
- ]
1144
- });
1145
- const address = accountInfo.smartAccountAddress;
1146
- const addresses = yield smartAccount.provider.request({ method: "eth_accounts" });
1147
- const owner = addresses[0];
1148
- const localKey = `particle_${name}_${version}_${owner}`;
1149
- if (typeof window !== "undefined" && localStorage && address) {
1150
- localStorage.setItem(localKey, address);
1151
- }
1152
- return accountInfo;
1153
- });
1154
1112
 
1155
1113
  // src/components/copyText/index.tsx
1156
1114
  import { useState as useState4 } from "react";
@@ -1420,7 +1378,11 @@ var sign_module_default = classes8;
1420
1378
 
1421
1379
  // src/components/signModal/index.tsx
1422
1380
  import { Fragment as Fragment3, jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
1423
- var SignModal = ({ open, onClose, onOpen }) => {
1381
+ var SignModal = ({
1382
+ open,
1383
+ onClose,
1384
+ onOpen
1385
+ }) => {
1424
1386
  const [userOpBundle, setUserOpBundle] = useState5();
1425
1387
  const [notRemindChecked, setNotRemindChecked] = useState5(false);
1426
1388
  const [loading, setLoading] = useState5(false);
@@ -1602,10 +1564,12 @@ var SignModal = ({ open, onClose, onOpen }) => {
1602
1564
  var _a, _b;
1603
1565
  return ((_b = (_a = item.estimatedChanges.natives) == null ? void 0 : _a[0]) == null ? void 0 : _b.nativeChange) && item.estimatedChanges.natives[0].nativeChange.startsWith("-");
1604
1566
  }
1605
- ).map((item) => {
1606
- var _a, _b, _c, _d;
1607
- return BigInt(((_d = (_c = (_b = (_a = item.estimatedChanges) == null ? void 0 : _a.natives) == null ? void 0 : _b[0]) == null ? void 0 : _c.nativeChange) == null ? void 0 : _d.replace("-", "")) || 0);
1608
- }).reduce((accumulator, currentValue) => accumulator + currentValue, BigInt(0));
1567
+ ).map(
1568
+ (item) => {
1569
+ var _a, _b, _c, _d;
1570
+ return BigInt(((_d = (_c = (_b = (_a = item.estimatedChanges) == null ? void 0 : _a.natives) == null ? void 0 : _b[0]) == null ? void 0 : _c.nativeChange) == null ? void 0 : _d.replace("-", "")) || 0);
1571
+ }
1572
+ ).reduce((accumulator, currentValue) => accumulator + currentValue, BigInt(0));
1609
1573
  if (userOpBundle.userOp.paymasterAndData.length > 2) {
1610
1574
  setDisabled(nativeBalance < nativeChange);
1611
1575
  } else {
@@ -1627,37 +1591,52 @@ var SignModal = ({ open, onClose, onOpen }) => {
1627
1591
  return JSON.stringify(obj, null, 2);
1628
1592
  }
1629
1593
  }, [requestArguments]);
1630
- return /* @__PURE__ */ jsx8(modal_default, { open, onClose, isDismissable: false, contentClassName: sign_module_default.modalContent, children: /* @__PURE__ */ jsxs5(Fragment3, { children: [
1631
- /* @__PURE__ */ jsx8("img", { className: sign_module_default.closeBtn, src: close_default, onClick: closeModal }),
1632
- requestArguments && /* @__PURE__ */ jsx8("div", { className: sign_module_default.signTitle, children: requestArguments.method == "personal_sign" /* personalSign */ ? "Sign Message" : "Sign Typed Data" }),
1633
- /* @__PURE__ */ jsxs5("div", { className: sign_module_default.chainInfo, children: [
1634
- /* @__PURE__ */ jsx8("img", { src: chainInfo == null ? void 0 : chainInfo.icon }),
1635
- chainInfo == null ? void 0 : chainInfo.fullname.replace("Mainnet", "")
1636
- ] }),
1637
- /* @__PURE__ */ jsx8("div", { className: sign_module_default.addressContainer, children: /* @__PURE__ */ jsx8(CopyText, { value: evmAccount, style: { textDecorationLine: "none" }, children: /* @__PURE__ */ jsxs5("div", { className: sign_module_default.addressInfo, children: [
1638
- shortString(evmAccount),
1639
- /* @__PURE__ */ jsx8("img", { src: copy_default })
1640
- ] }) }) }),
1641
- /* @__PURE__ */ jsxs5("div", { className: sign_module_default.detailsContent + (deserializeResult || requestArguments ? ` ${sign_module_default.fill}` : ""), children: [
1642
- deserializeResult && deserializeResult.map((details, index) => /* @__PURE__ */ jsx8(transactionDetails_default, { details }, `${details.type}-${index}`)),
1643
- unsignedMessage && /* @__PURE__ */ jsx8("div", { className: sign_module_default.unsignedMessage, children: unsignedMessage })
1644
- ] }),
1645
- gasFee && /* @__PURE__ */ jsx8("div", { className: sign_module_default.estimatedGas, children: `Estimated gas fee: ${formatEther(gasFee)} ${chainInfo == null ? void 0 : chainInfo.nativeCurrency.symbol}` }),
1646
- /* @__PURE__ */ jsx8(
1647
- button_default,
1648
- {
1649
- onClick: confirmTx,
1650
- className: sign_module_default.signBtn,
1651
- isLoading: loading || deserializeLoading,
1652
- isDisabled: disabled,
1653
- children: deserializeLoading ? "LOADING" : disabled ? "INSUFFICIENT FEE" : "CONFIRM"
1654
- }
1655
- ),
1656
- showNotRemind && /* @__PURE__ */ jsxs5("div", { className: sign_module_default.notRemind, onClick: toggleNotRemind, children: [
1657
- /* @__PURE__ */ jsx8("img", { src: notRemindChecked ? check_box_default : check_box_blank_default }),
1658
- "Do not remind me again"
1659
- ] })
1660
- ] }) });
1594
+ return /* @__PURE__ */ jsx8(
1595
+ modal_default,
1596
+ {
1597
+ open,
1598
+ onClose,
1599
+ isDismissable: false,
1600
+ contentClassName: sign_module_default.modalContent,
1601
+ children: /* @__PURE__ */ jsxs5(Fragment3, { children: [
1602
+ /* @__PURE__ */ jsx8("img", { className: sign_module_default.closeBtn, src: close_default, onClick: closeModal }),
1603
+ requestArguments && /* @__PURE__ */ jsx8("div", { className: sign_module_default.signTitle, children: requestArguments.method == "personal_sign" /* personalSign */ ? "Sign Message" : "Sign Typed Data" }),
1604
+ /* @__PURE__ */ jsxs5("div", { className: sign_module_default.chainInfo, children: [
1605
+ /* @__PURE__ */ jsx8("img", { src: chainInfo == null ? void 0 : chainInfo.icon }),
1606
+ chainInfo == null ? void 0 : chainInfo.fullname.replace("Mainnet", "")
1607
+ ] }),
1608
+ /* @__PURE__ */ jsx8("div", { className: sign_module_default.addressContainer, children: /* @__PURE__ */ jsx8(CopyText, { value: evmAccount, style: { textDecorationLine: "none" }, children: /* @__PURE__ */ jsxs5("div", { className: sign_module_default.addressInfo, children: [
1609
+ shortString(evmAccount),
1610
+ /* @__PURE__ */ jsx8("img", { src: copy_default })
1611
+ ] }) }) }),
1612
+ /* @__PURE__ */ jsxs5(
1613
+ "div",
1614
+ {
1615
+ className: sign_module_default.detailsContent + (deserializeResult || requestArguments ? ` ${sign_module_default.fill}` : ""),
1616
+ children: [
1617
+ deserializeResult && deserializeResult.map((details, index) => /* @__PURE__ */ jsx8(transactionDetails_default, { details }, `${details.type}-${index}`)),
1618
+ unsignedMessage && /* @__PURE__ */ jsx8("div", { className: sign_module_default.unsignedMessage, children: unsignedMessage })
1619
+ ]
1620
+ }
1621
+ ),
1622
+ gasFee && /* @__PURE__ */ jsx8("div", { className: sign_module_default.estimatedGas, children: `Estimated gas fee: ${formatEther(gasFee)} ${chainInfo == null ? void 0 : chainInfo.nativeCurrency.symbol}` }),
1623
+ /* @__PURE__ */ jsx8(
1624
+ button_default,
1625
+ {
1626
+ onClick: confirmTx,
1627
+ className: sign_module_default.signBtn,
1628
+ isLoading: loading || deserializeLoading,
1629
+ isDisabled: disabled,
1630
+ children: deserializeLoading ? "LOADING" : disabled ? "INSUFFICIENT FEE" : "CONFIRM"
1631
+ }
1632
+ ),
1633
+ showNotRemind && /* @__PURE__ */ jsxs5("div", { className: sign_module_default.notRemind, onClick: toggleNotRemind, children: [
1634
+ /* @__PURE__ */ jsx8("img", { src: notRemindChecked ? check_box_default : check_box_blank_default }),
1635
+ "Do not remind me again"
1636
+ ] })
1637
+ ] })
1638
+ }
1639
+ );
1661
1640
  };
1662
1641
  var signModal_default = SignModal;
1663
1642
 
@@ -1819,7 +1798,11 @@ var ConnectProvider = ({
1819
1798
  isModalOpen: connectModalOpen,
1820
1799
  openModal: openConnectModal
1821
1800
  } = useModalStateValue_default();
1822
- const { closeModal: closeSignModal, isModalOpen: signModalOpen, openModal: openSignModal } = useModalStateValue_default();
1801
+ const {
1802
+ closeModal: closeSignModal,
1803
+ isModalOpen: signModalOpen,
1804
+ openModal: openSignModal
1805
+ } = useModalStateValue_default();
1823
1806
  const [connectorId, setConnectorId] = useState7();
1824
1807
  const [accounts, setAccounts] = useState7([]);
1825
1808
  const [evmAccount, setEVMAccount] = useState7();
@@ -1904,7 +1887,12 @@ var ConnectProvider = ({
1904
1887
  }
1905
1888
  if (!window.__bitcoinSmartAccount || (window == null ? void 0 : window.__bitcoinSmartAccount) && ((window == null ? void 0 : window.__bitcoinSmartAccount.smartAccountContract.version) !== accountContract.version || (window == null ? void 0 : window.__bitcoinSmartAccount.smartAccountContract.name) !== accountContract.name)) {
1906
1889
  const smartAccount2 = new SmartAccount(
1907
- new AASignerProvider(evmSupportChainIds, options.projectId, options.clientKey, options.rpcUrls),
1890
+ new AASignerProvider(
1891
+ evmSupportChainIds,
1892
+ options.projectId,
1893
+ options.clientKey,
1894
+ options.rpcUrls
1895
+ ),
1908
1896
  options
1909
1897
  );
1910
1898
  smartAccount2.setSmartAccountContract(accountContract);
@@ -1914,35 +1902,9 @@ var ConnectProvider = ({
1914
1902
  window.__bitcoinSmartAccount.provider.personalSign = signMessage;
1915
1903
  return window.__bitcoinSmartAccount;
1916
1904
  }, [options, evmSupportChainIds, getPublicKey, signMessage, accountContract]);
1917
- useEffect5(() => {
1918
- if (accounts.length > 0 && smartAccount) {
1919
- getBTCAAAddress(smartAccount, accounts[0], accountContract.name, accountContract.version).then((res) => {
1920
- setEVMAccount(res);
1921
- }).catch((e) => {
1922
- setEVMAccount(void 0);
1923
- console.error("smartAccount getAddress error", e);
1924
- });
1925
- } else {
1926
- setEVMAccount(void 0);
1927
- }
1928
- }, [accountContract, accounts, smartAccount]);
1929
- const getSmartAccountInfo = useCallback7(() => __async(void 0, null, function* () {
1930
- if (accounts.length > 0 && smartAccount) {
1931
- const accountInfo = yield getBTCAccountInfo(
1932
- smartAccount,
1933
- accounts[0],
1934
- accountContract.name,
1935
- accountContract.version
1936
- );
1937
- setEVMAccount(accountInfo.smartAccountAddress);
1938
- return accountInfo;
1939
- }
1940
- return void 0;
1941
- }), [accounts, smartAccount, accountContract, setEVMAccount]);
1942
1905
  const requestAccount = useCallback7(
1943
1906
  (connector2) => __async(void 0, null, function* () {
1944
1907
  let accounts2 = yield connector2.getAccounts();
1945
- console.log("requestAccount start, autoConnect", accounts2, autoConnect);
1946
1908
  if (accounts2.length === 0 && autoConnect) {
1947
1909
  accounts2 = yield connector2.requestAccounts();
1948
1910
  }
@@ -1950,23 +1912,18 @@ var ConnectProvider = ({
1950
1912
  }),
1951
1913
  [autoConnect]
1952
1914
  );
1953
- const requestDirectAccount = useCallback7(
1954
- (connector2) => __async(void 0, null, function* () {
1955
- console.log(111);
1956
- let accounts2 = yield connector2.getAccounts();
1957
- console.log("requestAccount start, autoConnect", accounts2, autoConnect);
1958
- if (accounts2.length === 0) {
1959
- accounts2 = yield connector2.requestAccounts();
1960
- }
1961
- setAccounts(accounts2);
1962
- return accounts2;
1963
- }),
1964
- []
1965
- );
1915
+ const requestDirectAccount = useCallback7((connector2) => __async(void 0, null, function* () {
1916
+ let accounts2 = yield connector2.getAccounts();
1917
+ if (accounts2.length === 0) {
1918
+ accounts2 = yield connector2.requestAccounts();
1919
+ }
1920
+ setAccounts(accounts2);
1921
+ return accounts2;
1922
+ }), []);
1966
1923
  useEffect5(() => {
1967
1924
  if (connector) {
1968
1925
  requestAccount(connector).catch((e) => {
1969
- console.log("get account error", e);
1926
+ console.error("get account error", e);
1970
1927
  setAccounts([]);
1971
1928
  });
1972
1929
  } else {
@@ -2096,8 +2053,7 @@ var ConnectProvider = ({
2096
2053
  switchNetwork,
2097
2054
  sendBitcoin: sendBitcoin2,
2098
2055
  accountContract,
2099
- setAccountContract,
2100
- getSmartAccountInfo
2056
+ setAccountContract
2101
2057
  },
2102
2058
  children: [
2103
2059
  children,
@@ -2112,8 +2068,8 @@ var useConnectProvider = () => {
2112
2068
  return context;
2113
2069
  };
2114
2070
 
2115
- // src/components/btcWalletSelectorContext.tsx
2116
- import React, { useContext as useContext2, useEffect as useEffect7, useMemo as useMemo6, useRef, useState as useState8 } from "react";
2071
+ // src/core/btcWalletSelectorContext.tsx
2072
+ import React, { useContext as useContext2, useEffect as useEffect6, useMemo as useMemo6, useRef, useState as useState8 } from "react";
2117
2073
 
2118
2074
  // src/components/confirmBox/Modal.tsx
2119
2075
  import { jsx as jsx10, jsxs as jsxs7 } from "react/jsx-runtime";
@@ -2167,17 +2123,7 @@ function ComfirmBox({ onClose, status = 1, fromChain = {
2167
2123
  ] });
2168
2124
  }
2169
2125
 
2170
- // src/components/hook.tsx
2171
- import { useEffect as useEffect6 } from "react";
2172
- function InitContextHook() {
2173
- const btcContext = useBtcWalletSelector();
2174
- useEffect6(() => {
2175
- window.btcContext = btcContext;
2176
- }, [btcContext]);
2177
- return null;
2178
- }
2179
-
2180
- // src/components/btcWalletSelectorContext.tsx
2126
+ // src/core/btcWalletSelectorContext.tsx
2181
2127
  import { jsx as jsx12, jsxs as jsxs9 } from "react/jsx-runtime";
2182
2128
  var WalletSelectorContext = React.createContext(null);
2183
2129
  function BtcWalletSelectorContextProvider({
@@ -2237,11 +2183,18 @@ function BtcWalletSelectorContextProvider({
2237
2183
  }
2238
2184
  }
2239
2185
  ),
2240
- /* @__PURE__ */ jsx12(InitContextHook, {})
2186
+ /* @__PURE__ */ jsx12(InitBtcWalletSelectorContext, {})
2241
2187
  ]
2242
2188
  }
2243
2189
  ) });
2244
2190
  }
2191
+ function InitBtcWalletSelectorContext() {
2192
+ const context = useBtcWalletSelector();
2193
+ useEffect6(() => {
2194
+ window.btcContext = context;
2195
+ }, [context]);
2196
+ return null;
2197
+ }
2245
2198
  function useBtcWalletSelector() {
2246
2199
  const { openConnectModal, openConnectModalAsync, disconnect, requestDirectAccount } = useConnectModal();
2247
2200
  const { accounts, sendBitcoin: sendBitcoin2, getPublicKey, provider, signMessage, connector } = useBTCProvider();
@@ -2251,7 +2204,7 @@ function useBtcWalletSelector() {
2251
2204
  const providerRef = useRef(null);
2252
2205
  const [updater, setUpdater] = useState8(1);
2253
2206
  const context = useContext2(WalletSelectorContext);
2254
- useEffect7(() => {
2207
+ useEffect6(() => {
2255
2208
  if (provider) {
2256
2209
  getPublicKey().then((res) => {
2257
2210
  publicKey.current = res;
@@ -2259,10 +2212,10 @@ function useBtcWalletSelector() {
2259
2212
  providerRef.current = provider;
2260
2213
  }
2261
2214
  }, [provider, updater]);
2262
- useEffect7(() => {
2215
+ useEffect6(() => {
2263
2216
  signMessageFn.current = signMessage;
2264
2217
  }, [signMessage]);
2265
- useEffect7(() => {
2218
+ useEffect6(() => {
2266
2219
  const fn = (account) => {
2267
2220
  if (account) {
2268
2221
  getPublicKey().then((res) => {
@@ -2296,7 +2249,7 @@ function useBtcWalletSelector() {
2296
2249
  autoConnect: () => __async(this, null, function* () {
2297
2250
  let times = 0;
2298
2251
  while (!connectorRef.current) {
2299
- yield sleep(500);
2252
+ yield delay(500);
2300
2253
  if (times++ > 10) {
2301
2254
  return null;
2302
2255
  }
@@ -2313,7 +2266,7 @@ function useBtcWalletSelector() {
2313
2266
  getPublicKey: () => __async(this, null, function* () {
2314
2267
  let times = 0;
2315
2268
  while (!publicKey.current) {
2316
- yield sleep(1e3);
2269
+ yield delay(1e3);
2317
2270
  if (times++ > 10) {
2318
2271
  return null;
2319
2272
  }
@@ -2329,7 +2282,7 @@ function useBtcWalletSelector() {
2329
2282
  getBalance: () => __async(this, null, function* () {
2330
2283
  let times = 0;
2331
2284
  while (!providerRef.current) {
2332
- yield sleep(500);
2285
+ yield delay(500);
2333
2286
  if (times++ > 10) {
2334
2287
  return null;
2335
2288
  }
@@ -2340,13 +2293,8 @@ function useBtcWalletSelector() {
2340
2293
  sendBitcoin: sendBitcoin2
2341
2294
  };
2342
2295
  }
2343
- function sleep(time) {
2344
- return new Promise(function(resolve) {
2345
- setTimeout(resolve, time);
2346
- });
2347
- }
2348
2296
 
2349
- // src/utils/setupBTCWallet.ts
2297
+ // src/core/setupBTCWallet.ts
2350
2298
  import { providers, transactions } from "near-api-js";
2351
2299
  import { actionCreators } from "@near-js/transactions";
2352
2300
  import { PublicKey } from "near-api-js/lib/utils/key_pair";
@@ -2439,7 +2387,8 @@ function createIframe({
2439
2387
  zIndex: "100000",
2440
2388
  boxShadow: "0 0 10px rgba(0, 0, 0, 0.1)",
2441
2389
  borderRadius: "10px",
2442
- display: "block"
2390
+ display: "block",
2391
+ border: "none"
2443
2392
  }, iframeStyle));
2444
2393
  document.body.appendChild(iframe);
2445
2394
  return iframe;
@@ -2457,7 +2406,6 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
2457
2406
  originalAccountId && iframeSrc.searchParams.set("originalAccountId", originalAccountId);
2458
2407
  originalPublicKey && iframeSrc.searchParams.set("originalPublicKey", originalPublicKey);
2459
2408
  iframe.src = iframeSrc.toString();
2460
- console.log("iframe src", iframe.src);
2461
2409
  window.addEventListener("message", (event) => __async(this, null, function* () {
2462
2410
  var _a2, _b;
2463
2411
  if (event.origin !== iframeSrc.origin)
@@ -2533,8 +2481,8 @@ var nearRpcUrls = {
2533
2481
  ]
2534
2482
  };
2535
2483
  var btcRpcUrls = {
2536
- mainnet: "https://blockstream.info/api",
2537
- testnet: "https://blockstream.info/testnet/api"
2484
+ mainnet: "https://mempool.space/api",
2485
+ testnet: "https://mempool.space/testnet/api"
2538
2486
  };
2539
2487
 
2540
2488
  // src/utils/request.ts
@@ -2607,7 +2555,7 @@ function request(url, options) {
2607
2555
  });
2608
2556
  }
2609
2557
 
2610
- // src/utils/setupBTCWallet.ts
2558
+ // src/core/setupBTCWallet.ts
2611
2559
  var { transfer, functionCall } = actionCreators;
2612
2560
  var state = {
2613
2561
  saveAccount(account) {
@@ -2672,7 +2620,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2672
2620
  if (!inter) {
2673
2621
  inter = setInterval(() => __async(void 0, null, function* () {
2674
2622
  const btcContext = window.btcContext;
2675
- console.log("inter btcContext:", btcContext);
2676
2623
  if (btcContext) {
2677
2624
  clearInterval(inter);
2678
2625
  const context = btcContext.getContext();
@@ -2694,12 +2641,10 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2694
2641
  });
2695
2642
  }));
2696
2643
  context.on("btcLogOut", (e) => __async(void 0, null, function* () {
2697
- console.log(3333);
2698
2644
  emitter.emit("accountsChanged", {
2699
2645
  accounts: []
2700
2646
  });
2701
2647
  }));
2702
- console.log("metadata.autoConnect:", metadata);
2703
2648
  if ("autoConnect" in metadata && metadata.autoConnect && localStorage.getItem("near-wallet-selector:selectedWalletId") === '"btc-wallet"') {
2704
2649
  yield btcContext.autoConnect();
2705
2650
  }
@@ -2883,7 +2828,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2883
2828
  btcPubKey: state.getBtcPublicKey(),
2884
2829
  data: toHex(strIntention)
2885
2830
  });
2886
- console.log("result:", result);
2887
2831
  if (result.result_code === 0) {
2888
2832
  const hash = newTransactions.map((t) => t.hash);
2889
2833
  console.log("txHash:", hash);
@@ -2899,7 +2843,10 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2899
2843
  const checkAndSetupWalletButton = () => {
2900
2844
  const accountId = state.getAccount();
2901
2845
  const btcContext = window.btcContext;
2902
- console.log("checkAndSetupWalletButton:", accountId, btcContext.account);
2846
+ console.log("checkAndSetupWalletButton:", {
2847
+ nearAccountId: accountId,
2848
+ btcAccountId: btcContext.account
2849
+ });
2903
2850
  if (accountId && btcContext.account) {
2904
2851
  setupWalletButton(network, wallet2, btcContext);
2905
2852
  } else {
@@ -2995,7 +2942,7 @@ function pollTransactionStatuses(network, hashes) {
2995
2942
  });
2996
2943
  }
2997
2944
 
2998
- // src/utils/bridgeSupplyUtils.ts
2945
+ // src/core/bridgeSupplyUtils.ts
2999
2946
  import { providers as providers2 } from "near-api-js";
3000
2947
  import Big from "big.js";
3001
2948
  function nearViewMethod(contractId, methodName, args, network) {
@@ -3030,12 +2977,13 @@ function getDepositAddress(btcPublicKey, contractId, network) {
3030
2977
  return res;
3031
2978
  });
3032
2979
  }
3033
- function getGasPrice(btcRpcUrl) {
2980
+ function getGasPrice(network) {
3034
2981
  return __async(this, null, function* () {
3035
2982
  const defaultFeeRate = 100;
3036
2983
  try {
3037
- const res = yield request(`${btcRpcUrl}/fee-estimates`);
3038
- const feeRate = res[6];
2984
+ const btcRpcUrl = btcRpcUrls[network];
2985
+ const res = yield fetch(`${btcRpcUrl}/v1/fees/recommended`).then((res2) => res2.json());
2986
+ const feeRate = res.fastestFee;
3039
2987
  return feeRate || defaultFeeRate;
3040
2988
  } catch (error) {
3041
2989
  return defaultFeeRate;
@@ -3064,12 +3012,21 @@ function receiveDepositMsg(_0, _1) {
3064
3012
  }
3065
3013
  function checkTransactionStatus(baseUrl, txHash) {
3066
3014
  return __async(this, null, function* () {
3067
- const res = yield request(`${baseUrl}/v1/bridgeFromTx?fromTxHash=${txHash}`);
3015
+ const res = yield request(`${baseUrl}/v1/bridgeFromTx?fromTxHash=${txHash}`, {
3016
+ timeout: 6e4,
3017
+ pollingInterval: 5e3,
3018
+ maxPollingAttempts: 10,
3019
+ shouldStopPolling: (res2) => res2.result_code === 0
3020
+ });
3068
3021
  return res;
3069
3022
  });
3070
3023
  }
3071
- function executeBurrowSupply(amount, environment) {
3072
- return __async(this, null, function* () {
3024
+ function executeBurrowSupply(_0) {
3025
+ return __async(this, arguments, function* ({
3026
+ amount,
3027
+ feeRate,
3028
+ environment = "mainnet"
3029
+ }) {
3073
3030
  try {
3074
3031
  if (typeof window === "undefined" || !window.btcContext) {
3075
3032
  throw new Error("BTC Provider is not initialized.");
@@ -3077,17 +3034,18 @@ function executeBurrowSupply(amount, environment) {
3077
3034
  const btcProvider = window.btcContext;
3078
3035
  const network = environment === "dev" ? "testnet" : environment;
3079
3036
  const config = walletConfig[environment];
3080
- const btcRpcUrl = btcRpcUrls[network];
3081
3037
  const btcPublicKey = yield btcProvider.getPublicKey();
3082
3038
  if (!btcPublicKey) {
3083
3039
  throw new Error("BTC Public Key is not available.");
3084
3040
  }
3085
3041
  const address = yield getDepositAddress(btcPublicKey, config.contractId, network);
3086
- const feeRate = yield getGasPrice(btcRpcUrl);
3087
- const txHash = yield sendBitcoin(btcProvider, address, amount, feeRate);
3088
- yield receiveDepositMsg(config.base_url, { btcPublicKey, txHash });
3089
- const status = yield checkTransactionStatus(config.base_url, txHash);
3090
- console.log("Transaction Status:", status);
3042
+ const _feeRate = feeRate || (yield getGasPrice(network));
3043
+ console.log("feeRate", _feeRate);
3044
+ const txHash = yield sendBitcoin(btcProvider, address, amount, _feeRate);
3045
+ const receiveDepositMsgRes = yield receiveDepositMsg(config.base_url, { btcPublicKey, txHash });
3046
+ console.log("receiveDepositMsg resp:", receiveDepositMsgRes);
3047
+ const checkTransactionStatusRes = yield checkTransactionStatus(config.base_url, txHash);
3048
+ console.log("checkTransactionStatus resp:", checkTransactionStatusRes);
3091
3049
  } catch (error) {
3092
3050
  console.error("Error executing Bridge+BurrowSupply:", error);
3093
3051
  }
@@ -3096,7 +3054,7 @@ function executeBurrowSupply(amount, environment) {
3096
3054
 
3097
3055
  // src/index.ts
3098
3056
  var getVersion = () => {
3099
- return "0.2.6";
3057
+ return "0.2.7";
3100
3058
  };
3101
3059
  if (typeof window !== "undefined") {
3102
3060
  window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();
@@ -3107,7 +3065,6 @@ export {
3107
3065
  BtcWalletSelectorContextProvider,
3108
3066
  BybitConnector,
3109
3067
  ConnectProvider,
3110
- InitContextHook,
3111
3068
  InjectedConnector,
3112
3069
  OKXConnector,
3113
3070
  TokenPocketConnector,