btc-wallet 0.3.29 → 0.3.30

Sign up to get free protection for your applications and to get access to all the features.
package/esm/index.js CHANGED
@@ -3219,7 +3219,9 @@ function nearCall(contractId, methodName, args) {
3219
3219
  }
3220
3220
  function getAccountInfo(csna, accountContractId) {
3221
3221
  return __async(this, null, function* () {
3222
- const accountInfo = yield nearCall(accountContractId, "get_account", { account_id: csna });
3222
+ const accountInfo = yield nearCall(accountContractId, "get_account", {
3223
+ account_id: csna
3224
+ });
3223
3225
  console.log("get_account accountInfo:", accountInfo);
3224
3226
  return accountInfo;
3225
3227
  });
@@ -3239,23 +3241,25 @@ function checkGasTokenBalance(csna, gasToken, minAmount, env) {
3239
3241
  }
3240
3242
  });
3241
3243
  }
3242
- function checkGasTokenArrears(debtInfo, env, autoDeposit) {
3244
+ function checkGasTokenArrears(accountInfo, env, autoDeposit) {
3243
3245
  return __async(this, null, function* () {
3244
- if (!debtInfo)
3246
+ var _a, _b, _c, _d;
3247
+ if (!((_a = accountInfo == null ? void 0 : accountInfo.debt_info) == null ? void 0 : _a.transfer_amount) || !((_b = accountInfo == null ? void 0 : accountInfo.relayer_fee) == null ? void 0 : _b.amount))
3245
3248
  return;
3246
3249
  const config = yield getConfig(env);
3247
- const transferAmount = debtInfo.transfer_amount;
3248
- console.log("get_account debtInfo:", debtInfo);
3250
+ const arrearsType = accountInfo.debt_info.transfer_amount ? "Deposit" : ((_c = accountInfo.relayer_fee) == null ? void 0 : _c.amount) ? "RelayerFee" : void 0;
3251
+ const transferAmount = arrearsType === "Deposit" ? accountInfo.debt_info.transfer_amount : (_d = accountInfo.relayer_fee) == null ? void 0 : _d.amount;
3252
+ console.log("get_account:", accountInfo);
3249
3253
  const action = {
3250
3254
  receiver_id: config.accountContractId,
3251
3255
  amount: transferAmount,
3252
- msg: JSON.stringify("Deposit")
3256
+ msg: JSON.stringify(arrearsType)
3253
3257
  };
3254
3258
  if (!autoDeposit)
3255
3259
  return action;
3256
3260
  const confirmed = yield Dialog.confirm({
3257
- title: "Has gas token arrears",
3258
- message: "You have gas token arrears, please deposit gas token to continue."
3261
+ title: arrearsType === "Deposit" ? "Has gas token arrears" : "Has relayer fee arrears",
3262
+ message: arrearsType === "Deposit" ? "You have gas token arrears, please deposit gas token to continue." : "You have relayer fee arrears, please deposit relayer fee to continue."
3259
3263
  });
3260
3264
  if (confirmed) {
3261
3265
  yield executeBTCDepositAndAction({ action, env });
@@ -3397,16 +3401,16 @@ function executeBTCDepositAndAction(_0) {
3397
3401
  });
3398
3402
  const accountInfo = yield getAccountInfo(csna, config.accountContractId);
3399
3403
  const newActions = [];
3400
- const repayAction = yield checkGasTokenArrears(accountInfo == null ? void 0 : accountInfo.debt_info, env, false);
3401
- if (repayAction) {
3402
- newActions.push(__spreadProps(__spreadValues({}, repayAction), {
3404
+ const arrearsAction = yield checkGasTokenArrears(accountInfo, env, false);
3405
+ if (arrearsAction) {
3406
+ newActions.push(__spreadProps(__spreadValues({}, arrearsAction), {
3403
3407
  gas: GAS_LIMIT
3404
3408
  }));
3405
3409
  }
3406
3410
  if (action || !action && new Big((accountInfo == null ? void 0 : accountInfo.gas_token[config.token]) || 0).lt(MINIMUM_DEPOSIT_AMOUNT_BASE)) {
3407
3411
  newActions.push(
3408
3412
  action ? __spreadProps(__spreadValues({}, action), {
3409
- amount: (repayAction == null ? void 0 : repayAction.amount) && !fixedAmount ? new Big(receiveAmount).minus(repayAction.amount).toString() : receiveAmount.toString(),
3413
+ amount: (arrearsAction == null ? void 0 : arrearsAction.amount) && !fixedAmount ? new Big(receiveAmount).minus(arrearsAction.amount).toString() : receiveAmount.toString(),
3410
3414
  gas: GAS_LIMIT
3411
3415
  }) : {
3412
3416
  receiver_id: config.accountContractId,
@@ -3448,7 +3452,7 @@ function executeBTCDepositAndAction(_0) {
3448
3452
  { deposit_msg: depositMsg }
3449
3453
  );
3450
3454
  const _feeRate = feeRate || (yield getBtcGasPrice());
3451
- const sendAmount = (repayAction == null ? void 0 : repayAction.amount) && fixedAmount ? new Big(depositAmount).plus((repayAction == null ? void 0 : repayAction.amount) || 0).toString() : depositAmount;
3455
+ const sendAmount = (arrearsAction == null ? void 0 : arrearsAction.amount) && fixedAmount ? new Big(depositAmount).plus((arrearsAction == null ? void 0 : arrearsAction.amount) || 0).toString() : depositAmount;
3452
3456
  console.log("user deposit address:", userDepositAddress);
3453
3457
  console.log("send amount:", sendAmount);
3454
3458
  console.log("fee rate:", _feeRate);
@@ -3697,7 +3701,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
3697
3701
  const btcContext = window.btcContext;
3698
3702
  const accountId = state.getAccount();
3699
3703
  const accountInfo = yield getAccountInfo(accountId, currentConfig.accountContractId);
3700
- yield checkGasTokenArrears(accountInfo == null ? void 0 : accountInfo.debt_info, env, true);
3704
+ yield checkGasTokenArrears(accountInfo, env, true);
3701
3705
  const trans = [...params.transactions];
3702
3706
  console.log("raw trans:", trans);
3703
3707
  const gasTokenBalance = (accountInfo == null ? void 0 : accountInfo.gas_token[currentConfig.token]) || "0";
@@ -3955,7 +3959,7 @@ function setupBTCWallet({
3955
3959
 
3956
3960
  // src/index.ts
3957
3961
  var getVersion = () => {
3958
- return "0.3.29";
3962
+ return "0.3.30";
3959
3963
  };
3960
3964
  if (typeof window !== "undefined") {
3961
3965
  window.__BTC_WALLET_VERSION = getVersion();