btc-wallet 0.5.93-beta → 0.5.95-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/dist/index.js CHANGED
@@ -3061,7 +3061,7 @@ function getWalletConfig(env) {
3061
3061
  });
3062
3062
  }
3063
3063
  var nearRpcUrls = {
3064
- mainnet: ["https://free.rpc.fastnear.com", "https://near.lava.build"],
3064
+ mainnet: ["https://near.lava.build", "https://free.rpc.fastnear.com"],
3065
3065
  testnet: ["https://rpc.testnet.near.org"]
3066
3066
  };
3067
3067
  var btcRpcUrls = {
@@ -3094,7 +3094,7 @@ function withCache(key, fetcher, timeout = defaultCacheTimeout) {
3094
3094
  }
3095
3095
  function request(url, options) {
3096
3096
  return __async(this, null, function* () {
3097
- var _a;
3097
+ var _a, _b;
3098
3098
  const defaultHeaders = {
3099
3099
  "Content-Type": "application/json"
3100
3100
  };
@@ -3113,6 +3113,15 @@ function request(url, options) {
3113
3113
  return Promise.resolve(cached.data);
3114
3114
  }
3115
3115
  }
3116
+ const setCacheAndReturn = (data) => {
3117
+ if (cacheKey) {
3118
+ cache.set(cacheKey, { timestamp: Date.now(), data });
3119
+ setTimeout(() => {
3120
+ cache.delete(cacheKey);
3121
+ }, cacheTimeout);
3122
+ }
3123
+ return data;
3124
+ };
3116
3125
  const newOptions = __spreadProps(__spreadValues({}, options), {
3117
3126
  headers,
3118
3127
  body,
@@ -3129,33 +3138,22 @@ function request(url, options) {
3129
3138
  if (!res.ok)
3130
3139
  throw new Error(res.statusText);
3131
3140
  const data = yield res.json();
3132
- if (options == null ? void 0 : options.shouldStopPolling) {
3133
- if (options.shouldStopPolling(data)) {
3134
- return data;
3135
- }
3136
- throw new Error("Polling should continue");
3137
- }
3138
- if (cacheKey) {
3139
- cache.set(cacheKey, { timestamp: Date.now(), data });
3140
- setTimeout(() => {
3141
- cache.delete(cacheKey);
3142
- }, cacheTimeout);
3143
- }
3144
- return data;
3145
- } catch (err) {
3146
- if (retryCount > 0) {
3147
- console.log(`Retrying... attempts left: ${retryCount}`);
3148
- return request(url, __spreadProps(__spreadValues({}, options), { retryCount: retryCount - 1 }));
3149
- } else if ((options == null ? void 0 : options.pollingInterval) && (options == null ? void 0 : options.maxPollingAttempts)) {
3150
- if (options.maxPollingAttempts > 0) {
3141
+ if ((options == null ? void 0 : options.shouldStopPolling) && !options.shouldStopPolling(data)) {
3142
+ if ((options == null ? void 0 : options.pollingInterval) && (options == null ? void 0 : options.maxPollingAttempts) && options.maxPollingAttempts > 0) {
3151
3143
  console.log(`Polling... attempts left: ${options.maxPollingAttempts}`);
3152
3144
  yield new Promise((resolve) => setTimeout(resolve, options.pollingInterval));
3153
3145
  return request(url, __spreadProps(__spreadValues({}, options), {
3154
3146
  maxPollingAttempts: options.maxPollingAttempts - 1,
3155
- retryCount
3147
+ retryCount: (_b = options == null ? void 0 : options.retryCount) != null ? _b : 1
3156
3148
  }));
3157
3149
  }
3158
3150
  }
3151
+ return setCacheAndReturn(data);
3152
+ } catch (err) {
3153
+ if (retryCount > 0) {
3154
+ console.log(`Retrying... attempts left: ${retryCount}`);
3155
+ return request(url, __spreadProps(__spreadValues({}, options), { retryCount: retryCount - 1 }));
3156
+ }
3159
3157
  console.error(err);
3160
3158
  return Promise.reject(err);
3161
3159
  }
@@ -3508,7 +3506,6 @@ function getAccountInfo(_0) {
3508
3506
  console.log(`get_account error, please try again later`, error);
3509
3507
  throw error;
3510
3508
  });
3511
- console.log("getAccountInfo resp:", accountInfo);
3512
3509
  return accountInfo;
3513
3510
  });
3514
3511
  }
@@ -4438,11 +4435,25 @@ function calculateWithdraw(_0) {
4438
4435
  }
4439
4436
  const userSatoshis = Number(satoshis);
4440
4437
  const maxBtcFee = Number(brgConfig.max_btc_gas_fee);
4441
- const { inputs, outputs, fee } = (0, import_coinselect.default)(
4438
+ let { inputs, outputs, fee } = (0, import_coinselect.default)(
4442
4439
  utxos,
4443
4440
  [{ address: btcAddress, value: userSatoshis }],
4444
4441
  Math.ceil(feeRate)
4445
4442
  );
4443
+ if (inputs && inputs.length > 10) {
4444
+ const filteredUtxos = utxos.filter((utxo) => utxo.value >= userSatoshis);
4445
+ console.log("filteredUtxos", filteredUtxos);
4446
+ if (filteredUtxos.length > 0) {
4447
+ const result = (0, import_coinselect.default)(
4448
+ filteredUtxos,
4449
+ [{ address: btcAddress, value: userSatoshis }],
4450
+ Math.ceil(feeRate)
4451
+ );
4452
+ inputs = result.inputs;
4453
+ outputs = result.outputs;
4454
+ fee = result.fee;
4455
+ }
4456
+ }
4446
4457
  const newInputs = inputs;
4447
4458
  let newOutputs = outputs;
4448
4459
  let newFee = fee;
@@ -5414,7 +5425,7 @@ function getGroup(state) {
5414
5425
 
5415
5426
  // src/index.ts
5416
5427
  var getVersion = () => {
5417
- return "0.5.93-beta";
5428
+ return "0.5.95-beta";
5418
5429
  };
5419
5430
  if (typeof window !== "undefined") {
5420
5431
  window.__BTC_WALLET_VERSION = getVersion();