btc-wallet 0.5.55-beta → 0.5.57-beta

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.
@@ -100,9 +100,12 @@ interface CalculateGasLimitParams {
100
100
  transactions: Transaction[];
101
101
  csna: string;
102
102
  env: ENV;
103
+ gasStrategy?: 'auto' | 'near' | 'btc';
103
104
  }
104
105
  export declare function calculateGasLimit(params: CalculateGasLimitParams): Promise<string>;
105
- export declare function calculateGasStrategy({ csna, transactions, env, }: CalculateGasLimitParams): Promise<{
106
+ export declare function calculateGasStrategy({ csna, transactions, env, gasStrategy, }: CalculateGasLimitParams & {
107
+ gasStrategy?: 'auto' | 'near' | 'btc';
108
+ }): Promise<{
106
109
  transferGasTransaction?: Transaction;
107
110
  useNearPayGas: boolean;
108
111
  gasLimit: string;
package/esm/index.js CHANGED
@@ -478,7 +478,7 @@ var MobileWalletConnect = class {
478
478
  case "okx":
479
479
  return `okx://wallet/dapp/url?dappUrl=${encodeURIComponent(url)}`;
480
480
  case "bitget":
481
- return `https://bkcode.vip?action=dapp&url=${encodeURIComponent(url)}`;
481
+ return `bitkeep://bkconnect?action=dapp&url=${encodeURIComponent(url)}`;
482
482
  case "xverse":
483
483
  return `xverse://browser?url=${encodeURIComponent(url)}`;
484
484
  default:
@@ -564,9 +564,13 @@ var InjectedConnector = class extends BaseConnector {
564
564
  }
565
565
  requestAccounts() {
566
566
  return __async(this, null, function* () {
567
- if (isMobile() && !this.getProvider()) {
568
- MobileWalletConnect.redirectToWallet(this.metadata.id);
569
- return [];
567
+ if (isMobile()) {
568
+ try {
569
+ this.getProvider();
570
+ } catch (error) {
571
+ yield MobileWalletConnect.redirectToWallet(this.metadata.id);
572
+ return [];
573
+ }
570
574
  }
571
575
  const accounts = yield this.getProviderOrThrow().requestAccounts();
572
576
  console.log("network:", yield this.getNetwork());
@@ -2702,7 +2706,8 @@ function BtcWalletSelectorContextProvider({
2702
2706
  new XverseConnector(),
2703
2707
  new OKXConnector(),
2704
2708
  new BitgetConnector(),
2705
- new MagicEdenConnector()
2709
+ new MagicEdenConnector(),
2710
+ new BybitConnector()
2706
2711
  ];
2707
2712
  const walletSelectorContextValue = useMemo6(() => {
2708
2713
  const simpleFn = {};
@@ -2941,7 +2946,7 @@ var nearRpcUrls = {
2941
2946
  mainnet: [
2942
2947
  "https://near.lava.build",
2943
2948
  "https://rpc.mainnet.near.org",
2944
- "https://mw.rpc.fastnear.com",
2949
+ "https://free.rpc.fastnear.com",
2945
2950
  "https://near.drpc.org"
2946
2951
  ],
2947
2952
  testnet: ["https://rpc.testnet.near.org"]
@@ -3514,7 +3519,8 @@ function calculateGasStrategy(_0) {
3514
3519
  return __async(this, arguments, function* ({
3515
3520
  csna,
3516
3521
  transactions: transactions2,
3517
- env
3522
+ env,
3523
+ gasStrategy = "auto"
3518
3524
  }) {
3519
3525
  var _a;
3520
3526
  const currentConfig = getWalletConfig(env);
@@ -3546,6 +3552,7 @@ function calculateGasStrategy(_0) {
3546
3552
  const nearAvailableBalance = new Big(nearBalance).minus(transferAmount.near).toNumber();
3547
3553
  console.log("available near balance:", nearAvailableBalance);
3548
3554
  console.log("available gas token balance:", gasTokenBalance);
3555
+ console.log("gas strategy:", gasStrategy);
3549
3556
  const convertTx = yield Promise.all(
3550
3557
  transactions2.map(
3551
3558
  (transaction, index) => convertTransactionToTxHex({
@@ -3557,8 +3564,20 @@ function calculateGasStrategy(_0) {
3557
3564
  })
3558
3565
  )
3559
3566
  );
3560
- if (nearAvailableBalance > 0.5) {
3561
- console.log("near balance is enough, get the protocol fee of each transaction");
3567
+ let useNearPayGas = false;
3568
+ let perTxFee;
3569
+ if (gasStrategy === "near") {
3570
+ console.log("Forcing NEAR as gas token based on gasStrategy");
3571
+ useNearPayGas = true;
3572
+ } else if (gasStrategy === "btc") {
3573
+ console.log("Forcing BTC token as gas token based on gasStrategy");
3574
+ useNearPayGas = false;
3575
+ } else if (nearAvailableBalance > 0.5) {
3576
+ console.log("NEAR balance is enough, using NEAR to pay for gas");
3577
+ useNearPayGas = true;
3578
+ }
3579
+ let gasAmount;
3580
+ if (useNearPayGas) {
3562
3581
  const gasTokens = yield nearCallFunction(
3563
3582
  currentConfig.accountContractId,
3564
3583
  "list_gas_token",
@@ -3566,39 +3585,29 @@ function calculateGasStrategy(_0) {
3566
3585
  { network: currentConfig.network }
3567
3586
  );
3568
3587
  console.log("list_gas_token gas tokens:", gasTokens);
3569
- const perTxFee = Math.max(
3570
- Number(((_a = gasTokens[currentConfig.btcToken]) == null ? void 0 : _a.per_tx_protocol_fee) || 0),
3571
- 100
3572
- );
3588
+ const fee = Math.max(Number(((_a = gasTokens[currentConfig.btcToken]) == null ? void 0 : _a.per_tx_protocol_fee) || 0), 100);
3589
+ perTxFee = fee.toString();
3573
3590
  console.log("perTxFee:", perTxFee);
3574
- const protocolFee = new Big(perTxFee || "0").mul(convertTx.length).toFixed(0);
3575
- console.log("protocolFee:", protocolFee);
3576
- const transferTx = yield createGasTokenTransfer({ csna, amount: protocolFee, env });
3577
- return recalculateGasWithTransfer({
3578
- csna,
3579
- transferTx,
3580
- transactions: convertTx,
3581
- useNearPayGas: true,
3582
- perTxFee: perTxFee.toString(),
3583
- env
3584
- });
3591
+ gasAmount = new Big(perTxFee || "0").mul(convertTx.length).toFixed(0);
3585
3592
  } else {
3586
- console.log("near balance is not enough, predict the gas token amount required");
3587
- const adjustedGas = yield getPredictedGasAmount({
3593
+ gasAmount = yield getPredictedGasAmount({
3588
3594
  accountContractId: currentConfig.accountContractId,
3589
3595
  tokenId: currentConfig.btcToken,
3590
3596
  transactions: convertTx.map((t) => t.txHex),
3591
3597
  env
3592
3598
  });
3593
- const transferTx = yield createGasTokenTransfer({ csna, amount: adjustedGas, env });
3594
- return recalculateGasWithTransfer({
3595
- csna,
3596
- transferTx,
3597
- transactions: convertTx,
3598
- useNearPayGas: false,
3599
- env
3600
- });
3601
3599
  }
3600
+ console.log("useNearPayGas:", useNearPayGas);
3601
+ console.log("gasAmount:", gasAmount);
3602
+ const transferTx = yield createGasTokenTransfer({ csna, amount: gasAmount, env });
3603
+ return recalculateGasWithTransfer({
3604
+ csna,
3605
+ transferTx,
3606
+ transactions: convertTx,
3607
+ useNearPayGas,
3608
+ perTxFee,
3609
+ env
3610
+ });
3602
3611
  });
3603
3612
  }
3604
3613
  function createGasTokenTransfer(_0) {
@@ -4423,13 +4432,14 @@ function createFloatingButtonWithIframe({
4423
4432
  position: "fixed",
4424
4433
  bottom: `${bottom}px`,
4425
4434
  right: `${right}px`,
4426
- zIndex: "100000",
4435
+ zIndex: "2147483647",
4427
4436
  width: "60px",
4428
4437
  height: "60px",
4429
4438
  cursor: "grab",
4430
4439
  transition: "transform 0.15s ease",
4431
4440
  userSelect: "none",
4432
- touchAction: "none"
4441
+ touchAction: "none",
4442
+ pointerEvents: "auto"
4433
4443
  });
4434
4444
  document.body.appendChild(button);
4435
4445
  updateIframePosition(iframe, right, bottom, windowWidth, windowHeight);
@@ -4439,17 +4449,21 @@ function createFloatingButtonWithIframe({
4439
4449
  let initialRight = 0;
4440
4450
  let initialBottom = 0;
4441
4451
  let dragStartTime = 0;
4442
- button.addEventListener("mousedown", (e) => {
4452
+ const handleMouseDown = (e) => {
4443
4453
  startDrag(e.clientX, e.clientY);
4444
4454
  e.preventDefault();
4445
- });
4446
- button.addEventListener("touchstart", (e) => {
4455
+ e.stopPropagation();
4456
+ };
4457
+ const handleTouchStart = (e) => {
4447
4458
  if (e.touches.length === 1) {
4448
4459
  const touch = e.touches[0];
4449
4460
  startDrag(touch.clientX, touch.clientY);
4450
4461
  e.preventDefault();
4462
+ e.stopPropagation();
4451
4463
  }
4452
- });
4464
+ };
4465
+ button.addEventListener("mousedown", handleMouseDown, { capture: true });
4466
+ button.addEventListener("touchstart", handleTouchStart, { capture: true });
4453
4467
  function startDrag(clientX, clientY) {
4454
4468
  isDragging = true;
4455
4469
  startX = clientX;
@@ -4460,18 +4474,23 @@ function createFloatingButtonWithIframe({
4460
4474
  button.style.cursor = "grabbing";
4461
4475
  button.style.transition = "none";
4462
4476
  }
4463
- document.addEventListener("mousemove", (e) => {
4477
+ const handleMouseMove = (e) => {
4464
4478
  if (!isDragging)
4465
4479
  return;
4466
4480
  moveButton(e.clientX, e.clientY);
4467
- });
4468
- document.addEventListener("touchmove", (e) => {
4481
+ e.preventDefault();
4482
+ e.stopPropagation();
4483
+ };
4484
+ const handleTouchMove = (e) => {
4469
4485
  if (!isDragging || e.touches.length !== 1)
4470
4486
  return;
4471
4487
  const touch = e.touches[0];
4472
4488
  moveButton(touch.clientX, touch.clientY);
4473
4489
  e.preventDefault();
4474
- });
4490
+ e.stopPropagation();
4491
+ };
4492
+ document.addEventListener("mousemove", handleMouseMove, { capture: true });
4493
+ document.addEventListener("touchmove", handleTouchMove, { capture: true });
4475
4494
  function moveButton(clientX, clientY) {
4476
4495
  const deltaX = startX - clientX;
4477
4496
  const deltaY = startY - clientY;
@@ -4495,15 +4514,23 @@ function createFloatingButtonWithIframe({
4495
4514
  button.style.bottom = `${newBottom}px`;
4496
4515
  updateIframePosition(iframe, newRight, newBottom, windowWidth, windowHeight);
4497
4516
  }
4498
- document.addEventListener("mouseup", () => {
4499
- endDrag();
4500
- });
4501
- document.addEventListener("touchend", () => {
4517
+ const handleMouseUp = (e) => {
4518
+ if (isDragging) {
4519
+ e.preventDefault();
4520
+ e.stopPropagation();
4521
+ }
4502
4522
  endDrag();
4503
- });
4504
- document.addEventListener("touchcancel", () => {
4523
+ };
4524
+ const handleTouchEnd = (e) => {
4525
+ if (isDragging) {
4526
+ e.preventDefault();
4527
+ e.stopPropagation();
4528
+ }
4505
4529
  endDrag();
4506
- });
4530
+ };
4531
+ document.addEventListener("mouseup", handleMouseUp, { capture: true });
4532
+ document.addEventListener("touchend", handleTouchEnd, { capture: true });
4533
+ document.addEventListener("touchcancel", handleTouchEnd, { capture: true });
4507
4534
  function endDrag() {
4508
4535
  if (!isDragging)
4509
4536
  return;
@@ -4553,11 +4580,12 @@ function createIframe({
4553
4580
  position: "fixed",
4554
4581
  bottom: "90px",
4555
4582
  right: "20px",
4556
- zIndex: "100000",
4583
+ zIndex: "2147483646",
4557
4584
  boxShadow: "0 0 10px rgba(0, 0, 0, 0.1)",
4558
4585
  borderRadius: "10px",
4559
4586
  display: isVisible ? "block" : "none",
4560
- border: "none"
4587
+ border: "none",
4588
+ pointerEvents: "auto"
4561
4589
  }, iframeStyle));
4562
4590
  document.body.appendChild(iframe);
4563
4591
  return iframe;
@@ -4738,7 +4766,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
4738
4766
  });
4739
4767
  }
4740
4768
  } else {
4741
- removeWalletButton();
4742
4769
  connectionUpdateTimeout = setTimeout(() => {
4743
4770
  handleConnectionUpdate();
4744
4771
  }, 5e3);
@@ -4877,7 +4904,8 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
4877
4904
  const { transferGasTransaction, useNearPayGas, gasLimit } = yield calculateGasStrategy({
4878
4905
  csna,
4879
4906
  transactions: trans,
4880
- env
4907
+ env,
4908
+ gasStrategy: metadata.gasStrategy
4881
4909
  });
4882
4910
  console.log("transferGasTransaction:", transferGasTransaction);
4883
4911
  console.log("useNearPayGas:", useNearPayGas);
@@ -4949,9 +4977,10 @@ function setupBTCWallet({
4949
4977
  autoConnect = true,
4950
4978
  syncLogOut = true,
4951
4979
  env = "mainnet",
4952
- walletUrl
4980
+ walletUrl,
4981
+ gasStrategy = "auto"
4953
4982
  } = {}) {
4954
- console.log("\u26A1\uFE0F BTC Wallet Version:", getVersion(), "env:", env);
4983
+ console.log("\u26A1\uFE0F BTC Wallet Version:", getVersion(), "env:", env, "gasStrategy:", gasStrategy);
4955
4984
  const btcWallet = () => __async(this, null, function* () {
4956
4985
  return {
4957
4986
  id: "btc-wallet",
@@ -4966,7 +4995,8 @@ function setupBTCWallet({
4966
4995
  autoConnect,
4967
4996
  syncLogOut,
4968
4997
  env,
4969
- walletUrl
4998
+ walletUrl,
4999
+ gasStrategy
4970
5000
  },
4971
5001
  init: BTCWallet
4972
5002
  };
@@ -5050,7 +5080,7 @@ function openChainModal() {
5050
5080
  return div;
5051
5081
  };
5052
5082
  return yield Dialog.openModal({
5053
- title: "Choose Chain",
5083
+ title: "Choose Wallet",
5054
5084
  titleStyle: "font-size: 18px; font-weight: 600; color: #fff; text-align: center;padding-bottom: 10px;",
5055
5085
  content
5056
5086
  });
@@ -5069,7 +5099,7 @@ function getGroup(state) {
5069
5099
 
5070
5100
  // src/index.ts
5071
5101
  var getVersion = () => {
5072
- return "0.5.55-beta";
5102
+ return "0.5.57-beta";
5073
5103
  };
5074
5104
  if (typeof window !== "undefined") {
5075
5105
  window.__BTC_WALLET_VERSION = getVersion();