btc-wallet 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js CHANGED
@@ -2359,7 +2359,6 @@ var import_js_sha256 = require("js-sha256");
2359
2359
  // src/utils/initWalletButton.ts
2360
2360
  function setupWalletButton(network, wallet, originalWallet) {
2361
2361
  if (document.getElementById("satoshi-wallet-button")) {
2362
- sendInitializeData(wallet, originalWallet);
2363
2362
  return;
2364
2363
  }
2365
2364
  const iframe = createIframe({
@@ -2428,45 +2427,27 @@ function createIframe({
2428
2427
  document.body.appendChild(iframe);
2429
2428
  return iframe;
2430
2429
  }
2431
- function sendInitializeData(wallet, originalWallet) {
2430
+ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
2432
2431
  return __async(this, null, function* () {
2433
- var _a, _b;
2434
- yield delay(1e3);
2432
+ var _a;
2435
2433
  const accountId = (_a = yield wallet == null ? void 0 : wallet.getAccounts()) == null ? void 0 : _a[0].accountId;
2436
2434
  const originalAccountId = originalWallet.account;
2437
2435
  const originalPublicKey = yield originalWallet.getPublicKey();
2438
- const iframe = document.getElementById("satoshi-wallet-iframe");
2439
- if ((iframe == null ? void 0 : iframe.contentWindow) && ((_b = iframe.contentDocument) == null ? void 0 : _b.readyState) === "complete") {
2440
- iframe.contentWindow.postMessage(
2441
- {
2442
- action: "initializeData",
2443
- success: true,
2444
- data: {
2445
- accountId,
2446
- originalAccountId,
2447
- originalPublicKey
2448
- }
2449
- },
2450
- { targetOrigin: window.location.origin }
2451
- );
2452
- }
2453
- });
2454
- }
2455
- function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
2456
- return __async(this, null, function* () {
2457
- iframe.onload = () => sendInitializeData(wallet, originalWallet);
2458
2436
  const iframeSrc = new URL(iframe.src);
2459
2437
  iframeSrc.searchParams.set("origin", window.location.origin);
2438
+ accountId && iframeSrc.searchParams.set("accountId", accountId);
2439
+ originalAccountId && iframeSrc.searchParams.set("originalAccountId", originalAccountId);
2440
+ originalPublicKey && iframeSrc.searchParams.set("originalPublicKey", originalPublicKey);
2460
2441
  iframe.src = iframeSrc.toString();
2461
2442
  window.addEventListener("message", (event) => __async(this, null, function* () {
2462
- var _a, _b;
2443
+ var _a2, _b;
2463
2444
  if (event.origin !== iframeSrc.origin)
2464
2445
  return;
2465
2446
  const { action, requestId, data } = event.data;
2466
2447
  if (action === "signAndSendTransaction") {
2467
2448
  try {
2468
2449
  const result = yield wallet.signAndSendTransaction(data);
2469
- (_a = event.source) == null ? void 0 : _a.postMessage(
2450
+ (_a2 = event.source) == null ? void 0 : _a2.postMessage(
2470
2451
  {
2471
2452
  requestId,
2472
2453
  data,
@@ -2829,16 +2810,16 @@ function toHex(originalString) {
2829
2810
  }
2830
2811
  function initWalletButton(network, accountId, wallet) {
2831
2812
  return __async(this, null, function* () {
2832
- yield delay(2e3);
2813
+ yield delay(1e3);
2833
2814
  const checkAndSetupWalletButton = () => {
2834
2815
  if (accountId && window.btcContext.account) {
2835
2816
  setupWalletButton(network, wallet, window.btcContext);
2836
2817
  } else {
2837
2818
  removeWalletButton();
2819
+ !window.btcContext.account && setTimeout(() => {
2820
+ checkAndSetupWalletButton();
2821
+ }, 5e3);
2838
2822
  }
2839
- !window.btcContext.account && setTimeout(() => {
2840
- checkAndSetupWalletButton();
2841
- }, 1e4);
2842
2823
  };
2843
2824
  checkAndSetupWalletButton();
2844
2825
  });
@@ -2888,7 +2869,7 @@ function pollTransactionStatuses(network, hashes) {
2888
2869
 
2889
2870
  // src/index.ts
2890
2871
  var getVersion = () => {
2891
- return "0.1.0";
2872
+ return "0.1.1";
2892
2873
  };
2893
2874
  if (typeof window !== "undefined") {
2894
2875
  window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();