btc-wallet 0.3.13 → 0.3.15

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
@@ -2686,21 +2686,24 @@ var walletConfig = {
2686
2686
  token: "nbtc-dev.testnet",
2687
2687
  accountContractId: "acc-dev.testnet",
2688
2688
  bridgeContractId: "brg-dev.testnet",
2689
- walletUrl: "https://wallet-dev.satoshibridge.top"
2689
+ walletUrl: "https://wallet-dev.satoshibridge.top",
2690
+ bridgeUrl: "https://dev.satoshibridge.top/"
2690
2691
  },
2691
2692
  testnet: {
2692
2693
  base_url: "https://api.testnet.satoshibridge.top",
2693
2694
  token: "nbtc2-nsp.testnet",
2694
- accountContractId: "dev2-nsp.testnet",
2695
+ accountContractId: "acc2-nsp.testnet",
2695
2696
  bridgeContractId: "brg2-nsp.testnet",
2696
- walletUrl: "https://wallet-test.satoshibridge.top"
2697
+ walletUrl: "https://wallet-test.satoshibridge.top",
2698
+ bridgeUrl: "https://testnet.satoshibridge.top/"
2697
2699
  },
2698
2700
  mainnet: {
2699
2701
  base_url: "https://api.mainnet.satoshibridge.top",
2700
- token: "",
2701
- accountContractId: "",
2702
- bridgeContractId: "",
2703
- walletUrl: "https://wallet.satoshibridge.top"
2702
+ token: "nbtc.toalice.near",
2703
+ accountContractId: "acc.toalice.near",
2704
+ bridgeContractId: "brg.toalice.near",
2705
+ walletUrl: "https://wallet.satoshibridge.top",
2706
+ bridgeUrl: "https://www.satoshibridge.top/"
2704
2707
  }
2705
2708
  };
2706
2709
  var nearRpcUrls = {
@@ -3135,6 +3138,8 @@ Dialog.style = `
3135
3138
  `;
3136
3139
 
3137
3140
  // src/core/btcUtils.ts
3141
+ var MINIMUM_DEPOSIT_AMOUNT = 5e3;
3142
+ var MINIMUM_DEPOSIT_AMOUNT_BASE = 1e3;
3138
3143
  function getBtcProvider() {
3139
3144
  if (typeof window === "undefined" || !window.btcContext) {
3140
3145
  throw new Error("BTC Provider is not initialized.");
@@ -3172,15 +3177,30 @@ function getAccountInfo(csna, accountContractId) {
3172
3177
  return accountInfo;
3173
3178
  });
3174
3179
  }
3180
+ function checkGasTokenBalance(csna, gasToken, isDev) {
3181
+ return __async(this, null, function* () {
3182
+ const amount = yield nearCall(gasToken, "ft_balance_of", { account_id: csna });
3183
+ console.log("gas token balance:", amount);
3184
+ if (new Big(amount).lte(MINIMUM_DEPOSIT_AMOUNT_BASE)) {
3185
+ yield Dialog.confirm({
3186
+ title: "Gas token balance is insufficient",
3187
+ message: "Please deposit gas token to continue, will open bridge website."
3188
+ });
3189
+ const config = yield getConfig(isDev);
3190
+ window.open(config.bridgeUrl, "_blank");
3191
+ throw new Error("Gas token balance is insufficient");
3192
+ }
3193
+ });
3194
+ }
3175
3195
  function checkGasTokenArrears(debtInfo, isDev, autoDeposit) {
3176
3196
  return __async(this, null, function* () {
3197
+ if (!debtInfo)
3198
+ return;
3177
3199
  const config = yield getConfig(isDev);
3178
- const transferAmount = debtInfo.transfer_amount || "0";
3200
+ const transferAmount = debtInfo.transfer_amount;
3179
3201
  console.log("get_account debtInfo:", debtInfo);
3180
- if (transferAmount === "0")
3181
- return;
3182
3202
  const action = {
3183
- receiver_id: config.token,
3203
+ receiver_id: config.accountContractId,
3184
3204
  amount: transferAmount,
3185
3205
  msg: JSON.stringify("Deposit")
3186
3206
  };
@@ -3248,8 +3268,6 @@ function sendBitcoin(address, amount, feeRate) {
3248
3268
  return txHash;
3249
3269
  });
3250
3270
  }
3251
- var MINIMUM_DEPOSIT_AMOUNT = 5e3;
3252
- var MINIMUM_DEPOSIT_AMOUNT_BASE = 1e3;
3253
3271
  function estimateDepositAmount(amount, option) {
3254
3272
  return __async(this, null, function* () {
3255
3273
  const { receiveAmount } = yield getDepositAmount(amount, __spreadProps(__spreadValues({}, option), { isEstimate: true }));
@@ -3306,13 +3324,13 @@ function executeBTCDepositAndAction(_0) {
3306
3324
  if (new Big(rawDepositAmount).lt(0)) {
3307
3325
  throw new Error("amount must be greater than 0");
3308
3326
  }
3309
- const { depositAmount } = yield getDepositAmount(rawDepositAmount, {
3327
+ const { depositAmount, receiveAmount } = yield getDepositAmount(rawDepositAmount, {
3310
3328
  isDev
3311
3329
  });
3312
3330
  const accountInfo = yield getAccountInfo(csna, config.accountContractId);
3313
3331
  const newActions = [];
3314
3332
  const gasLimit = new Big(50).mul(__pow(10, 12)).toFixed(0);
3315
- const repayAction = yield checkGasTokenArrears(accountInfo.debt_info, isDev);
3333
+ const repayAction = yield checkGasTokenArrears(accountInfo.debt_info, isDev, false);
3316
3334
  if (repayAction) {
3317
3335
  newActions.push(__spreadProps(__spreadValues({}, repayAction), {
3318
3336
  gas: gasLimit
@@ -3320,7 +3338,7 @@ function executeBTCDepositAndAction(_0) {
3320
3338
  }
3321
3339
  if (action) {
3322
3340
  newActions.push(__spreadProps(__spreadValues({}, action), {
3323
- amount: (repayAction == null ? void 0 : repayAction.amount) && !fixedAmount ? new Big(depositAmount).minus(repayAction.amount).toString() : depositAmount.toString(),
3341
+ amount: (repayAction == null ? void 0 : repayAction.amount) && !fixedAmount ? new Big(receiveAmount).minus(repayAction.amount).toString() : receiveAmount.toString(),
3324
3342
  gas: gasLimit
3325
3343
  }));
3326
3344
  }
@@ -3581,6 +3599,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
3581
3599
  const btcContext = window.btcContext;
3582
3600
  const accountId = state.getAccount();
3583
3601
  const accountInfo = yield getAccountInfo(accountId, currentConfig.accountContractId);
3602
+ yield checkGasTokenBalance(accountId, currentConfig.token, isDev);
3584
3603
  yield checkGasTokenArrears(accountInfo.debt_info, isDev, true);
3585
3604
  const trans = [...params.transactions];
3586
3605
  console.log("raw trans:", trans);
@@ -3840,7 +3859,7 @@ function setupBTCWallet({
3840
3859
 
3841
3860
  // src/index.ts
3842
3861
  var getVersion = () => {
3843
- return "0.3.13";
3862
+ return "0.3.15";
3844
3863
  };
3845
3864
  if (typeof window !== "undefined") {
3846
3865
  window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();
@@ -3859,6 +3878,7 @@ export {
3859
3878
  WizzConnector,
3860
3879
  XverseConnector,
3861
3880
  checkGasTokenArrears,
3881
+ checkGasTokenBalance,
3862
3882
  estimateDepositAmount,
3863
3883
  executeBTCDepositAndAction,
3864
3884
  getAccountInfo,