btc-wallet 0.5.44-beta → 0.5.45-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
@@ -3732,19 +3732,23 @@ function getDepositAmount(amount, option) {
3732
3732
  const accountInfo = yield getAccountInfo({ csna, env });
3733
3733
  const debtAction = yield checkGasTokenDebt(csna, env, false);
3734
3734
  const repayAmount = (debtAction == null ? void 0 : debtAction.amount) || 0;
3735
+ const depositAmount = Number(amount);
3735
3736
  const {
3736
3737
  deposit_bridge_fee: { fee_min, fee_rate },
3737
3738
  min_deposit_amount
3738
3739
  } = yield getBridgeConfig({ env });
3739
- const depositAmount = Math.max(Number(min_deposit_amount), Number(amount));
3740
- const protocolFee = Math.max(Number(fee_min), Number(depositAmount) * fee_rate);
3740
+ const protocolFee = Math.max(Number(fee_min), depositAmount * fee_rate);
3741
3741
  const newAccountMinDepositAmount = !(accountInfo == null ? void 0 : accountInfo.nonce) && _newAccountMinDepositAmount ? NEW_ACCOUNT_MIN_DEPOSIT_AMOUNT : 0;
3742
- const receiveAmount = new Big2(depositAmount).minus(protocolFee).minus(repayAmount).round(0, Big2.roundDown).toNumber();
3742
+ let receiveAmount = new Big2(depositAmount).minus(protocolFee).minus(repayAmount).round(0, Big2.roundDown).toNumber();
3743
+ receiveAmount = Math.max(receiveAmount, 0);
3743
3744
  if (Number(newAccountMinDepositAmount) > 0 && receiveAmount < Number(newAccountMinDepositAmount)) {
3744
- throw new Error(
3745
- `Receive amount (${receiveAmount}) is less than minimum required amount for new account (${newAccountMinDepositAmount})`
3745
+ console.error(
3746
+ `Receive amount (${receiveAmount}) is less than minimum required amount for new account (${newAccountMinDepositAmount} sat)`
3746
3747
  );
3747
3748
  }
3749
+ if (receiveAmount <= 0) {
3750
+ console.error(`Receive amount (${receiveAmount}) is less than 0`);
3751
+ }
3748
3752
  return {
3749
3753
  depositAmount,
3750
3754
  receiveAmount,
@@ -3804,17 +3808,20 @@ function executeBTCDepositAndAction(_0) {
3804
3808
  throw new Error("BTC Public Key is not available.");
3805
3809
  }
3806
3810
  if (!amount && !action) {
3807
- throw new Error("amount or action is required");
3811
+ throw new Error("Deposit amount or action is required");
3808
3812
  }
3809
3813
  const csna = yield getCsnaAccountId(env);
3810
3814
  const depositAmount = (_a = action ? action.amount : amount) != null ? _a : "0";
3811
3815
  if (new Big2(depositAmount).lt(0)) {
3812
- throw new Error("amount must be greater than 0");
3816
+ throw new Error("Deposit amount must be greater than 0");
3813
3817
  }
3814
3818
  const { receiveAmount, protocolFee, repayAmount } = yield getDepositAmount(depositAmount, {
3815
3819
  env,
3816
3820
  newAccountMinDepositAmount
3817
3821
  });
3822
+ if (receiveAmount <= 0) {
3823
+ throw new Error("Invalid deposit amount, too small");
3824
+ }
3818
3825
  const accountInfo = yield getAccountInfo({ csna, env });
3819
3826
  const newActions = [];
3820
3827
  const debtAction = yield checkGasTokenDebt(csna, env, false);
@@ -4858,7 +4865,7 @@ function getGroup(state) {
4858
4865
 
4859
4866
  // src/index.ts
4860
4867
  var getVersion = () => {
4861
- return "0.5.44-beta";
4868
+ return "0.5.45-beta";
4862
4869
  };
4863
4870
  if (typeof window !== "undefined") {
4864
4871
  window.__BTC_WALLET_VERSION = getVersion();