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/esm/index.js
CHANGED
@@ -418,39 +418,11 @@ var XverseConnector = class extends BaseConnector {
|
|
418
418
|
if (!provider) {
|
419
419
|
throw new Error(`${this.metadata.name} is not install!`);
|
420
420
|
}
|
421
|
-
const {
|
422
|
-
|
423
|
-
if (addresses.length === 0) {
|
424
|
-
throw new Error(`${this.metadata.name} not connected!`);
|
425
|
-
}
|
426
|
-
const result = yield new Promise((resolve, reject) => {
|
427
|
-
const sendBtcOptions = {
|
428
|
-
payload: {
|
429
|
-
network: {
|
430
|
-
type: __privateGet(this, _network)
|
431
|
-
},
|
432
|
-
recipients: [
|
433
|
-
{
|
434
|
-
address: toAddress,
|
435
|
-
amountSats: BigInt(satoshis)
|
436
|
-
}
|
437
|
-
],
|
438
|
-
senderAddress: addresses[0]
|
439
|
-
},
|
440
|
-
onFinish: (response) => {
|
441
|
-
resolve(response);
|
442
|
-
},
|
443
|
-
onCancel: () => {
|
444
|
-
reject({
|
445
|
-
code: 4001,
|
446
|
-
message: "User rejected the request."
|
447
|
-
});
|
448
|
-
}
|
449
|
-
};
|
450
|
-
console.log("\u{1F680} ~ XverseConnector ~ sendBitcoin ~ sendBtcOptions:", sendBtcOptions);
|
451
|
-
sendBtcTransaction(sendBtcOptions).catch((e) => reject(e));
|
421
|
+
const { result } = yield provider.request("sendTransfer", {
|
422
|
+
recipients: [{ address: toAddress, amount: satoshis }]
|
452
423
|
});
|
453
|
-
|
424
|
+
console.log("\u{1F680} ~ XverseConnector ~ sendBitcoin ~ res:", result);
|
425
|
+
return result.txid;
|
454
426
|
});
|
455
427
|
}
|
456
428
|
disconnect() {
|
@@ -3259,6 +3231,8 @@ function getAccountInfo(csna, accountContractId) {
|
|
3259
3231
|
return __async(this, null, function* () {
|
3260
3232
|
const accountInfo = yield nearCall(accountContractId, "get_account", {
|
3261
3233
|
account_id: csna
|
3234
|
+
}).catch((error) => {
|
3235
|
+
return void 0;
|
3262
3236
|
});
|
3263
3237
|
console.log("get_account accountInfo:", accountInfo);
|
3264
3238
|
return accountInfo;
|
@@ -3371,8 +3345,11 @@ function sendBitcoin(address, amount, feeRate) {
|
|
3371
3345
|
}
|
3372
3346
|
function estimateDepositAmount(amount, option) {
|
3373
3347
|
return __async(this, null, function* () {
|
3348
|
+
const config = yield getConfig((option == null ? void 0 : option.env) || "mainnet");
|
3349
|
+
const csna = yield getCsnaAccountId((option == null ? void 0 : option.env) || "mainnet");
|
3350
|
+
const accountInfo = yield getAccountInfo(csna, config.accountContractId);
|
3374
3351
|
const { receiveAmount } = yield getDepositAmount(amount, __spreadProps(__spreadValues({}, option), { isEstimate: true }));
|
3375
|
-
return receiveAmount;
|
3352
|
+
return (accountInfo == null ? void 0 : accountInfo.nonce) ? receiveAmount : new Big(receiveAmount).minus(NBTC_STORAGE_DEPOSIT_AMOUNT).round(0, Big.roundDown).toNumber();
|
3376
3353
|
});
|
3377
3354
|
}
|
3378
3355
|
function getDepositAmount(amount, option) {
|
@@ -3445,18 +3422,11 @@ function executeBTCDepositAndAction(_0) {
|
|
3445
3422
|
gas: GAS_LIMIT
|
3446
3423
|
}));
|
3447
3424
|
}
|
3448
|
-
if (action
|
3449
|
-
newActions.push(
|
3450
|
-
|
3451
|
-
|
3452
|
-
|
3453
|
-
}) : {
|
3454
|
-
receiver_id: config.accountContractId,
|
3455
|
-
amount: MINIMUM_DEPOSIT_AMOUNT_BASE.toString(),
|
3456
|
-
msg: JSON.stringify("Deposit"),
|
3457
|
-
gas: GAS_LIMIT
|
3458
|
-
}
|
3459
|
-
);
|
3425
|
+
if (action) {
|
3426
|
+
newActions.push(__spreadProps(__spreadValues({}, action), {
|
3427
|
+
amount: (arrearsAction == null ? void 0 : arrearsAction.amount) && !fixedAmount ? new Big(receiveAmount).minus(arrearsAction.amount).toString() : receiveAmount.toString(),
|
3428
|
+
gas: GAS_LIMIT
|
3429
|
+
}));
|
3460
3430
|
}
|
3461
3431
|
const storageDepositMsg = {};
|
3462
3432
|
const registerRes = yield nearCall((action == null ? void 0 : action.receiver_id) || config.token, "storage_balance_of", {
|
@@ -3840,7 +3810,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3840
3810
|
args: {
|
3841
3811
|
receiver_id: currentConfig.accountContractId,
|
3842
3812
|
amount,
|
3843
|
-
msg: JSON.stringify("
|
3813
|
+
msg: JSON.stringify("Repay")
|
3844
3814
|
},
|
3845
3815
|
gas: new Big2(50).mul(__pow(10, 12)).toFixed(0),
|
3846
3816
|
deposit: "1"
|
@@ -3874,7 +3844,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3874
3844
|
near_transactions: transactions2
|
3875
3845
|
});
|
3876
3846
|
const predictedGasAmount = new Big2(predictedGas).mul(1.2).toFixed(0);
|
3877
|
-
const miniGasAmount = 200;
|
3847
|
+
const miniGasAmount = 200 * transactions2.length;
|
3878
3848
|
const gasAmount = Math.max(Number(predictedGasAmount), miniGasAmount);
|
3879
3849
|
console.log("predictedGas:", predictedGasAmount);
|
3880
3850
|
return gasAmount.toString();
|
@@ -4009,7 +3979,7 @@ function setupBTCWallet({
|
|
4009
3979
|
|
4010
3980
|
// src/index.ts
|
4011
3981
|
var getVersion = () => {
|
4012
|
-
return "0.4.
|
3982
|
+
return "0.4.4-beta";
|
4013
3983
|
};
|
4014
3984
|
if (typeof window !== "undefined") {
|
4015
3985
|
window.__BTC_WALLET_VERSION = getVersion();
|