btc-wallet 0.5.55-beta → 0.5.56-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 +52 -41
- package/dist/index.js.map +2 -2
- package/dist/utils/satoshi.d.ts +4 -1
- package/esm/index.js +52 -41
- 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) {
|
@@ -4808,7 +4817,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
4808
4817
|
});
|
4809
4818
|
}
|
4810
4819
|
} else {
|
4811
|
-
removeWalletButton();
|
4812
4820
|
connectionUpdateTimeout = setTimeout(() => {
|
4813
4821
|
handleConnectionUpdate();
|
4814
4822
|
}, 5e3);
|
@@ -4947,7 +4955,8 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
4947
4955
|
const { transferGasTransaction, useNearPayGas, gasLimit } = yield calculateGasStrategy({
|
4948
4956
|
csna,
|
4949
4957
|
transactions: trans,
|
4950
|
-
env
|
4958
|
+
env,
|
4959
|
+
gasStrategy: metadata.gasStrategy
|
4951
4960
|
});
|
4952
4961
|
console.log("transferGasTransaction:", transferGasTransaction);
|
4953
4962
|
console.log("useNearPayGas:", useNearPayGas);
|
@@ -5019,9 +5028,10 @@ function setupBTCWallet({
|
|
5019
5028
|
autoConnect = true,
|
5020
5029
|
syncLogOut = true,
|
5021
5030
|
env = "mainnet",
|
5022
|
-
walletUrl
|
5031
|
+
walletUrl,
|
5032
|
+
gasStrategy = "auto"
|
5023
5033
|
} = {}) {
|
5024
|
-
console.log("\u26A1\uFE0F BTC Wallet Version:", getVersion(), "env:", env);
|
5034
|
+
console.log("\u26A1\uFE0F BTC Wallet Version:", getVersion(), "env:", env, "gasStrategy:", gasStrategy);
|
5025
5035
|
const btcWallet = () => __async(this, null, function* () {
|
5026
5036
|
return {
|
5027
5037
|
id: "btc-wallet",
|
@@ -5036,7 +5046,8 @@ function setupBTCWallet({
|
|
5036
5046
|
autoConnect,
|
5037
5047
|
syncLogOut,
|
5038
5048
|
env,
|
5039
|
-
walletUrl
|
5049
|
+
walletUrl,
|
5050
|
+
gasStrategy
|
5040
5051
|
},
|
5041
5052
|
init: BTCWallet
|
5042
5053
|
};
|
@@ -5118,7 +5129,7 @@ function openChainModal() {
|
|
5118
5129
|
return div;
|
5119
5130
|
};
|
5120
5131
|
return yield Dialog.openModal({
|
5121
|
-
title: "Choose
|
5132
|
+
title: "Choose Wallet",
|
5122
5133
|
titleStyle: "font-size: 18px; font-weight: 600; color: #fff; text-align: center;padding-bottom: 10px;",
|
5123
5134
|
content
|
5124
5135
|
});
|
@@ -5137,7 +5148,7 @@ function getGroup(state) {
|
|
5137
5148
|
|
5138
5149
|
// src/index.ts
|
5139
5150
|
var getVersion = () => {
|
5140
|
-
return "0.5.
|
5151
|
+
return "0.5.56-beta";
|
5141
5152
|
};
|
5142
5153
|
if (typeof window !== "undefined") {
|
5143
5154
|
window.__BTC_WALLET_VERSION = getVersion();
|