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.
- package/README.md +5 -1
- package/dist/core/setupModal.d.ts +7 -0
- package/dist/index.js +163 -111
- package/dist/index.js.map +2 -2
- package/dist/utils/initWalletButton.d.ts +8 -1
- package/esm/index.js +163 -111
- package/esm/index.js.map +2 -2
- package/package.json +1 -1
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,14 +4482,22 @@ 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
4502
|
const button = document.createElement("img");
|
4490
4503
|
button.id = "satoshi-wallet-button";
|
@@ -4493,32 +4506,49 @@ function createFloatingButtonWithIframe({
|
|
4493
4506
|
iframe.style.display = isIframeVisible ? "block" : "none";
|
4494
4507
|
const windowWidth = window.innerWidth;
|
4495
4508
|
const windowHeight = window.innerHeight;
|
4496
|
-
const savedPosition =
|
4509
|
+
const savedPosition = storage4 == null ? void 0 : storage4.get("position");
|
4510
|
+
const currentInitialPosition = initialPosition || savedPosition || {
|
4497
4511
|
right: "20px",
|
4498
4512
|
bottom: "20px"
|
4499
4513
|
};
|
4500
|
-
const
|
4501
|
-
const
|
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
|
+
);
|
4502
4525
|
Object.assign(button.style, {
|
4503
4526
|
position: "fixed",
|
4504
4527
|
bottom: `${bottom}px`,
|
4505
4528
|
right: `${right}px`,
|
4506
4529
|
zIndex: "100000",
|
4507
|
-
width: "60px",
|
4508
|
-
height: "60px",
|
4509
|
-
cursor: "grab",
|
4530
|
+
width: buttonSize || "60px",
|
4531
|
+
height: buttonSize || "60px",
|
4532
|
+
cursor: draggable ? "grab" : "pointer",
|
4510
4533
|
transition: "transform 0.15s ease",
|
4511
4534
|
userSelect: "none",
|
4512
4535
|
touchAction: "none"
|
4513
4536
|
});
|
4514
4537
|
if (isMobile()) {
|
4515
4538
|
Object.assign(button.style, {
|
4516
|
-
width: "40px",
|
4517
|
-
height: "40px"
|
4539
|
+
width: mobileButtonSize || buttonSize || "40px",
|
4540
|
+
height: mobileButtonSize || buttonSize || "40px"
|
4518
4541
|
});
|
4519
4542
|
}
|
4520
4543
|
document.body.appendChild(button);
|
4521
|
-
updateIframePosition(
|
4544
|
+
updateIframePosition(
|
4545
|
+
iframe,
|
4546
|
+
right,
|
4547
|
+
bottom,
|
4548
|
+
windowWidth,
|
4549
|
+
windowHeight,
|
4550
|
+
parseInt(button.style.width)
|
4551
|
+
);
|
4522
4552
|
let isDragging = false;
|
4523
4553
|
let startX = 0;
|
4524
4554
|
let startY = 0;
|
@@ -4526,6 +4556,8 @@ function createFloatingButtonWithIframe({
|
|
4526
4556
|
let initialBottom = 0;
|
4527
4557
|
let dragStartTime = 0;
|
4528
4558
|
function startDrag(clientX, clientY) {
|
4559
|
+
if (!draggable)
|
4560
|
+
return;
|
4529
4561
|
isDragging = true;
|
4530
4562
|
startX = clientX;
|
4531
4563
|
startY = clientY;
|
@@ -4554,7 +4586,7 @@ function createFloatingButtonWithIframe({
|
|
4554
4586
|
button.addEventListener(
|
4555
4587
|
"click",
|
4556
4588
|
(e) => {
|
4557
|
-
if (!isDragging) {
|
4589
|
+
if (!isDragging || !draggable) {
|
4558
4590
|
toggleWallet();
|
4559
4591
|
}
|
4560
4592
|
e.preventDefault();
|
@@ -4562,107 +4594,117 @@ function createFloatingButtonWithIframe({
|
|
4562
4594
|
},
|
4563
4595
|
{ capture: true }
|
4564
4596
|
);
|
4565
|
-
|
4566
|
-
|
4567
|
-
|
4568
|
-
|
4569
|
-
|
4570
|
-
e.stopPropagation();
|
4571
|
-
},
|
4572
|
-
{ capture: true }
|
4573
|
-
);
|
4574
|
-
button.addEventListener(
|
4575
|
-
"touchstart",
|
4576
|
-
(e) => {
|
4577
|
-
if (e.touches.length === 1) {
|
4578
|
-
const touch = e.touches[0];
|
4579
|
-
startDrag(touch.clientX, touch.clientY);
|
4597
|
+
if (draggable) {
|
4598
|
+
button.addEventListener(
|
4599
|
+
"mousedown",
|
4600
|
+
(e) => {
|
4601
|
+
startDrag(e.clientX, e.clientY);
|
4580
4602
|
e.preventDefault();
|
4581
4603
|
e.stopPropagation();
|
4582
|
-
}
|
4583
|
-
|
4584
|
-
|
4585
|
-
|
4586
|
-
|
4587
|
-
|
4588
|
-
|
4589
|
-
|
4590
|
-
|
4591
|
-
|
4592
|
-
|
4593
|
-
|
4594
|
-
|
4595
|
-
|
4596
|
-
|
4597
|
-
|
4598
|
-
|
4599
|
-
|
4600
|
-
|
4601
|
-
|
4602
|
-
|
4603
|
-
|
4604
|
-
|
4605
|
-
|
4606
|
-
|
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
|
+
}
|
4607
4675
|
function moveButton(clientX, clientY) {
|
4608
4676
|
const deltaX = startX - clientX;
|
4609
4677
|
const deltaY = startY - clientY;
|
4610
4678
|
let newRight = initialRight + deltaX;
|
4611
4679
|
let newBottom = initialBottom + deltaY;
|
4612
|
-
|
4613
|
-
|
4614
|
-
|
4615
|
-
|
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;
|
4616
4691
|
if (buttonLeft < snapThreshold) {
|
4617
|
-
newRight = windowWidth -
|
4618
|
-
} else if (
|
4619
|
-
newRight =
|
4692
|
+
newRight = windowWidth - currentButtonSize - minimumMargin;
|
4693
|
+
} else if (newRight < snapThreshold) {
|
4694
|
+
newRight = minimumMargin;
|
4620
4695
|
}
|
4621
|
-
|
4622
|
-
|
4623
|
-
|
4624
|
-
|
4696
|
+
const buttonTop = windowHeight - newBottom - currentButtonSize;
|
4697
|
+
if (buttonTop < snapThreshold) {
|
4698
|
+
newBottom = windowHeight - currentButtonSize - minimumMargin;
|
4699
|
+
} else if (newBottom < snapThreshold) {
|
4700
|
+
newBottom = minimumMargin;
|
4625
4701
|
}
|
4626
4702
|
button.style.right = `${newRight}px`;
|
4627
4703
|
button.style.bottom = `${newBottom}px`;
|
4628
|
-
updateIframePosition(iframe, newRight, newBottom, windowWidth, windowHeight);
|
4704
|
+
updateIframePosition(iframe, newRight, newBottom, windowWidth, windowHeight, currentButtonSize);
|
4629
4705
|
}
|
4630
|
-
document.addEventListener(
|
4631
|
-
"mouseup",
|
4632
|
-
(e) => {
|
4633
|
-
if (isDragging) {
|
4634
|
-
e.preventDefault();
|
4635
|
-
e.stopPropagation();
|
4636
|
-
}
|
4637
|
-
endDrag();
|
4638
|
-
},
|
4639
|
-
{ capture: true }
|
4640
|
-
);
|
4641
|
-
document.addEventListener(
|
4642
|
-
"touchend",
|
4643
|
-
(e) => {
|
4644
|
-
if (isDragging) {
|
4645
|
-
e.preventDefault();
|
4646
|
-
e.stopPropagation();
|
4647
|
-
}
|
4648
|
-
endDrag();
|
4649
|
-
const dragEndTime = Date.now();
|
4650
|
-
const dragDuration = dragEndTime - dragStartTime;
|
4651
|
-
if (dragDuration < 200 && Math.abs(parseInt(button.style.right) - initialRight) < 5 && Math.abs(parseInt(button.style.bottom) - initialBottom) < 5) {
|
4652
|
-
toggleWallet();
|
4653
|
-
}
|
4654
|
-
},
|
4655
|
-
{ capture: true }
|
4656
|
-
);
|
4657
|
-
document.addEventListener(
|
4658
|
-
"touchcancel",
|
4659
|
-
() => {
|
4660
|
-
endDrag();
|
4661
|
-
},
|
4662
|
-
{ capture: true }
|
4663
|
-
);
|
4664
4706
|
function endDrag() {
|
4665
|
-
if (!isDragging)
|
4707
|
+
if (!isDragging || !draggable)
|
4666
4708
|
return;
|
4667
4709
|
isDragging = false;
|
4668
4710
|
button.style.cursor = "grab";
|
@@ -4672,8 +4714,6 @@ function createFloatingButtonWithIframe({
|
|
4672
4714
|
bottom: button.style.bottom
|
4673
4715
|
});
|
4674
4716
|
}
|
4675
|
-
const handleButtonClick = () => {
|
4676
|
-
};
|
4677
4717
|
button.onclick = null;
|
4678
4718
|
return button;
|
4679
4719
|
}
|
@@ -4766,16 +4806,16 @@ function removeWalletButton() {
|
|
4766
4806
|
const iframe = document.getElementById("satoshi-wallet-iframe");
|
4767
4807
|
iframe == null ? void 0 : iframe.remove();
|
4768
4808
|
}
|
4769
|
-
function updateIframePosition(iframe, buttonRight, buttonBottom, windowWidth, windowHeight) {
|
4809
|
+
function updateIframePosition(iframe, buttonRight, buttonBottom, windowWidth, windowHeight, buttonSize) {
|
4770
4810
|
const iframeWidth = parseInt(iframe.style.width);
|
4771
4811
|
const iframeHeight = parseInt(iframe.style.height);
|
4772
4812
|
let iframeRight = buttonRight;
|
4773
|
-
let iframeBottom = buttonBottom +
|
4774
|
-
if (iframeRight + iframeWidth > windowWidth -
|
4775
|
-
iframeRight = Math.max(
|
4813
|
+
let iframeBottom = buttonBottom + buttonSize + 10;
|
4814
|
+
if (iframeRight + iframeWidth > windowWidth - minimumMargin) {
|
4815
|
+
iframeRight = Math.max(minimumMargin, windowWidth - iframeWidth - minimumMargin);
|
4776
4816
|
}
|
4777
|
-
if (iframeBottom + iframeHeight > windowHeight -
|
4778
|
-
iframeBottom = Math.max(
|
4817
|
+
if (iframeBottom + iframeHeight > windowHeight - minimumMargin) {
|
4818
|
+
iframeBottom = Math.max(minimumMargin, buttonBottom - iframeHeight - 10);
|
4779
4819
|
}
|
4780
4820
|
iframe.style.right = `${iframeRight}px`;
|
4781
4821
|
iframe.style.bottom = `${iframeBottom}px`;
|
@@ -5123,7 +5163,11 @@ function setupWalletSelectorModal(selector, options) {
|
|
5123
5163
|
showChainGroups = true,
|
5124
5164
|
showWalletUIForNearAccount = true,
|
5125
5165
|
env = "mainnet",
|
5126
|
-
walletUrl
|
5166
|
+
walletUrl,
|
5167
|
+
draggable = true,
|
5168
|
+
initialPosition = { right: "20px", bottom: "20px" },
|
5169
|
+
buttonSize = "60px",
|
5170
|
+
mobileButtonSize = "40px"
|
5127
5171
|
} = options;
|
5128
5172
|
subscription == null ? void 0 : subscription.unsubscribe();
|
5129
5173
|
const state = selector.store.getState();
|
@@ -5135,7 +5179,15 @@ function setupWalletSelectorModal(selector, options) {
|
|
5135
5179
|
removeWalletButton();
|
5136
5180
|
if (showWalletUIForNearAccount && walletId !== "btc-wallet") {
|
5137
5181
|
selector.wallet().then((wallet) => {
|
5138
|
-
setupWalletButton({
|
5182
|
+
setupWalletButton({
|
5183
|
+
env,
|
5184
|
+
nearWallet: wallet,
|
5185
|
+
walletUrl,
|
5186
|
+
draggable,
|
5187
|
+
initialPosition,
|
5188
|
+
buttonSize,
|
5189
|
+
mobileButtonSize
|
5190
|
+
});
|
5139
5191
|
});
|
5140
5192
|
}
|
5141
5193
|
});
|
@@ -5227,7 +5279,7 @@ function getGroup(state) {
|
|
5227
5279
|
|
5228
5280
|
// src/index.ts
|
5229
5281
|
var getVersion = () => {
|
5230
|
-
return "0.5.
|
5282
|
+
return "0.5.64-beta";
|
5231
5283
|
};
|
5232
5284
|
if (typeof window !== "undefined") {
|
5233
5285
|
window.__BTC_WALLET_VERSION = getVersion();
|