btc-wallet 0.5.63-beta → 0.5.65-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 +167 -116
- package/dist/index.js.map +3 -3
- package/dist/utils/initWalletButton.d.ts +8 -1
- package/esm/index.js +167 -116
- package/esm/index.js.map +3 -3
- 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
@@ -2571,6 +2571,8 @@ var ConnectProvider = ({
|
|
2571
2571
|
}, [connector, requestAccount]);
|
2572
2572
|
(0, import_react10.useEffect)(() => {
|
2573
2573
|
const onAccountChange = (accounts2) => {
|
2574
|
+
if (!accounts2.length)
|
2575
|
+
return;
|
2574
2576
|
setAccounts(accounts2);
|
2575
2577
|
};
|
2576
2578
|
connector == null ? void 0 : connector.on("accountsChanged", onAccountChange);
|
@@ -2882,16 +2884,13 @@ function useBtcWalletSelector() {
|
|
2882
2884
|
const connectWallet = (useModal = false) => __async(this, null, function* () {
|
2883
2885
|
if (connectModalOpen)
|
2884
2886
|
return null;
|
2885
|
-
const account = accounts == null ? void 0 : accounts[0];
|
2886
|
-
if (account)
|
2887
|
-
return account;
|
2888
2887
|
try {
|
2889
2888
|
if (useModal) {
|
2890
2889
|
openConnectModal == null ? void 0 : openConnectModal();
|
2891
2890
|
} else {
|
2892
2891
|
yield requestDirectAccount(connectorRef.current);
|
2893
2892
|
}
|
2894
|
-
const
|
2893
|
+
const account = yield retryOperation(
|
2895
2894
|
() => window.btcContext.account,
|
2896
2895
|
(res) => !!res,
|
2897
2896
|
{
|
@@ -2899,7 +2898,7 @@ function useBtcWalletSelector() {
|
|
2899
2898
|
delayMs: 1e3
|
2900
2899
|
}
|
2901
2900
|
);
|
2902
|
-
return
|
2901
|
+
return account || null;
|
2903
2902
|
} catch (error) {
|
2904
2903
|
console.error("btcLoginError", error);
|
2905
2904
|
context.emit("btcLoginError");
|
@@ -4449,11 +4448,16 @@ function uint8ArrayToHex(uint8Array) {
|
|
4449
4448
|
|
4450
4449
|
// src/utils/initWalletButton.ts
|
4451
4450
|
var storage4 = storageStore("SATOSHI_WALLET_BUTTON");
|
4451
|
+
var minimumMargin = 10;
|
4452
4452
|
function setupWalletButton({
|
4453
4453
|
env,
|
4454
4454
|
nearWallet,
|
4455
4455
|
btcWallet,
|
4456
|
-
walletUrl
|
4456
|
+
walletUrl,
|
4457
|
+
draggable = true,
|
4458
|
+
initialPosition,
|
4459
|
+
buttonSize,
|
4460
|
+
mobileButtonSize
|
4457
4461
|
}) {
|
4458
4462
|
if (document.getElementById("satoshi-wallet-button")) {
|
4459
4463
|
return;
|
@@ -4477,14 +4481,22 @@ function setupWalletButton({
|
|
4477
4481
|
const button = createFloatingButtonWithIframe({
|
4478
4482
|
openImageUrl,
|
4479
4483
|
closeImageUrl,
|
4480
|
-
iframe
|
4484
|
+
iframe,
|
4485
|
+
draggable,
|
4486
|
+
initialPosition,
|
4487
|
+
buttonSize,
|
4488
|
+
mobileButtonSize
|
4481
4489
|
});
|
4482
4490
|
setupButtonClickHandler(button, iframe, nearWallet, btcWallet);
|
4483
4491
|
}
|
4484
4492
|
function createFloatingButtonWithIframe({
|
4485
4493
|
openImageUrl,
|
4486
4494
|
closeImageUrl,
|
4487
|
-
iframe
|
4495
|
+
iframe,
|
4496
|
+
draggable,
|
4497
|
+
initialPosition,
|
4498
|
+
buttonSize,
|
4499
|
+
mobileButtonSize
|
4488
4500
|
}) {
|
4489
4501
|
const button = document.createElement("img");
|
4490
4502
|
button.id = "satoshi-wallet-button";
|
@@ -4493,32 +4505,49 @@ function createFloatingButtonWithIframe({
|
|
4493
4505
|
iframe.style.display = isIframeVisible ? "block" : "none";
|
4494
4506
|
const windowWidth = window.innerWidth;
|
4495
4507
|
const windowHeight = window.innerHeight;
|
4496
|
-
const savedPosition =
|
4508
|
+
const savedPosition = storage4 == null ? void 0 : storage4.get("position");
|
4509
|
+
const currentInitialPosition = initialPosition || savedPosition || {
|
4497
4510
|
right: "20px",
|
4498
4511
|
bottom: "20px"
|
4499
4512
|
};
|
4500
|
-
const
|
4501
|
-
const
|
4513
|
+
const tempButtonSize = buttonSize || "60px";
|
4514
|
+
const tempMobileButtonSize = mobileButtonSize || buttonSize || "40px";
|
4515
|
+
const actualButtonSize = isMobile() ? parseInt(tempMobileButtonSize) : parseInt(tempButtonSize);
|
4516
|
+
const right = Math.min(
|
4517
|
+
Math.max(minimumMargin, parseInt(currentInitialPosition.right)),
|
4518
|
+
windowWidth - actualButtonSize - minimumMargin
|
4519
|
+
);
|
4520
|
+
const bottom = Math.min(
|
4521
|
+
Math.max(minimumMargin, parseInt(currentInitialPosition.bottom)),
|
4522
|
+
windowHeight - actualButtonSize - minimumMargin
|
4523
|
+
);
|
4502
4524
|
Object.assign(button.style, {
|
4503
4525
|
position: "fixed",
|
4504
4526
|
bottom: `${bottom}px`,
|
4505
4527
|
right: `${right}px`,
|
4506
4528
|
zIndex: "100000",
|
4507
|
-
width: "60px",
|
4508
|
-
height: "60px",
|
4509
|
-
cursor: "grab",
|
4529
|
+
width: buttonSize || "60px",
|
4530
|
+
height: buttonSize || "60px",
|
4531
|
+
cursor: draggable ? "grab" : "pointer",
|
4510
4532
|
transition: "transform 0.15s ease",
|
4511
4533
|
userSelect: "none",
|
4512
4534
|
touchAction: "none"
|
4513
4535
|
});
|
4514
4536
|
if (isMobile()) {
|
4515
4537
|
Object.assign(button.style, {
|
4516
|
-
width: "40px",
|
4517
|
-
height: "40px"
|
4538
|
+
width: mobileButtonSize || buttonSize || "40px",
|
4539
|
+
height: mobileButtonSize || buttonSize || "40px"
|
4518
4540
|
});
|
4519
4541
|
}
|
4520
4542
|
document.body.appendChild(button);
|
4521
|
-
updateIframePosition(
|
4543
|
+
updateIframePosition(
|
4544
|
+
iframe,
|
4545
|
+
right,
|
4546
|
+
bottom,
|
4547
|
+
windowWidth,
|
4548
|
+
windowHeight,
|
4549
|
+
parseInt(button.style.width)
|
4550
|
+
);
|
4522
4551
|
let isDragging = false;
|
4523
4552
|
let startX = 0;
|
4524
4553
|
let startY = 0;
|
@@ -4526,6 +4555,8 @@ function createFloatingButtonWithIframe({
|
|
4526
4555
|
let initialBottom = 0;
|
4527
4556
|
let dragStartTime = 0;
|
4528
4557
|
function startDrag(clientX, clientY) {
|
4558
|
+
if (!draggable)
|
4559
|
+
return;
|
4529
4560
|
isDragging = true;
|
4530
4561
|
startX = clientX;
|
4531
4562
|
startY = clientY;
|
@@ -4554,7 +4585,7 @@ function createFloatingButtonWithIframe({
|
|
4554
4585
|
button.addEventListener(
|
4555
4586
|
"click",
|
4556
4587
|
(e) => {
|
4557
|
-
if (!isDragging) {
|
4588
|
+
if (!isDragging || !draggable) {
|
4558
4589
|
toggleWallet();
|
4559
4590
|
}
|
4560
4591
|
e.preventDefault();
|
@@ -4562,107 +4593,117 @@ function createFloatingButtonWithIframe({
|
|
4562
4593
|
},
|
4563
4594
|
{ capture: true }
|
4564
4595
|
);
|
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);
|
4596
|
+
if (draggable) {
|
4597
|
+
button.addEventListener(
|
4598
|
+
"mousedown",
|
4599
|
+
(e) => {
|
4600
|
+
startDrag(e.clientX, e.clientY);
|
4580
4601
|
e.preventDefault();
|
4581
4602
|
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
|
-
|
4603
|
+
},
|
4604
|
+
{ capture: true }
|
4605
|
+
);
|
4606
|
+
button.addEventListener(
|
4607
|
+
"touchstart",
|
4608
|
+
(e) => {
|
4609
|
+
if (e.touches.length === 1) {
|
4610
|
+
const touch = e.touches[0];
|
4611
|
+
startDrag(touch.clientX, touch.clientY);
|
4612
|
+
e.preventDefault();
|
4613
|
+
e.stopPropagation();
|
4614
|
+
}
|
4615
|
+
},
|
4616
|
+
{ capture: true }
|
4617
|
+
);
|
4618
|
+
document.addEventListener(
|
4619
|
+
"mousemove",
|
4620
|
+
(e) => {
|
4621
|
+
if (!isDragging)
|
4622
|
+
return;
|
4623
|
+
moveButton(e.clientX, e.clientY);
|
4624
|
+
e.preventDefault();
|
4625
|
+
},
|
4626
|
+
{ capture: true }
|
4627
|
+
);
|
4628
|
+
document.addEventListener(
|
4629
|
+
"touchmove",
|
4630
|
+
(e) => {
|
4631
|
+
if (!isDragging || e.touches.length !== 1)
|
4632
|
+
return;
|
4633
|
+
const touch = e.touches[0];
|
4634
|
+
moveButton(touch.clientX, touch.clientY);
|
4635
|
+
e.preventDefault();
|
4636
|
+
},
|
4637
|
+
{ capture: true }
|
4638
|
+
);
|
4639
|
+
document.addEventListener(
|
4640
|
+
"mouseup",
|
4641
|
+
(e) => {
|
4642
|
+
if (isDragging) {
|
4643
|
+
e.preventDefault();
|
4644
|
+
e.stopPropagation();
|
4645
|
+
}
|
4646
|
+
endDrag();
|
4647
|
+
},
|
4648
|
+
{ capture: true }
|
4649
|
+
);
|
4650
|
+
document.addEventListener(
|
4651
|
+
"touchend",
|
4652
|
+
(e) => {
|
4653
|
+
if (isDragging) {
|
4654
|
+
e.preventDefault();
|
4655
|
+
e.stopPropagation();
|
4656
|
+
}
|
4657
|
+
endDrag();
|
4658
|
+
const dragEndTime = Date.now();
|
4659
|
+
const dragDuration = dragEndTime - dragStartTime;
|
4660
|
+
if (dragDuration < 200 && Math.abs(parseInt(button.style.right) - initialRight) < 5 && Math.abs(parseInt(button.style.bottom) - initialBottom) < 5) {
|
4661
|
+
toggleWallet();
|
4662
|
+
}
|
4663
|
+
},
|
4664
|
+
{ capture: true }
|
4665
|
+
);
|
4666
|
+
document.addEventListener(
|
4667
|
+
"touchcancel",
|
4668
|
+
() => {
|
4669
|
+
endDrag();
|
4670
|
+
},
|
4671
|
+
{ capture: true }
|
4672
|
+
);
|
4673
|
+
}
|
4607
4674
|
function moveButton(clientX, clientY) {
|
4608
4675
|
const deltaX = startX - clientX;
|
4609
4676
|
const deltaY = startY - clientY;
|
4610
4677
|
let newRight = initialRight + deltaX;
|
4611
4678
|
let newBottom = initialBottom + deltaY;
|
4612
|
-
|
4613
|
-
|
4614
|
-
|
4615
|
-
|
4679
|
+
const currentButtonSize = parseInt(button.style.width);
|
4680
|
+
newRight = Math.min(
|
4681
|
+
Math.max(minimumMargin, newRight),
|
4682
|
+
windowWidth - currentButtonSize - minimumMargin
|
4683
|
+
);
|
4684
|
+
newBottom = Math.min(
|
4685
|
+
Math.max(minimumMargin, newBottom),
|
4686
|
+
windowHeight - currentButtonSize - minimumMargin
|
4687
|
+
);
|
4688
|
+
const snapThreshold = minimumMargin;
|
4689
|
+
const buttonLeft = windowWidth - newRight - currentButtonSize;
|
4616
4690
|
if (buttonLeft < snapThreshold) {
|
4617
|
-
newRight = windowWidth -
|
4618
|
-
} else if (
|
4619
|
-
newRight =
|
4691
|
+
newRight = windowWidth - currentButtonSize - minimumMargin;
|
4692
|
+
} else if (newRight < snapThreshold) {
|
4693
|
+
newRight = minimumMargin;
|
4620
4694
|
}
|
4621
|
-
|
4622
|
-
|
4623
|
-
|
4624
|
-
|
4695
|
+
const buttonTop = windowHeight - newBottom - currentButtonSize;
|
4696
|
+
if (buttonTop < snapThreshold) {
|
4697
|
+
newBottom = windowHeight - currentButtonSize - minimumMargin;
|
4698
|
+
} else if (newBottom < snapThreshold) {
|
4699
|
+
newBottom = minimumMargin;
|
4625
4700
|
}
|
4626
4701
|
button.style.right = `${newRight}px`;
|
4627
4702
|
button.style.bottom = `${newBottom}px`;
|
4628
|
-
updateIframePosition(iframe, newRight, newBottom, windowWidth, windowHeight);
|
4703
|
+
updateIframePosition(iframe, newRight, newBottom, windowWidth, windowHeight, currentButtonSize);
|
4629
4704
|
}
|
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
4705
|
function endDrag() {
|
4665
|
-
if (!isDragging)
|
4706
|
+
if (!isDragging || !draggable)
|
4666
4707
|
return;
|
4667
4708
|
isDragging = false;
|
4668
4709
|
button.style.cursor = "grab";
|
@@ -4672,8 +4713,6 @@ function createFloatingButtonWithIframe({
|
|
4672
4713
|
bottom: button.style.bottom
|
4673
4714
|
});
|
4674
4715
|
}
|
4675
|
-
const handleButtonClick = () => {
|
4676
|
-
};
|
4677
4716
|
button.onclick = null;
|
4678
4717
|
return button;
|
4679
4718
|
}
|
@@ -4766,16 +4805,16 @@ function removeWalletButton() {
|
|
4766
4805
|
const iframe = document.getElementById("satoshi-wallet-iframe");
|
4767
4806
|
iframe == null ? void 0 : iframe.remove();
|
4768
4807
|
}
|
4769
|
-
function updateIframePosition(iframe, buttonRight, buttonBottom, windowWidth, windowHeight) {
|
4808
|
+
function updateIframePosition(iframe, buttonRight, buttonBottom, windowWidth, windowHeight, buttonSize) {
|
4770
4809
|
const iframeWidth = parseInt(iframe.style.width);
|
4771
4810
|
const iframeHeight = parseInt(iframe.style.height);
|
4772
4811
|
let iframeRight = buttonRight;
|
4773
|
-
let iframeBottom = buttonBottom +
|
4774
|
-
if (iframeRight + iframeWidth > windowWidth -
|
4775
|
-
iframeRight = Math.max(
|
4812
|
+
let iframeBottom = buttonBottom + buttonSize + 10;
|
4813
|
+
if (iframeRight + iframeWidth > windowWidth - minimumMargin) {
|
4814
|
+
iframeRight = Math.max(minimumMargin, windowWidth - iframeWidth - minimumMargin);
|
4776
4815
|
}
|
4777
|
-
if (iframeBottom + iframeHeight > windowHeight -
|
4778
|
-
iframeBottom = Math.max(
|
4816
|
+
if (iframeBottom + iframeHeight > windowHeight - minimumMargin) {
|
4817
|
+
iframeBottom = Math.max(minimumMargin, buttonBottom - iframeHeight - 10);
|
4779
4818
|
}
|
4780
4819
|
iframe.style.right = `${iframeRight}px`;
|
4781
4820
|
iframe.style.bottom = `${iframeBottom}px`;
|
@@ -5123,7 +5162,11 @@ function setupWalletSelectorModal(selector, options) {
|
|
5123
5162
|
showChainGroups = true,
|
5124
5163
|
showWalletUIForNearAccount = true,
|
5125
5164
|
env = "mainnet",
|
5126
|
-
walletUrl
|
5165
|
+
walletUrl,
|
5166
|
+
draggable = true,
|
5167
|
+
initialPosition = { right: "20px", bottom: "20px" },
|
5168
|
+
buttonSize = "60px",
|
5169
|
+
mobileButtonSize = "40px"
|
5127
5170
|
} = options;
|
5128
5171
|
subscription == null ? void 0 : subscription.unsubscribe();
|
5129
5172
|
const state = selector.store.getState();
|
@@ -5135,7 +5178,15 @@ function setupWalletSelectorModal(selector, options) {
|
|
5135
5178
|
removeWalletButton();
|
5136
5179
|
if (showWalletUIForNearAccount && walletId !== "btc-wallet") {
|
5137
5180
|
selector.wallet().then((wallet) => {
|
5138
|
-
setupWalletButton({
|
5181
|
+
setupWalletButton({
|
5182
|
+
env,
|
5183
|
+
nearWallet: wallet,
|
5184
|
+
walletUrl,
|
5185
|
+
draggable,
|
5186
|
+
initialPosition,
|
5187
|
+
buttonSize,
|
5188
|
+
mobileButtonSize
|
5189
|
+
});
|
5139
5190
|
});
|
5140
5191
|
}
|
5141
5192
|
});
|
@@ -5227,7 +5278,7 @@ function getGroup(state) {
|
|
5227
5278
|
|
5228
5279
|
// src/index.ts
|
5229
5280
|
var getVersion = () => {
|
5230
|
-
return "0.5.
|
5281
|
+
return "0.5.65-beta";
|
5231
5282
|
};
|
5232
5283
|
if (typeof window !== "undefined") {
|
5233
5284
|
window.__BTC_WALLET_VERSION = getVersion();
|