btc-wallet 0.5.80-beta → 0.5.82-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.
@@ -7,7 +7,12 @@ type CheckGasTokenDebtReturnType<T extends boolean> = T extends true ? void : {
7
7
  amount: string;
8
8
  msg: string;
9
9
  } | undefined;
10
- export declare function checkGasTokenDebt<T extends boolean>(csna: string, env: ENV, autoDeposit?: T): Promise<CheckGasTokenDebtReturnType<T>>;
10
+ export declare function checkGasTokenDebt<T extends boolean>({ csna, btcAccount, env, autoDeposit, }: {
11
+ csna: string;
12
+ btcAccount: string;
13
+ env: ENV;
14
+ autoDeposit?: T;
15
+ }): Promise<CheckGasTokenDebtReturnType<T>>;
11
16
  export declare function getBtcGasPrice(): Promise<number>;
12
17
  export declare function getBtcUtxos(account: string): Promise<{
13
18
  value: number;
@@ -32,6 +37,7 @@ export declare function estimateDepositAmount(amount: string, option?: {
32
37
  }): Promise<string>;
33
38
  export declare function getDepositAmount(amount: string, option?: {
34
39
  csna?: string;
40
+ btcAccount?: string;
35
41
  env?: ENV;
36
42
  /** default is true, if true, new account minimum deposit amount 1000sat, otherwise 0 */
37
43
  newAccountMinDepositAmount?: boolean;
package/dist/index.js CHANGED
@@ -281,26 +281,6 @@ function storageStore(namespace, options) {
281
281
  }
282
282
  };
283
283
  }
284
- var getUrlQuery = (url) => {
285
- var _a;
286
- try {
287
- const search = url ? (_a = url.split("?")[1]) == null ? void 0 : _a.split("#")[0] : window.location.search.substring(1).split("#")[0];
288
- const urlSearchParams = new URLSearchParams(search);
289
- const entries = urlSearchParams.entries();
290
- const query = {};
291
- for (const [key, value] of entries) {
292
- if (query[key]) {
293
- query[key] = Array.isArray(query[key]) ? [...query[key], value] : [query[key], value];
294
- } else {
295
- query[key] = value;
296
- }
297
- }
298
- return query;
299
- } catch (error) {
300
- console.error("getUrlQuery", error);
301
- return {};
302
- }
303
- };
304
284
 
305
285
  // src/utils/Dialog.ts
306
286
  var Dialog = class {
@@ -3080,12 +3060,7 @@ function getWalletConfig(env) {
3080
3060
  });
3081
3061
  }
3082
3062
  var nearRpcUrls = {
3083
- mainnet: [
3084
- "https://near.lava.build",
3085
- "https://rpc.mainnet.near.org",
3086
- "https://free.rpc.fastnear.com",
3087
- "https://near.drpc.org"
3088
- ],
3063
+ mainnet: ["https://near.lava.build", "https://free.rpc.fastnear.com"],
3089
3064
  testnet: ["https://rpc.testnet.near.org"]
3090
3065
  };
3091
3066
  var btcRpcUrls = {
@@ -3444,11 +3419,9 @@ function receiveDepositMsg(_0) {
3444
3419
  });
3445
3420
  }
3446
3421
  function hasBridgeTransaction(_0) {
3447
- return __async(this, arguments, function* ({ env }) {
3448
- var _a, _b;
3422
+ return __async(this, arguments, function* ({ env, btcAccount }) {
3449
3423
  try {
3450
3424
  const config = getWalletConfig(env);
3451
- const btcAccount = ((_a = window.btcContext) == null ? void 0 : _a.account) || ((_b = getUrlQuery()) == null ? void 0 : _b.originalAccountId);
3452
3425
  const { result_data = [] } = yield request(
3453
3426
  `${config.base_url}/v1/history?fromChainId=0&fromAddress=${btcAccount}&page=1&pageSize=1`
3454
3427
  );
@@ -3857,7 +3830,7 @@ var import_coinselect = __toESM(require("coinselect"), 1);
3857
3830
  var ecc = __toESM(require("@bitcoinerlab/secp256k1"), 1);
3858
3831
  bitcoin.initEccLib(ecc);
3859
3832
  var NEAR_STORAGE_DEPOSIT_AMOUNT = "1250000000000000000000";
3860
- var NBTC_STORAGE_DEPOSIT_AMOUNT = 800;
3833
+ var NBTC_STORAGE_DEPOSIT_AMOUNT = 2e3;
3861
3834
  var NEW_ACCOUNT_MIN_DEPOSIT_AMOUNT = 1e3;
3862
3835
  function getBtcProvider() {
3863
3836
  if (typeof window === "undefined" || !window.btcContext) {
@@ -3891,12 +3864,18 @@ function nearCall(contractId, methodName, args) {
3891
3864
  return nearCallFunction(contractId, methodName, args, { network });
3892
3865
  });
3893
3866
  }
3894
- function checkGasTokenDebt(csna, env, autoDeposit) {
3895
- return __async(this, null, function* () {
3867
+ function checkGasTokenDebt(_0) {
3868
+ return __async(this, arguments, function* ({
3869
+ csna,
3870
+ btcAccount,
3871
+ env,
3872
+ autoDeposit
3873
+ }) {
3896
3874
  var _a, _b, _c;
3897
3875
  const accountInfo = yield getAccountInfo({ csna, env });
3898
3876
  const bridgeTransactions = yield hasBridgeTransaction({
3899
- env
3877
+ env,
3878
+ btcAccount
3900
3879
  });
3901
3880
  const isNewAccount = !(accountInfo == null ? void 0 : accountInfo.nonce) && !bridgeTransactions;
3902
3881
  const debtAmount = new import_big2.default(((_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();
@@ -4016,8 +3995,9 @@ function getDepositAmount(amount, option) {
4016
3995
  const env = (option == null ? void 0 : option.env) || "mainnet";
4017
3996
  const _newAccountMinDepositAmount = (_a = option == null ? void 0 : option.newAccountMinDepositAmount) != null ? _a : true;
4018
3997
  const csna = (option == null ? void 0 : option.csna) || (yield getCsnaAccountId(env));
3998
+ const btcAccount = (option == null ? void 0 : option.btcAccount) || getBtcProvider().account;
4019
3999
  const accountInfo = yield getAccountInfo({ csna, env });
4020
- const debtAction = yield checkGasTokenDebt(csna, env, false);
4000
+ const debtAction = yield checkGasTokenDebt({ csna, btcAccount, env, autoDeposit: false });
4021
4001
  const repayAmount = (debtAction == null ? void 0 : debtAction.amount) || 0;
4022
4002
  const depositAmount = Number(amount);
4023
4003
  const {
@@ -4094,7 +4074,7 @@ function executeBTCDepositAndAction(_0) {
4094
4074
  registerContractId
4095
4075
  });
4096
4076
  checkDepositDisabledAddress();
4097
- const { getPublicKey } = getBtcProvider();
4077
+ const { getPublicKey, account: btcAccount } = getBtcProvider();
4098
4078
  const config = getWalletConfig(env);
4099
4079
  const btcPublicKey = yield getPublicKey();
4100
4080
  if (!btcPublicKey) {
@@ -4123,7 +4103,7 @@ function executeBTCDepositAndAction(_0) {
4123
4103
  }
4124
4104
  const accountInfo = yield getAccountInfo({ csna, env });
4125
4105
  const newActions = [];
4126
- const debtAction = yield checkGasTokenDebt(csna, env, false);
4106
+ const debtAction = yield checkGasTokenDebt({ csna, btcAccount, env, autoDeposit: false });
4127
4107
  if (debtAction) {
4128
4108
  newActions.push(__spreadProps(__spreadValues({}, debtAction), {
4129
4109
  gas: "30000000000000"
@@ -5168,7 +5148,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
5168
5148
  const btcContext = window.btcContext;
5169
5149
  const csna = state_default.getAccount();
5170
5150
  const accountInfo = yield getAccountInfo({ csna, env });
5171
- yield checkGasTokenDebt(csna, env, true);
5151
+ yield checkGasTokenDebt({ csna, env, btcAccount: btcContext.account, autoDeposit: true });
5172
5152
  const trans = [...params.transactions];
5173
5153
  console.log("signAndSendTransactions raw trans:", trans);
5174
5154
  const { transferGasTransaction, useNearPayGas, gasLimit } = yield calculateGasStrategy({
@@ -5410,7 +5390,7 @@ function getGroup(state) {
5410
5390
 
5411
5391
  // src/index.ts
5412
5392
  var getVersion = () => {
5413
- return "0.5.80-beta";
5393
+ return "0.5.82-beta";
5414
5394
  };
5415
5395
  if (typeof window !== "undefined") {
5416
5396
  window.__BTC_WALLET_VERSION = getVersion();