btc-wallet 0.5.28-beta → 0.5.30-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.
@@ -9,7 +9,12 @@ type CheckGasTokenDebtReturnType<T extends boolean> = T extends true ? void : {
9
9
  } | undefined;
10
10
  export declare function checkGasTokenDebt<T extends boolean>(csna: string, env: ENV, autoDeposit?: T): Promise<CheckGasTokenDebtReturnType<T>>;
11
11
  export declare function getBtcGasPrice(): Promise<number>;
12
- export declare function getBtcUtxos(account: string): Promise<any>;
12
+ export declare function getBtcUtxos(account: string): Promise<{
13
+ value: number;
14
+ status: {
15
+ confirmed: boolean;
16
+ };
17
+ }[]>;
13
18
  export declare function calculateGasFee(account: string, amount: number, feeRate?: number): Promise<any>;
14
19
  export declare function getBtcBalance(account?: string): Promise<{
15
20
  rawBalance: number;
package/dist/index.js CHANGED
@@ -3838,10 +3838,10 @@ function calculateWithdraw(_0) {
3838
3838
  }
3839
3839
 
3840
3840
  // src/core/btcUtils.ts
3841
- var import_bitcoinjs_lib = __toESM(require("bitcoinjs-lib"), 1);
3841
+ var bitcoin = __toESM(require("bitcoinjs-lib"), 1);
3842
3842
  var import_coinselect2 = __toESM(require("coinselect"), 1);
3843
3843
  var ecc = __toESM(require("@bitcoinerlab/secp256k1"), 1);
3844
- import_bitcoinjs_lib.default.initEccLib(ecc);
3844
+ bitcoin.initEccLib(ecc);
3845
3845
  var NEAR_STORAGE_DEPOSIT_AMOUNT = "1250000000000000000000";
3846
3846
  var NBTC_STORAGE_DEPOSIT_AMOUNT = "3000";
3847
3847
  var GAS_LIMIT = "50000000000000";
@@ -3926,8 +3926,10 @@ function getBtcGasPrice() {
3926
3926
  function getBtcUtxos(account) {
3927
3927
  return __async(this, null, function* () {
3928
3928
  const btcRpcUrl = yield getBtcRpcUrl();
3929
- const utxos = yield fetch(`${btcRpcUrl}/address/${account}/utxo`).then((res) => res.json());
3930
- return utxos;
3929
+ const utxos = yield fetch(
3930
+ `${btcRpcUrl}/address/${account}/utxo`
3931
+ ).then((res) => res.json());
3932
+ return utxos.filter((item) => item.status.confirmed);
3931
3933
  });
3932
3934
  }
3933
3935
  function calculateGasFee(account, amount, feeRate) {
@@ -4201,8 +4203,8 @@ function getWithdrawTransaction(_0) {
4201
4203
  `(${inputs.map((item) => item.value).join(" + ")}) - (${outputs.map((item) => item.value).join(" + ")}) = ${gasFee}`
4202
4204
  );
4203
4205
  const network = yield getNetwork();
4204
- const btcNetwork = network === "mainnet" ? import_bitcoinjs_lib.default.networks.bitcoin : import_bitcoinjs_lib.default.networks.testnet;
4205
- const psbt = new import_bitcoinjs_lib.default.Psbt({ network: btcNetwork });
4206
+ const btcNetwork = network === "mainnet" ? bitcoin.networks.bitcoin : bitcoin.networks.testnet;
4207
+ const psbt = new bitcoin.Psbt({ network: btcNetwork });
4206
4208
  const btcRpcUrl = yield getBtcRpcUrl();
4207
4209
  yield Promise.all(
4208
4210
  inputs.map((input) => __async(this, null, function* () {
@@ -4251,7 +4253,7 @@ function getWithdrawTransaction(_0) {
4251
4253
  methodName: "ft_transfer_call",
4252
4254
  args: {
4253
4255
  receiver_id: config.bridgeContractId,
4254
- amount: fromAmount,
4256
+ amount: fromAmount == null ? void 0 : fromAmount.toString(),
4255
4257
  msg: JSON.stringify(msg)
4256
4258
  },
4257
4259
  gas: "300000000000000",
@@ -4426,6 +4428,7 @@ function createIframe({
4426
4428
  document.body.appendChild(iframe);
4427
4429
  return iframe;
4428
4430
  }
4431
+ var currentMessageHandler = null;
4429
4432
  function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
4430
4433
  return __async(this, null, function* () {
4431
4434
  var _a;
@@ -4445,7 +4448,11 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
4445
4448
  executeBTCDepositAndAction,
4446
4449
  getWithdrawTransaction
4447
4450
  };
4448
- window.addEventListener("message", (event) => __async(this, null, function* () {
4451
+ if (currentMessageHandler) {
4452
+ window.removeEventListener("message", currentMessageHandler);
4453
+ currentMessageHandler = null;
4454
+ }
4455
+ const handleWalletMessage = (event) => __async(this, null, function* () {
4449
4456
  var _a2, _b;
4450
4457
  if (event.origin !== iframeSrc.origin)
4451
4458
  return;
@@ -4476,7 +4483,9 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
4476
4483
  { targetOrigin: event.origin }
4477
4484
  );
4478
4485
  }
4479
- }));
4486
+ });
4487
+ currentMessageHandler = handleWalletMessage;
4488
+ window.addEventListener("message", handleWalletMessage);
4480
4489
  });
4481
4490
  }
4482
4491
  function removeWalletButton() {
@@ -4897,7 +4906,7 @@ function getGroup(state) {
4897
4906
 
4898
4907
  // src/index.ts
4899
4908
  var getVersion = () => {
4900
- return "0.5.28-beta";
4909
+ return "0.5.30-beta";
4901
4910
  };
4902
4911
  if (typeof window !== "undefined") {
4903
4912
  window.__BTC_WALLET_VERSION = getVersion();