btc-wallet 0.5.55-beta → 0.5.57-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/setupBTCWallet/index.d.ts +2 -1
- package/dist/index.js +90 -60
- package/dist/index.js.map +2 -2
- package/dist/utils/satoshi.d.ts +4 -1
- package/esm/index.js +90 -60
- package/esm/index.js.map +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
@@ -30,7 +30,11 @@ const selector = await setupWalletSelector({
|
|
30
30
|
deprecated?: boolean, // optional: mark as deprecated
|
31
31
|
autoConnect?: boolean, // optional: enable auto-connect, defaults to true
|
32
32
|
syncLogOut?: boolean, // optional: sync logout across tabs, defaults to true
|
33
|
-
env?: 'mainnet' | 'testnet' | 'private_mainnet' | 'dev' // optional: defaults to NEAR network environment
|
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'
|
35
|
+
// 'auto': use NEAR if balance > 0.5, otherwise use BTC token
|
36
|
+
// 'near': force use NEAR for gas payment
|
37
|
+
// 'btc': force use BTC token for gas payment
|
34
38
|
}),
|
35
39
|
// setup other wallets...
|
36
40
|
],
|
@@ -13,8 +13,9 @@ interface BTCWalletParams {
|
|
13
13
|
syncLogOut?: boolean;
|
14
14
|
env?: ENV;
|
15
15
|
walletUrl?: string;
|
16
|
+
gasStrategy?: 'auto' | 'near' | 'btc';
|
16
17
|
}
|
17
|
-
export declare function setupBTCWallet({ iconUrl, deprecated, autoConnect, syncLogOut, env, walletUrl, }?: BTCWalletParams | undefined): WalletModuleFactory<InjectedWallet>;
|
18
|
+
export declare function setupBTCWallet({ iconUrl, deprecated, autoConnect, syncLogOut, env, walletUrl, gasStrategy, }?: BTCWalletParams | undefined): WalletModuleFactory<InjectedWallet>;
|
18
19
|
declare const _default: {
|
19
20
|
setupBTCWallet: typeof setupBTCWallet;
|
20
21
|
};
|
package/dist/index.js
CHANGED
@@ -548,7 +548,7 @@ var MobileWalletConnect = class {
|
|
548
548
|
case "okx":
|
549
549
|
return `okx://wallet/dapp/url?dappUrl=${encodeURIComponent(url)}`;
|
550
550
|
case "bitget":
|
551
|
-
return `
|
551
|
+
return `bitkeep://bkconnect?action=dapp&url=${encodeURIComponent(url)}`;
|
552
552
|
case "xverse":
|
553
553
|
return `xverse://browser?url=${encodeURIComponent(url)}`;
|
554
554
|
default:
|
@@ -634,9 +634,13 @@ var InjectedConnector = class extends BaseConnector {
|
|
634
634
|
}
|
635
635
|
requestAccounts() {
|
636
636
|
return __async(this, null, function* () {
|
637
|
-
if (isMobile()
|
638
|
-
|
639
|
-
|
637
|
+
if (isMobile()) {
|
638
|
+
try {
|
639
|
+
this.getProvider();
|
640
|
+
} catch (error) {
|
641
|
+
yield MobileWalletConnect.redirectToWallet(this.metadata.id);
|
642
|
+
return [];
|
643
|
+
}
|
640
644
|
}
|
641
645
|
const accounts = yield this.getProviderOrThrow().requestAccounts();
|
642
646
|
console.log("network:", yield this.getNetwork());
|
@@ -2772,7 +2776,8 @@ function BtcWalletSelectorContextProvider({
|
|
2772
2776
|
new XverseConnector(),
|
2773
2777
|
new OKXConnector(),
|
2774
2778
|
new BitgetConnector(),
|
2775
|
-
new MagicEdenConnector()
|
2779
|
+
new MagicEdenConnector(),
|
2780
|
+
new BybitConnector()
|
2776
2781
|
];
|
2777
2782
|
const walletSelectorContextValue = (0, import_react11.useMemo)(() => {
|
2778
2783
|
const simpleFn = {};
|
@@ -3011,7 +3016,7 @@ var nearRpcUrls = {
|
|
3011
3016
|
mainnet: [
|
3012
3017
|
"https://near.lava.build",
|
3013
3018
|
"https://rpc.mainnet.near.org",
|
3014
|
-
"https://
|
3019
|
+
"https://free.rpc.fastnear.com",
|
3015
3020
|
"https://near.drpc.org"
|
3016
3021
|
],
|
3017
3022
|
testnet: ["https://rpc.testnet.near.org"]
|
@@ -3584,7 +3589,8 @@ function calculateGasStrategy(_0) {
|
|
3584
3589
|
return __async(this, arguments, function* ({
|
3585
3590
|
csna,
|
3586
3591
|
transactions: transactions2,
|
3587
|
-
env
|
3592
|
+
env,
|
3593
|
+
gasStrategy = "auto"
|
3588
3594
|
}) {
|
3589
3595
|
var _a;
|
3590
3596
|
const currentConfig = getWalletConfig(env);
|
@@ -3616,6 +3622,7 @@ function calculateGasStrategy(_0) {
|
|
3616
3622
|
const nearAvailableBalance = new import_big.default(nearBalance).minus(transferAmount.near).toNumber();
|
3617
3623
|
console.log("available near balance:", nearAvailableBalance);
|
3618
3624
|
console.log("available gas token balance:", gasTokenBalance);
|
3625
|
+
console.log("gas strategy:", gasStrategy);
|
3619
3626
|
const convertTx = yield Promise.all(
|
3620
3627
|
transactions2.map(
|
3621
3628
|
(transaction, index) => convertTransactionToTxHex({
|
@@ -3627,8 +3634,20 @@ function calculateGasStrategy(_0) {
|
|
3627
3634
|
})
|
3628
3635
|
)
|
3629
3636
|
);
|
3630
|
-
|
3631
|
-
|
3637
|
+
let useNearPayGas = false;
|
3638
|
+
let perTxFee;
|
3639
|
+
if (gasStrategy === "near") {
|
3640
|
+
console.log("Forcing NEAR as gas token based on gasStrategy");
|
3641
|
+
useNearPayGas = true;
|
3642
|
+
} else if (gasStrategy === "btc") {
|
3643
|
+
console.log("Forcing BTC token as gas token based on gasStrategy");
|
3644
|
+
useNearPayGas = false;
|
3645
|
+
} else if (nearAvailableBalance > 0.5) {
|
3646
|
+
console.log("NEAR balance is enough, using NEAR to pay for gas");
|
3647
|
+
useNearPayGas = true;
|
3648
|
+
}
|
3649
|
+
let gasAmount;
|
3650
|
+
if (useNearPayGas) {
|
3632
3651
|
const gasTokens = yield nearCallFunction(
|
3633
3652
|
currentConfig.accountContractId,
|
3634
3653
|
"list_gas_token",
|
@@ -3636,39 +3655,29 @@ function calculateGasStrategy(_0) {
|
|
3636
3655
|
{ network: currentConfig.network }
|
3637
3656
|
);
|
3638
3657
|
console.log("list_gas_token gas tokens:", gasTokens);
|
3639
|
-
const
|
3640
|
-
|
3641
|
-
100
|
3642
|
-
);
|
3658
|
+
const fee = Math.max(Number(((_a = gasTokens[currentConfig.btcToken]) == null ? void 0 : _a.per_tx_protocol_fee) || 0), 100);
|
3659
|
+
perTxFee = fee.toString();
|
3643
3660
|
console.log("perTxFee:", perTxFee);
|
3644
|
-
|
3645
|
-
console.log("protocolFee:", protocolFee);
|
3646
|
-
const transferTx = yield createGasTokenTransfer({ csna, amount: protocolFee, env });
|
3647
|
-
return recalculateGasWithTransfer({
|
3648
|
-
csna,
|
3649
|
-
transferTx,
|
3650
|
-
transactions: convertTx,
|
3651
|
-
useNearPayGas: true,
|
3652
|
-
perTxFee: perTxFee.toString(),
|
3653
|
-
env
|
3654
|
-
});
|
3661
|
+
gasAmount = new import_big.default(perTxFee || "0").mul(convertTx.length).toFixed(0);
|
3655
3662
|
} else {
|
3656
|
-
|
3657
|
-
const adjustedGas = yield getPredictedGasAmount({
|
3663
|
+
gasAmount = yield getPredictedGasAmount({
|
3658
3664
|
accountContractId: currentConfig.accountContractId,
|
3659
3665
|
tokenId: currentConfig.btcToken,
|
3660
3666
|
transactions: convertTx.map((t) => t.txHex),
|
3661
3667
|
env
|
3662
3668
|
});
|
3663
|
-
const transferTx = yield createGasTokenTransfer({ csna, amount: adjustedGas, env });
|
3664
|
-
return recalculateGasWithTransfer({
|
3665
|
-
csna,
|
3666
|
-
transferTx,
|
3667
|
-
transactions: convertTx,
|
3668
|
-
useNearPayGas: false,
|
3669
|
-
env
|
3670
|
-
});
|
3671
3669
|
}
|
3670
|
+
console.log("useNearPayGas:", useNearPayGas);
|
3671
|
+
console.log("gasAmount:", gasAmount);
|
3672
|
+
const transferTx = yield createGasTokenTransfer({ csna, amount: gasAmount, env });
|
3673
|
+
return recalculateGasWithTransfer({
|
3674
|
+
csna,
|
3675
|
+
transferTx,
|
3676
|
+
transactions: convertTx,
|
3677
|
+
useNearPayGas,
|
3678
|
+
perTxFee,
|
3679
|
+
env
|
3680
|
+
});
|
3672
3681
|
});
|
3673
3682
|
}
|
3674
3683
|
function createGasTokenTransfer(_0) {
|
@@ -4493,13 +4502,14 @@ function createFloatingButtonWithIframe({
|
|
4493
4502
|
position: "fixed",
|
4494
4503
|
bottom: `${bottom}px`,
|
4495
4504
|
right: `${right}px`,
|
4496
|
-
zIndex: "
|
4505
|
+
zIndex: "2147483647",
|
4497
4506
|
width: "60px",
|
4498
4507
|
height: "60px",
|
4499
4508
|
cursor: "grab",
|
4500
4509
|
transition: "transform 0.15s ease",
|
4501
4510
|
userSelect: "none",
|
4502
|
-
touchAction: "none"
|
4511
|
+
touchAction: "none",
|
4512
|
+
pointerEvents: "auto"
|
4503
4513
|
});
|
4504
4514
|
document.body.appendChild(button);
|
4505
4515
|
updateIframePosition(iframe, right, bottom, windowWidth, windowHeight);
|
@@ -4509,17 +4519,21 @@ function createFloatingButtonWithIframe({
|
|
4509
4519
|
let initialRight = 0;
|
4510
4520
|
let initialBottom = 0;
|
4511
4521
|
let dragStartTime = 0;
|
4512
|
-
|
4522
|
+
const handleMouseDown = (e) => {
|
4513
4523
|
startDrag(e.clientX, e.clientY);
|
4514
4524
|
e.preventDefault();
|
4515
|
-
|
4516
|
-
|
4525
|
+
e.stopPropagation();
|
4526
|
+
};
|
4527
|
+
const handleTouchStart = (e) => {
|
4517
4528
|
if (e.touches.length === 1) {
|
4518
4529
|
const touch = e.touches[0];
|
4519
4530
|
startDrag(touch.clientX, touch.clientY);
|
4520
4531
|
e.preventDefault();
|
4532
|
+
e.stopPropagation();
|
4521
4533
|
}
|
4522
|
-
}
|
4534
|
+
};
|
4535
|
+
button.addEventListener("mousedown", handleMouseDown, { capture: true });
|
4536
|
+
button.addEventListener("touchstart", handleTouchStart, { capture: true });
|
4523
4537
|
function startDrag(clientX, clientY) {
|
4524
4538
|
isDragging = true;
|
4525
4539
|
startX = clientX;
|
@@ -4530,18 +4544,23 @@ function createFloatingButtonWithIframe({
|
|
4530
4544
|
button.style.cursor = "grabbing";
|
4531
4545
|
button.style.transition = "none";
|
4532
4546
|
}
|
4533
|
-
|
4547
|
+
const handleMouseMove = (e) => {
|
4534
4548
|
if (!isDragging)
|
4535
4549
|
return;
|
4536
4550
|
moveButton(e.clientX, e.clientY);
|
4537
|
-
|
4538
|
-
|
4551
|
+
e.preventDefault();
|
4552
|
+
e.stopPropagation();
|
4553
|
+
};
|
4554
|
+
const handleTouchMove = (e) => {
|
4539
4555
|
if (!isDragging || e.touches.length !== 1)
|
4540
4556
|
return;
|
4541
4557
|
const touch = e.touches[0];
|
4542
4558
|
moveButton(touch.clientX, touch.clientY);
|
4543
4559
|
e.preventDefault();
|
4544
|
-
|
4560
|
+
e.stopPropagation();
|
4561
|
+
};
|
4562
|
+
document.addEventListener("mousemove", handleMouseMove, { capture: true });
|
4563
|
+
document.addEventListener("touchmove", handleTouchMove, { capture: true });
|
4545
4564
|
function moveButton(clientX, clientY) {
|
4546
4565
|
const deltaX = startX - clientX;
|
4547
4566
|
const deltaY = startY - clientY;
|
@@ -4565,15 +4584,23 @@ function createFloatingButtonWithIframe({
|
|
4565
4584
|
button.style.bottom = `${newBottom}px`;
|
4566
4585
|
updateIframePosition(iframe, newRight, newBottom, windowWidth, windowHeight);
|
4567
4586
|
}
|
4568
|
-
|
4569
|
-
|
4570
|
-
|
4571
|
-
|
4587
|
+
const handleMouseUp = (e) => {
|
4588
|
+
if (isDragging) {
|
4589
|
+
e.preventDefault();
|
4590
|
+
e.stopPropagation();
|
4591
|
+
}
|
4572
4592
|
endDrag();
|
4573
|
-
}
|
4574
|
-
|
4593
|
+
};
|
4594
|
+
const handleTouchEnd = (e) => {
|
4595
|
+
if (isDragging) {
|
4596
|
+
e.preventDefault();
|
4597
|
+
e.stopPropagation();
|
4598
|
+
}
|
4575
4599
|
endDrag();
|
4576
|
-
}
|
4600
|
+
};
|
4601
|
+
document.addEventListener("mouseup", handleMouseUp, { capture: true });
|
4602
|
+
document.addEventListener("touchend", handleTouchEnd, { capture: true });
|
4603
|
+
document.addEventListener("touchcancel", handleTouchEnd, { capture: true });
|
4577
4604
|
function endDrag() {
|
4578
4605
|
if (!isDragging)
|
4579
4606
|
return;
|
@@ -4623,11 +4650,12 @@ function createIframe({
|
|
4623
4650
|
position: "fixed",
|
4624
4651
|
bottom: "90px",
|
4625
4652
|
right: "20px",
|
4626
|
-
zIndex: "
|
4653
|
+
zIndex: "2147483646",
|
4627
4654
|
boxShadow: "0 0 10px rgba(0, 0, 0, 0.1)",
|
4628
4655
|
borderRadius: "10px",
|
4629
4656
|
display: isVisible ? "block" : "none",
|
4630
|
-
border: "none"
|
4657
|
+
border: "none",
|
4658
|
+
pointerEvents: "auto"
|
4631
4659
|
}, iframeStyle));
|
4632
4660
|
document.body.appendChild(iframe);
|
4633
4661
|
return iframe;
|
@@ -4808,7 +4836,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
4808
4836
|
});
|
4809
4837
|
}
|
4810
4838
|
} else {
|
4811
|
-
removeWalletButton();
|
4812
4839
|
connectionUpdateTimeout = setTimeout(() => {
|
4813
4840
|
handleConnectionUpdate();
|
4814
4841
|
}, 5e3);
|
@@ -4947,7 +4974,8 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
4947
4974
|
const { transferGasTransaction, useNearPayGas, gasLimit } = yield calculateGasStrategy({
|
4948
4975
|
csna,
|
4949
4976
|
transactions: trans,
|
4950
|
-
env
|
4977
|
+
env,
|
4978
|
+
gasStrategy: metadata.gasStrategy
|
4951
4979
|
});
|
4952
4980
|
console.log("transferGasTransaction:", transferGasTransaction);
|
4953
4981
|
console.log("useNearPayGas:", useNearPayGas);
|
@@ -5019,9 +5047,10 @@ function setupBTCWallet({
|
|
5019
5047
|
autoConnect = true,
|
5020
5048
|
syncLogOut = true,
|
5021
5049
|
env = "mainnet",
|
5022
|
-
walletUrl
|
5050
|
+
walletUrl,
|
5051
|
+
gasStrategy = "auto"
|
5023
5052
|
} = {}) {
|
5024
|
-
console.log("\u26A1\uFE0F BTC Wallet Version:", getVersion(), "env:", env);
|
5053
|
+
console.log("\u26A1\uFE0F BTC Wallet Version:", getVersion(), "env:", env, "gasStrategy:", gasStrategy);
|
5025
5054
|
const btcWallet = () => __async(this, null, function* () {
|
5026
5055
|
return {
|
5027
5056
|
id: "btc-wallet",
|
@@ -5036,7 +5065,8 @@ function setupBTCWallet({
|
|
5036
5065
|
autoConnect,
|
5037
5066
|
syncLogOut,
|
5038
5067
|
env,
|
5039
|
-
walletUrl
|
5068
|
+
walletUrl,
|
5069
|
+
gasStrategy
|
5040
5070
|
},
|
5041
5071
|
init: BTCWallet
|
5042
5072
|
};
|
@@ -5118,7 +5148,7 @@ function openChainModal() {
|
|
5118
5148
|
return div;
|
5119
5149
|
};
|
5120
5150
|
return yield Dialog.openModal({
|
5121
|
-
title: "Choose
|
5151
|
+
title: "Choose Wallet",
|
5122
5152
|
titleStyle: "font-size: 18px; font-weight: 600; color: #fff; text-align: center;padding-bottom: 10px;",
|
5123
5153
|
content
|
5124
5154
|
});
|
@@ -5137,7 +5167,7 @@ function getGroup(state) {
|
|
5137
5167
|
|
5138
5168
|
// src/index.ts
|
5139
5169
|
var getVersion = () => {
|
5140
|
-
return "0.5.
|
5170
|
+
return "0.5.57-beta";
|
5141
5171
|
};
|
5142
5172
|
if (typeof window !== "undefined") {
|
5143
5173
|
window.__BTC_WALLET_VERSION = getVersion();
|