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.
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,15 @@ 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 walletSelectorContextValue = (0, import_react11.useMemo)(() => {
2231
2170
  const simpleFn = {};
2232
2171
  return {
2233
2172
  setIsProcessing,
@@ -2279,21 +2218,28 @@ function BtcWalletSelectorContextProvider({
2279
2218
  }
2280
2219
  }
2281
2220
  ),
2282
- /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(InitContextHook, {})
2221
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(InitBtcWalletSelectorContext, {})
2283
2222
  ]
2284
2223
  }
2285
2224
  ) });
2286
2225
  }
2226
+ function InitBtcWalletSelectorContext() {
2227
+ const context = useBtcWalletSelector();
2228
+ (0, import_react11.useEffect)(() => {
2229
+ window.btcContext = context;
2230
+ }, [context]);
2231
+ return null;
2232
+ }
2287
2233
  function useBtcWalletSelector() {
2288
2234
  const { openConnectModal, openConnectModalAsync, disconnect, requestDirectAccount } = useConnectModal();
2289
2235
  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)(() => {
2236
+ const publicKey = (0, import_react11.useRef)(null);
2237
+ const signMessageFn = (0, import_react11.useRef)(null);
2238
+ const connectorRef = (0, import_react11.useRef)(null);
2239
+ const providerRef = (0, import_react11.useRef)(null);
2240
+ const [updater, setUpdater] = (0, import_react11.useState)(1);
2241
+ const context = (0, import_react11.useContext)(WalletSelectorContext);
2242
+ (0, import_react11.useEffect)(() => {
2297
2243
  if (provider) {
2298
2244
  getPublicKey().then((res) => {
2299
2245
  publicKey.current = res;
@@ -2301,10 +2247,10 @@ function useBtcWalletSelector() {
2301
2247
  providerRef.current = provider;
2302
2248
  }
2303
2249
  }, [provider, updater]);
2304
- (0, import_react12.useEffect)(() => {
2250
+ (0, import_react11.useEffect)(() => {
2305
2251
  signMessageFn.current = signMessage;
2306
2252
  }, [signMessage]);
2307
- (0, import_react12.useEffect)(() => {
2253
+ (0, import_react11.useEffect)(() => {
2308
2254
  const fn = (account) => {
2309
2255
  if (account) {
2310
2256
  getPublicKey().then((res) => {
@@ -2338,7 +2284,7 @@ function useBtcWalletSelector() {
2338
2284
  autoConnect: () => __async(this, null, function* () {
2339
2285
  let times = 0;
2340
2286
  while (!connectorRef.current) {
2341
- yield sleep(500);
2287
+ yield delay(500);
2342
2288
  if (times++ > 10) {
2343
2289
  return null;
2344
2290
  }
@@ -2355,7 +2301,7 @@ function useBtcWalletSelector() {
2355
2301
  getPublicKey: () => __async(this, null, function* () {
2356
2302
  let times = 0;
2357
2303
  while (!publicKey.current) {
2358
- yield sleep(1e3);
2304
+ yield delay(1e3);
2359
2305
  if (times++ > 10) {
2360
2306
  return null;
2361
2307
  }
@@ -2371,7 +2317,7 @@ function useBtcWalletSelector() {
2371
2317
  getBalance: () => __async(this, null, function* () {
2372
2318
  let times = 0;
2373
2319
  while (!providerRef.current) {
2374
- yield sleep(500);
2320
+ yield delay(500);
2375
2321
  if (times++ > 10) {
2376
2322
  return null;
2377
2323
  }
@@ -2382,18 +2328,13 @@ function useBtcWalletSelector() {
2382
2328
  sendBitcoin: sendBitcoin2
2383
2329
  };
2384
2330
  }
2385
- function sleep(time) {
2386
- return new Promise(function(resolve) {
2387
- setTimeout(resolve, time);
2388
- });
2389
- }
2390
2331
 
2391
- // src/utils/setupBTCWallet.ts
2332
+ // src/core/setupBTCWallet.ts
2392
2333
  var import_near_api_js = require("near-api-js");
2393
2334
  var import_transactions = require("@near-js/transactions");
2394
2335
  var import_key_pair = require("near-api-js/lib/utils/key_pair");
2395
2336
  var import_transaction = require("near-api-js/lib/transaction");
2396
- var import_utils5 = require("@near-js/utils");
2337
+ var import_utils6 = require("@near-js/utils");
2397
2338
  var import_bs58 = __toESM(require("bs58"), 1);
2398
2339
  var import_js_sha256 = require("js-sha256");
2399
2340
 
@@ -2481,7 +2422,8 @@ function createIframe({
2481
2422
  zIndex: "100000",
2482
2423
  boxShadow: "0 0 10px rgba(0, 0, 0, 0.1)",
2483
2424
  borderRadius: "10px",
2484
- display: "block"
2425
+ display: "block",
2426
+ border: "none"
2485
2427
  }, iframeStyle));
2486
2428
  document.body.appendChild(iframe);
2487
2429
  return iframe;
@@ -2499,7 +2441,6 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
2499
2441
  originalAccountId && iframeSrc.searchParams.set("originalAccountId", originalAccountId);
2500
2442
  originalPublicKey && iframeSrc.searchParams.set("originalPublicKey", originalPublicKey);
2501
2443
  iframe.src = iframeSrc.toString();
2502
- console.log("iframe src", iframe.src);
2503
2444
  window.addEventListener("message", (event) => __async(this, null, function* () {
2504
2445
  var _a2, _b;
2505
2446
  if (event.origin !== iframeSrc.origin)
@@ -2575,8 +2516,8 @@ var nearRpcUrls = {
2575
2516
  ]
2576
2517
  };
2577
2518
  var btcRpcUrls = {
2578
- mainnet: "https://blockstream.info/api",
2579
- testnet: "https://blockstream.info/testnet/api"
2519
+ mainnet: "https://mempool.space/api",
2520
+ testnet: "https://mempool.space/testnet/api"
2580
2521
  };
2581
2522
 
2582
2523
  // src/utils/request.ts
@@ -2649,7 +2590,7 @@ function request(url, options) {
2649
2590
  });
2650
2591
  }
2651
2592
 
2652
- // src/utils/setupBTCWallet.ts
2593
+ // src/core/setupBTCWallet.ts
2653
2594
  var { transfer, functionCall } = import_transactions.actionCreators;
2654
2595
  var state = {
2655
2596
  saveAccount(account) {
@@ -2714,7 +2655,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2714
2655
  if (!inter) {
2715
2656
  inter = setInterval(() => __async(void 0, null, function* () {
2716
2657
  const btcContext = window.btcContext;
2717
- console.log("inter btcContext:", btcContext);
2718
2658
  if (btcContext) {
2719
2659
  clearInterval(inter);
2720
2660
  const context = btcContext.getContext();
@@ -2736,12 +2676,10 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2736
2676
  });
2737
2677
  }));
2738
2678
  context.on("btcLogOut", (e) => __async(void 0, null, function* () {
2739
- console.log(3333);
2740
2679
  emitter.emit("accountsChanged", {
2741
2680
  accounts: []
2742
2681
  });
2743
2682
  }));
2744
- console.log("metadata.autoConnect:", metadata);
2745
2683
  if ("autoConnect" in metadata && metadata.autoConnect && localStorage.getItem("near-wallet-selector:selectedWalletId") === '"btc-wallet"') {
2746
2684
  yield btcContext.autoConnect();
2747
2685
  }
@@ -2883,7 +2821,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2883
2821
  transaction.receiverId,
2884
2822
  BigInt(nearNonceNumber) + BigInt(index),
2885
2823
  newActions,
2886
- (0, import_utils5.baseDecode)(header.hash)
2824
+ (0, import_utils6.baseDecode)(header.hash)
2887
2825
  );
2888
2826
  const txBytes = (0, import_transaction.encodeTransaction)(_transaction);
2889
2827
  const txHex = Array.from(
@@ -2925,7 +2863,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2925
2863
  btcPubKey: state.getBtcPublicKey(),
2926
2864
  data: toHex(strIntention)
2927
2865
  });
2928
- console.log("result:", result);
2929
2866
  if (result.result_code === 0) {
2930
2867
  const hash = newTransactions.map((t) => t.hash);
2931
2868
  console.log("txHash:", hash);
@@ -2941,7 +2878,10 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2941
2878
  const checkAndSetupWalletButton = () => {
2942
2879
  const accountId = state.getAccount();
2943
2880
  const btcContext = window.btcContext;
2944
- console.log("checkAndSetupWalletButton:", accountId, btcContext.account);
2881
+ console.log("checkAndSetupWalletButton:", {
2882
+ nearAccountId: accountId,
2883
+ btcAccountId: btcContext.account
2884
+ });
2945
2885
  if (accountId && btcContext.account) {
2946
2886
  setupWalletButton(network, wallet2, btcContext);
2947
2887
  } else {
@@ -3037,7 +2977,7 @@ function pollTransactionStatuses(network, hashes) {
3037
2977
  });
3038
2978
  }
3039
2979
 
3040
- // src/utils/bridgeSupplyUtils.ts
2980
+ // src/core/bridgeSupplyUtils.ts
3041
2981
  var import_near_api_js2 = require("near-api-js");
3042
2982
  var import_big = __toESM(require("big.js"), 1);
3043
2983
  function nearViewMethod(contractId, methodName, args, network) {
@@ -3072,12 +3012,13 @@ function getDepositAddress(btcPublicKey, contractId, network) {
3072
3012
  return res;
3073
3013
  });
3074
3014
  }
3075
- function getGasPrice(btcRpcUrl) {
3015
+ function getGasPrice(network) {
3076
3016
  return __async(this, null, function* () {
3077
3017
  const defaultFeeRate = 100;
3078
3018
  try {
3079
- const res = yield request(`${btcRpcUrl}/fee-estimates`);
3080
- const feeRate = res[6];
3019
+ const btcRpcUrl = btcRpcUrls[network];
3020
+ const res = yield fetch(`${btcRpcUrl}/v1/fees/recommended`).then((res2) => res2.json());
3021
+ const feeRate = res.fastestFee;
3081
3022
  return feeRate || defaultFeeRate;
3082
3023
  } catch (error) {
3083
3024
  return defaultFeeRate;
@@ -3106,12 +3047,21 @@ function receiveDepositMsg(_0, _1) {
3106
3047
  }
3107
3048
  function checkTransactionStatus(baseUrl, txHash) {
3108
3049
  return __async(this, null, function* () {
3109
- const res = yield request(`${baseUrl}/v1/bridgeFromTx?fromTxHash=${txHash}`);
3050
+ const res = yield request(`${baseUrl}/v1/bridgeFromTx?fromTxHash=${txHash}`, {
3051
+ timeout: 6e4,
3052
+ pollingInterval: 5e3,
3053
+ maxPollingAttempts: 10,
3054
+ shouldStopPolling: (res2) => res2.result_code === 0
3055
+ });
3110
3056
  return res;
3111
3057
  });
3112
3058
  }
3113
- function executeBurrowSupply(amount, environment) {
3114
- return __async(this, null, function* () {
3059
+ function executeBurrowSupply(_0) {
3060
+ return __async(this, arguments, function* ({
3061
+ amount,
3062
+ feeRate,
3063
+ environment = "mainnet"
3064
+ }) {
3115
3065
  try {
3116
3066
  if (typeof window === "undefined" || !window.btcContext) {
3117
3067
  throw new Error("BTC Provider is not initialized.");
@@ -3119,17 +3069,18 @@ function executeBurrowSupply(amount, environment) {
3119
3069
  const btcProvider = window.btcContext;
3120
3070
  const network = environment === "dev" ? "testnet" : environment;
3121
3071
  const config = walletConfig[environment];
3122
- const btcRpcUrl = btcRpcUrls[network];
3123
3072
  const btcPublicKey = yield btcProvider.getPublicKey();
3124
3073
  if (!btcPublicKey) {
3125
3074
  throw new Error("BTC Public Key is not available.");
3126
3075
  }
3127
3076
  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);
3077
+ const _feeRate = feeRate || (yield getGasPrice(network));
3078
+ console.log("feeRate", _feeRate);
3079
+ const txHash = yield sendBitcoin(btcProvider, address, amount, _feeRate);
3080
+ const receiveDepositMsgRes = yield receiveDepositMsg(config.base_url, { btcPublicKey, txHash });
3081
+ console.log("receiveDepositMsg resp:", receiveDepositMsgRes);
3082
+ const checkTransactionStatusRes = yield checkTransactionStatus(config.base_url, txHash);
3083
+ console.log("checkTransactionStatus resp:", checkTransactionStatusRes);
3133
3084
  } catch (error) {
3134
3085
  console.error("Error executing Bridge+BurrowSupply:", error);
3135
3086
  }
@@ -3138,7 +3089,7 @@ function executeBurrowSupply(amount, environment) {
3138
3089
 
3139
3090
  // src/index.ts
3140
3091
  var getVersion = () => {
3141
- return "0.2.6";
3092
+ return "0.2.7";
3142
3093
  };
3143
3094
  if (typeof window !== "undefined") {
3144
3095
  window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();