btc-wallet 0.4.2-beta → 0.4.4-beta
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/core/btcUtils.d.ts +1 -1
- package/dist/index.js +18 -48
- package/dist/index.js.map +2 -2
- package/esm/index.js +18 -48
- package/esm/index.js.map +2 -2
- package/package.json +1 -1
package/dist/core/btcUtils.d.ts
CHANGED
@@ -13,7 +13,7 @@ export interface DebtInfo {
|
|
13
13
|
near_gas_debt_amount: string;
|
14
14
|
protocol_fee_debt_amount: string;
|
15
15
|
}
|
16
|
-
export declare function getAccountInfo(csna: string, accountContractId: string): Promise<AccountInfo>;
|
16
|
+
export declare function getAccountInfo(csna: string, accountContractId: string): Promise<AccountInfo | undefined>;
|
17
17
|
export declare function checkGasTokenBalance(csna: string, gasToken: string, minAmount: string, env: ENV): Promise<void>;
|
18
18
|
type CheckGasTokenArrearsReturnType<T extends boolean> = T extends true ? void : {
|
19
19
|
receiver_id: string;
|
package/dist/index.js
CHANGED
@@ -479,39 +479,11 @@ var XverseConnector = class extends BaseConnector {
|
|
479
479
|
if (!provider) {
|
480
480
|
throw new Error(`${this.metadata.name} is not install!`);
|
481
481
|
}
|
482
|
-
const {
|
483
|
-
|
484
|
-
if (addresses.length === 0) {
|
485
|
-
throw new Error(`${this.metadata.name} not connected!`);
|
486
|
-
}
|
487
|
-
const result = yield new Promise((resolve, reject) => {
|
488
|
-
const sendBtcOptions = {
|
489
|
-
payload: {
|
490
|
-
network: {
|
491
|
-
type: __privateGet(this, _network)
|
492
|
-
},
|
493
|
-
recipients: [
|
494
|
-
{
|
495
|
-
address: toAddress,
|
496
|
-
amountSats: BigInt(satoshis)
|
497
|
-
}
|
498
|
-
],
|
499
|
-
senderAddress: addresses[0]
|
500
|
-
},
|
501
|
-
onFinish: (response) => {
|
502
|
-
resolve(response);
|
503
|
-
},
|
504
|
-
onCancel: () => {
|
505
|
-
reject({
|
506
|
-
code: 4001,
|
507
|
-
message: "User rejected the request."
|
508
|
-
});
|
509
|
-
}
|
510
|
-
};
|
511
|
-
console.log("\u{1F680} ~ XverseConnector ~ sendBitcoin ~ sendBtcOptions:", sendBtcOptions);
|
512
|
-
sendBtcTransaction(sendBtcOptions).catch((e) => reject(e));
|
482
|
+
const { result } = yield provider.request("sendTransfer", {
|
483
|
+
recipients: [{ address: toAddress, amount: satoshis }]
|
513
484
|
});
|
514
|
-
|
485
|
+
console.log("\u{1F680} ~ XverseConnector ~ sendBitcoin ~ res:", result);
|
486
|
+
return result.txid;
|
515
487
|
});
|
516
488
|
}
|
517
489
|
disconnect() {
|
@@ -3306,6 +3278,8 @@ function getAccountInfo(csna, accountContractId) {
|
|
3306
3278
|
return __async(this, null, function* () {
|
3307
3279
|
const accountInfo = yield nearCall(accountContractId, "get_account", {
|
3308
3280
|
account_id: csna
|
3281
|
+
}).catch((error) => {
|
3282
|
+
return void 0;
|
3309
3283
|
});
|
3310
3284
|
console.log("get_account accountInfo:", accountInfo);
|
3311
3285
|
return accountInfo;
|
@@ -3418,8 +3392,11 @@ function sendBitcoin(address, amount, feeRate) {
|
|
3418
3392
|
}
|
3419
3393
|
function estimateDepositAmount(amount, option) {
|
3420
3394
|
return __async(this, null, function* () {
|
3395
|
+
const config = yield getConfig((option == null ? void 0 : option.env) || "mainnet");
|
3396
|
+
const csna = yield getCsnaAccountId((option == null ? void 0 : option.env) || "mainnet");
|
3397
|
+
const accountInfo = yield getAccountInfo(csna, config.accountContractId);
|
3421
3398
|
const { receiveAmount } = yield getDepositAmount(amount, __spreadProps(__spreadValues({}, option), { isEstimate: true }));
|
3422
|
-
return receiveAmount;
|
3399
|
+
return (accountInfo == null ? void 0 : accountInfo.nonce) ? receiveAmount : new import_big.default(receiveAmount).minus(NBTC_STORAGE_DEPOSIT_AMOUNT).round(0, import_big.default.roundDown).toNumber();
|
3423
3400
|
});
|
3424
3401
|
}
|
3425
3402
|
function getDepositAmount(amount, option) {
|
@@ -3492,18 +3469,11 @@ function executeBTCDepositAndAction(_0) {
|
|
3492
3469
|
gas: GAS_LIMIT
|
3493
3470
|
}));
|
3494
3471
|
}
|
3495
|
-
if (action
|
3496
|
-
newActions.push(
|
3497
|
-
|
3498
|
-
|
3499
|
-
|
3500
|
-
}) : {
|
3501
|
-
receiver_id: config.accountContractId,
|
3502
|
-
amount: MINIMUM_DEPOSIT_AMOUNT_BASE.toString(),
|
3503
|
-
msg: JSON.stringify("Deposit"),
|
3504
|
-
gas: GAS_LIMIT
|
3505
|
-
}
|
3506
|
-
);
|
3472
|
+
if (action) {
|
3473
|
+
newActions.push(__spreadProps(__spreadValues({}, action), {
|
3474
|
+
amount: (arrearsAction == null ? void 0 : arrearsAction.amount) && !fixedAmount ? new import_big.default(receiveAmount).minus(arrearsAction.amount).toString() : receiveAmount.toString(),
|
3475
|
+
gas: GAS_LIMIT
|
3476
|
+
}));
|
3507
3477
|
}
|
3508
3478
|
const storageDepositMsg = {};
|
3509
3479
|
const registerRes = yield nearCall((action == null ? void 0 : action.receiver_id) || config.token, "storage_balance_of", {
|
@@ -3887,7 +3857,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3887
3857
|
args: {
|
3888
3858
|
receiver_id: currentConfig.accountContractId,
|
3889
3859
|
amount,
|
3890
|
-
msg: JSON.stringify("
|
3860
|
+
msg: JSON.stringify("Repay")
|
3891
3861
|
},
|
3892
3862
|
gas: new import_big2.default(50).mul(__pow(10, 12)).toFixed(0),
|
3893
3863
|
deposit: "1"
|
@@ -3921,7 +3891,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3921
3891
|
near_transactions: transactions2
|
3922
3892
|
});
|
3923
3893
|
const predictedGasAmount = new import_big2.default(predictedGas).mul(1.2).toFixed(0);
|
3924
|
-
const miniGasAmount = 200;
|
3894
|
+
const miniGasAmount = 200 * transactions2.length;
|
3925
3895
|
const gasAmount = Math.max(Number(predictedGasAmount), miniGasAmount);
|
3926
3896
|
console.log("predictedGas:", predictedGasAmount);
|
3927
3897
|
return gasAmount.toString();
|
@@ -4056,7 +4026,7 @@ function setupBTCWallet({
|
|
4056
4026
|
|
4057
4027
|
// src/index.ts
|
4058
4028
|
var getVersion = () => {
|
4059
|
-
return "0.4.
|
4029
|
+
return "0.4.4-beta";
|
4060
4030
|
};
|
4061
4031
|
if (typeof window !== "undefined") {
|
4062
4032
|
window.__BTC_WALLET_VERSION = getVersion();
|