btc-wallet 0.5.87-beta → 0.5.89-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.
package/esm/index.js CHANGED
@@ -3800,12 +3800,8 @@ function checkGasTokenDebt(_0) {
3800
3800
  autoDeposit
3801
3801
  }) {
3802
3802
  var _a, _b, _c;
3803
+ const isNewAccount = yield checkNewAccount({ csna, btcAccount, env });
3803
3804
  const accountInfo = yield getAccountInfo({ csna, env });
3804
- const bridgeTransactions = yield hasBridgeTransaction({
3805
- env,
3806
- btcAccount
3807
- });
3808
- const isNewAccount = !(accountInfo == null ? void 0 : accountInfo.nonce) && !bridgeTransactions;
3809
3805
  const debtAmount = new Big2(((_a = accountInfo == null ? void 0 : accountInfo.debt_info) == null ? void 0 : _a.near_gas_debt_amount) || 0).plus(((_b = accountInfo == null ? void 0 : accountInfo.debt_info) == null ? void 0 : _b.protocol_fee_debt_amount) || 0).toString();
3810
3806
  const relayerFeeAmount = isNewAccount ? NBTC_STORAGE_DEPOSIT_AMOUNT : ((_c = accountInfo == null ? void 0 : accountInfo.relayer_fee) == null ? void 0 : _c.amount) || 0;
3811
3807
  const hasDebtArrears = new Big2(debtAmount).gt(0);
@@ -3841,14 +3837,14 @@ function checkGasTokenDebt(_0) {
3841
3837
  }
3842
3838
  });
3843
3839
  }
3844
- function getBtcGasPrice() {
3840
+ function getBtcGasPrice(type = "halfHour") {
3845
3841
  return __async(this, null, function* () {
3846
3842
  const network = yield getNetwork();
3847
3843
  const defaultFeeRate = network === "mainnet" ? 5 : 2500;
3848
3844
  try {
3849
3845
  const btcRpcUrl = yield getBtcRpcUrl();
3850
3846
  const res = yield fetch(`${btcRpcUrl}/v1/fees/recommended`).then((res2) => res2.json());
3851
- const feeRate = res.fastestFee ? Number(res.fastestFee) + 1 : defaultFeeRate;
3847
+ const feeRate = res[type + "Fee"] ? Number(res[type + "Fee"]) : defaultFeeRate;
3852
3848
  return feeRate;
3853
3849
  } catch (error) {
3854
3850
  return defaultFeeRate;
@@ -3869,7 +3865,7 @@ function calculateGasFee(account, amount, feeRate) {
3869
3865
  const _feeRate = feeRate || (yield getBtcGasPrice());
3870
3866
  const utxos = yield getBtcUtxos(account);
3871
3867
  const { fee } = coinselect(utxos, [{ address: account, value: amount }], Math.ceil(_feeRate));
3872
- console.log("calculateGasFee fee:", fee);
3868
+ console.log("calculateGasFee fee:", fee, "feeRate:", _feeRate);
3873
3869
  return fee;
3874
3870
  });
3875
3871
  }
@@ -3968,6 +3964,30 @@ function getCsnaAccountId(env) {
3968
3964
  return csna;
3969
3965
  });
3970
3966
  }
3967
+ function checkNewAccount(_0) {
3968
+ return __async(this, arguments, function* ({
3969
+ csna,
3970
+ btcAccount,
3971
+ env = "mainnet"
3972
+ }) {
3973
+ try {
3974
+ const _csna = csna || (yield getCsnaAccountId(env));
3975
+ const _btcAccount = btcAccount || getBtcProvider().account;
3976
+ if (!_csna || !_btcAccount)
3977
+ return false;
3978
+ const accountInfo = yield getAccountInfo({ csna: _csna, env });
3979
+ const bridgeTransactions = yield hasBridgeTransaction({
3980
+ env,
3981
+ btcAccount: _btcAccount
3982
+ });
3983
+ const isNewAccount = !(accountInfo == null ? void 0 : accountInfo.nonce) && !bridgeTransactions;
3984
+ return isNewAccount;
3985
+ } catch (error) {
3986
+ console.error("checkNewAccount error:", error);
3987
+ return false;
3988
+ }
3989
+ });
3990
+ }
3971
3991
  function checkDepositDisabledAddress() {
3972
3992
  var _a;
3973
3993
  const data = (_a = storageStore("SATOSHI_WALLET_XVERSE")) == null ? void 0 : _a.get(
@@ -5320,7 +5340,7 @@ function getGroup(state) {
5320
5340
 
5321
5341
  // src/index.ts
5322
5342
  var getVersion = () => {
5323
- return "0.5.87-beta";
5343
+ return "0.5.89-beta";
5324
5344
  };
5325
5345
  if (typeof window !== "undefined") {
5326
5346
  window.__BTC_WALLET_VERSION = getVersion();
@@ -5346,6 +5366,7 @@ export {
5346
5366
  calculateWithdraw,
5347
5367
  checkBridgeTransactionStatus,
5348
5368
  checkGasTokenDebt,
5369
+ checkNewAccount,
5349
5370
  checkSatoshiWhitelist,
5350
5371
  estimateDepositAmount,
5351
5372
  executeBTCDepositAndAction,