btc-wallet 0.5.78-beta → 0.5.80-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
@@ -281,6 +281,26 @@ 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
+ };
284
304
 
285
305
  // src/utils/Dialog.ts
286
306
  var Dialog = class {
@@ -3381,14 +3401,15 @@ function preReceiveDepositMsg(_0) {
3381
3401
  btcPublicKey,
3382
3402
  depositType = 1,
3383
3403
  postActions,
3384
- extraMsg
3404
+ extraMsg,
3405
+ userDepositAddress
3385
3406
  }) {
3386
3407
  const config = getWalletConfig(env);
3387
3408
  const { result_code, result_message, result_data } = yield request(
3388
3409
  `${config.base_url}/v1/preReceiveDepositMsg`,
3389
3410
  {
3390
3411
  method: "POST",
3391
- body: { btcPublicKey, depositType, postActions, extraMsg }
3412
+ body: { btcPublicKey, depositType, postActions, extraMsg, userDepositAddress }
3392
3413
  }
3393
3414
  );
3394
3415
  console.log("preReceiveDepositMsg resp:", { result_code, result_message, result_data });
@@ -3422,23 +3443,19 @@ function receiveDepositMsg(_0) {
3422
3443
  return result_data;
3423
3444
  });
3424
3445
  }
3425
- function getBridgeTransactions(_0) {
3426
- return __async(this, arguments, function* ({
3427
- env,
3428
- fromChainId = 0,
3429
- fromAddress,
3430
- page = 1,
3431
- pageSize = 10
3432
- }) {
3446
+ function hasBridgeTransaction(_0) {
3447
+ return __async(this, arguments, function* ({ env }) {
3448
+ var _a, _b;
3433
3449
  try {
3434
3450
  const config = getWalletConfig(env);
3451
+ const btcAccount = ((_a = window.btcContext) == null ? void 0 : _a.account) || ((_b = getUrlQuery()) == null ? void 0 : _b.originalAccountId);
3435
3452
  const { result_data = [] } = yield request(
3436
- `${config.base_url}/v1/history?fromChainId=${fromChainId}&fromAddress=${fromAddress}&page=${page}&pageSize=${pageSize}`
3453
+ `${config.base_url}/v1/history?fromChainId=0&fromAddress=${btcAccount}&page=1&pageSize=1`
3437
3454
  );
3438
- return result_data;
3455
+ return (result_data == null ? void 0 : result_data.length) > 0;
3439
3456
  } catch (error) {
3440
- console.error("getBridgeTransactions error:", error);
3441
- return [];
3457
+ console.error("hasBridgeTransaction error:", error);
3458
+ return false;
3442
3459
  }
3443
3460
  });
3444
3461
  }
@@ -3843,10 +3860,10 @@ var NEAR_STORAGE_DEPOSIT_AMOUNT = "1250000000000000000000";
3843
3860
  var NBTC_STORAGE_DEPOSIT_AMOUNT = 800;
3844
3861
  var NEW_ACCOUNT_MIN_DEPOSIT_AMOUNT = 1e3;
3845
3862
  function getBtcProvider() {
3846
- if (typeof window === "undefined" || !(window.btcContext || (parent == null ? void 0 : parent.btcContext))) {
3863
+ if (typeof window === "undefined" || !window.btcContext) {
3847
3864
  throw new Error("BTC Provider is not initialized.");
3848
3865
  }
3849
- return window.btcContext || parent.btcContext;
3866
+ return window.btcContext;
3850
3867
  }
3851
3868
  function getNetwork() {
3852
3869
  return __async(this, null, function* () {
@@ -3878,14 +3895,10 @@ function checkGasTokenDebt(csna, env, autoDeposit) {
3878
3895
  return __async(this, null, function* () {
3879
3896
  var _a, _b, _c;
3880
3897
  const accountInfo = yield getAccountInfo({ csna, env });
3881
- const { account } = getBtcProvider();
3882
- const bridgeTransactions = yield getBridgeTransactions({
3883
- env,
3884
- fromAddress: account,
3885
- page: 1,
3886
- pageSize: 1
3898
+ const bridgeTransactions = yield hasBridgeTransaction({
3899
+ env
3887
3900
  });
3888
- const isNewAccount = !(accountInfo == null ? void 0 : accountInfo.nonce) && bridgeTransactions.length === 0;
3901
+ const isNewAccount = !(accountInfo == null ? void 0 : accountInfo.nonce) && !bridgeTransactions;
3889
3902
  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();
3890
3903
  const relayerFeeAmount = isNewAccount ? NBTC_STORAGE_DEPOSIT_AMOUNT : ((_c = accountInfo == null ? void 0 : accountInfo.relayer_fee) == null ? void 0 : _c.amount) || 0;
3891
3904
  const hasDebtArrears = new import_big2.default(debtAmount).gt(0);
@@ -4151,11 +4164,11 @@ function executeBTCDepositAndAction(_0) {
4151
4164
  const _feeRate = feeRate || (yield getBtcGasPrice());
4152
4165
  console.table({
4153
4166
  "User Deposit Address": userDepositAddress,
4154
- "Deposit Amount": depositAmount,
4155
- "Protocol Fee": protocolFee,
4156
- "Repay Amount": repayAmount,
4157
- "Receive Amount": receiveAmount,
4158
- "Fee Rate": _feeRate
4167
+ "Deposit Amount": Number(depositAmount),
4168
+ "Protocol Fee": Number(protocolFee),
4169
+ "Repay Amount": Number(repayAmount),
4170
+ "Receive Amount": Number(receiveAmount),
4171
+ "Fee Rate": Number(_feeRate)
4159
4172
  });
4160
4173
  const postActionsStr = newActions.length > 0 ? JSON.stringify(newActions) : void 0;
4161
4174
  yield preReceiveDepositMsg({
@@ -4163,7 +4176,8 @@ function executeBTCDepositAndAction(_0) {
4163
4176
  btcPublicKey,
4164
4177
  depositType: postActionsStr || depositMsg.extra_msg ? 1 : 0,
4165
4178
  postActions: postActionsStr,
4166
- extraMsg: depositMsg.extra_msg
4179
+ extraMsg: depositMsg.extra_msg,
4180
+ userDepositAddress
4167
4181
  });
4168
4182
  const txHash = yield sendBitcoin(userDepositAddress, depositAmount, _feeRate);
4169
4183
  yield receiveDepositMsg({
@@ -5396,7 +5410,7 @@ function getGroup(state) {
5396
5410
 
5397
5411
  // src/index.ts
5398
5412
  var getVersion = () => {
5399
- return "0.5.78-beta";
5413
+ return "0.5.80-beta";
5400
5414
  };
5401
5415
  if (typeof window !== "undefined") {
5402
5416
  window.__BTC_WALLET_VERSION = getVersion();