btc-wallet 0.1.0 → 0.1.2

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({
@@ -2375,6 +2374,9 @@ function createIframe({
2375
2374
  iframe.id = "satoshi-wallet-iframe";
2376
2375
  iframe.allow = "clipboard-read; clipboard-write";
2377
2376
  iframe.src = iframeUrl;
2377
+ iframe.onclick = () => {
2378
+ iframe.focus();
2379
+ };
2378
2380
  Object.assign(iframe.style, __spreadValues({
2379
2381
  position: "fixed",
2380
2382
  bottom: "90px",
@@ -2387,45 +2389,27 @@ function createIframe({
2387
2389
  document.body.appendChild(iframe);
2388
2390
  return iframe;
2389
2391
  }
2390
- function sendInitializeData(wallet, originalWallet) {
2392
+ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
2391
2393
  return __async(this, null, function* () {
2392
- var _a, _b;
2393
- yield delay(1e3);
2394
+ var _a;
2394
2395
  const accountId = (_a = yield wallet == null ? void 0 : wallet.getAccounts()) == null ? void 0 : _a[0].accountId;
2395
2396
  const originalAccountId = originalWallet.account;
2396
2397
  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
- {
2401
- action: "initializeData",
2402
- success: true,
2403
- data: {
2404
- accountId,
2405
- originalAccountId,
2406
- originalPublicKey
2407
- }
2408
- },
2409
- { targetOrigin: window.location.origin }
2410
- );
2411
- }
2412
- });
2413
- }
2414
- function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
2415
- return __async(this, null, function* () {
2416
- iframe.onload = () => sendInitializeData(wallet, originalWallet);
2417
2398
  const iframeSrc = new URL(iframe.src);
2418
2399
  iframeSrc.searchParams.set("origin", window.location.origin);
2400
+ accountId && iframeSrc.searchParams.set("accountId", accountId);
2401
+ originalAccountId && iframeSrc.searchParams.set("originalAccountId", originalAccountId);
2402
+ originalPublicKey && iframeSrc.searchParams.set("originalPublicKey", originalPublicKey);
2419
2403
  iframe.src = iframeSrc.toString();
2420
2404
  window.addEventListener("message", (event) => __async(this, null, function* () {
2421
- var _a, _b;
2405
+ var _a2, _b;
2422
2406
  if (event.origin !== iframeSrc.origin)
2423
2407
  return;
2424
2408
  const { action, requestId, data } = event.data;
2425
2409
  if (action === "signAndSendTransaction") {
2426
2410
  try {
2427
2411
  const result = yield wallet.signAndSendTransaction(data);
2428
- (_a = event.source) == null ? void 0 : _a.postMessage(
2412
+ (_a2 = event.source) == null ? void 0 : _a2.postMessage(
2429
2413
  {
2430
2414
  requestId,
2431
2415
  data,
@@ -2531,11 +2515,8 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2531
2515
  if (btcContext) {
2532
2516
  clearInterval(inter);
2533
2517
  const context = btcContext.getContext();
2534
- const accountId = state.getAccount();
2535
- initWalletButton(options.network.networkId, accountId, wallet);
2536
2518
  context.on("updatePublicKey", (btcPublicKey) => __async(void 0, null, function* () {
2537
2519
  const { nearTempAddress } = yield getNearAccountByBtcPublicKey(btcPublicKey);
2538
- initWalletButton(options.network.networkId, nearTempAddress, wallet);
2539
2520
  emitter.emit("accountsChanged", {
2540
2521
  accounts: [
2541
2522
  {
@@ -2556,6 +2537,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2556
2537
  }
2557
2538
  }), 500);
2558
2539
  }
2540
+ initWalletButton(options.network.networkId, state.getAccount(), wallet);
2559
2541
  function viewMethod(_02) {
2560
2542
  return __async(this, arguments, function* ({ method, args = {} }) {
2561
2543
  const res = yield provider.query({
@@ -2581,6 +2563,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2581
2563
  state.saveAccount(nearTempAddress);
2582
2564
  state.savePublicKey(nearTempPublicKey);
2583
2565
  state.saveBtcPublicKey(btcPublicKey);
2566
+ initWalletButton(options.network.networkId, nearTempAddress, wallet);
2584
2567
  return {
2585
2568
  nearTempAddress,
2586
2569
  nearTempPublicKey
@@ -2603,7 +2586,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2603
2586
  const btcAccount = yield btcContext.login();
2604
2587
  const btcPublicKey = yield btcContext.getPublicKey();
2605
2588
  const { nearTempAddress, nearTempPublicKey } = yield getNearAccountByBtcPublicKey(btcPublicKey);
2606
- initWalletButton(options.network.networkId, accountId, wallet);
2607
2589
  return [
2608
2590
  {
2609
2591
  accountId: nearTempAddress,
@@ -2788,16 +2770,16 @@ function toHex(originalString) {
2788
2770
  }
2789
2771
  function initWalletButton(network, accountId, wallet) {
2790
2772
  return __async(this, null, function* () {
2791
- yield delay(2e3);
2773
+ yield delay(1e3);
2792
2774
  const checkAndSetupWalletButton = () => {
2793
2775
  if (accountId && window.btcContext.account) {
2794
2776
  setupWalletButton(network, wallet, window.btcContext);
2795
2777
  } else {
2796
2778
  removeWalletButton();
2779
+ !window.btcContext.account && setTimeout(() => {
2780
+ checkAndSetupWalletButton();
2781
+ }, 5e3);
2797
2782
  }
2798
- !window.btcContext.account && setTimeout(() => {
2799
- checkAndSetupWalletButton();
2800
- }, 1e4);
2801
2783
  };
2802
2784
  checkAndSetupWalletButton();
2803
2785
  });
@@ -2847,7 +2829,7 @@ function pollTransactionStatuses(network, hashes) {
2847
2829
 
2848
2830
  // src/index.ts
2849
2831
  var getVersion = () => {
2850
- return "0.1.0";
2832
+ return "0.1.2";
2851
2833
  };
2852
2834
  if (typeof window !== "undefined") {
2853
2835
  window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();