btc-wallet 0.2.6 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -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({
@@ -2185,6 +2131,7 @@ function BtcWalletSelectorContextProvider({
2185
2131
  autoConnect = false
2186
2132
  }) {
2187
2133
  const [isProcessing, setIsProcessing] = useState8(false);
2134
+ const connectors = [new UnisatConnector(), new XverseConnector()];
2188
2135
  const walletSelectorContextValue = useMemo6(() => {
2189
2136
  const simpleFn = {};
2190
2137
  return {
@@ -2224,7 +2171,7 @@ function BtcWalletSelectorContextProvider({
2224
2171
  }
2225
2172
  },
2226
2173
  autoConnect: false,
2227
- connectors: [new UnisatConnector()],
2174
+ connectors,
2228
2175
  children: [
2229
2176
  children,
2230
2177
  isProcessing && /* @__PURE__ */ jsx12(
@@ -2237,11 +2184,18 @@ function BtcWalletSelectorContextProvider({
2237
2184
  }
2238
2185
  }
2239
2186
  ),
2240
- /* @__PURE__ */ jsx12(InitContextHook, {})
2187
+ /* @__PURE__ */ jsx12(InitBtcWalletSelectorContext, {})
2241
2188
  ]
2242
2189
  }
2243
2190
  ) });
2244
2191
  }
2192
+ function InitBtcWalletSelectorContext() {
2193
+ const context = useBtcWalletSelector();
2194
+ useEffect6(() => {
2195
+ window.btcContext = context;
2196
+ }, [context]);
2197
+ return null;
2198
+ }
2245
2199
  function useBtcWalletSelector() {
2246
2200
  const { openConnectModal, openConnectModalAsync, disconnect, requestDirectAccount } = useConnectModal();
2247
2201
  const { accounts, sendBitcoin: sendBitcoin2, getPublicKey, provider, signMessage, connector } = useBTCProvider();
@@ -2251,7 +2205,7 @@ function useBtcWalletSelector() {
2251
2205
  const providerRef = useRef(null);
2252
2206
  const [updater, setUpdater] = useState8(1);
2253
2207
  const context = useContext2(WalletSelectorContext);
2254
- useEffect7(() => {
2208
+ useEffect6(() => {
2255
2209
  if (provider) {
2256
2210
  getPublicKey().then((res) => {
2257
2211
  publicKey.current = res;
@@ -2259,10 +2213,10 @@ function useBtcWalletSelector() {
2259
2213
  providerRef.current = provider;
2260
2214
  }
2261
2215
  }, [provider, updater]);
2262
- useEffect7(() => {
2216
+ useEffect6(() => {
2263
2217
  signMessageFn.current = signMessage;
2264
2218
  }, [signMessage]);
2265
- useEffect7(() => {
2219
+ useEffect6(() => {
2266
2220
  const fn = (account) => {
2267
2221
  if (account) {
2268
2222
  getPublicKey().then((res) => {
@@ -2296,7 +2250,7 @@ function useBtcWalletSelector() {
2296
2250
  autoConnect: () => __async(this, null, function* () {
2297
2251
  let times = 0;
2298
2252
  while (!connectorRef.current) {
2299
- yield sleep(500);
2253
+ yield delay(500);
2300
2254
  if (times++ > 10) {
2301
2255
  return null;
2302
2256
  }
@@ -2313,7 +2267,7 @@ function useBtcWalletSelector() {
2313
2267
  getPublicKey: () => __async(this, null, function* () {
2314
2268
  let times = 0;
2315
2269
  while (!publicKey.current) {
2316
- yield sleep(1e3);
2270
+ yield delay(1e3);
2317
2271
  if (times++ > 10) {
2318
2272
  return null;
2319
2273
  }
@@ -2329,7 +2283,7 @@ function useBtcWalletSelector() {
2329
2283
  getBalance: () => __async(this, null, function* () {
2330
2284
  let times = 0;
2331
2285
  while (!providerRef.current) {
2332
- yield sleep(500);
2286
+ yield delay(500);
2333
2287
  if (times++ > 10) {
2334
2288
  return null;
2335
2289
  }
@@ -2340,13 +2294,8 @@ function useBtcWalletSelector() {
2340
2294
  sendBitcoin: sendBitcoin2
2341
2295
  };
2342
2296
  }
2343
- function sleep(time) {
2344
- return new Promise(function(resolve) {
2345
- setTimeout(resolve, time);
2346
- });
2347
- }
2348
2297
 
2349
- // src/utils/setupBTCWallet.ts
2298
+ // src/core/setupBTCWallet.ts
2350
2299
  import { providers, transactions } from "near-api-js";
2351
2300
  import { actionCreators } from "@near-js/transactions";
2352
2301
  import { PublicKey } from "near-api-js/lib/utils/key_pair";
@@ -2439,7 +2388,8 @@ function createIframe({
2439
2388
  zIndex: "100000",
2440
2389
  boxShadow: "0 0 10px rgba(0, 0, 0, 0.1)",
2441
2390
  borderRadius: "10px",
2442
- display: "block"
2391
+ display: "block",
2392
+ border: "none"
2443
2393
  }, iframeStyle));
2444
2394
  document.body.appendChild(iframe);
2445
2395
  return iframe;
@@ -2457,7 +2407,6 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
2457
2407
  originalAccountId && iframeSrc.searchParams.set("originalAccountId", originalAccountId);
2458
2408
  originalPublicKey && iframeSrc.searchParams.set("originalPublicKey", originalPublicKey);
2459
2409
  iframe.src = iframeSrc.toString();
2460
- console.log("iframe src", iframe.src);
2461
2410
  window.addEventListener("message", (event) => __async(this, null, function* () {
2462
2411
  var _a2, _b;
2463
2412
  if (event.origin !== iframeSrc.origin)
@@ -2533,8 +2482,8 @@ var nearRpcUrls = {
2533
2482
  ]
2534
2483
  };
2535
2484
  var btcRpcUrls = {
2536
- mainnet: "https://blockstream.info/api",
2537
- testnet: "https://blockstream.info/testnet/api"
2485
+ mainnet: "https://mempool.space/api",
2486
+ testnet: "https://mempool.space/testnet/api"
2538
2487
  };
2539
2488
 
2540
2489
  // src/utils/request.ts
@@ -2607,7 +2556,7 @@ function request(url, options) {
2607
2556
  });
2608
2557
  }
2609
2558
 
2610
- // src/utils/setupBTCWallet.ts
2559
+ // src/core/setupBTCWallet.ts
2611
2560
  var { transfer, functionCall } = actionCreators;
2612
2561
  var state = {
2613
2562
  saveAccount(account) {
@@ -2672,7 +2621,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2672
2621
  if (!inter) {
2673
2622
  inter = setInterval(() => __async(void 0, null, function* () {
2674
2623
  const btcContext = window.btcContext;
2675
- console.log("inter btcContext:", btcContext);
2676
2624
  if (btcContext) {
2677
2625
  clearInterval(inter);
2678
2626
  const context = btcContext.getContext();
@@ -2694,12 +2642,10 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2694
2642
  });
2695
2643
  }));
2696
2644
  context.on("btcLogOut", (e) => __async(void 0, null, function* () {
2697
- console.log(3333);
2698
2645
  emitter.emit("accountsChanged", {
2699
2646
  accounts: []
2700
2647
  });
2701
2648
  }));
2702
- console.log("metadata.autoConnect:", metadata);
2703
2649
  if ("autoConnect" in metadata && metadata.autoConnect && localStorage.getItem("near-wallet-selector:selectedWalletId") === '"btc-wallet"') {
2704
2650
  yield btcContext.autoConnect();
2705
2651
  }
@@ -2883,7 +2829,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2883
2829
  btcPubKey: state.getBtcPublicKey(),
2884
2830
  data: toHex(strIntention)
2885
2831
  });
2886
- console.log("result:", result);
2887
2832
  if (result.result_code === 0) {
2888
2833
  const hash = newTransactions.map((t) => t.hash);
2889
2834
  console.log("txHash:", hash);
@@ -2899,7 +2844,10 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2899
2844
  const checkAndSetupWalletButton = () => {
2900
2845
  const accountId = state.getAccount();
2901
2846
  const btcContext = window.btcContext;
2902
- console.log("checkAndSetupWalletButton:", accountId, btcContext.account);
2847
+ console.log("checkAndSetupWalletButton:", {
2848
+ nearAccountId: accountId,
2849
+ btcAccountId: btcContext.account
2850
+ });
2903
2851
  if (accountId && btcContext.account) {
2904
2852
  setupWalletButton(network, wallet2, btcContext);
2905
2853
  } else {
@@ -2995,7 +2943,7 @@ function pollTransactionStatuses(network, hashes) {
2995
2943
  });
2996
2944
  }
2997
2945
 
2998
- // src/utils/bridgeSupplyUtils.ts
2946
+ // src/core/bridgeSupplyUtils.ts
2999
2947
  import { providers as providers2 } from "near-api-js";
3000
2948
  import Big from "big.js";
3001
2949
  function nearViewMethod(contractId, methodName, args, network) {
@@ -3030,12 +2978,13 @@ function getDepositAddress(btcPublicKey, contractId, network) {
3030
2978
  return res;
3031
2979
  });
3032
2980
  }
3033
- function getGasPrice(btcRpcUrl) {
2981
+ function getGasPrice(network) {
3034
2982
  return __async(this, null, function* () {
3035
2983
  const defaultFeeRate = 100;
3036
2984
  try {
3037
- const res = yield request(`${btcRpcUrl}/fee-estimates`);
3038
- const feeRate = res[6];
2985
+ const btcRpcUrl = btcRpcUrls[network];
2986
+ const res = yield fetch(`${btcRpcUrl}/v1/fees/recommended`).then((res2) => res2.json());
2987
+ const feeRate = res.fastestFee;
3039
2988
  return feeRate || defaultFeeRate;
3040
2989
  } catch (error) {
3041
2990
  return defaultFeeRate;
@@ -3064,12 +3013,21 @@ function receiveDepositMsg(_0, _1) {
3064
3013
  }
3065
3014
  function checkTransactionStatus(baseUrl, txHash) {
3066
3015
  return __async(this, null, function* () {
3067
- const res = yield request(`${baseUrl}/v1/bridgeFromTx?fromTxHash=${txHash}`);
3016
+ const res = yield request(`${baseUrl}/v1/bridgeFromTx?fromTxHash=${txHash}`, {
3017
+ timeout: 6e4,
3018
+ pollingInterval: 5e3,
3019
+ maxPollingAttempts: 10,
3020
+ shouldStopPolling: (res2) => res2.result_code === 0
3021
+ });
3068
3022
  return res;
3069
3023
  });
3070
3024
  }
3071
- function executeBurrowSupply(amount, environment) {
3072
- return __async(this, null, function* () {
3025
+ function executeBurrowSupply(_0) {
3026
+ return __async(this, arguments, function* ({
3027
+ amount,
3028
+ feeRate,
3029
+ environment = "mainnet"
3030
+ }) {
3073
3031
  try {
3074
3032
  if (typeof window === "undefined" || !window.btcContext) {
3075
3033
  throw new Error("BTC Provider is not initialized.");
@@ -3077,17 +3035,18 @@ function executeBurrowSupply(amount, environment) {
3077
3035
  const btcProvider = window.btcContext;
3078
3036
  const network = environment === "dev" ? "testnet" : environment;
3079
3037
  const config = walletConfig[environment];
3080
- const btcRpcUrl = btcRpcUrls[network];
3081
3038
  const btcPublicKey = yield btcProvider.getPublicKey();
3082
3039
  if (!btcPublicKey) {
3083
3040
  throw new Error("BTC Public Key is not available.");
3084
3041
  }
3085
3042
  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);
3043
+ const _feeRate = feeRate || (yield getGasPrice(network));
3044
+ console.log("feeRate", _feeRate);
3045
+ const txHash = yield sendBitcoin(btcProvider, address, amount, _feeRate);
3046
+ const receiveDepositMsgRes = yield receiveDepositMsg(config.base_url, { btcPublicKey, txHash });
3047
+ console.log("receiveDepositMsg resp:", receiveDepositMsgRes);
3048
+ const checkTransactionStatusRes = yield checkTransactionStatus(config.base_url, txHash);
3049
+ console.log("checkTransactionStatus resp:", checkTransactionStatusRes);
3091
3050
  } catch (error) {
3092
3051
  console.error("Error executing Bridge+BurrowSupply:", error);
3093
3052
  }
@@ -3096,7 +3055,7 @@ function executeBurrowSupply(amount, environment) {
3096
3055
 
3097
3056
  // src/index.ts
3098
3057
  var getVersion = () => {
3099
- return "0.2.6";
3058
+ return "0.2.8";
3100
3059
  };
3101
3060
  if (typeof window !== "undefined") {
3102
3061
  window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();
@@ -3107,7 +3066,6 @@ export {
3107
3066
  BtcWalletSelectorContextProvider,
3108
3067
  BybitConnector,
3109
3068
  ConnectProvider,
3110
- InitContextHook,
3111
3069
  InjectedConnector,
3112
3070
  OKXConnector,
3113
3071
  TokenPocketConnector,