btc-wallet 0.5.63-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,14 +4412,22 @@ 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
4432
  const button = document.createElement("img");
4420
4433
  button.id = "satoshi-wallet-button";
@@ -4423,32 +4436,49 @@ function createFloatingButtonWithIframe({
4423
4436
  iframe.style.display = isIframeVisible ? "block" : "none";
4424
4437
  const windowWidth = window.innerWidth;
4425
4438
  const windowHeight = window.innerHeight;
4426
- const savedPosition = (storage4 == null ? void 0 : storage4.get("position")) || {
4439
+ const savedPosition = storage4 == null ? void 0 : storage4.get("position");
4440
+ const currentInitialPosition = initialPosition || savedPosition || {
4427
4441
  right: "20px",
4428
4442
  bottom: "20px"
4429
4443
  };
4430
- const right = Math.min(Math.max(20, parseInt(savedPosition.right)), windowWidth - 80);
4431
- 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
+ );
4432
4455
  Object.assign(button.style, {
4433
4456
  position: "fixed",
4434
4457
  bottom: `${bottom}px`,
4435
4458
  right: `${right}px`,
4436
4459
  zIndex: "100000",
4437
- width: "60px",
4438
- height: "60px",
4439
- cursor: "grab",
4460
+ width: buttonSize || "60px",
4461
+ height: buttonSize || "60px",
4462
+ cursor: draggable ? "grab" : "pointer",
4440
4463
  transition: "transform 0.15s ease",
4441
4464
  userSelect: "none",
4442
4465
  touchAction: "none"
4443
4466
  });
4444
4467
  if (isMobile()) {
4445
4468
  Object.assign(button.style, {
4446
- width: "40px",
4447
- height: "40px"
4469
+ width: mobileButtonSize || buttonSize || "40px",
4470
+ height: mobileButtonSize || buttonSize || "40px"
4448
4471
  });
4449
4472
  }
4450
4473
  document.body.appendChild(button);
4451
- updateIframePosition(iframe, right, bottom, windowWidth, windowHeight);
4474
+ updateIframePosition(
4475
+ iframe,
4476
+ right,
4477
+ bottom,
4478
+ windowWidth,
4479
+ windowHeight,
4480
+ parseInt(button.style.width)
4481
+ );
4452
4482
  let isDragging = false;
4453
4483
  let startX = 0;
4454
4484
  let startY = 0;
@@ -4456,6 +4486,8 @@ function createFloatingButtonWithIframe({
4456
4486
  let initialBottom = 0;
4457
4487
  let dragStartTime = 0;
4458
4488
  function startDrag(clientX, clientY) {
4489
+ if (!draggable)
4490
+ return;
4459
4491
  isDragging = true;
4460
4492
  startX = clientX;
4461
4493
  startY = clientY;
@@ -4484,7 +4516,7 @@ function createFloatingButtonWithIframe({
4484
4516
  button.addEventListener(
4485
4517
  "click",
4486
4518
  (e) => {
4487
- if (!isDragging) {
4519
+ if (!isDragging || !draggable) {
4488
4520
  toggleWallet();
4489
4521
  }
4490
4522
  e.preventDefault();
@@ -4492,107 +4524,117 @@ function createFloatingButtonWithIframe({
4492
4524
  },
4493
4525
  { capture: true }
4494
4526
  );
4495
- button.addEventListener(
4496
- "mousedown",
4497
- (e) => {
4498
- startDrag(e.clientX, e.clientY);
4499
- e.preventDefault();
4500
- e.stopPropagation();
4501
- },
4502
- { capture: true }
4503
- );
4504
- button.addEventListener(
4505
- "touchstart",
4506
- (e) => {
4507
- if (e.touches.length === 1) {
4508
- const touch = e.touches[0];
4509
- startDrag(touch.clientX, touch.clientY);
4527
+ if (draggable) {
4528
+ button.addEventListener(
4529
+ "mousedown",
4530
+ (e) => {
4531
+ startDrag(e.clientX, e.clientY);
4510
4532
  e.preventDefault();
4511
4533
  e.stopPropagation();
4512
- }
4513
- },
4514
- { capture: true }
4515
- );
4516
- document.addEventListener(
4517
- "mousemove",
4518
- (e) => {
4519
- if (!isDragging)
4520
- return;
4521
- moveButton(e.clientX, e.clientY);
4522
- e.preventDefault();
4523
- },
4524
- { capture: true }
4525
- );
4526
- document.addEventListener(
4527
- "touchmove",
4528
- (e) => {
4529
- if (!isDragging || e.touches.length !== 1)
4530
- return;
4531
- const touch = e.touches[0];
4532
- moveButton(touch.clientX, touch.clientY);
4533
- e.preventDefault();
4534
- },
4535
- { capture: true }
4536
- );
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
+ }
4537
4605
  function moveButton(clientX, clientY) {
4538
4606
  const deltaX = startX - clientX;
4539
4607
  const deltaY = startY - clientY;
4540
4608
  let newRight = initialRight + deltaX;
4541
4609
  let newBottom = initialBottom + deltaY;
4542
- newRight = Math.min(Math.max(20, newRight), windowWidth - 80);
4543
- newBottom = Math.min(Math.max(20, newBottom), windowHeight - 80);
4544
- const snapThreshold = 20;
4545
- 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;
4546
4621
  if (buttonLeft < snapThreshold) {
4547
- newRight = windowWidth - 80;
4548
- } else if (buttonLeft > windowWidth - snapThreshold - 60) {
4549
- newRight = 20;
4622
+ newRight = windowWidth - currentButtonSize - minimumMargin;
4623
+ } else if (newRight < snapThreshold) {
4624
+ newRight = minimumMargin;
4550
4625
  }
4551
- if (newBottom < snapThreshold) {
4552
- newBottom = 20;
4553
- } else if (newBottom > windowHeight - snapThreshold - 60) {
4554
- 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;
4555
4631
  }
4556
4632
  button.style.right = `${newRight}px`;
4557
4633
  button.style.bottom = `${newBottom}px`;
4558
- updateIframePosition(iframe, newRight, newBottom, windowWidth, windowHeight);
4634
+ updateIframePosition(iframe, newRight, newBottom, windowWidth, windowHeight, currentButtonSize);
4559
4635
  }
4560
- document.addEventListener(
4561
- "mouseup",
4562
- (e) => {
4563
- if (isDragging) {
4564
- e.preventDefault();
4565
- e.stopPropagation();
4566
- }
4567
- endDrag();
4568
- },
4569
- { capture: true }
4570
- );
4571
- document.addEventListener(
4572
- "touchend",
4573
- (e) => {
4574
- if (isDragging) {
4575
- e.preventDefault();
4576
- e.stopPropagation();
4577
- }
4578
- endDrag();
4579
- const dragEndTime = Date.now();
4580
- const dragDuration = dragEndTime - dragStartTime;
4581
- if (dragDuration < 200 && Math.abs(parseInt(button.style.right) - initialRight) < 5 && Math.abs(parseInt(button.style.bottom) - initialBottom) < 5) {
4582
- toggleWallet();
4583
- }
4584
- },
4585
- { capture: true }
4586
- );
4587
- document.addEventListener(
4588
- "touchcancel",
4589
- () => {
4590
- endDrag();
4591
- },
4592
- { capture: true }
4593
- );
4594
4636
  function endDrag() {
4595
- if (!isDragging)
4637
+ if (!isDragging || !draggable)
4596
4638
  return;
4597
4639
  isDragging = false;
4598
4640
  button.style.cursor = "grab";
@@ -4602,8 +4644,6 @@ function createFloatingButtonWithIframe({
4602
4644
  bottom: button.style.bottom
4603
4645
  });
4604
4646
  }
4605
- const handleButtonClick = () => {
4606
- };
4607
4647
  button.onclick = null;
4608
4648
  return button;
4609
4649
  }
@@ -4696,16 +4736,16 @@ function removeWalletButton() {
4696
4736
  const iframe = document.getElementById("satoshi-wallet-iframe");
4697
4737
  iframe == null ? void 0 : iframe.remove();
4698
4738
  }
4699
- function updateIframePosition(iframe, buttonRight, buttonBottom, windowWidth, windowHeight) {
4739
+ function updateIframePosition(iframe, buttonRight, buttonBottom, windowWidth, windowHeight, buttonSize) {
4700
4740
  const iframeWidth = parseInt(iframe.style.width);
4701
4741
  const iframeHeight = parseInt(iframe.style.height);
4702
4742
  let iframeRight = buttonRight;
4703
- let iframeBottom = buttonBottom + 70;
4704
- if (iframeRight + iframeWidth > windowWidth - 20) {
4705
- 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);
4706
4746
  }
4707
- if (iframeBottom + iframeHeight > windowHeight - 20) {
4708
- iframeBottom = Math.max(20, buttonBottom - iframeHeight - 10);
4747
+ if (iframeBottom + iframeHeight > windowHeight - minimumMargin) {
4748
+ iframeBottom = Math.max(minimumMargin, buttonBottom - iframeHeight - 10);
4709
4749
  }
4710
4750
  iframe.style.right = `${iframeRight}px`;
4711
4751
  iframe.style.bottom = `${iframeBottom}px`;
@@ -5055,7 +5095,11 @@ function setupWalletSelectorModal(selector, options) {
5055
5095
  showChainGroups = true,
5056
5096
  showWalletUIForNearAccount = true,
5057
5097
  env = "mainnet",
5058
- walletUrl
5098
+ walletUrl,
5099
+ draggable = true,
5100
+ initialPosition = { right: "20px", bottom: "20px" },
5101
+ buttonSize = "60px",
5102
+ mobileButtonSize = "40px"
5059
5103
  } = options;
5060
5104
  subscription == null ? void 0 : subscription.unsubscribe();
5061
5105
  const state = selector.store.getState();
@@ -5067,7 +5111,15 @@ function setupWalletSelectorModal(selector, options) {
5067
5111
  removeWalletButton();
5068
5112
  if (showWalletUIForNearAccount && walletId !== "btc-wallet") {
5069
5113
  selector.wallet().then((wallet) => {
5070
- setupWalletButton({ env, nearWallet: wallet, walletUrl });
5114
+ setupWalletButton({
5115
+ env,
5116
+ nearWallet: wallet,
5117
+ walletUrl,
5118
+ draggable,
5119
+ initialPosition,
5120
+ buttonSize,
5121
+ mobileButtonSize
5122
+ });
5071
5123
  });
5072
5124
  }
5073
5125
  });
@@ -5159,7 +5211,7 @@ function getGroup(state) {
5159
5211
 
5160
5212
  // src/index.ts
5161
5213
  var getVersion = () => {
5162
- return "0.5.63-beta";
5214
+ return "0.5.64-beta";
5163
5215
  };
5164
5216
  if (typeof window !== "undefined") {
5165
5217
  window.__BTC_WALLET_VERSION = getVersion();