btc-wallet 0.3.28 → 0.3.30
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +5 -4
- package/dist/core/btcUtils.d.ts +13 -7
- package/dist/index.js +21 -16
- package/dist/index.js.map +2 -2
- package/esm/index.js +21 -16
- package/esm/index.js.map +2 -2
- package/package.json +1 -1
package/esm/index.js
CHANGED
@@ -3219,7 +3219,9 @@ function nearCall(contractId, methodName, args) {
|
|
3219
3219
|
}
|
3220
3220
|
function getAccountInfo(csna, accountContractId) {
|
3221
3221
|
return __async(this, null, function* () {
|
3222
|
-
const accountInfo = yield nearCall(accountContractId, "get_account", {
|
3222
|
+
const accountInfo = yield nearCall(accountContractId, "get_account", {
|
3223
|
+
account_id: csna
|
3224
|
+
});
|
3223
3225
|
console.log("get_account accountInfo:", accountInfo);
|
3224
3226
|
return accountInfo;
|
3225
3227
|
});
|
@@ -3239,23 +3241,25 @@ function checkGasTokenBalance(csna, gasToken, minAmount, env) {
|
|
3239
3241
|
}
|
3240
3242
|
});
|
3241
3243
|
}
|
3242
|
-
function checkGasTokenArrears(
|
3244
|
+
function checkGasTokenArrears(accountInfo, env, autoDeposit) {
|
3243
3245
|
return __async(this, null, function* () {
|
3244
|
-
|
3246
|
+
var _a, _b, _c, _d;
|
3247
|
+
if (!((_a = accountInfo == null ? void 0 : accountInfo.debt_info) == null ? void 0 : _a.transfer_amount) || !((_b = accountInfo == null ? void 0 : accountInfo.relayer_fee) == null ? void 0 : _b.amount))
|
3245
3248
|
return;
|
3246
3249
|
const config = yield getConfig(env);
|
3247
|
-
const
|
3248
|
-
|
3250
|
+
const arrearsType = accountInfo.debt_info.transfer_amount ? "Deposit" : ((_c = accountInfo.relayer_fee) == null ? void 0 : _c.amount) ? "RelayerFee" : void 0;
|
3251
|
+
const transferAmount = arrearsType === "Deposit" ? accountInfo.debt_info.transfer_amount : (_d = accountInfo.relayer_fee) == null ? void 0 : _d.amount;
|
3252
|
+
console.log("get_account:", accountInfo);
|
3249
3253
|
const action = {
|
3250
3254
|
receiver_id: config.accountContractId,
|
3251
3255
|
amount: transferAmount,
|
3252
|
-
msg: JSON.stringify(
|
3256
|
+
msg: JSON.stringify(arrearsType)
|
3253
3257
|
};
|
3254
3258
|
if (!autoDeposit)
|
3255
3259
|
return action;
|
3256
3260
|
const confirmed = yield Dialog.confirm({
|
3257
|
-
title: "Has gas token arrears",
|
3258
|
-
message: "You have gas token arrears, please deposit gas token to continue."
|
3261
|
+
title: arrearsType === "Deposit" ? "Has gas token arrears" : "Has relayer fee arrears",
|
3262
|
+
message: arrearsType === "Deposit" ? "You have gas token arrears, please deposit gas token to continue." : "You have relayer fee arrears, please deposit relayer fee to continue."
|
3259
3263
|
});
|
3260
3264
|
if (confirmed) {
|
3261
3265
|
yield executeBTCDepositAndAction({ action, env });
|
@@ -3373,6 +3377,7 @@ function executeBTCDepositAndAction(_0) {
|
|
3373
3377
|
feeRate,
|
3374
3378
|
fixedAmount = true,
|
3375
3379
|
pollResult = true,
|
3380
|
+
registerDeposit,
|
3376
3381
|
env = "mainnet"
|
3377
3382
|
}) {
|
3378
3383
|
var _a;
|
@@ -3396,16 +3401,16 @@ function executeBTCDepositAndAction(_0) {
|
|
3396
3401
|
});
|
3397
3402
|
const accountInfo = yield getAccountInfo(csna, config.accountContractId);
|
3398
3403
|
const newActions = [];
|
3399
|
-
const
|
3400
|
-
if (
|
3401
|
-
newActions.push(__spreadProps(__spreadValues({},
|
3404
|
+
const arrearsAction = yield checkGasTokenArrears(accountInfo, env, false);
|
3405
|
+
if (arrearsAction) {
|
3406
|
+
newActions.push(__spreadProps(__spreadValues({}, arrearsAction), {
|
3402
3407
|
gas: GAS_LIMIT
|
3403
3408
|
}));
|
3404
3409
|
}
|
3405
3410
|
if (action || !action && new Big((accountInfo == null ? void 0 : accountInfo.gas_token[config.token]) || 0).lt(MINIMUM_DEPOSIT_AMOUNT_BASE)) {
|
3406
3411
|
newActions.push(
|
3407
3412
|
action ? __spreadProps(__spreadValues({}, action), {
|
3408
|
-
amount: (
|
3413
|
+
amount: (arrearsAction == null ? void 0 : arrearsAction.amount) && !fixedAmount ? new Big(receiveAmount).minus(arrearsAction.amount).toString() : receiveAmount.toString(),
|
3409
3414
|
gas: GAS_LIMIT
|
3410
3415
|
}) : {
|
3411
3416
|
receiver_id: config.accountContractId,
|
@@ -3422,7 +3427,7 @@ function executeBTCDepositAndAction(_0) {
|
|
3422
3427
|
if (!(registerRes == null ? void 0 : registerRes.available)) {
|
3423
3428
|
storageDepositMsg.storage_deposit_msg = {
|
3424
3429
|
contract_id: (action == null ? void 0 : action.receiver_id) || config.token,
|
3425
|
-
deposit: NEAR_STORAGE_DEPOSIT_AMOUNT,
|
3430
|
+
deposit: registerDeposit || NEAR_STORAGE_DEPOSIT_AMOUNT,
|
3426
3431
|
registration_only: true
|
3427
3432
|
};
|
3428
3433
|
}
|
@@ -3447,7 +3452,7 @@ function executeBTCDepositAndAction(_0) {
|
|
3447
3452
|
{ deposit_msg: depositMsg }
|
3448
3453
|
);
|
3449
3454
|
const _feeRate = feeRate || (yield getBtcGasPrice());
|
3450
|
-
const sendAmount = (
|
3455
|
+
const sendAmount = (arrearsAction == null ? void 0 : arrearsAction.amount) && fixedAmount ? new Big(depositAmount).plus((arrearsAction == null ? void 0 : arrearsAction.amount) || 0).toString() : depositAmount;
|
3451
3456
|
console.log("user deposit address:", userDepositAddress);
|
3452
3457
|
console.log("send amount:", sendAmount);
|
3453
3458
|
console.log("fee rate:", _feeRate);
|
@@ -3696,7 +3701,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3696
3701
|
const btcContext = window.btcContext;
|
3697
3702
|
const accountId = state.getAccount();
|
3698
3703
|
const accountInfo = yield getAccountInfo(accountId, currentConfig.accountContractId);
|
3699
|
-
yield checkGasTokenArrears(accountInfo
|
3704
|
+
yield checkGasTokenArrears(accountInfo, env, true);
|
3700
3705
|
const trans = [...params.transactions];
|
3701
3706
|
console.log("raw trans:", trans);
|
3702
3707
|
const gasTokenBalance = (accountInfo == null ? void 0 : accountInfo.gas_token[currentConfig.token]) || "0";
|
@@ -3954,7 +3959,7 @@ function setupBTCWallet({
|
|
3954
3959
|
|
3955
3960
|
// src/index.ts
|
3956
3961
|
var getVersion = () => {
|
3957
|
-
return "0.3.
|
3962
|
+
return "0.3.30";
|
3958
3963
|
};
|
3959
3964
|
if (typeof window !== "undefined") {
|
3960
3965
|
window.__BTC_WALLET_VERSION = getVersion();
|