btc-wallet 0.5.40-beta → 0.5.42-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
@@ -3874,7 +3874,7 @@ function calculateGasFee(account, amount, feeRate) {
3874
3874
  return fee;
3875
3875
  });
3876
3876
  }
3877
- function getBtcBalance(account, option) {
3877
+ function getBtcBalance(account) {
3878
3878
  return __async(this, null, function* () {
3879
3879
  if (!account) {
3880
3880
  const res = yield retryOperation(getBtcProvider, (res2) => !!res2.account);
@@ -3889,11 +3889,7 @@ function getBtcBalance(account, option) {
3889
3889
  const rawBalance = (utxos == null ? void 0 : utxos.reduce((acc, cur) => acc + cur.value, 0)) || 0;
3890
3890
  const balance = rawBalance / __pow(10, btcDecimals);
3891
3891
  const estimatedFee = yield calculateGasFee(account, rawBalance);
3892
- let availableRawBalance = (rawBalance - estimatedFee).toFixed(0);
3893
- if (option == null ? void 0 : option.csna) {
3894
- const { protocolFee, repayAmount } = yield getDepositAmount(rawBalance.toString(), option);
3895
- availableRawBalance = new Big2(availableRawBalance).minus(protocolFee).minus(repayAmount).toFixed(0);
3896
- }
3892
+ const availableRawBalance = (rawBalance - estimatedFee).toFixed(0);
3897
3893
  const availableBalance = new Big2(availableRawBalance).div(__pow(10, btcDecimals)).round(btcDecimals, Big2.roundDown).toNumber();
3898
3894
  return {
3899
3895
  rawBalance,
@@ -3930,10 +3926,15 @@ function getDepositAmount(amount, option) {
3930
3926
  const depositAmount = Math.max(Number(min_deposit_amount), Number(amount));
3931
3927
  const protocolFee = Math.max(Number(fee_min), Number(depositAmount) * fee_rate);
3932
3928
  const newAccountMinDepositAmount = !(accountInfo == null ? void 0 : accountInfo.nonce) && _newAccountMinDepositAmount ? NEW_ACCOUNT_MIN_DEPOSIT_AMOUNT : 0;
3933
- const totalDepositAmount = new Big2(depositAmount).plus(protocolFee).plus(repayAmount).plus(newAccountMinDepositAmount).round(0, Big2.roundDown).toNumber();
3929
+ const receiveAmount = new Big2(depositAmount).minus(protocolFee).minus(repayAmount).round(0, Big2.roundDown).toNumber();
3930
+ if (Number(newAccountMinDepositAmount) > 0 && receiveAmount < Number(newAccountMinDepositAmount)) {
3931
+ throw new Error(
3932
+ `Receive amount (${receiveAmount}) is less than minimum required amount for new account (${newAccountMinDepositAmount})`
3933
+ );
3934
+ }
3934
3935
  return {
3935
3936
  depositAmount,
3936
- totalDepositAmount,
3937
+ receiveAmount,
3937
3938
  protocolFee,
3938
3939
  repayAmount,
3939
3940
  newAccountMinDepositAmount
@@ -3997,7 +3998,7 @@ function executeBTCDepositAndAction(_0) {
3997
3998
  if (new Big2(depositAmount).lt(0)) {
3998
3999
  throw new Error("amount must be greater than 0");
3999
4000
  }
4000
- const { totalDepositAmount, protocolFee, repayAmount } = yield getDepositAmount(depositAmount, {
4001
+ const { receiveAmount, protocolFee, repayAmount } = yield getDepositAmount(depositAmount, {
4001
4002
  env,
4002
4003
  newAccountMinDepositAmount
4003
4004
  });
@@ -4047,7 +4048,7 @@ function executeBTCDepositAndAction(_0) {
4047
4048
  "Deposit Amount": depositAmount,
4048
4049
  "Protocol Fee": protocolFee,
4049
4050
  "Repay Amount": repayAmount,
4050
- "Total Deposit Amount": totalDepositAmount,
4051
+ "Receive Amount": receiveAmount,
4051
4052
  "Fee Rate": _feeRate
4052
4053
  });
4053
4054
  const postActionsStr = newActions.length > 0 ? JSON.stringify(newActions) : void 0;
@@ -4057,7 +4058,7 @@ function executeBTCDepositAndAction(_0) {
4057
4058
  postActions: postActionsStr,
4058
4059
  extraMsg: depositMsg.extra_msg
4059
4060
  });
4060
- const txHash = yield sendBitcoin(userDepositAddress, totalDepositAmount, _feeRate);
4061
+ const txHash = yield sendBitcoin(userDepositAddress, Number(depositAmount), _feeRate);
4061
4062
  yield receiveDepositMsg(config.base_url, {
4062
4063
  btcPublicKey,
4063
4064
  txHash,
@@ -4849,7 +4850,7 @@ function getGroup(state) {
4849
4850
 
4850
4851
  // src/index.ts
4851
4852
  var getVersion = () => {
4852
- return "0.5.40-beta";
4853
+ return "0.5.42-beta";
4853
4854
  };
4854
4855
  if (typeof window !== "undefined") {
4855
4856
  window.__BTC_WALLET_VERSION = getVersion();