btc-wallet 0.3.15 → 0.3.16
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/dist/core/btcUtils.d.ts +2 -2
- package/dist/index.js +20 -11
- package/dist/index.js.map +2 -2
- package/esm/index.js +20 -11
- package/esm/index.js.map +2 -2
- package/package.json +1 -1
package/esm/index.js
CHANGED
@@ -2831,7 +2831,13 @@ function request(url, options) {
|
|
2831
2831
|
if (options.shouldStopPolling(data)) {
|
2832
2832
|
return data;
|
2833
2833
|
}
|
2834
|
-
|
2834
|
+
if (options.maxPollingAttempts && options.maxPollingAttempts > 0) {
|
2835
|
+
yield new Promise((resolve) => setTimeout(resolve, options.pollingInterval));
|
2836
|
+
return request(url, __spreadProps(__spreadValues({}, options), {
|
2837
|
+
maxPollingAttempts: options.maxPollingAttempts - 1
|
2838
|
+
}));
|
2839
|
+
}
|
2840
|
+
throw new Error("Polling failed: maximum attempts reached without meeting the condition");
|
2835
2841
|
}
|
2836
2842
|
if (cacheKey) {
|
2837
2843
|
cache.set(cacheKey, { timestamp: Date.now(), data });
|
@@ -3174,6 +3180,7 @@ function nearCall(contractId, methodName, args) {
|
|
3174
3180
|
function getAccountInfo(csna, accountContractId) {
|
3175
3181
|
return __async(this, null, function* () {
|
3176
3182
|
const accountInfo = yield nearCall(accountContractId, "get_account", { account_id: csna });
|
3183
|
+
console.log("get_account accountInfo:", accountInfo);
|
3177
3184
|
return accountInfo;
|
3178
3185
|
});
|
3179
3186
|
}
|
@@ -3244,16 +3251,17 @@ function getBtcBalance() {
|
|
3244
3251
|
}
|
3245
3252
|
const btcRpcUrl = yield getBtcRpcUrl();
|
3246
3253
|
const utxos = yield fetch(`${btcRpcUrl}/address/${account}/utxo`).then((res) => res.json());
|
3254
|
+
const btcDecimals = 8;
|
3247
3255
|
const rawBalance = (utxos == null ? void 0 : utxos.reduce((acc, cur) => acc + cur.value, 0)) || 0;
|
3248
|
-
const balance = rawBalance / __pow(10,
|
3256
|
+
const balance = rawBalance / __pow(10, btcDecimals);
|
3249
3257
|
const feeRate = yield getBtcGasPrice();
|
3250
3258
|
const inputSize = ((utxos == null ? void 0 : utxos.length) || 0) * 66;
|
3251
3259
|
const outputSize = 34;
|
3252
3260
|
const overheadSize = 10;
|
3253
3261
|
const estimatedTxSize = inputSize + outputSize + overheadSize;
|
3254
|
-
const estimatedFee = estimatedTxSize * feeRate
|
3255
|
-
|
3256
|
-
const availableBalance =
|
3262
|
+
const estimatedFee = estimatedTxSize * feeRate;
|
3263
|
+
const availableRawBalance = (rawBalance - estimatedFee).toFixed(0);
|
3264
|
+
const availableBalance = new Big(availableRawBalance).div(__pow(10, btcDecimals)).round(btcDecimals, Big.roundDown).toNumber();
|
3257
3265
|
return {
|
3258
3266
|
rawBalance,
|
3259
3267
|
balance,
|
@@ -3330,7 +3338,7 @@ function executeBTCDepositAndAction(_0) {
|
|
3330
3338
|
const accountInfo = yield getAccountInfo(csna, config.accountContractId);
|
3331
3339
|
const newActions = [];
|
3332
3340
|
const gasLimit = new Big(50).mul(__pow(10, 12)).toFixed(0);
|
3333
|
-
const repayAction = yield checkGasTokenArrears(accountInfo.debt_info, isDev, false);
|
3341
|
+
const repayAction = yield checkGasTokenArrears(accountInfo == null ? void 0 : accountInfo.debt_info, isDev, false);
|
3334
3342
|
if (repayAction) {
|
3335
3343
|
newActions.push(__spreadProps(__spreadValues({}, repayAction), {
|
3336
3344
|
gas: gasLimit
|
@@ -3600,10 +3608,10 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3600
3608
|
const accountId = state.getAccount();
|
3601
3609
|
const accountInfo = yield getAccountInfo(accountId, currentConfig.accountContractId);
|
3602
3610
|
yield checkGasTokenBalance(accountId, currentConfig.token, isDev);
|
3603
|
-
yield checkGasTokenArrears(accountInfo.debt_info, isDev, true);
|
3611
|
+
yield checkGasTokenArrears(accountInfo == null ? void 0 : accountInfo.debt_info, isDev, true);
|
3604
3612
|
const trans = [...params.transactions];
|
3605
3613
|
console.log("raw trans:", trans);
|
3606
|
-
const gasTokenBalance = accountInfo.gas_token[currentConfig.token] || "0";
|
3614
|
+
const gasTokenBalance = (accountInfo == null ? void 0 : accountInfo.gas_token[currentConfig.token]) || "0";
|
3607
3615
|
const { transferGasTransaction, useNearPayGas, gasLimit } = yield calculateGasStrategy(
|
3608
3616
|
gasTokenBalance,
|
3609
3617
|
trans
|
@@ -3619,7 +3627,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3619
3627
|
trans.map((transaction, index) => convertTransactionToTxHex(transaction, index))
|
3620
3628
|
);
|
3621
3629
|
const nonceFromApi = yield getNonce(currentConfig.base_url, accountId);
|
3622
|
-
const nonce = Number(nonceFromApi) > Number(accountInfo.nonce) ? String(nonceFromApi) : String(accountInfo.nonce);
|
3630
|
+
const nonce = Number(nonceFromApi) > Number(accountInfo == null ? void 0 : accountInfo.nonce) ? String(nonceFromApi) : String(accountInfo == null ? void 0 : accountInfo.nonce);
|
3623
3631
|
const intention = {
|
3624
3632
|
chain_id: "397",
|
3625
3633
|
csna: accountId,
|
@@ -3836,6 +3844,7 @@ function setupBTCWallet({
|
|
3836
3844
|
syncLogOut = true,
|
3837
3845
|
isDev = false
|
3838
3846
|
} = {}) {
|
3847
|
+
console.log("\u26A1\uFE0F BTC Wallet Version:", getVersion());
|
3839
3848
|
const btcWallet = () => __async(this, null, function* () {
|
3840
3849
|
return {
|
3841
3850
|
id: "btc-wallet",
|
@@ -3859,10 +3868,10 @@ function setupBTCWallet({
|
|
3859
3868
|
|
3860
3869
|
// src/index.ts
|
3861
3870
|
var getVersion = () => {
|
3862
|
-
return "0.3.
|
3871
|
+
return "0.3.16";
|
3863
3872
|
};
|
3864
3873
|
if (typeof window !== "undefined") {
|
3865
|
-
window.
|
3874
|
+
window.__BTC_WALLET_VERSION = getVersion();
|
3866
3875
|
}
|
3867
3876
|
export {
|
3868
3877
|
BaseConnector,
|