btc-wallet 0.5.27-beta → 0.5.29-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
@@ -24,18 +24,6 @@ var __spreadValues = (a, b) => {
24
24
  return a;
25
25
  };
26
26
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
27
- var __objRest = (source, exclude) => {
28
- var target = {};
29
- for (var prop in source)
30
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
31
- target[prop] = source[prop];
32
- if (source != null && __getOwnPropSymbols)
33
- for (var prop of __getOwnPropSymbols(source)) {
34
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
35
- target[prop] = source[prop];
36
- }
37
- return target;
38
- };
39
27
  var __export = (target, all) => {
40
28
  for (var name in all)
41
29
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -3938,8 +3926,10 @@ function getBtcGasPrice() {
3938
3926
  function getBtcUtxos(account) {
3939
3927
  return __async(this, null, function* () {
3940
3928
  const btcRpcUrl = yield getBtcRpcUrl();
3941
- const utxos = yield fetch(`${btcRpcUrl}/address/${account}/utxo`).then((res) => res.json());
3942
- 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);
3943
3933
  });
3944
3934
  }
3945
3935
  function calculateGasFee(account, amount, feeRate) {
@@ -4196,13 +4186,13 @@ function getWithdrawTransaction(_0) {
4196
4186
  const config = getWalletConfig(env);
4197
4187
  const _btcAddress = btcAddress || getBtcProvider().account;
4198
4188
  const _csna = csna || (yield getCsnaAccountId(env));
4199
- const _a = yield calculateWithdraw({
4189
+ const { inputs, outputs, isError, errorMsg, fromAmount, gasFee } = yield calculateWithdraw({
4200
4190
  amount,
4201
4191
  feeRate,
4202
4192
  csna: _csna,
4203
4193
  btcAddress: _btcAddress,
4204
4194
  env
4205
- }), { inputs, outputs, isError, errorMsg } = _a, rest = __objRest(_a, ["inputs", "outputs", "isError", "errorMsg"]);
4195
+ });
4206
4196
  if (isError || !inputs || !outputs) {
4207
4197
  throw new Error(errorMsg);
4208
4198
  }
@@ -4210,7 +4200,7 @@ function getWithdrawTransaction(_0) {
4210
4200
  console.log("outputs:", JSON.stringify(outputs));
4211
4201
  console.log("inputs - outputs = gas");
4212
4202
  console.log(
4213
- `(${inputs.map((item) => item.value).join(" + ")}) - (${outputs.map((item) => item.value).join(" + ")}) = ${rest.gasFee}`
4203
+ `(${inputs.map((item) => item.value).join(" + ")}) - (${outputs.map((item) => item.value).join(" + ")}) = ${gasFee}`
4214
4204
  );
4215
4205
  const network = yield getNetwork();
4216
4206
  const btcNetwork = network === "mainnet" ? import_bitcoinjs_lib.default.networks.bitcoin : import_bitcoinjs_lib.default.networks.testnet;
@@ -4263,7 +4253,7 @@ function getWithdrawTransaction(_0) {
4263
4253
  methodName: "ft_transfer_call",
4264
4254
  args: {
4265
4255
  receiver_id: config.bridgeContractId,
4266
- amount: amount.toString(),
4256
+ amount: fromAmount == null ? void 0 : fromAmount.toString(),
4267
4257
  msg: JSON.stringify(msg)
4268
4258
  },
4269
4259
  gas: "300000000000000",
@@ -4438,6 +4428,7 @@ function createIframe({
4438
4428
  document.body.appendChild(iframe);
4439
4429
  return iframe;
4440
4430
  }
4431
+ var currentMessageHandler = null;
4441
4432
  function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
4442
4433
  return __async(this, null, function* () {
4443
4434
  var _a;
@@ -4457,7 +4448,11 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
4457
4448
  executeBTCDepositAndAction,
4458
4449
  getWithdrawTransaction
4459
4450
  };
4460
- 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* () {
4461
4456
  var _a2, _b;
4462
4457
  if (event.origin !== iframeSrc.origin)
4463
4458
  return;
@@ -4488,7 +4483,9 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
4488
4483
  { targetOrigin: event.origin }
4489
4484
  );
4490
4485
  }
4491
- }));
4486
+ });
4487
+ currentMessageHandler = handleWalletMessage;
4488
+ window.addEventListener("message", handleWalletMessage);
4492
4489
  });
4493
4490
  }
4494
4491
  function removeWalletButton() {
@@ -4909,7 +4906,7 @@ function getGroup(state) {
4909
4906
 
4910
4907
  // src/index.ts
4911
4908
  var getVersion = () => {
4912
- return "0.5.27-beta";
4909
+ return "0.5.29-beta";
4913
4910
  };
4914
4911
  if (typeof window !== "undefined") {
4915
4912
  window.__BTC_WALLET_VERSION = getVersion();