btc-wallet 0.3.29 → 0.3.31

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
@@ -2225,7 +2225,6 @@ var ConnectProvider = ({
2225
2225
  })
2226
2226
  })
2227
2227
  );
2228
- console.log("walletEntryPlugin init");
2229
2228
  }
2230
2229
  }, [options, evmSupportChainIds, accountContract]);
2231
2230
  useEffect5(() => {
@@ -2234,7 +2233,6 @@ var ConnectProvider = ({
2234
2233
  walletEntryPlugin.setWalletCore({
2235
2234
  ethereum: smartAccount.provider
2236
2235
  });
2237
- console.log("walletEntryPlugin setWalletCore");
2238
2236
  }
2239
2237
  }, [smartAccount, options]);
2240
2238
  useEffect5(() => {
@@ -2242,10 +2240,8 @@ var ConnectProvider = ({
2242
2240
  if (((_a2 = options.walletOptions) == null ? void 0 : _a2.visible) !== false) {
2243
2241
  if (evmAccount) {
2244
2242
  walletEntryPlugin.walletEntryCreate();
2245
- console.log("walletEntryPlugin walletEntryCreate");
2246
2243
  } else {
2247
2244
  walletEntryPlugin.walletEntryDestroy();
2248
- console.log("walletEntryPlugin walletEntryDestroy");
2249
2245
  }
2250
2246
  }
2251
2247
  }, [evmAccount, smartAccount, options]);
@@ -3182,8 +3178,7 @@ Dialog.style = `
3182
3178
  `;
3183
3179
 
3184
3180
  // src/core/btcUtils.ts
3185
- var MINIMUM_DEPOSIT_AMOUNT = 5e3;
3186
- var MINIMUM_DEPOSIT_AMOUNT_BASE = 1e3;
3181
+ var MINIMUM_DEPOSIT_AMOUNT_BASE = 0;
3187
3182
  var NEAR_STORAGE_DEPOSIT_AMOUNT = "1250000000000000000000";
3188
3183
  var NBTC_STORAGE_DEPOSIT_AMOUNT = 3e3;
3189
3184
  var GAS_LIMIT = "50000000000000";
@@ -3219,7 +3214,9 @@ function nearCall(contractId, methodName, args) {
3219
3214
  }
3220
3215
  function getAccountInfo(csna, accountContractId) {
3221
3216
  return __async(this, null, function* () {
3222
- const accountInfo = yield nearCall(accountContractId, "get_account", { account_id: csna });
3217
+ const accountInfo = yield nearCall(accountContractId, "get_account", {
3218
+ account_id: csna
3219
+ });
3223
3220
  console.log("get_account accountInfo:", accountInfo);
3224
3221
  return accountInfo;
3225
3222
  });
@@ -3239,23 +3236,25 @@ function checkGasTokenBalance(csna, gasToken, minAmount, env) {
3239
3236
  }
3240
3237
  });
3241
3238
  }
3242
- function checkGasTokenArrears(debtInfo, env, autoDeposit) {
3239
+ function checkGasTokenArrears(accountInfo, env, autoDeposit) {
3243
3240
  return __async(this, null, function* () {
3244
- if (!debtInfo)
3241
+ var _a, _b, _c, _d;
3242
+ 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
3243
  return;
3246
3244
  const config = yield getConfig(env);
3247
- const transferAmount = debtInfo.transfer_amount;
3248
- console.log("get_account debtInfo:", debtInfo);
3245
+ const arrearsType = accountInfo.debt_info.transfer_amount ? "Deposit" : ((_c = accountInfo.relayer_fee) == null ? void 0 : _c.amount) ? "RelayerFee" : void 0;
3246
+ const transferAmount = arrearsType === "Deposit" ? accountInfo.debt_info.transfer_amount : (_d = accountInfo.relayer_fee) == null ? void 0 : _d.amount;
3247
+ console.log("get_account:", accountInfo);
3249
3248
  const action = {
3250
3249
  receiver_id: config.accountContractId,
3251
3250
  amount: transferAmount,
3252
- msg: JSON.stringify("Deposit")
3251
+ msg: JSON.stringify(arrearsType)
3253
3252
  };
3254
3253
  if (!autoDeposit)
3255
3254
  return action;
3256
3255
  const confirmed = yield Dialog.confirm({
3257
- title: "Has gas token arrears",
3258
- message: "You have gas token arrears, please deposit gas token to continue."
3256
+ title: arrearsType === "Deposit" ? "Has gas token arrears" : "Has relayer fee arrears",
3257
+ 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
3258
  });
3260
3259
  if (confirmed) {
3261
3260
  yield executeBTCDepositAndAction({ action, env });
@@ -3334,13 +3333,10 @@ function getDepositAmount(amount, option) {
3334
3333
  return __async(this, null, function* () {
3335
3334
  const config = yield getConfig((option == null ? void 0 : option.env) || "mainnet");
3336
3335
  const {
3337
- deposit_bridge_fee: { fee_min, fee_rate }
3338
- } = yield nearCall(
3339
- config.bridgeContractId,
3340
- "get_config",
3341
- {}
3342
- );
3343
- const depositAmount = (option == null ? void 0 : option.isEstimate) ? Number(amount) : Math.max(MINIMUM_DEPOSIT_AMOUNT + MINIMUM_DEPOSIT_AMOUNT_BASE, Number(amount));
3336
+ deposit_bridge_fee: { fee_min, fee_rate },
3337
+ min_deposit_amount
3338
+ } = yield nearCall(config.bridgeContractId, "get_config", {});
3339
+ const depositAmount = (option == null ? void 0 : option.isEstimate) ? Number(amount) : Math.max(Number(min_deposit_amount) + MINIMUM_DEPOSIT_AMOUNT_BASE, Number(amount));
3344
3340
  const fee = Math.max(Number(fee_min), Number(depositAmount) * fee_rate);
3345
3341
  const receiveAmount = new Big(depositAmount).minus(fee).minus(MINIMUM_DEPOSIT_AMOUNT_BASE).round(0, Big.roundDown).toNumber();
3346
3342
  console.log("getDepositAmount:", { depositAmount, receiveAmount, fee });
@@ -3397,16 +3393,16 @@ function executeBTCDepositAndAction(_0) {
3397
3393
  });
3398
3394
  const accountInfo = yield getAccountInfo(csna, config.accountContractId);
3399
3395
  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), {
3396
+ const arrearsAction = yield checkGasTokenArrears(accountInfo, env, false);
3397
+ if (arrearsAction) {
3398
+ newActions.push(__spreadProps(__spreadValues({}, arrearsAction), {
3403
3399
  gas: GAS_LIMIT
3404
3400
  }));
3405
3401
  }
3406
3402
  if (action || !action && new Big((accountInfo == null ? void 0 : accountInfo.gas_token[config.token]) || 0).lt(MINIMUM_DEPOSIT_AMOUNT_BASE)) {
3407
3403
  newActions.push(
3408
3404
  action ? __spreadProps(__spreadValues({}, action), {
3409
- amount: (repayAction == null ? void 0 : repayAction.amount) && !fixedAmount ? new Big(receiveAmount).minus(repayAction.amount).toString() : receiveAmount.toString(),
3405
+ amount: (arrearsAction == null ? void 0 : arrearsAction.amount) && !fixedAmount ? new Big(receiveAmount).minus(arrearsAction.amount).toString() : receiveAmount.toString(),
3410
3406
  gas: GAS_LIMIT
3411
3407
  }) : {
3412
3408
  receiver_id: config.accountContractId,
@@ -3448,7 +3444,7 @@ function executeBTCDepositAndAction(_0) {
3448
3444
  { deposit_msg: depositMsg }
3449
3445
  );
3450
3446
  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;
3447
+ const sendAmount = (arrearsAction == null ? void 0 : arrearsAction.amount) && fixedAmount ? new Big(depositAmount).plus((arrearsAction == null ? void 0 : arrearsAction.amount) || 0).toString() : depositAmount;
3452
3448
  console.log("user deposit address:", userDepositAddress);
3453
3449
  console.log("send amount:", sendAmount);
3454
3450
  console.log("fee rate:", _feeRate);
@@ -3546,6 +3542,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
3546
3542
  const accountId = state.getAccount();
3547
3543
  const btcContext = window.btcContext;
3548
3544
  if (accountId && btcContext.account) {
3545
+ removeWalletButton();
3549
3546
  setupWalletButton(env, wallet, btcContext);
3550
3547
  } else {
3551
3548
  removeWalletButton();
@@ -3697,7 +3694,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
3697
3694
  const btcContext = window.btcContext;
3698
3695
  const accountId = state.getAccount();
3699
3696
  const accountInfo = yield getAccountInfo(accountId, currentConfig.accountContractId);
3700
- yield checkGasTokenArrears(accountInfo == null ? void 0 : accountInfo.debt_info, env, true);
3697
+ yield checkGasTokenArrears(accountInfo, env, true);
3701
3698
  const trans = [...params.transactions];
3702
3699
  console.log("raw trans:", trans);
3703
3700
  const gasTokenBalance = (accountInfo == null ? void 0 : accountInfo.gas_token[currentConfig.token]) || "0";
@@ -3955,7 +3952,7 @@ function setupBTCWallet({
3955
3952
 
3956
3953
  // src/index.ts
3957
3954
  var getVersion = () => {
3958
- return "0.3.29";
3955
+ return "0.3.31";
3959
3956
  };
3960
3957
  if (typeof window !== "undefined") {
3961
3958
  window.__BTC_WALLET_VERSION = getVersion();