btc-wallet 0.5.62-beta → 0.5.64-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.
@@ -5,11 +5,18 @@ interface setupWalletButtonOptions {
5
5
  nearWallet: Wallet;
6
6
  btcWallet?: OriginalWallet;
7
7
  walletUrl?: string;
8
+ draggable?: boolean;
9
+ initialPosition?: {
10
+ right: string;
11
+ bottom: string;
12
+ };
13
+ buttonSize?: string;
14
+ mobileButtonSize?: string;
8
15
  }
9
16
  interface OriginalWallet {
10
17
  account: string | undefined;
11
18
  getPublicKey: () => Promise<string | undefined>;
12
19
  }
13
- export declare function setupWalletButton({ env, nearWallet, btcWallet, walletUrl, }: setupWalletButtonOptions): void;
20
+ export declare function setupWalletButton({ env, nearWallet, btcWallet, walletUrl, draggable, initialPosition, buttonSize, mobileButtonSize, }: setupWalletButtonOptions): void;
14
21
  export declare function removeWalletButton(): void;
15
22
  export {};
package/esm/index.js CHANGED
@@ -4379,11 +4379,16 @@ function uint8ArrayToHex(uint8Array) {
4379
4379
 
4380
4380
  // src/utils/initWalletButton.ts
4381
4381
  var storage4 = storageStore("SATOSHI_WALLET_BUTTON");
4382
+ var minimumMargin = 10;
4382
4383
  function setupWalletButton({
4383
4384
  env,
4384
4385
  nearWallet,
4385
4386
  btcWallet,
4386
- walletUrl
4387
+ walletUrl,
4388
+ draggable = true,
4389
+ initialPosition,
4390
+ buttonSize,
4391
+ mobileButtonSize
4387
4392
  }) {
4388
4393
  if (document.getElementById("satoshi-wallet-button")) {
4389
4394
  return;
@@ -4407,49 +4412,73 @@ function setupWalletButton({
4407
4412
  const button = createFloatingButtonWithIframe({
4408
4413
  openImageUrl,
4409
4414
  closeImageUrl,
4410
- iframe
4415
+ iframe,
4416
+ draggable,
4417
+ initialPosition,
4418
+ buttonSize,
4419
+ mobileButtonSize
4411
4420
  });
4412
4421
  setupButtonClickHandler(button, iframe, nearWallet, btcWallet);
4413
4422
  }
4414
4423
  function createFloatingButtonWithIframe({
4415
4424
  openImageUrl,
4416
4425
  closeImageUrl,
4417
- iframe
4426
+ iframe,
4427
+ draggable,
4428
+ initialPosition,
4429
+ buttonSize,
4430
+ mobileButtonSize
4418
4431
  }) {
4419
- var _a;
4420
4432
  const button = document.createElement("img");
4421
4433
  button.id = "satoshi-wallet-button";
4422
- const isIframeVisible = (_a = storage4 == null ? void 0 : storage4.get("visible")) != null ? _a : !isMobile();
4434
+ const isIframeVisible = storage4 == null ? void 0 : storage4.get("visible");
4423
4435
  button.src = isIframeVisible ? closeImageUrl : openImageUrl;
4424
4436
  iframe.style.display = isIframeVisible ? "block" : "none";
4425
4437
  const windowWidth = window.innerWidth;
4426
4438
  const windowHeight = window.innerHeight;
4427
- const savedPosition = (storage4 == null ? void 0 : storage4.get("position")) || {
4439
+ const savedPosition = storage4 == null ? void 0 : storage4.get("position");
4440
+ const currentInitialPosition = initialPosition || savedPosition || {
4428
4441
  right: "20px",
4429
4442
  bottom: "20px"
4430
4443
  };
4431
- const right = Math.min(Math.max(20, parseInt(savedPosition.right)), windowWidth - 80);
4432
- const bottom = Math.min(Math.max(20, parseInt(savedPosition.bottom)), windowHeight - 80);
4444
+ const tempButtonSize = buttonSize || "60px";
4445
+ const tempMobileButtonSize = mobileButtonSize || buttonSize || "40px";
4446
+ const actualButtonSize = isMobile() ? parseInt(tempMobileButtonSize) : parseInt(tempButtonSize);
4447
+ const right = Math.min(
4448
+ Math.max(minimumMargin, parseInt(currentInitialPosition.right)),
4449
+ windowWidth - actualButtonSize - minimumMargin
4450
+ );
4451
+ const bottom = Math.min(
4452
+ Math.max(minimumMargin, parseInt(currentInitialPosition.bottom)),
4453
+ windowHeight - actualButtonSize - minimumMargin
4454
+ );
4433
4455
  Object.assign(button.style, {
4434
4456
  position: "fixed",
4435
4457
  bottom: `${bottom}px`,
4436
4458
  right: `${right}px`,
4437
4459
  zIndex: "100000",
4438
- width: "60px",
4439
- height: "60px",
4440
- cursor: "grab",
4460
+ width: buttonSize || "60px",
4461
+ height: buttonSize || "60px",
4462
+ cursor: draggable ? "grab" : "pointer",
4441
4463
  transition: "transform 0.15s ease",
4442
4464
  userSelect: "none",
4443
4465
  touchAction: "none"
4444
4466
  });
4445
4467
  if (isMobile()) {
4446
4468
  Object.assign(button.style, {
4447
- width: "40px",
4448
- height: "40px"
4469
+ width: mobileButtonSize || buttonSize || "40px",
4470
+ height: mobileButtonSize || buttonSize || "40px"
4449
4471
  });
4450
4472
  }
4451
4473
  document.body.appendChild(button);
4452
- updateIframePosition(iframe, right, bottom, windowWidth, windowHeight);
4474
+ updateIframePosition(
4475
+ iframe,
4476
+ right,
4477
+ bottom,
4478
+ windowWidth,
4479
+ windowHeight,
4480
+ parseInt(button.style.width)
4481
+ );
4453
4482
  let isDragging = false;
4454
4483
  let startX = 0;
4455
4484
  let startY = 0;
@@ -4457,6 +4486,8 @@ function createFloatingButtonWithIframe({
4457
4486
  let initialBottom = 0;
4458
4487
  let dragStartTime = 0;
4459
4488
  function startDrag(clientX, clientY) {
4489
+ if (!draggable)
4490
+ return;
4460
4491
  isDragging = true;
4461
4492
  startX = clientX;
4462
4493
  startY = clientY;
@@ -4485,7 +4516,7 @@ function createFloatingButtonWithIframe({
4485
4516
  button.addEventListener(
4486
4517
  "click",
4487
4518
  (e) => {
4488
- if (!isDragging) {
4519
+ if (!isDragging || !draggable) {
4489
4520
  toggleWallet();
4490
4521
  }
4491
4522
  e.preventDefault();
@@ -4493,107 +4524,117 @@ function createFloatingButtonWithIframe({
4493
4524
  },
4494
4525
  { capture: true }
4495
4526
  );
4496
- button.addEventListener(
4497
- "mousedown",
4498
- (e) => {
4499
- startDrag(e.clientX, e.clientY);
4500
- e.preventDefault();
4501
- e.stopPropagation();
4502
- },
4503
- { capture: true }
4504
- );
4505
- button.addEventListener(
4506
- "touchstart",
4507
- (e) => {
4508
- if (e.touches.length === 1) {
4509
- const touch = e.touches[0];
4510
- startDrag(touch.clientX, touch.clientY);
4527
+ if (draggable) {
4528
+ button.addEventListener(
4529
+ "mousedown",
4530
+ (e) => {
4531
+ startDrag(e.clientX, e.clientY);
4511
4532
  e.preventDefault();
4512
4533
  e.stopPropagation();
4513
- }
4514
- },
4515
- { capture: true }
4516
- );
4517
- document.addEventListener(
4518
- "mousemove",
4519
- (e) => {
4520
- if (!isDragging)
4521
- return;
4522
- moveButton(e.clientX, e.clientY);
4523
- e.preventDefault();
4524
- },
4525
- { capture: true }
4526
- );
4527
- document.addEventListener(
4528
- "touchmove",
4529
- (e) => {
4530
- if (!isDragging || e.touches.length !== 1)
4531
- return;
4532
- const touch = e.touches[0];
4533
- moveButton(touch.clientX, touch.clientY);
4534
- e.preventDefault();
4535
- },
4536
- { capture: true }
4537
- );
4534
+ },
4535
+ { capture: true }
4536
+ );
4537
+ button.addEventListener(
4538
+ "touchstart",
4539
+ (e) => {
4540
+ if (e.touches.length === 1) {
4541
+ const touch = e.touches[0];
4542
+ startDrag(touch.clientX, touch.clientY);
4543
+ e.preventDefault();
4544
+ e.stopPropagation();
4545
+ }
4546
+ },
4547
+ { capture: true }
4548
+ );
4549
+ document.addEventListener(
4550
+ "mousemove",
4551
+ (e) => {
4552
+ if (!isDragging)
4553
+ return;
4554
+ moveButton(e.clientX, e.clientY);
4555
+ e.preventDefault();
4556
+ },
4557
+ { capture: true }
4558
+ );
4559
+ document.addEventListener(
4560
+ "touchmove",
4561
+ (e) => {
4562
+ if (!isDragging || e.touches.length !== 1)
4563
+ return;
4564
+ const touch = e.touches[0];
4565
+ moveButton(touch.clientX, touch.clientY);
4566
+ e.preventDefault();
4567
+ },
4568
+ { capture: true }
4569
+ );
4570
+ document.addEventListener(
4571
+ "mouseup",
4572
+ (e) => {
4573
+ if (isDragging) {
4574
+ e.preventDefault();
4575
+ e.stopPropagation();
4576
+ }
4577
+ endDrag();
4578
+ },
4579
+ { capture: true }
4580
+ );
4581
+ document.addEventListener(
4582
+ "touchend",
4583
+ (e) => {
4584
+ if (isDragging) {
4585
+ e.preventDefault();
4586
+ e.stopPropagation();
4587
+ }
4588
+ endDrag();
4589
+ const dragEndTime = Date.now();
4590
+ const dragDuration = dragEndTime - dragStartTime;
4591
+ if (dragDuration < 200 && Math.abs(parseInt(button.style.right) - initialRight) < 5 && Math.abs(parseInt(button.style.bottom) - initialBottom) < 5) {
4592
+ toggleWallet();
4593
+ }
4594
+ },
4595
+ { capture: true }
4596
+ );
4597
+ document.addEventListener(
4598
+ "touchcancel",
4599
+ () => {
4600
+ endDrag();
4601
+ },
4602
+ { capture: true }
4603
+ );
4604
+ }
4538
4605
  function moveButton(clientX, clientY) {
4539
4606
  const deltaX = startX - clientX;
4540
4607
  const deltaY = startY - clientY;
4541
4608
  let newRight = initialRight + deltaX;
4542
4609
  let newBottom = initialBottom + deltaY;
4543
- newRight = Math.min(Math.max(20, newRight), windowWidth - 80);
4544
- newBottom = Math.min(Math.max(20, newBottom), windowHeight - 80);
4545
- const snapThreshold = 20;
4546
- const buttonLeft = windowWidth - newRight - 60;
4610
+ const currentButtonSize = parseInt(button.style.width);
4611
+ newRight = Math.min(
4612
+ Math.max(minimumMargin, newRight),
4613
+ windowWidth - currentButtonSize - minimumMargin
4614
+ );
4615
+ newBottom = Math.min(
4616
+ Math.max(minimumMargin, newBottom),
4617
+ windowHeight - currentButtonSize - minimumMargin
4618
+ );
4619
+ const snapThreshold = minimumMargin;
4620
+ const buttonLeft = windowWidth - newRight - currentButtonSize;
4547
4621
  if (buttonLeft < snapThreshold) {
4548
- newRight = windowWidth - 80;
4549
- } else if (buttonLeft > windowWidth - snapThreshold - 60) {
4550
- newRight = 20;
4622
+ newRight = windowWidth - currentButtonSize - minimumMargin;
4623
+ } else if (newRight < snapThreshold) {
4624
+ newRight = minimumMargin;
4551
4625
  }
4552
- if (newBottom < snapThreshold) {
4553
- newBottom = 20;
4554
- } else if (newBottom > windowHeight - snapThreshold - 60) {
4555
- newBottom = windowHeight - 80;
4626
+ const buttonTop = windowHeight - newBottom - currentButtonSize;
4627
+ if (buttonTop < snapThreshold) {
4628
+ newBottom = windowHeight - currentButtonSize - minimumMargin;
4629
+ } else if (newBottom < snapThreshold) {
4630
+ newBottom = minimumMargin;
4556
4631
  }
4557
4632
  button.style.right = `${newRight}px`;
4558
4633
  button.style.bottom = `${newBottom}px`;
4559
- updateIframePosition(iframe, newRight, newBottom, windowWidth, windowHeight);
4634
+ updateIframePosition(iframe, newRight, newBottom, windowWidth, windowHeight, currentButtonSize);
4560
4635
  }
4561
- document.addEventListener(
4562
- "mouseup",
4563
- (e) => {
4564
- if (isDragging) {
4565
- e.preventDefault();
4566
- e.stopPropagation();
4567
- }
4568
- endDrag();
4569
- },
4570
- { capture: true }
4571
- );
4572
- document.addEventListener(
4573
- "touchend",
4574
- (e) => {
4575
- if (isDragging) {
4576
- e.preventDefault();
4577
- e.stopPropagation();
4578
- }
4579
- endDrag();
4580
- const dragEndTime = Date.now();
4581
- const dragDuration = dragEndTime - dragStartTime;
4582
- if (dragDuration < 200 && Math.abs(parseInt(button.style.right) - initialRight) < 5 && Math.abs(parseInt(button.style.bottom) - initialBottom) < 5) {
4583
- toggleWallet();
4584
- }
4585
- },
4586
- { capture: true }
4587
- );
4588
- document.addEventListener(
4589
- "touchcancel",
4590
- () => {
4591
- endDrag();
4592
- },
4593
- { capture: true }
4594
- );
4595
4636
  function endDrag() {
4596
- if (!isDragging)
4637
+ if (!isDragging || !draggable)
4597
4638
  return;
4598
4639
  isDragging = false;
4599
4640
  button.style.cursor = "grab";
@@ -4603,8 +4644,6 @@ function createFloatingButtonWithIframe({
4603
4644
  bottom: button.style.bottom
4604
4645
  });
4605
4646
  }
4606
- const handleButtonClick = () => {
4607
- };
4608
4647
  button.onclick = null;
4609
4648
  return button;
4610
4649
  }
@@ -4612,12 +4651,11 @@ function createIframe({
4612
4651
  iframeUrl,
4613
4652
  iframeStyle = {}
4614
4653
  }) {
4615
- var _a;
4616
4654
  const iframe = document.createElement("iframe");
4617
4655
  iframe.id = "satoshi-wallet-iframe";
4618
4656
  iframe.allow = "clipboard-read; clipboard-write";
4619
4657
  iframe.src = iframeUrl;
4620
- const isVisible = (_a = storage4 == null ? void 0 : storage4.get("visible")) != null ? _a : !isMobile();
4658
+ const isVisible = storage4 == null ? void 0 : storage4.get("visible");
4621
4659
  Object.assign(iframe.style, __spreadValues({
4622
4660
  position: "fixed",
4623
4661
  bottom: "90px",
@@ -4698,16 +4736,16 @@ function removeWalletButton() {
4698
4736
  const iframe = document.getElementById("satoshi-wallet-iframe");
4699
4737
  iframe == null ? void 0 : iframe.remove();
4700
4738
  }
4701
- function updateIframePosition(iframe, buttonRight, buttonBottom, windowWidth, windowHeight) {
4739
+ function updateIframePosition(iframe, buttonRight, buttonBottom, windowWidth, windowHeight, buttonSize) {
4702
4740
  const iframeWidth = parseInt(iframe.style.width);
4703
4741
  const iframeHeight = parseInt(iframe.style.height);
4704
4742
  let iframeRight = buttonRight;
4705
- let iframeBottom = buttonBottom + 70;
4706
- if (iframeRight + iframeWidth > windowWidth - 20) {
4707
- iframeRight = Math.max(20, windowWidth - iframeWidth - 20);
4743
+ let iframeBottom = buttonBottom + buttonSize + 10;
4744
+ if (iframeRight + iframeWidth > windowWidth - minimumMargin) {
4745
+ iframeRight = Math.max(minimumMargin, windowWidth - iframeWidth - minimumMargin);
4708
4746
  }
4709
- if (iframeBottom + iframeHeight > windowHeight - 20) {
4710
- iframeBottom = Math.max(20, buttonBottom - iframeHeight - 10);
4747
+ if (iframeBottom + iframeHeight > windowHeight - minimumMargin) {
4748
+ iframeBottom = Math.max(minimumMargin, buttonBottom - iframeHeight - 10);
4711
4749
  }
4712
4750
  iframe.style.right = `${iframeRight}px`;
4713
4751
  iframe.style.bottom = `${iframeBottom}px`;
@@ -5057,7 +5095,11 @@ function setupWalletSelectorModal(selector, options) {
5057
5095
  showChainGroups = true,
5058
5096
  showWalletUIForNearAccount = true,
5059
5097
  env = "mainnet",
5060
- walletUrl
5098
+ walletUrl,
5099
+ draggable = true,
5100
+ initialPosition = { right: "20px", bottom: "20px" },
5101
+ buttonSize = "60px",
5102
+ mobileButtonSize = "40px"
5061
5103
  } = options;
5062
5104
  subscription == null ? void 0 : subscription.unsubscribe();
5063
5105
  const state = selector.store.getState();
@@ -5069,7 +5111,15 @@ function setupWalletSelectorModal(selector, options) {
5069
5111
  removeWalletButton();
5070
5112
  if (showWalletUIForNearAccount && walletId !== "btc-wallet") {
5071
5113
  selector.wallet().then((wallet) => {
5072
- setupWalletButton({ env, nearWallet: wallet, walletUrl });
5114
+ setupWalletButton({
5115
+ env,
5116
+ nearWallet: wallet,
5117
+ walletUrl,
5118
+ draggable,
5119
+ initialPosition,
5120
+ buttonSize,
5121
+ mobileButtonSize
5122
+ });
5073
5123
  });
5074
5124
  }
5075
5125
  });
@@ -5161,7 +5211,7 @@ function getGroup(state) {
5161
5211
 
5162
5212
  // src/index.ts
5163
5213
  var getVersion = () => {
5164
- return "0.5.62-beta";
5214
+ return "0.5.64-beta";
5165
5215
  };
5166
5216
  if (typeof window !== "undefined") {
5167
5217
  window.__BTC_WALLET_VERSION = getVersion();