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
@@ -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
@@ -2501,6 +2501,8 @@ var ConnectProvider = ({
|
|
2501
2501
|
}, [connector, requestAccount]);
|
2502
2502
|
useEffect5(() => {
|
2503
2503
|
const onAccountChange = (accounts2) => {
|
2504
|
+
if (!accounts2.length)
|
2505
|
+
return;
|
2504
2506
|
setAccounts(accounts2);
|
2505
2507
|
};
|
2506
2508
|
connector == null ? void 0 : connector.on("accountsChanged", onAccountChange);
|
@@ -2812,16 +2814,13 @@ function useBtcWalletSelector() {
|
|
2812
2814
|
const connectWallet = (useModal = false) => __async(this, null, function* () {
|
2813
2815
|
if (connectModalOpen)
|
2814
2816
|
return null;
|
2815
|
-
const account = accounts == null ? void 0 : accounts[0];
|
2816
|
-
if (account)
|
2817
|
-
return account;
|
2818
2817
|
try {
|
2819
2818
|
if (useModal) {
|
2820
2819
|
openConnectModal == null ? void 0 : openConnectModal();
|
2821
2820
|
} else {
|
2822
2821
|
yield requestDirectAccount(connectorRef.current);
|
2823
2822
|
}
|
2824
|
-
const
|
2823
|
+
const account = yield retryOperation(
|
2825
2824
|
() => window.btcContext.account,
|
2826
2825
|
(res) => !!res,
|
2827
2826
|
{
|
@@ -2829,7 +2828,7 @@ function useBtcWalletSelector() {
|
|
2829
2828
|
delayMs: 1e3
|
2830
2829
|
}
|
2831
2830
|
);
|
2832
|
-
return
|
2831
|
+
return account || null;
|
2833
2832
|
} catch (error) {
|
2834
2833
|
console.error("btcLoginError", error);
|
2835
2834
|
context.emit("btcLoginError");
|
@@ -4379,11 +4378,16 @@ function uint8ArrayToHex(uint8Array) {
|
|
4379
4378
|
|
4380
4379
|
// src/utils/initWalletButton.ts
|
4381
4380
|
var storage4 = storageStore("SATOSHI_WALLET_BUTTON");
|
4381
|
+
var minimumMargin = 10;
|
4382
4382
|
function setupWalletButton({
|
4383
4383
|
env,
|
4384
4384
|
nearWallet,
|
4385
4385
|
btcWallet,
|
4386
|
-
walletUrl
|
4386
|
+
walletUrl,
|
4387
|
+
draggable = true,
|
4388
|
+
initialPosition,
|
4389
|
+
buttonSize,
|
4390
|
+
mobileButtonSize
|
4387
4391
|
}) {
|
4388
4392
|
if (document.getElementById("satoshi-wallet-button")) {
|
4389
4393
|
return;
|
@@ -4407,14 +4411,22 @@ function setupWalletButton({
|
|
4407
4411
|
const button = createFloatingButtonWithIframe({
|
4408
4412
|
openImageUrl,
|
4409
4413
|
closeImageUrl,
|
4410
|
-
iframe
|
4414
|
+
iframe,
|
4415
|
+
draggable,
|
4416
|
+
initialPosition,
|
4417
|
+
buttonSize,
|
4418
|
+
mobileButtonSize
|
4411
4419
|
});
|
4412
4420
|
setupButtonClickHandler(button, iframe, nearWallet, btcWallet);
|
4413
4421
|
}
|
4414
4422
|
function createFloatingButtonWithIframe({
|
4415
4423
|
openImageUrl,
|
4416
4424
|
closeImageUrl,
|
4417
|
-
iframe
|
4425
|
+
iframe,
|
4426
|
+
draggable,
|
4427
|
+
initialPosition,
|
4428
|
+
buttonSize,
|
4429
|
+
mobileButtonSize
|
4418
4430
|
}) {
|
4419
4431
|
const button = document.createElement("img");
|
4420
4432
|
button.id = "satoshi-wallet-button";
|
@@ -4423,32 +4435,49 @@ function createFloatingButtonWithIframe({
|
|
4423
4435
|
iframe.style.display = isIframeVisible ? "block" : "none";
|
4424
4436
|
const windowWidth = window.innerWidth;
|
4425
4437
|
const windowHeight = window.innerHeight;
|
4426
|
-
const savedPosition =
|
4438
|
+
const savedPosition = storage4 == null ? void 0 : storage4.get("position");
|
4439
|
+
const currentInitialPosition = initialPosition || savedPosition || {
|
4427
4440
|
right: "20px",
|
4428
4441
|
bottom: "20px"
|
4429
4442
|
};
|
4430
|
-
const
|
4431
|
-
const
|
4443
|
+
const tempButtonSize = buttonSize || "60px";
|
4444
|
+
const tempMobileButtonSize = mobileButtonSize || buttonSize || "40px";
|
4445
|
+
const actualButtonSize = isMobile() ? parseInt(tempMobileButtonSize) : parseInt(tempButtonSize);
|
4446
|
+
const right = Math.min(
|
4447
|
+
Math.max(minimumMargin, parseInt(currentInitialPosition.right)),
|
4448
|
+
windowWidth - actualButtonSize - minimumMargin
|
4449
|
+
);
|
4450
|
+
const bottom = Math.min(
|
4451
|
+
Math.max(minimumMargin, parseInt(currentInitialPosition.bottom)),
|
4452
|
+
windowHeight - actualButtonSize - minimumMargin
|
4453
|
+
);
|
4432
4454
|
Object.assign(button.style, {
|
4433
4455
|
position: "fixed",
|
4434
4456
|
bottom: `${bottom}px`,
|
4435
4457
|
right: `${right}px`,
|
4436
4458
|
zIndex: "100000",
|
4437
|
-
width: "60px",
|
4438
|
-
height: "60px",
|
4439
|
-
cursor: "grab",
|
4459
|
+
width: buttonSize || "60px",
|
4460
|
+
height: buttonSize || "60px",
|
4461
|
+
cursor: draggable ? "grab" : "pointer",
|
4440
4462
|
transition: "transform 0.15s ease",
|
4441
4463
|
userSelect: "none",
|
4442
4464
|
touchAction: "none"
|
4443
4465
|
});
|
4444
4466
|
if (isMobile()) {
|
4445
4467
|
Object.assign(button.style, {
|
4446
|
-
width: "40px",
|
4447
|
-
height: "40px"
|
4468
|
+
width: mobileButtonSize || buttonSize || "40px",
|
4469
|
+
height: mobileButtonSize || buttonSize || "40px"
|
4448
4470
|
});
|
4449
4471
|
}
|
4450
4472
|
document.body.appendChild(button);
|
4451
|
-
updateIframePosition(
|
4473
|
+
updateIframePosition(
|
4474
|
+
iframe,
|
4475
|
+
right,
|
4476
|
+
bottom,
|
4477
|
+
windowWidth,
|
4478
|
+
windowHeight,
|
4479
|
+
parseInt(button.style.width)
|
4480
|
+
);
|
4452
4481
|
let isDragging = false;
|
4453
4482
|
let startX = 0;
|
4454
4483
|
let startY = 0;
|
@@ -4456,6 +4485,8 @@ function createFloatingButtonWithIframe({
|
|
4456
4485
|
let initialBottom = 0;
|
4457
4486
|
let dragStartTime = 0;
|
4458
4487
|
function startDrag(clientX, clientY) {
|
4488
|
+
if (!draggable)
|
4489
|
+
return;
|
4459
4490
|
isDragging = true;
|
4460
4491
|
startX = clientX;
|
4461
4492
|
startY = clientY;
|
@@ -4484,7 +4515,7 @@ function createFloatingButtonWithIframe({
|
|
4484
4515
|
button.addEventListener(
|
4485
4516
|
"click",
|
4486
4517
|
(e) => {
|
4487
|
-
if (!isDragging) {
|
4518
|
+
if (!isDragging || !draggable) {
|
4488
4519
|
toggleWallet();
|
4489
4520
|
}
|
4490
4521
|
e.preventDefault();
|
@@ -4492,107 +4523,117 @@ function createFloatingButtonWithIframe({
|
|
4492
4523
|
},
|
4493
4524
|
{ capture: true }
|
4494
4525
|
);
|
4495
|
-
|
4496
|
-
|
4497
|
-
|
4498
|
-
|
4499
|
-
|
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);
|
4526
|
+
if (draggable) {
|
4527
|
+
button.addEventListener(
|
4528
|
+
"mousedown",
|
4529
|
+
(e) => {
|
4530
|
+
startDrag(e.clientX, e.clientY);
|
4510
4531
|
e.preventDefault();
|
4511
4532
|
e.stopPropagation();
|
4512
|
-
}
|
4513
|
-
|
4514
|
-
|
4515
|
-
|
4516
|
-
|
4517
|
-
|
4518
|
-
|
4519
|
-
|
4520
|
-
|
4521
|
-
|
4522
|
-
|
4523
|
-
|
4524
|
-
|
4525
|
-
|
4526
|
-
|
4527
|
-
|
4528
|
-
|
4529
|
-
|
4530
|
-
|
4531
|
-
|
4532
|
-
|
4533
|
-
|
4534
|
-
|
4535
|
-
|
4536
|
-
|
4533
|
+
},
|
4534
|
+
{ capture: true }
|
4535
|
+
);
|
4536
|
+
button.addEventListener(
|
4537
|
+
"touchstart",
|
4538
|
+
(e) => {
|
4539
|
+
if (e.touches.length === 1) {
|
4540
|
+
const touch = e.touches[0];
|
4541
|
+
startDrag(touch.clientX, touch.clientY);
|
4542
|
+
e.preventDefault();
|
4543
|
+
e.stopPropagation();
|
4544
|
+
}
|
4545
|
+
},
|
4546
|
+
{ capture: true }
|
4547
|
+
);
|
4548
|
+
document.addEventListener(
|
4549
|
+
"mousemove",
|
4550
|
+
(e) => {
|
4551
|
+
if (!isDragging)
|
4552
|
+
return;
|
4553
|
+
moveButton(e.clientX, e.clientY);
|
4554
|
+
e.preventDefault();
|
4555
|
+
},
|
4556
|
+
{ capture: true }
|
4557
|
+
);
|
4558
|
+
document.addEventListener(
|
4559
|
+
"touchmove",
|
4560
|
+
(e) => {
|
4561
|
+
if (!isDragging || e.touches.length !== 1)
|
4562
|
+
return;
|
4563
|
+
const touch = e.touches[0];
|
4564
|
+
moveButton(touch.clientX, touch.clientY);
|
4565
|
+
e.preventDefault();
|
4566
|
+
},
|
4567
|
+
{ capture: true }
|
4568
|
+
);
|
4569
|
+
document.addEventListener(
|
4570
|
+
"mouseup",
|
4571
|
+
(e) => {
|
4572
|
+
if (isDragging) {
|
4573
|
+
e.preventDefault();
|
4574
|
+
e.stopPropagation();
|
4575
|
+
}
|
4576
|
+
endDrag();
|
4577
|
+
},
|
4578
|
+
{ capture: true }
|
4579
|
+
);
|
4580
|
+
document.addEventListener(
|
4581
|
+
"touchend",
|
4582
|
+
(e) => {
|
4583
|
+
if (isDragging) {
|
4584
|
+
e.preventDefault();
|
4585
|
+
e.stopPropagation();
|
4586
|
+
}
|
4587
|
+
endDrag();
|
4588
|
+
const dragEndTime = Date.now();
|
4589
|
+
const dragDuration = dragEndTime - dragStartTime;
|
4590
|
+
if (dragDuration < 200 && Math.abs(parseInt(button.style.right) - initialRight) < 5 && Math.abs(parseInt(button.style.bottom) - initialBottom) < 5) {
|
4591
|
+
toggleWallet();
|
4592
|
+
}
|
4593
|
+
},
|
4594
|
+
{ capture: true }
|
4595
|
+
);
|
4596
|
+
document.addEventListener(
|
4597
|
+
"touchcancel",
|
4598
|
+
() => {
|
4599
|
+
endDrag();
|
4600
|
+
},
|
4601
|
+
{ capture: true }
|
4602
|
+
);
|
4603
|
+
}
|
4537
4604
|
function moveButton(clientX, clientY) {
|
4538
4605
|
const deltaX = startX - clientX;
|
4539
4606
|
const deltaY = startY - clientY;
|
4540
4607
|
let newRight = initialRight + deltaX;
|
4541
4608
|
let newBottom = initialBottom + deltaY;
|
4542
|
-
|
4543
|
-
|
4544
|
-
|
4545
|
-
|
4609
|
+
const currentButtonSize = parseInt(button.style.width);
|
4610
|
+
newRight = Math.min(
|
4611
|
+
Math.max(minimumMargin, newRight),
|
4612
|
+
windowWidth - currentButtonSize - minimumMargin
|
4613
|
+
);
|
4614
|
+
newBottom = Math.min(
|
4615
|
+
Math.max(minimumMargin, newBottom),
|
4616
|
+
windowHeight - currentButtonSize - minimumMargin
|
4617
|
+
);
|
4618
|
+
const snapThreshold = minimumMargin;
|
4619
|
+
const buttonLeft = windowWidth - newRight - currentButtonSize;
|
4546
4620
|
if (buttonLeft < snapThreshold) {
|
4547
|
-
newRight = windowWidth -
|
4548
|
-
} else if (
|
4549
|
-
newRight =
|
4621
|
+
newRight = windowWidth - currentButtonSize - minimumMargin;
|
4622
|
+
} else if (newRight < snapThreshold) {
|
4623
|
+
newRight = minimumMargin;
|
4550
4624
|
}
|
4551
|
-
|
4552
|
-
|
4553
|
-
|
4554
|
-
|
4625
|
+
const buttonTop = windowHeight - newBottom - currentButtonSize;
|
4626
|
+
if (buttonTop < snapThreshold) {
|
4627
|
+
newBottom = windowHeight - currentButtonSize - minimumMargin;
|
4628
|
+
} else if (newBottom < snapThreshold) {
|
4629
|
+
newBottom = minimumMargin;
|
4555
4630
|
}
|
4556
4631
|
button.style.right = `${newRight}px`;
|
4557
4632
|
button.style.bottom = `${newBottom}px`;
|
4558
|
-
updateIframePosition(iframe, newRight, newBottom, windowWidth, windowHeight);
|
4633
|
+
updateIframePosition(iframe, newRight, newBottom, windowWidth, windowHeight, currentButtonSize);
|
4559
4634
|
}
|
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
4635
|
function endDrag() {
|
4595
|
-
if (!isDragging)
|
4636
|
+
if (!isDragging || !draggable)
|
4596
4637
|
return;
|
4597
4638
|
isDragging = false;
|
4598
4639
|
button.style.cursor = "grab";
|
@@ -4602,8 +4643,6 @@ function createFloatingButtonWithIframe({
|
|
4602
4643
|
bottom: button.style.bottom
|
4603
4644
|
});
|
4604
4645
|
}
|
4605
|
-
const handleButtonClick = () => {
|
4606
|
-
};
|
4607
4646
|
button.onclick = null;
|
4608
4647
|
return button;
|
4609
4648
|
}
|
@@ -4696,16 +4735,16 @@ function removeWalletButton() {
|
|
4696
4735
|
const iframe = document.getElementById("satoshi-wallet-iframe");
|
4697
4736
|
iframe == null ? void 0 : iframe.remove();
|
4698
4737
|
}
|
4699
|
-
function updateIframePosition(iframe, buttonRight, buttonBottom, windowWidth, windowHeight) {
|
4738
|
+
function updateIframePosition(iframe, buttonRight, buttonBottom, windowWidth, windowHeight, buttonSize) {
|
4700
4739
|
const iframeWidth = parseInt(iframe.style.width);
|
4701
4740
|
const iframeHeight = parseInt(iframe.style.height);
|
4702
4741
|
let iframeRight = buttonRight;
|
4703
|
-
let iframeBottom = buttonBottom +
|
4704
|
-
if (iframeRight + iframeWidth > windowWidth -
|
4705
|
-
iframeRight = Math.max(
|
4742
|
+
let iframeBottom = buttonBottom + buttonSize + 10;
|
4743
|
+
if (iframeRight + iframeWidth > windowWidth - minimumMargin) {
|
4744
|
+
iframeRight = Math.max(minimumMargin, windowWidth - iframeWidth - minimumMargin);
|
4706
4745
|
}
|
4707
|
-
if (iframeBottom + iframeHeight > windowHeight -
|
4708
|
-
iframeBottom = Math.max(
|
4746
|
+
if (iframeBottom + iframeHeight > windowHeight - minimumMargin) {
|
4747
|
+
iframeBottom = Math.max(minimumMargin, buttonBottom - iframeHeight - 10);
|
4709
4748
|
}
|
4710
4749
|
iframe.style.right = `${iframeRight}px`;
|
4711
4750
|
iframe.style.bottom = `${iframeBottom}px`;
|
@@ -5055,7 +5094,11 @@ function setupWalletSelectorModal(selector, options) {
|
|
5055
5094
|
showChainGroups = true,
|
5056
5095
|
showWalletUIForNearAccount = true,
|
5057
5096
|
env = "mainnet",
|
5058
|
-
walletUrl
|
5097
|
+
walletUrl,
|
5098
|
+
draggable = true,
|
5099
|
+
initialPosition = { right: "20px", bottom: "20px" },
|
5100
|
+
buttonSize = "60px",
|
5101
|
+
mobileButtonSize = "40px"
|
5059
5102
|
} = options;
|
5060
5103
|
subscription == null ? void 0 : subscription.unsubscribe();
|
5061
5104
|
const state = selector.store.getState();
|
@@ -5067,7 +5110,15 @@ function setupWalletSelectorModal(selector, options) {
|
|
5067
5110
|
removeWalletButton();
|
5068
5111
|
if (showWalletUIForNearAccount && walletId !== "btc-wallet") {
|
5069
5112
|
selector.wallet().then((wallet) => {
|
5070
|
-
setupWalletButton({
|
5113
|
+
setupWalletButton({
|
5114
|
+
env,
|
5115
|
+
nearWallet: wallet,
|
5116
|
+
walletUrl,
|
5117
|
+
draggable,
|
5118
|
+
initialPosition,
|
5119
|
+
buttonSize,
|
5120
|
+
mobileButtonSize
|
5121
|
+
});
|
5071
5122
|
});
|
5072
5123
|
}
|
5073
5124
|
});
|
@@ -5159,7 +5210,7 @@ function getGroup(state) {
|
|
5159
5210
|
|
5160
5211
|
// src/index.ts
|
5161
5212
|
var getVersion = () => {
|
5162
|
-
return "0.5.
|
5213
|
+
return "0.5.65-beta";
|
5163
5214
|
};
|
5164
5215
|
if (typeof window !== "undefined") {
|
5165
5216
|
window.__BTC_WALLET_VERSION = getVersion();
|