btc-wallet 0.2.6 → 0.2.8

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
@@ -83,7 +83,6 @@ __export(src_exports, {
83
83
  BtcWalletSelectorContextProvider: () => BtcWalletSelectorContextProvider,
84
84
  BybitConnector: () => BybitConnector,
85
85
  ConnectProvider: () => ConnectProvider,
86
- InitContextHook: () => InitContextHook,
87
86
  InjectedConnector: () => InjectedConnector,
88
87
  OKXConnector: () => OKXConnector,
89
88
  TokenPocketConnector: () => TokenPocketConnector,
@@ -731,7 +730,7 @@ var WalletClientProvider = class {
731
730
 
732
731
  // src/hooks/useETHProvider.ts
733
732
  var useETHProvider = () => {
734
- const { evmAccount, smartAccount, getSmartAccountInfo } = useConnectProvider();
733
+ const { evmAccount, smartAccount } = useConnectProvider();
735
734
  const [chainId, setChainId] = (0, import_react3.useState)();
736
735
  (0, import_react3.useEffect)(() => {
737
736
  if (smartAccount) {
@@ -825,7 +824,11 @@ var useETHProvider = () => {
825
824
  return (smartAccount == null ? void 0 : smartAccount.provider).publicClient;
826
825
  }, [smartAccount, chainId]);
827
826
  const provider = (0, import_react3.useMemo)(() => {
828
- const ethereumProvider = new EthereumProvider(sendUserOp, smartAccount == null ? void 0 : smartAccount.provider, evmAccount);
827
+ const ethereumProvider = new EthereumProvider(
828
+ sendUserOp,
829
+ smartAccount == null ? void 0 : smartAccount.provider,
830
+ evmAccount
831
+ );
829
832
  return ethereumProvider;
830
833
  }, [evmAccount, sendUserOp, smartAccount == null ? void 0 : smartAccount.provider]);
831
834
  const walletClient = (0, import_react3.useMemo)(() => {
@@ -837,7 +840,6 @@ var useETHProvider = () => {
837
840
  provider,
838
841
  evmAccount,
839
842
  account: evmAccount,
840
- getSmartAccountInfo,
841
843
  switchChain,
842
844
  chainId,
843
845
  getFeeQuotes,
@@ -1150,57 +1152,6 @@ var convertSignature = (signature) => {
1150
1152
  function caculateNativeFee(userOp) {
1151
1153
  return (BigInt(userOp.callGasLimit) + BigInt(userOp.verificationGasLimit) + BigInt(userOp.preVerificationGas)) * BigInt(userOp.maxFeePerGas);
1152
1154
  }
1153
- var getBTCAAAddress = (smartAccount, btcAddress, name, version) => __async(void 0, null, function* () {
1154
- var _a;
1155
- const addresses = yield smartAccount.provider.request({ method: "eth_accounts" });
1156
- const owner = addresses[0];
1157
- const localKey = `particle_${name}_${version}_${owner}`;
1158
- if (typeof window !== "undefined" && localStorage) {
1159
- const localAA = localStorage.getItem(localKey);
1160
- if (localAA) {
1161
- return localAA;
1162
- }
1163
- }
1164
- const btcPublicKey = yield smartAccount.provider.getPublicKey();
1165
- const accountInfo = yield smartAccount.sendRpc({
1166
- method: "particle_aa_getBTCAccount",
1167
- params: [
1168
- {
1169
- name,
1170
- version,
1171
- btcPublicKey,
1172
- btcAddress
1173
- }
1174
- ]
1175
- });
1176
- const address = (_a = accountInfo == null ? void 0 : accountInfo[0]) == null ? void 0 : _a.smartAccountAddress;
1177
- if (typeof window !== "undefined" && localStorage && address) {
1178
- localStorage.setItem(localKey, address);
1179
- }
1180
- return address;
1181
- });
1182
- var getBTCAccountInfo = (smartAccount, btcAddress, name, version) => __async(void 0, null, function* () {
1183
- const btcPublicKey = yield smartAccount.provider.getPublicKey();
1184
- const [accountInfo] = yield smartAccount.sendRpc({
1185
- method: "particle_aa_getBTCAccount",
1186
- params: [
1187
- {
1188
- name,
1189
- version,
1190
- btcPublicKey,
1191
- btcAddress
1192
- }
1193
- ]
1194
- });
1195
- const address = accountInfo.smartAccountAddress;
1196
- const addresses = yield smartAccount.provider.request({ method: "eth_accounts" });
1197
- const owner = addresses[0];
1198
- const localKey = `particle_${name}_${version}_${owner}`;
1199
- if (typeof window !== "undefined" && localStorage && address) {
1200
- localStorage.setItem(localKey, address);
1201
- }
1202
- return accountInfo;
1203
- });
1204
1155
 
1205
1156
  // src/components/copyText/index.tsx
1206
1157
  var import_react6 = require("react");
@@ -1470,7 +1421,11 @@ var sign_module_default = classes8;
1470
1421
 
1471
1422
  // src/components/signModal/index.tsx
1472
1423
  var import_jsx_runtime8 = require("react/jsx-runtime");
1473
- var SignModal = ({ open, onClose, onOpen }) => {
1424
+ var SignModal = ({
1425
+ open,
1426
+ onClose,
1427
+ onOpen
1428
+ }) => {
1474
1429
  const [userOpBundle, setUserOpBundle] = (0, import_react8.useState)();
1475
1430
  const [notRemindChecked, setNotRemindChecked] = (0, import_react8.useState)(false);
1476
1431
  const [loading, setLoading] = (0, import_react8.useState)(false);
@@ -1652,10 +1607,12 @@ var SignModal = ({ open, onClose, onOpen }) => {
1652
1607
  var _a, _b;
1653
1608
  return ((_b = (_a = item.estimatedChanges.natives) == null ? void 0 : _a[0]) == null ? void 0 : _b.nativeChange) && item.estimatedChanges.natives[0].nativeChange.startsWith("-");
1654
1609
  }
1655
- ).map((item) => {
1656
- var _a, _b, _c, _d;
1657
- 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);
1658
- }).reduce((accumulator, currentValue) => accumulator + currentValue, BigInt(0));
1610
+ ).map(
1611
+ (item) => {
1612
+ var _a, _b, _c, _d;
1613
+ 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);
1614
+ }
1615
+ ).reduce((accumulator, currentValue) => accumulator + currentValue, BigInt(0));
1659
1616
  if (userOpBundle.userOp.paymasterAndData.length > 2) {
1660
1617
  setDisabled(nativeBalance < nativeChange);
1661
1618
  } else {
@@ -1677,37 +1634,52 @@ var SignModal = ({ open, onClose, onOpen }) => {
1677
1634
  return JSON.stringify(obj, null, 2);
1678
1635
  }
1679
1636
  }, [requestArguments]);
1680
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(modal_default, { open, onClose, isDismissable: false, contentClassName: sign_module_default.modalContent, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
1681
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("img", { className: sign_module_default.closeBtn, src: close_default, onClick: closeModal }),
1682
- requestArguments && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: sign_module_default.signTitle, children: requestArguments.method == "personal_sign" /* personalSign */ ? "Sign Message" : "Sign Typed Data" }),
1683
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: sign_module_default.chainInfo, children: [
1684
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("img", { src: chainInfo == null ? void 0 : chainInfo.icon }),
1685
- chainInfo == null ? void 0 : chainInfo.fullname.replace("Mainnet", "")
1686
- ] }),
1687
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: sign_module_default.addressContainer, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(CopyText, { value: evmAccount, style: { textDecorationLine: "none" }, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: sign_module_default.addressInfo, children: [
1688
- shortString(evmAccount),
1689
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("img", { src: copy_default })
1690
- ] }) }) }),
1691
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: sign_module_default.detailsContent + (deserializeResult || requestArguments ? ` ${sign_module_default.fill}` : ""), children: [
1692
- deserializeResult && deserializeResult.map((details, index) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(transactionDetails_default, { details }, `${details.type}-${index}`)),
1693
- unsignedMessage && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: sign_module_default.unsignedMessage, children: unsignedMessage })
1694
- ] }),
1695
- gasFee && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: sign_module_default.estimatedGas, children: `Estimated gas fee: ${(0, import_viem3.formatEther)(gasFee)} ${chainInfo == null ? void 0 : chainInfo.nativeCurrency.symbol}` }),
1696
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1697
- button_default,
1698
- {
1699
- onClick: confirmTx,
1700
- className: sign_module_default.signBtn,
1701
- isLoading: loading || deserializeLoading,
1702
- isDisabled: disabled,
1703
- children: deserializeLoading ? "LOADING" : disabled ? "INSUFFICIENT FEE" : "CONFIRM"
1704
- }
1705
- ),
1706
- showNotRemind && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: sign_module_default.notRemind, onClick: toggleNotRemind, children: [
1707
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("img", { src: notRemindChecked ? check_box_default : check_box_blank_default }),
1708
- "Do not remind me again"
1709
- ] })
1710
- ] }) });
1637
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1638
+ modal_default,
1639
+ {
1640
+ open,
1641
+ onClose,
1642
+ isDismissable: false,
1643
+ contentClassName: sign_module_default.modalContent,
1644
+ children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
1645
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("img", { className: sign_module_default.closeBtn, src: close_default, onClick: closeModal }),
1646
+ requestArguments && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: sign_module_default.signTitle, children: requestArguments.method == "personal_sign" /* personalSign */ ? "Sign Message" : "Sign Typed Data" }),
1647
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: sign_module_default.chainInfo, children: [
1648
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("img", { src: chainInfo == null ? void 0 : chainInfo.icon }),
1649
+ chainInfo == null ? void 0 : chainInfo.fullname.replace("Mainnet", "")
1650
+ ] }),
1651
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: sign_module_default.addressContainer, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(CopyText, { value: evmAccount, style: { textDecorationLine: "none" }, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: sign_module_default.addressInfo, children: [
1652
+ shortString(evmAccount),
1653
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("img", { src: copy_default })
1654
+ ] }) }) }),
1655
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
1656
+ "div",
1657
+ {
1658
+ className: sign_module_default.detailsContent + (deserializeResult || requestArguments ? ` ${sign_module_default.fill}` : ""),
1659
+ children: [
1660
+ deserializeResult && deserializeResult.map((details, index) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(transactionDetails_default, { details }, `${details.type}-${index}`)),
1661
+ unsignedMessage && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: sign_module_default.unsignedMessage, children: unsignedMessage })
1662
+ ]
1663
+ }
1664
+ ),
1665
+ gasFee && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: sign_module_default.estimatedGas, children: `Estimated gas fee: ${(0, import_viem3.formatEther)(gasFee)} ${chainInfo == null ? void 0 : chainInfo.nativeCurrency.symbol}` }),
1666
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1667
+ button_default,
1668
+ {
1669
+ onClick: confirmTx,
1670
+ className: sign_module_default.signBtn,
1671
+ isLoading: loading || deserializeLoading,
1672
+ isDisabled: disabled,
1673
+ children: deserializeLoading ? "LOADING" : disabled ? "INSUFFICIENT FEE" : "CONFIRM"
1674
+ }
1675
+ ),
1676
+ showNotRemind && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: sign_module_default.notRemind, onClick: toggleNotRemind, children: [
1677
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("img", { src: notRemindChecked ? check_box_default : check_box_blank_default }),
1678
+ "Do not remind me again"
1679
+ ] })
1680
+ ] })
1681
+ }
1682
+ );
1711
1683
  };
1712
1684
  var signModal_default = SignModal;
1713
1685
 
@@ -1861,7 +1833,11 @@ var ConnectProvider = ({
1861
1833
  isModalOpen: connectModalOpen,
1862
1834
  openModal: openConnectModal
1863
1835
  } = useModalStateValue_default();
1864
- const { closeModal: closeSignModal, isModalOpen: signModalOpen, openModal: openSignModal } = useModalStateValue_default();
1836
+ const {
1837
+ closeModal: closeSignModal,
1838
+ isModalOpen: signModalOpen,
1839
+ openModal: openSignModal
1840
+ } = useModalStateValue_default();
1865
1841
  const [connectorId, setConnectorId] = (0, import_react10.useState)();
1866
1842
  const [accounts, setAccounts] = (0, import_react10.useState)([]);
1867
1843
  const [evmAccount, setEVMAccount] = (0, import_react10.useState)();
@@ -1946,7 +1922,12 @@ var ConnectProvider = ({
1946
1922
  }
1947
1923
  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)) {
1948
1924
  const smartAccount2 = new import_aa.SmartAccount(
1949
- new AASignerProvider(evmSupportChainIds, options.projectId, options.clientKey, options.rpcUrls),
1925
+ new AASignerProvider(
1926
+ evmSupportChainIds,
1927
+ options.projectId,
1928
+ options.clientKey,
1929
+ options.rpcUrls
1930
+ ),
1950
1931
  options
1951
1932
  );
1952
1933
  smartAccount2.setSmartAccountContract(accountContract);
@@ -1956,35 +1937,9 @@ var ConnectProvider = ({
1956
1937
  window.__bitcoinSmartAccount.provider.personalSign = signMessage;
1957
1938
  return window.__bitcoinSmartAccount;
1958
1939
  }, [options, evmSupportChainIds, getPublicKey, signMessage, accountContract]);
1959
- (0, import_react10.useEffect)(() => {
1960
- if (accounts.length > 0 && smartAccount) {
1961
- getBTCAAAddress(smartAccount, accounts[0], accountContract.name, accountContract.version).then((res) => {
1962
- setEVMAccount(res);
1963
- }).catch((e) => {
1964
- setEVMAccount(void 0);
1965
- console.error("smartAccount getAddress error", e);
1966
- });
1967
- } else {
1968
- setEVMAccount(void 0);
1969
- }
1970
- }, [accountContract, accounts, smartAccount]);
1971
- const getSmartAccountInfo = (0, import_react10.useCallback)(() => __async(void 0, null, function* () {
1972
- if (accounts.length > 0 && smartAccount) {
1973
- const accountInfo = yield getBTCAccountInfo(
1974
- smartAccount,
1975
- accounts[0],
1976
- accountContract.name,
1977
- accountContract.version
1978
- );
1979
- setEVMAccount(accountInfo.smartAccountAddress);
1980
- return accountInfo;
1981
- }
1982
- return void 0;
1983
- }), [accounts, smartAccount, accountContract, setEVMAccount]);
1984
1940
  const requestAccount = (0, import_react10.useCallback)(
1985
1941
  (connector2) => __async(void 0, null, function* () {
1986
1942
  let accounts2 = yield connector2.getAccounts();
1987
- console.log("requestAccount start, autoConnect", accounts2, autoConnect);
1988
1943
  if (accounts2.length === 0 && autoConnect) {
1989
1944
  accounts2 = yield connector2.requestAccounts();
1990
1945
  }
@@ -1992,23 +1947,18 @@ var ConnectProvider = ({
1992
1947
  }),
1993
1948
  [autoConnect]
1994
1949
  );
1995
- const requestDirectAccount = (0, import_react10.useCallback)(
1996
- (connector2) => __async(void 0, null, function* () {
1997
- console.log(111);
1998
- let accounts2 = yield connector2.getAccounts();
1999
- console.log("requestAccount start, autoConnect", accounts2, autoConnect);
2000
- if (accounts2.length === 0) {
2001
- accounts2 = yield connector2.requestAccounts();
2002
- }
2003
- setAccounts(accounts2);
2004
- return accounts2;
2005
- }),
2006
- []
2007
- );
1950
+ const requestDirectAccount = (0, import_react10.useCallback)((connector2) => __async(void 0, null, function* () {
1951
+ let accounts2 = yield connector2.getAccounts();
1952
+ if (accounts2.length === 0) {
1953
+ accounts2 = yield connector2.requestAccounts();
1954
+ }
1955
+ setAccounts(accounts2);
1956
+ return accounts2;
1957
+ }), []);
2008
1958
  (0, import_react10.useEffect)(() => {
2009
1959
  if (connector) {
2010
1960
  requestAccount(connector).catch((e) => {
2011
- console.log("get account error", e);
1961
+ console.error("get account error", e);
2012
1962
  setAccounts([]);
2013
1963
  });
2014
1964
  } else {
@@ -2138,8 +2088,7 @@ var ConnectProvider = ({
2138
2088
  switchNetwork,
2139
2089
  sendBitcoin: sendBitcoin2,
2140
2090
  accountContract,
2141
- setAccountContract,
2142
- getSmartAccountInfo
2091
+ setAccountContract
2143
2092
  },
2144
2093
  children: [
2145
2094
  children,
@@ -2154,8 +2103,8 @@ var useConnectProvider = () => {
2154
2103
  return context;
2155
2104
  };
2156
2105
 
2157
- // src/components/btcWalletSelectorContext.tsx
2158
- var import_react12 = __toESM(require("react"), 1);
2106
+ // src/core/btcWalletSelectorContext.tsx
2107
+ var import_react11 = __toESM(require("react"), 1);
2159
2108
 
2160
2109
  // src/components/confirmBox/Modal.tsx
2161
2110
  var import_jsx_runtime10 = require("react/jsx-runtime");
@@ -2209,25 +2158,16 @@ function ComfirmBox({ onClose, status = 1, fromChain = {
2209
2158
  ] });
2210
2159
  }
2211
2160
 
2212
- // src/components/hook.tsx
2213
- var import_react11 = require("react");
2214
- function InitContextHook() {
2215
- const btcContext = useBtcWalletSelector();
2216
- (0, import_react11.useEffect)(() => {
2217
- window.btcContext = btcContext;
2218
- }, [btcContext]);
2219
- return null;
2220
- }
2221
-
2222
- // src/components/btcWalletSelectorContext.tsx
2161
+ // src/core/btcWalletSelectorContext.tsx
2223
2162
  var import_jsx_runtime12 = require("react/jsx-runtime");
2224
- var WalletSelectorContext = import_react12.default.createContext(null);
2163
+ var WalletSelectorContext = import_react11.default.createContext(null);
2225
2164
  function BtcWalletSelectorContextProvider({
2226
2165
  children,
2227
2166
  autoConnect = false
2228
2167
  }) {
2229
- const [isProcessing, setIsProcessing] = (0, import_react12.useState)(false);
2230
- const walletSelectorContextValue = (0, import_react12.useMemo)(() => {
2168
+ const [isProcessing, setIsProcessing] = (0, import_react11.useState)(false);
2169
+ const connectors = [new UnisatConnector(), new XverseConnector()];
2170
+ const walletSelectorContextValue = (0, import_react11.useMemo)(() => {
2231
2171
  const simpleFn = {};
2232
2172
  return {
2233
2173
  setIsProcessing,
@@ -2266,7 +2206,7 @@ function BtcWalletSelectorContextProvider({
2266
2206
  }
2267
2207
  },
2268
2208
  autoConnect: false,
2269
- connectors: [new UnisatConnector()],
2209
+ connectors,
2270
2210
  children: [
2271
2211
  children,
2272
2212
  isProcessing && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
@@ -2279,21 +2219,28 @@ function BtcWalletSelectorContextProvider({
2279
2219
  }
2280
2220
  }
2281
2221
  ),
2282
- /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(InitContextHook, {})
2222
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(InitBtcWalletSelectorContext, {})
2283
2223
  ]
2284
2224
  }
2285
2225
  ) });
2286
2226
  }
2227
+ function InitBtcWalletSelectorContext() {
2228
+ const context = useBtcWalletSelector();
2229
+ (0, import_react11.useEffect)(() => {
2230
+ window.btcContext = context;
2231
+ }, [context]);
2232
+ return null;
2233
+ }
2287
2234
  function useBtcWalletSelector() {
2288
2235
  const { openConnectModal, openConnectModalAsync, disconnect, requestDirectAccount } = useConnectModal();
2289
2236
  const { accounts, sendBitcoin: sendBitcoin2, getPublicKey, provider, signMessage, connector } = useBTCProvider();
2290
- const publicKey = (0, import_react12.useRef)(null);
2291
- const signMessageFn = (0, import_react12.useRef)(null);
2292
- const connectorRef = (0, import_react12.useRef)(null);
2293
- const providerRef = (0, import_react12.useRef)(null);
2294
- const [updater, setUpdater] = (0, import_react12.useState)(1);
2295
- const context = (0, import_react12.useContext)(WalletSelectorContext);
2296
- (0, import_react12.useEffect)(() => {
2237
+ const publicKey = (0, import_react11.useRef)(null);
2238
+ const signMessageFn = (0, import_react11.useRef)(null);
2239
+ const connectorRef = (0, import_react11.useRef)(null);
2240
+ const providerRef = (0, import_react11.useRef)(null);
2241
+ const [updater, setUpdater] = (0, import_react11.useState)(1);
2242
+ const context = (0, import_react11.useContext)(WalletSelectorContext);
2243
+ (0, import_react11.useEffect)(() => {
2297
2244
  if (provider) {
2298
2245
  getPublicKey().then((res) => {
2299
2246
  publicKey.current = res;
@@ -2301,10 +2248,10 @@ function useBtcWalletSelector() {
2301
2248
  providerRef.current = provider;
2302
2249
  }
2303
2250
  }, [provider, updater]);
2304
- (0, import_react12.useEffect)(() => {
2251
+ (0, import_react11.useEffect)(() => {
2305
2252
  signMessageFn.current = signMessage;
2306
2253
  }, [signMessage]);
2307
- (0, import_react12.useEffect)(() => {
2254
+ (0, import_react11.useEffect)(() => {
2308
2255
  const fn = (account) => {
2309
2256
  if (account) {
2310
2257
  getPublicKey().then((res) => {
@@ -2338,7 +2285,7 @@ function useBtcWalletSelector() {
2338
2285
  autoConnect: () => __async(this, null, function* () {
2339
2286
  let times = 0;
2340
2287
  while (!connectorRef.current) {
2341
- yield sleep(500);
2288
+ yield delay(500);
2342
2289
  if (times++ > 10) {
2343
2290
  return null;
2344
2291
  }
@@ -2355,7 +2302,7 @@ function useBtcWalletSelector() {
2355
2302
  getPublicKey: () => __async(this, null, function* () {
2356
2303
  let times = 0;
2357
2304
  while (!publicKey.current) {
2358
- yield sleep(1e3);
2305
+ yield delay(1e3);
2359
2306
  if (times++ > 10) {
2360
2307
  return null;
2361
2308
  }
@@ -2371,7 +2318,7 @@ function useBtcWalletSelector() {
2371
2318
  getBalance: () => __async(this, null, function* () {
2372
2319
  let times = 0;
2373
2320
  while (!providerRef.current) {
2374
- yield sleep(500);
2321
+ yield delay(500);
2375
2322
  if (times++ > 10) {
2376
2323
  return null;
2377
2324
  }
@@ -2382,18 +2329,13 @@ function useBtcWalletSelector() {
2382
2329
  sendBitcoin: sendBitcoin2
2383
2330
  };
2384
2331
  }
2385
- function sleep(time) {
2386
- return new Promise(function(resolve) {
2387
- setTimeout(resolve, time);
2388
- });
2389
- }
2390
2332
 
2391
- // src/utils/setupBTCWallet.ts
2333
+ // src/core/setupBTCWallet.ts
2392
2334
  var import_near_api_js = require("near-api-js");
2393
2335
  var import_transactions = require("@near-js/transactions");
2394
2336
  var import_key_pair = require("near-api-js/lib/utils/key_pair");
2395
2337
  var import_transaction = require("near-api-js/lib/transaction");
2396
- var import_utils5 = require("@near-js/utils");
2338
+ var import_utils6 = require("@near-js/utils");
2397
2339
  var import_bs58 = __toESM(require("bs58"), 1);
2398
2340
  var import_js_sha256 = require("js-sha256");
2399
2341
 
@@ -2481,7 +2423,8 @@ function createIframe({
2481
2423
  zIndex: "100000",
2482
2424
  boxShadow: "0 0 10px rgba(0, 0, 0, 0.1)",
2483
2425
  borderRadius: "10px",
2484
- display: "block"
2426
+ display: "block",
2427
+ border: "none"
2485
2428
  }, iframeStyle));
2486
2429
  document.body.appendChild(iframe);
2487
2430
  return iframe;
@@ -2499,7 +2442,6 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
2499
2442
  originalAccountId && iframeSrc.searchParams.set("originalAccountId", originalAccountId);
2500
2443
  originalPublicKey && iframeSrc.searchParams.set("originalPublicKey", originalPublicKey);
2501
2444
  iframe.src = iframeSrc.toString();
2502
- console.log("iframe src", iframe.src);
2503
2445
  window.addEventListener("message", (event) => __async(this, null, function* () {
2504
2446
  var _a2, _b;
2505
2447
  if (event.origin !== iframeSrc.origin)
@@ -2575,8 +2517,8 @@ var nearRpcUrls = {
2575
2517
  ]
2576
2518
  };
2577
2519
  var btcRpcUrls = {
2578
- mainnet: "https://blockstream.info/api",
2579
- testnet: "https://blockstream.info/testnet/api"
2520
+ mainnet: "https://mempool.space/api",
2521
+ testnet: "https://mempool.space/testnet/api"
2580
2522
  };
2581
2523
 
2582
2524
  // src/utils/request.ts
@@ -2649,7 +2591,7 @@ function request(url, options) {
2649
2591
  });
2650
2592
  }
2651
2593
 
2652
- // src/utils/setupBTCWallet.ts
2594
+ // src/core/setupBTCWallet.ts
2653
2595
  var { transfer, functionCall } = import_transactions.actionCreators;
2654
2596
  var state = {
2655
2597
  saveAccount(account) {
@@ -2714,7 +2656,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2714
2656
  if (!inter) {
2715
2657
  inter = setInterval(() => __async(void 0, null, function* () {
2716
2658
  const btcContext = window.btcContext;
2717
- console.log("inter btcContext:", btcContext);
2718
2659
  if (btcContext) {
2719
2660
  clearInterval(inter);
2720
2661
  const context = btcContext.getContext();
@@ -2736,12 +2677,10 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2736
2677
  });
2737
2678
  }));
2738
2679
  context.on("btcLogOut", (e) => __async(void 0, null, function* () {
2739
- console.log(3333);
2740
2680
  emitter.emit("accountsChanged", {
2741
2681
  accounts: []
2742
2682
  });
2743
2683
  }));
2744
- console.log("metadata.autoConnect:", metadata);
2745
2684
  if ("autoConnect" in metadata && metadata.autoConnect && localStorage.getItem("near-wallet-selector:selectedWalletId") === '"btc-wallet"') {
2746
2685
  yield btcContext.autoConnect();
2747
2686
  }
@@ -2883,7 +2822,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2883
2822
  transaction.receiverId,
2884
2823
  BigInt(nearNonceNumber) + BigInt(index),
2885
2824
  newActions,
2886
- (0, import_utils5.baseDecode)(header.hash)
2825
+ (0, import_utils6.baseDecode)(header.hash)
2887
2826
  );
2888
2827
  const txBytes = (0, import_transaction.encodeTransaction)(_transaction);
2889
2828
  const txHex = Array.from(
@@ -2925,7 +2864,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2925
2864
  btcPubKey: state.getBtcPublicKey(),
2926
2865
  data: toHex(strIntention)
2927
2866
  });
2928
- console.log("result:", result);
2929
2867
  if (result.result_code === 0) {
2930
2868
  const hash = newTransactions.map((t) => t.hash);
2931
2869
  console.log("txHash:", hash);
@@ -2941,7 +2879,10 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2941
2879
  const checkAndSetupWalletButton = () => {
2942
2880
  const accountId = state.getAccount();
2943
2881
  const btcContext = window.btcContext;
2944
- console.log("checkAndSetupWalletButton:", accountId, btcContext.account);
2882
+ console.log("checkAndSetupWalletButton:", {
2883
+ nearAccountId: accountId,
2884
+ btcAccountId: btcContext.account
2885
+ });
2945
2886
  if (accountId && btcContext.account) {
2946
2887
  setupWalletButton(network, wallet2, btcContext);
2947
2888
  } else {
@@ -3037,7 +2978,7 @@ function pollTransactionStatuses(network, hashes) {
3037
2978
  });
3038
2979
  }
3039
2980
 
3040
- // src/utils/bridgeSupplyUtils.ts
2981
+ // src/core/bridgeSupplyUtils.ts
3041
2982
  var import_near_api_js2 = require("near-api-js");
3042
2983
  var import_big = __toESM(require("big.js"), 1);
3043
2984
  function nearViewMethod(contractId, methodName, args, network) {
@@ -3072,12 +3013,13 @@ function getDepositAddress(btcPublicKey, contractId, network) {
3072
3013
  return res;
3073
3014
  });
3074
3015
  }
3075
- function getGasPrice(btcRpcUrl) {
3016
+ function getGasPrice(network) {
3076
3017
  return __async(this, null, function* () {
3077
3018
  const defaultFeeRate = 100;
3078
3019
  try {
3079
- const res = yield request(`${btcRpcUrl}/fee-estimates`);
3080
- const feeRate = res[6];
3020
+ const btcRpcUrl = btcRpcUrls[network];
3021
+ const res = yield fetch(`${btcRpcUrl}/v1/fees/recommended`).then((res2) => res2.json());
3022
+ const feeRate = res.fastestFee;
3081
3023
  return feeRate || defaultFeeRate;
3082
3024
  } catch (error) {
3083
3025
  return defaultFeeRate;
@@ -3106,12 +3048,21 @@ function receiveDepositMsg(_0, _1) {
3106
3048
  }
3107
3049
  function checkTransactionStatus(baseUrl, txHash) {
3108
3050
  return __async(this, null, function* () {
3109
- const res = yield request(`${baseUrl}/v1/bridgeFromTx?fromTxHash=${txHash}`);
3051
+ const res = yield request(`${baseUrl}/v1/bridgeFromTx?fromTxHash=${txHash}`, {
3052
+ timeout: 6e4,
3053
+ pollingInterval: 5e3,
3054
+ maxPollingAttempts: 10,
3055
+ shouldStopPolling: (res2) => res2.result_code === 0
3056
+ });
3110
3057
  return res;
3111
3058
  });
3112
3059
  }
3113
- function executeBurrowSupply(amount, environment) {
3114
- return __async(this, null, function* () {
3060
+ function executeBurrowSupply(_0) {
3061
+ return __async(this, arguments, function* ({
3062
+ amount,
3063
+ feeRate,
3064
+ environment = "mainnet"
3065
+ }) {
3115
3066
  try {
3116
3067
  if (typeof window === "undefined" || !window.btcContext) {
3117
3068
  throw new Error("BTC Provider is not initialized.");
@@ -3119,17 +3070,18 @@ function executeBurrowSupply(amount, environment) {
3119
3070
  const btcProvider = window.btcContext;
3120
3071
  const network = environment === "dev" ? "testnet" : environment;
3121
3072
  const config = walletConfig[environment];
3122
- const btcRpcUrl = btcRpcUrls[network];
3123
3073
  const btcPublicKey = yield btcProvider.getPublicKey();
3124
3074
  if (!btcPublicKey) {
3125
3075
  throw new Error("BTC Public Key is not available.");
3126
3076
  }
3127
3077
  const address = yield getDepositAddress(btcPublicKey, config.contractId, network);
3128
- const feeRate = yield getGasPrice(btcRpcUrl);
3129
- const txHash = yield sendBitcoin(btcProvider, address, amount, feeRate);
3130
- yield receiveDepositMsg(config.base_url, { btcPublicKey, txHash });
3131
- const status = yield checkTransactionStatus(config.base_url, txHash);
3132
- console.log("Transaction Status:", status);
3078
+ const _feeRate = feeRate || (yield getGasPrice(network));
3079
+ console.log("feeRate", _feeRate);
3080
+ const txHash = yield sendBitcoin(btcProvider, address, amount, _feeRate);
3081
+ const receiveDepositMsgRes = yield receiveDepositMsg(config.base_url, { btcPublicKey, txHash });
3082
+ console.log("receiveDepositMsg resp:", receiveDepositMsgRes);
3083
+ const checkTransactionStatusRes = yield checkTransactionStatus(config.base_url, txHash);
3084
+ console.log("checkTransactionStatus resp:", checkTransactionStatusRes);
3133
3085
  } catch (error) {
3134
3086
  console.error("Error executing Bridge+BurrowSupply:", error);
3135
3087
  }
@@ -3138,7 +3090,7 @@ function executeBurrowSupply(amount, environment) {
3138
3090
 
3139
3091
  // src/index.ts
3140
3092
  var getVersion = () => {
3141
- return "0.2.6";
3093
+ return "0.2.8";
3142
3094
  };
3143
3095
  if (typeof window !== "undefined") {
3144
3096
  window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();