btc-wallet 0.5.4-beta → 0.5.6-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/esm/index.js CHANGED
@@ -649,26 +649,19 @@ var XverseConnector = class extends BaseConnector {
649
649
  downloadUrl: "https://www.xverse.app"
650
650
  };
651
651
  this.loadAccounts = (network) => __async(this, null, function* () {
652
- const { getAddress, AddressPurpose } = yield import("sats-connect");
653
- const addresses = yield new Promise((resolve, reject) => {
654
- const getAddressOptions = {
655
- payload: {
656
- purposes: [AddressPurpose.Payment, AddressPurpose.Ordinals],
657
- message: "Address for receiving Ordinals and payments",
658
- network: {
659
- type: network
660
- }
661
- },
662
- onFinish: (response) => {
663
- resolve(response.addresses);
664
- },
665
- onCancel: () => reject({
666
- code: 4001,
667
- message: "User rejected the request."
668
- })
669
- };
670
- getAddress(getAddressOptions).catch((error) => reject(error));
652
+ const { AddressPurpose } = yield import("sats-connect");
653
+ const provider = this.getProvider();
654
+ if (!provider) {
655
+ throw new Error(`${this.metadata.name} is not install!`);
656
+ }
657
+ yield provider.request("wallet_requestPermissions", void 0);
658
+ const { result: walletType } = yield provider.request("wallet_getWalletType", void 0);
659
+ const { result } = yield provider.request("getAddresses", {
660
+ purposes: [AddressPurpose.Payment, AddressPurpose.Ordinals],
661
+ message: "Address for receiving Ordinals and payments"
671
662
  });
663
+ const addresses = result.addresses.map((item) => __spreadProps(__spreadValues({}, item), { walletType }));
664
+ console.log("\u{1F680} ~ XverseConnector ~ loadAccounts ~ res:", addresses);
672
665
  localStorage.setItem("btc-connect-xverse-addresses-" + network, JSON.stringify(addresses));
673
666
  return addresses;
674
667
  });
@@ -3355,6 +3348,9 @@ function getCsnaAccountId(env) {
3355
3348
  const config = yield getConfig(env);
3356
3349
  const { getPublicKey } = getBtcProvider();
3357
3350
  const btcPublicKey = yield getPublicKey();
3351
+ if (!btcPublicKey) {
3352
+ throw new Error("BTC Public Key is not available.");
3353
+ }
3358
3354
  const csna = yield nearCall(
3359
3355
  config.accountContractId,
3360
3356
  "get_chain_signature_near_account_id",
@@ -3473,7 +3469,7 @@ function executeBTCDepositAndAction(_0) {
3473
3469
  }
3474
3470
  function checkSatoshiWhitelist(btcAccountId, env = "mainnet") {
3475
3471
  return __async(this, null, function* () {
3476
- if (env !== "private_mainnet")
3472
+ if (env !== "mainnet")
3477
3473
  return;
3478
3474
  const hasShownNotice = localStorage.getItem("btc-wallet-private-mainnet-notice");
3479
3475
  if (!hasShownNotice) {
@@ -3819,7 +3815,9 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
3819
3815
  iframe.src = iframeSrc.toString();
3820
3816
  const actions = {
3821
3817
  signAndSendTransaction: wallet.signAndSendTransaction,
3822
- executeBTCDepositAndAction
3818
+ signAndSendTransactions: wallet.signAndSendTransactions,
3819
+ executeBTCDepositAndAction,
3820
+ getWithdrawTransaction
3823
3821
  };
3824
3822
  window.addEventListener("message", (event) => __async(this, null, function* () {
3825
3823
  var _a2, _b;
@@ -3996,6 +3994,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
3996
3994
  yield checkBtcNetwork(walletNetwork);
3997
3995
  if (!state.isValid()) {
3998
3996
  state.clear();
3997
+ console.log("setupBtcContextListeners clear");
3999
3998
  }
4000
3999
  validateWalletState();
4001
4000
  const btcContext = window.btcContext;
@@ -4018,6 +4017,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
4018
4017
  context.on("updatePublicKey", (btcPublicKey) => __async(this, null, function* () {
4019
4018
  console.log("updatePublicKey");
4020
4019
  state.clear();
4020
+ console.log("updatePublicKey clear");
4021
4021
  try {
4022
4022
  const { nearAddress, nearPublicKey } = yield getNearAccountByBtcPublicKey(btcPublicKey);
4023
4023
  if (!nearAddress || !nearPublicKey) {
@@ -4029,8 +4029,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
4029
4029
  yield handleConnectionUpdate();
4030
4030
  } catch (error) {
4031
4031
  console.error("Error updating public key:", error);
4032
- state.clear();
4033
- emitter.emit("accountsChanged", { accounts: [] });
4034
4032
  }
4035
4033
  }));
4036
4034
  context.on("btcLoginError", () => __async(this, null, function* () {
@@ -4431,7 +4429,7 @@ function setupBTCWallet({
4431
4429
 
4432
4430
  // src/index.ts
4433
4431
  var getVersion = () => {
4434
- return "0.5.4-beta";
4432
+ return "0.5.6-beta";
4435
4433
  };
4436
4434
  if (typeof window !== "undefined") {
4437
4435
  window.__BTC_WALLET_VERSION = getVersion();