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.
package/README.md CHANGED
@@ -31,7 +31,7 @@ const selector = await setupWalletSelector({
31
31
  autoConnect?: boolean, // optional: enable auto-connect, defaults to true
32
32
  syncLogOut?: boolean, // optional: sync logout across tabs, defaults to true
33
33
  env?: 'mainnet' | 'testnet' | 'private_mainnet' | 'dev', // optional: defaults to NEAR network environment
34
- gasStrategy?: 'auto' | 'near' | 'btc' // optional: specify gas payment strategy, defaults to 'auto'
34
+ gasStrategy?: 'auto' | 'near' | 'btc', // optional: specify gas payment strategy, defaults to 'auto'
35
35
  // 'auto': use NEAR if balance > 0.5, otherwise use BTC token
36
36
  // 'near': force use NEAR for gas payment
37
37
  // 'btc': force use BTC token for gas payment
@@ -48,6 +48,10 @@ setupWalletSelectorModal(selector, {
48
48
  showChainGroups?: boolean, // optional: show chain group selection, defaults to true
49
49
  showWalletUIForNearAccount?: boolean, // optional: show wallet UI for regular NEAR accounts, defaults to true
50
50
  env?: 'mainnet' | 'testnet' | 'private_mainnet' | 'dev', // optional: defaults to NEAR network environment
51
+ draggable?: boolean, // optional: enable button dragging, defaults to true
52
+ initialPosition?: { right: string; bottom: string }, // optional: initial button position, defaults to { right: '20px', bottom: '20px' }
53
+ buttonSize?: string, // optional: button size, defaults to '60px'
54
+ mobileButtonSize?: string, // optional: mobile button size, defaults to '40px'
51
55
  });
52
56
 
53
57
  // 3. Wrap your app with BtcWalletSelectorContextProvider
@@ -6,6 +6,13 @@ export interface WalletSelectorModalOptions extends _ModalOptions {
6
6
  showWalletUIForNearAccount?: boolean;
7
7
  walletUrl?: string;
8
8
  env?: ENV;
9
+ draggable?: boolean;
10
+ initialPosition?: {
11
+ right: string;
12
+ bottom: string;
13
+ };
14
+ buttonSize?: string;
15
+ mobileButtonSize?: string;
9
16
  }
10
17
  export type WalletSelectorModal = _WalletSelectorModal;
11
18
  export declare function setupWalletSelectorModal(selector: WalletSelector, options: WalletSelectorModalOptions): _WalletSelectorModal;
package/dist/index.js CHANGED
@@ -4449,11 +4449,16 @@ function uint8ArrayToHex(uint8Array) {
4449
4449
 
4450
4450
  // src/utils/initWalletButton.ts
4451
4451
  var storage4 = storageStore("SATOSHI_WALLET_BUTTON");
4452
+ var minimumMargin = 10;
4452
4453
  function setupWalletButton({
4453
4454
  env,
4454
4455
  nearWallet,
4455
4456
  btcWallet,
4456
- walletUrl
4457
+ walletUrl,
4458
+ draggable = true,
4459
+ initialPosition,
4460
+ buttonSize,
4461
+ mobileButtonSize
4457
4462
  }) {
4458
4463
  if (document.getElementById("satoshi-wallet-button")) {
4459
4464
  return;
@@ -4477,49 +4482,73 @@ function setupWalletButton({
4477
4482
  const button = createFloatingButtonWithIframe({
4478
4483
  openImageUrl,
4479
4484
  closeImageUrl,
4480
- iframe
4485
+ iframe,
4486
+ draggable,
4487
+ initialPosition,
4488
+ buttonSize,
4489
+ mobileButtonSize
4481
4490
  });
4482
4491
  setupButtonClickHandler(button, iframe, nearWallet, btcWallet);
4483
4492
  }
4484
4493
  function createFloatingButtonWithIframe({
4485
4494
  openImageUrl,
4486
4495
  closeImageUrl,
4487
- iframe
4496
+ iframe,
4497
+ draggable,
4498
+ initialPosition,
4499
+ buttonSize,
4500
+ mobileButtonSize
4488
4501
  }) {
4489
- var _a;
4490
4502
  const button = document.createElement("img");
4491
4503
  button.id = "satoshi-wallet-button";
4492
- const isIframeVisible = (_a = storage4 == null ? void 0 : storage4.get("visible")) != null ? _a : !isMobile();
4504
+ const isIframeVisible = storage4 == null ? void 0 : storage4.get("visible");
4493
4505
  button.src = isIframeVisible ? closeImageUrl : openImageUrl;
4494
4506
  iframe.style.display = isIframeVisible ? "block" : "none";
4495
4507
  const windowWidth = window.innerWidth;
4496
4508
  const windowHeight = window.innerHeight;
4497
- const savedPosition = (storage4 == null ? void 0 : storage4.get("position")) || {
4509
+ const savedPosition = storage4 == null ? void 0 : storage4.get("position");
4510
+ const currentInitialPosition = initialPosition || savedPosition || {
4498
4511
  right: "20px",
4499
4512
  bottom: "20px"
4500
4513
  };
4501
- const right = Math.min(Math.max(20, parseInt(savedPosition.right)), windowWidth - 80);
4502
- const bottom = Math.min(Math.max(20, parseInt(savedPosition.bottom)), windowHeight - 80);
4514
+ const tempButtonSize = buttonSize || "60px";
4515
+ const tempMobileButtonSize = mobileButtonSize || buttonSize || "40px";
4516
+ const actualButtonSize = isMobile() ? parseInt(tempMobileButtonSize) : parseInt(tempButtonSize);
4517
+ const right = Math.min(
4518
+ Math.max(minimumMargin, parseInt(currentInitialPosition.right)),
4519
+ windowWidth - actualButtonSize - minimumMargin
4520
+ );
4521
+ const bottom = Math.min(
4522
+ Math.max(minimumMargin, parseInt(currentInitialPosition.bottom)),
4523
+ windowHeight - actualButtonSize - minimumMargin
4524
+ );
4503
4525
  Object.assign(button.style, {
4504
4526
  position: "fixed",
4505
4527
  bottom: `${bottom}px`,
4506
4528
  right: `${right}px`,
4507
4529
  zIndex: "100000",
4508
- width: "60px",
4509
- height: "60px",
4510
- cursor: "grab",
4530
+ width: buttonSize || "60px",
4531
+ height: buttonSize || "60px",
4532
+ cursor: draggable ? "grab" : "pointer",
4511
4533
  transition: "transform 0.15s ease",
4512
4534
  userSelect: "none",
4513
4535
  touchAction: "none"
4514
4536
  });
4515
4537
  if (isMobile()) {
4516
4538
  Object.assign(button.style, {
4517
- width: "40px",
4518
- height: "40px"
4539
+ width: mobileButtonSize || buttonSize || "40px",
4540
+ height: mobileButtonSize || buttonSize || "40px"
4519
4541
  });
4520
4542
  }
4521
4543
  document.body.appendChild(button);
4522
- updateIframePosition(iframe, right, bottom, windowWidth, windowHeight);
4544
+ updateIframePosition(
4545
+ iframe,
4546
+ right,
4547
+ bottom,
4548
+ windowWidth,
4549
+ windowHeight,
4550
+ parseInt(button.style.width)
4551
+ );
4523
4552
  let isDragging = false;
4524
4553
  let startX = 0;
4525
4554
  let startY = 0;
@@ -4527,6 +4556,8 @@ function createFloatingButtonWithIframe({
4527
4556
  let initialBottom = 0;
4528
4557
  let dragStartTime = 0;
4529
4558
  function startDrag(clientX, clientY) {
4559
+ if (!draggable)
4560
+ return;
4530
4561
  isDragging = true;
4531
4562
  startX = clientX;
4532
4563
  startY = clientY;
@@ -4555,7 +4586,7 @@ function createFloatingButtonWithIframe({
4555
4586
  button.addEventListener(
4556
4587
  "click",
4557
4588
  (e) => {
4558
- if (!isDragging) {
4589
+ if (!isDragging || !draggable) {
4559
4590
  toggleWallet();
4560
4591
  }
4561
4592
  e.preventDefault();
@@ -4563,107 +4594,117 @@ function createFloatingButtonWithIframe({
4563
4594
  },
4564
4595
  { capture: true }
4565
4596
  );
4566
- button.addEventListener(
4567
- "mousedown",
4568
- (e) => {
4569
- startDrag(e.clientX, e.clientY);
4570
- e.preventDefault();
4571
- e.stopPropagation();
4572
- },
4573
- { capture: true }
4574
- );
4575
- button.addEventListener(
4576
- "touchstart",
4577
- (e) => {
4578
- if (e.touches.length === 1) {
4579
- const touch = e.touches[0];
4580
- startDrag(touch.clientX, touch.clientY);
4597
+ if (draggable) {
4598
+ button.addEventListener(
4599
+ "mousedown",
4600
+ (e) => {
4601
+ startDrag(e.clientX, e.clientY);
4581
4602
  e.preventDefault();
4582
4603
  e.stopPropagation();
4583
- }
4584
- },
4585
- { capture: true }
4586
- );
4587
- document.addEventListener(
4588
- "mousemove",
4589
- (e) => {
4590
- if (!isDragging)
4591
- return;
4592
- moveButton(e.clientX, e.clientY);
4593
- e.preventDefault();
4594
- },
4595
- { capture: true }
4596
- );
4597
- document.addEventListener(
4598
- "touchmove",
4599
- (e) => {
4600
- if (!isDragging || e.touches.length !== 1)
4601
- return;
4602
- const touch = e.touches[0];
4603
- moveButton(touch.clientX, touch.clientY);
4604
- e.preventDefault();
4605
- },
4606
- { capture: true }
4607
- );
4604
+ },
4605
+ { capture: true }
4606
+ );
4607
+ button.addEventListener(
4608
+ "touchstart",
4609
+ (e) => {
4610
+ if (e.touches.length === 1) {
4611
+ const touch = e.touches[0];
4612
+ startDrag(touch.clientX, touch.clientY);
4613
+ e.preventDefault();
4614
+ e.stopPropagation();
4615
+ }
4616
+ },
4617
+ { capture: true }
4618
+ );
4619
+ document.addEventListener(
4620
+ "mousemove",
4621
+ (e) => {
4622
+ if (!isDragging)
4623
+ return;
4624
+ moveButton(e.clientX, e.clientY);
4625
+ e.preventDefault();
4626
+ },
4627
+ { capture: true }
4628
+ );
4629
+ document.addEventListener(
4630
+ "touchmove",
4631
+ (e) => {
4632
+ if (!isDragging || e.touches.length !== 1)
4633
+ return;
4634
+ const touch = e.touches[0];
4635
+ moveButton(touch.clientX, touch.clientY);
4636
+ e.preventDefault();
4637
+ },
4638
+ { capture: true }
4639
+ );
4640
+ document.addEventListener(
4641
+ "mouseup",
4642
+ (e) => {
4643
+ if (isDragging) {
4644
+ e.preventDefault();
4645
+ e.stopPropagation();
4646
+ }
4647
+ endDrag();
4648
+ },
4649
+ { capture: true }
4650
+ );
4651
+ document.addEventListener(
4652
+ "touchend",
4653
+ (e) => {
4654
+ if (isDragging) {
4655
+ e.preventDefault();
4656
+ e.stopPropagation();
4657
+ }
4658
+ endDrag();
4659
+ const dragEndTime = Date.now();
4660
+ const dragDuration = dragEndTime - dragStartTime;
4661
+ if (dragDuration < 200 && Math.abs(parseInt(button.style.right) - initialRight) < 5 && Math.abs(parseInt(button.style.bottom) - initialBottom) < 5) {
4662
+ toggleWallet();
4663
+ }
4664
+ },
4665
+ { capture: true }
4666
+ );
4667
+ document.addEventListener(
4668
+ "touchcancel",
4669
+ () => {
4670
+ endDrag();
4671
+ },
4672
+ { capture: true }
4673
+ );
4674
+ }
4608
4675
  function moveButton(clientX, clientY) {
4609
4676
  const deltaX = startX - clientX;
4610
4677
  const deltaY = startY - clientY;
4611
4678
  let newRight = initialRight + deltaX;
4612
4679
  let newBottom = initialBottom + deltaY;
4613
- newRight = Math.min(Math.max(20, newRight), windowWidth - 80);
4614
- newBottom = Math.min(Math.max(20, newBottom), windowHeight - 80);
4615
- const snapThreshold = 20;
4616
- const buttonLeft = windowWidth - newRight - 60;
4680
+ const currentButtonSize = parseInt(button.style.width);
4681
+ newRight = Math.min(
4682
+ Math.max(minimumMargin, newRight),
4683
+ windowWidth - currentButtonSize - minimumMargin
4684
+ );
4685
+ newBottom = Math.min(
4686
+ Math.max(minimumMargin, newBottom),
4687
+ windowHeight - currentButtonSize - minimumMargin
4688
+ );
4689
+ const snapThreshold = minimumMargin;
4690
+ const buttonLeft = windowWidth - newRight - currentButtonSize;
4617
4691
  if (buttonLeft < snapThreshold) {
4618
- newRight = windowWidth - 80;
4619
- } else if (buttonLeft > windowWidth - snapThreshold - 60) {
4620
- newRight = 20;
4692
+ newRight = windowWidth - currentButtonSize - minimumMargin;
4693
+ } else if (newRight < snapThreshold) {
4694
+ newRight = minimumMargin;
4621
4695
  }
4622
- if (newBottom < snapThreshold) {
4623
- newBottom = 20;
4624
- } else if (newBottom > windowHeight - snapThreshold - 60) {
4625
- newBottom = windowHeight - 80;
4696
+ const buttonTop = windowHeight - newBottom - currentButtonSize;
4697
+ if (buttonTop < snapThreshold) {
4698
+ newBottom = windowHeight - currentButtonSize - minimumMargin;
4699
+ } else if (newBottom < snapThreshold) {
4700
+ newBottom = minimumMargin;
4626
4701
  }
4627
4702
  button.style.right = `${newRight}px`;
4628
4703
  button.style.bottom = `${newBottom}px`;
4629
- updateIframePosition(iframe, newRight, newBottom, windowWidth, windowHeight);
4704
+ updateIframePosition(iframe, newRight, newBottom, windowWidth, windowHeight, currentButtonSize);
4630
4705
  }
4631
- document.addEventListener(
4632
- "mouseup",
4633
- (e) => {
4634
- if (isDragging) {
4635
- e.preventDefault();
4636
- e.stopPropagation();
4637
- }
4638
- endDrag();
4639
- },
4640
- { capture: true }
4641
- );
4642
- document.addEventListener(
4643
- "touchend",
4644
- (e) => {
4645
- if (isDragging) {
4646
- e.preventDefault();
4647
- e.stopPropagation();
4648
- }
4649
- endDrag();
4650
- const dragEndTime = Date.now();
4651
- const dragDuration = dragEndTime - dragStartTime;
4652
- if (dragDuration < 200 && Math.abs(parseInt(button.style.right) - initialRight) < 5 && Math.abs(parseInt(button.style.bottom) - initialBottom) < 5) {
4653
- toggleWallet();
4654
- }
4655
- },
4656
- { capture: true }
4657
- );
4658
- document.addEventListener(
4659
- "touchcancel",
4660
- () => {
4661
- endDrag();
4662
- },
4663
- { capture: true }
4664
- );
4665
4706
  function endDrag() {
4666
- if (!isDragging)
4707
+ if (!isDragging || !draggable)
4667
4708
  return;
4668
4709
  isDragging = false;
4669
4710
  button.style.cursor = "grab";
@@ -4673,8 +4714,6 @@ function createFloatingButtonWithIframe({
4673
4714
  bottom: button.style.bottom
4674
4715
  });
4675
4716
  }
4676
- const handleButtonClick = () => {
4677
- };
4678
4717
  button.onclick = null;
4679
4718
  return button;
4680
4719
  }
@@ -4682,12 +4721,11 @@ function createIframe({
4682
4721
  iframeUrl,
4683
4722
  iframeStyle = {}
4684
4723
  }) {
4685
- var _a;
4686
4724
  const iframe = document.createElement("iframe");
4687
4725
  iframe.id = "satoshi-wallet-iframe";
4688
4726
  iframe.allow = "clipboard-read; clipboard-write";
4689
4727
  iframe.src = iframeUrl;
4690
- const isVisible = (_a = storage4 == null ? void 0 : storage4.get("visible")) != null ? _a : !isMobile();
4728
+ const isVisible = storage4 == null ? void 0 : storage4.get("visible");
4691
4729
  Object.assign(iframe.style, __spreadValues({
4692
4730
  position: "fixed",
4693
4731
  bottom: "90px",
@@ -4768,16 +4806,16 @@ function removeWalletButton() {
4768
4806
  const iframe = document.getElementById("satoshi-wallet-iframe");
4769
4807
  iframe == null ? void 0 : iframe.remove();
4770
4808
  }
4771
- function updateIframePosition(iframe, buttonRight, buttonBottom, windowWidth, windowHeight) {
4809
+ function updateIframePosition(iframe, buttonRight, buttonBottom, windowWidth, windowHeight, buttonSize) {
4772
4810
  const iframeWidth = parseInt(iframe.style.width);
4773
4811
  const iframeHeight = parseInt(iframe.style.height);
4774
4812
  let iframeRight = buttonRight;
4775
- let iframeBottom = buttonBottom + 70;
4776
- if (iframeRight + iframeWidth > windowWidth - 20) {
4777
- iframeRight = Math.max(20, windowWidth - iframeWidth - 20);
4813
+ let iframeBottom = buttonBottom + buttonSize + 10;
4814
+ if (iframeRight + iframeWidth > windowWidth - minimumMargin) {
4815
+ iframeRight = Math.max(minimumMargin, windowWidth - iframeWidth - minimumMargin);
4778
4816
  }
4779
- if (iframeBottom + iframeHeight > windowHeight - 20) {
4780
- iframeBottom = Math.max(20, buttonBottom - iframeHeight - 10);
4817
+ if (iframeBottom + iframeHeight > windowHeight - minimumMargin) {
4818
+ iframeBottom = Math.max(minimumMargin, buttonBottom - iframeHeight - 10);
4781
4819
  }
4782
4820
  iframe.style.right = `${iframeRight}px`;
4783
4821
  iframe.style.bottom = `${iframeBottom}px`;
@@ -5125,7 +5163,11 @@ function setupWalletSelectorModal(selector, options) {
5125
5163
  showChainGroups = true,
5126
5164
  showWalletUIForNearAccount = true,
5127
5165
  env = "mainnet",
5128
- walletUrl
5166
+ walletUrl,
5167
+ draggable = true,
5168
+ initialPosition = { right: "20px", bottom: "20px" },
5169
+ buttonSize = "60px",
5170
+ mobileButtonSize = "40px"
5129
5171
  } = options;
5130
5172
  subscription == null ? void 0 : subscription.unsubscribe();
5131
5173
  const state = selector.store.getState();
@@ -5137,7 +5179,15 @@ function setupWalletSelectorModal(selector, options) {
5137
5179
  removeWalletButton();
5138
5180
  if (showWalletUIForNearAccount && walletId !== "btc-wallet") {
5139
5181
  selector.wallet().then((wallet) => {
5140
- setupWalletButton({ env, nearWallet: wallet, walletUrl });
5182
+ setupWalletButton({
5183
+ env,
5184
+ nearWallet: wallet,
5185
+ walletUrl,
5186
+ draggable,
5187
+ initialPosition,
5188
+ buttonSize,
5189
+ mobileButtonSize
5190
+ });
5141
5191
  });
5142
5192
  }
5143
5193
  });
@@ -5229,7 +5279,7 @@ function getGroup(state) {
5229
5279
 
5230
5280
  // src/index.ts
5231
5281
  var getVersion = () => {
5232
- return "0.5.62-beta";
5282
+ return "0.5.64-beta";
5233
5283
  };
5234
5284
  if (typeof window !== "undefined") {
5235
5285
  window.__BTC_WALLET_VERSION = getVersion();