btc-wallet 0.0.9 → 0.1.1

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
@@ -2318,7 +2318,6 @@ import { sha256 } from "js-sha256";
2318
2318
  // src/utils/initWalletButton.ts
2319
2319
  function setupWalletButton(network, wallet, originalWallet) {
2320
2320
  if (document.getElementById("satoshi-wallet-button")) {
2321
- sendInitializeData(wallet, originalWallet);
2322
2321
  return;
2323
2322
  }
2324
2323
  const iframe = createIframe({
@@ -2387,42 +2386,27 @@ function createIframe({
2387
2386
  document.body.appendChild(iframe);
2388
2387
  return iframe;
2389
2388
  }
2390
- function sendInitializeData(wallet, originalWallet) {
2389
+ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
2391
2390
  return __async(this, null, function* () {
2392
- var _a, _b;
2393
- yield delay(1e3);
2391
+ var _a;
2394
2392
  const accountId = (_a = yield wallet == null ? void 0 : wallet.getAccounts()) == null ? void 0 : _a[0].accountId;
2395
2393
  const originalAccountId = originalWallet.account;
2396
2394
  const originalPublicKey = yield originalWallet.getPublicKey();
2397
- const iframe = document.getElementById("satoshi-wallet-iframe");
2398
- if ((iframe == null ? void 0 : iframe.contentWindow) && ((_b = iframe.contentDocument) == null ? void 0 : _b.readyState) === "complete") {
2399
- iframe.contentWindow.postMessage({
2400
- action: "initializeData",
2401
- success: true,
2402
- data: {
2403
- accountId,
2404
- originalAccountId,
2405
- originalPublicKey
2406
- }
2407
- });
2408
- }
2409
- });
2410
- }
2411
- function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
2412
- return __async(this, null, function* () {
2413
- iframe.onload = () => sendInitializeData(wallet, originalWallet);
2414
2395
  const iframeSrc = new URL(iframe.src);
2415
2396
  iframeSrc.searchParams.set("origin", window.location.origin);
2397
+ accountId && iframeSrc.searchParams.set("accountId", accountId);
2398
+ originalAccountId && iframeSrc.searchParams.set("originalAccountId", originalAccountId);
2399
+ originalPublicKey && iframeSrc.searchParams.set("originalPublicKey", originalPublicKey);
2416
2400
  iframe.src = iframeSrc.toString();
2417
2401
  window.addEventListener("message", (event) => __async(this, null, function* () {
2418
- var _a, _b;
2402
+ var _a2, _b;
2419
2403
  if (event.origin !== iframeSrc.origin)
2420
2404
  return;
2421
2405
  const { action, requestId, data } = event.data;
2422
2406
  if (action === "signAndSendTransaction") {
2423
2407
  try {
2424
2408
  const result = yield wallet.signAndSendTransaction(data);
2425
- (_a = event.source) == null ? void 0 : _a.postMessage(
2409
+ (_a2 = event.source) == null ? void 0 : _a2.postMessage(
2426
2410
  {
2427
2411
  requestId,
2428
2412
  data,
@@ -2785,16 +2769,16 @@ function toHex(originalString) {
2785
2769
  }
2786
2770
  function initWalletButton(network, accountId, wallet) {
2787
2771
  return __async(this, null, function* () {
2788
- yield delay(2e3);
2772
+ yield delay(1e3);
2789
2773
  const checkAndSetupWalletButton = () => {
2790
2774
  if (accountId && window.btcContext.account) {
2791
2775
  setupWalletButton(network, wallet, window.btcContext);
2792
2776
  } else {
2793
2777
  removeWalletButton();
2778
+ !window.btcContext.account && setTimeout(() => {
2779
+ checkAndSetupWalletButton();
2780
+ }, 5e3);
2794
2781
  }
2795
- !window.btcContext.account && setTimeout(() => {
2796
- checkAndSetupWalletButton();
2797
- }, 1e4);
2798
2782
  };
2799
2783
  checkAndSetupWalletButton();
2800
2784
  });
@@ -2844,7 +2828,7 @@ function pollTransactionStatuses(network, hashes) {
2844
2828
 
2845
2829
  // src/index.ts
2846
2830
  var getVersion = () => {
2847
- return "0.0.9";
2831
+ return "0.1.1";
2848
2832
  };
2849
2833
  if (typeof window !== "undefined") {
2850
2834
  window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();