btc-wallet 0.5.55-beta → 0.5.56-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) {
@@ -4738,7 +4747,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
4738
4747
  });
4739
4748
  }
4740
4749
  } else {
4741
- removeWalletButton();
4742
4750
  connectionUpdateTimeout = setTimeout(() => {
4743
4751
  handleConnectionUpdate();
4744
4752
  }, 5e3);
@@ -4877,7 +4885,8 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
4877
4885
  const { transferGasTransaction, useNearPayGas, gasLimit } = yield calculateGasStrategy({
4878
4886
  csna,
4879
4887
  transactions: trans,
4880
- env
4888
+ env,
4889
+ gasStrategy: metadata.gasStrategy
4881
4890
  });
4882
4891
  console.log("transferGasTransaction:", transferGasTransaction);
4883
4892
  console.log("useNearPayGas:", useNearPayGas);
@@ -4949,9 +4958,10 @@ function setupBTCWallet({
4949
4958
  autoConnect = true,
4950
4959
  syncLogOut = true,
4951
4960
  env = "mainnet",
4952
- walletUrl
4961
+ walletUrl,
4962
+ gasStrategy = "auto"
4953
4963
  } = {}) {
4954
- console.log("\u26A1\uFE0F BTC Wallet Version:", getVersion(), "env:", env);
4964
+ console.log("\u26A1\uFE0F BTC Wallet Version:", getVersion(), "env:", env, "gasStrategy:", gasStrategy);
4955
4965
  const btcWallet = () => __async(this, null, function* () {
4956
4966
  return {
4957
4967
  id: "btc-wallet",
@@ -4966,7 +4976,8 @@ function setupBTCWallet({
4966
4976
  autoConnect,
4967
4977
  syncLogOut,
4968
4978
  env,
4969
- walletUrl
4979
+ walletUrl,
4980
+ gasStrategy
4970
4981
  },
4971
4982
  init: BTCWallet
4972
4983
  };
@@ -5050,7 +5061,7 @@ function openChainModal() {
5050
5061
  return div;
5051
5062
  };
5052
5063
  return yield Dialog.openModal({
5053
- title: "Choose Chain",
5064
+ title: "Choose Wallet",
5054
5065
  titleStyle: "font-size: 18px; font-weight: 600; color: #fff; text-align: center;padding-bottom: 10px;",
5055
5066
  content
5056
5067
  });
@@ -5069,7 +5080,7 @@ function getGroup(state) {
5069
5080
 
5070
5081
  // src/index.ts
5071
5082
  var getVersion = () => {
5072
- return "0.5.55-beta";
5083
+ return "0.5.56-beta";
5073
5084
  };
5074
5085
  if (typeof window !== "undefined") {
5075
5086
  window.__BTC_WALLET_VERSION = getVersion();