btc-wallet 0.3.29 → 0.3.30
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +3 -4
- package/dist/core/btcUtils.d.ts +10 -6
- package/dist/index.js +19 -15
- package/dist/index.js.map +2 -2
- package/esm/index.js +19 -15
- package/esm/index.js.map +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
@@ -75,11 +75,10 @@ interface ExecuteBTCDepositAndActionParams<T extends boolean = true> {
|
|
75
75
|
// Example 1: dApp one-click BTC deposit
|
76
76
|
await executeBTCDepositAndAction({
|
77
77
|
action: {
|
78
|
-
receiver_id: '
|
79
|
-
amount: '1000000',
|
80
|
-
msg: '
|
78
|
+
receiver_id: 'token.near',
|
79
|
+
amount: '1000000',
|
80
|
+
msg: 'ft_transfer_call message' // ft_transfer_call message
|
81
81
|
},
|
82
|
-
feeRate: 5,
|
83
82
|
registerDeposit: '100000000000000000000000', // default 0.000125 NEAR, you can set it according to your needs
|
84
83
|
});
|
85
84
|
|
package/dist/core/btcUtils.d.ts
CHANGED
@@ -1,23 +1,27 @@
|
|
1
1
|
import type { ENV } from '../config';
|
2
2
|
import type { FinalExecutionOutcome } from '@near-wallet-selector/core';
|
3
|
+
export interface AccountInfo {
|
4
|
+
nonce: string;
|
5
|
+
gas_token: Record<string, string>;
|
6
|
+
debt_info?: DebtInfo;
|
7
|
+
relayer_fee?: {
|
8
|
+
amount?: string;
|
9
|
+
};
|
10
|
+
}
|
3
11
|
export interface DebtInfo {
|
4
12
|
gas_token_id: string;
|
5
13
|
transfer_amount: string;
|
6
14
|
near_gas_debt_amount: string;
|
7
15
|
protocol_fee_debt_amount: string;
|
8
16
|
}
|
9
|
-
export declare function getAccountInfo(csna: string, accountContractId: string): Promise<
|
10
|
-
nonce: string;
|
11
|
-
gas_token: Record<string, string>;
|
12
|
-
debt_info?: DebtInfo;
|
13
|
-
} | undefined>;
|
17
|
+
export declare function getAccountInfo(csna: string, accountContractId: string): Promise<AccountInfo>;
|
14
18
|
export declare function checkGasTokenBalance(csna: string, gasToken: string, minAmount: string, env: ENV): Promise<void>;
|
15
19
|
type CheckGasTokenArrearsReturnType<T extends boolean> = T extends true ? void : {
|
16
20
|
receiver_id: string;
|
17
21
|
amount: string;
|
18
22
|
msg: string;
|
19
23
|
} | undefined;
|
20
|
-
export declare function checkGasTokenArrears<T extends boolean>(
|
24
|
+
export declare function checkGasTokenArrears<T extends boolean>(accountInfo: AccountInfo | undefined, env: ENV, autoDeposit?: T): Promise<CheckGasTokenArrearsReturnType<T>>;
|
21
25
|
export declare function queryGasTokenArrears(env: ENV): Promise<DebtInfo | undefined>;
|
22
26
|
export declare function getBtcGasPrice(): Promise<number>;
|
23
27
|
export declare function getBtcBalance(): Promise<{
|
package/dist/index.js
CHANGED
@@ -3265,7 +3265,9 @@ function nearCall(contractId, methodName, args) {
|
|
3265
3265
|
}
|
3266
3266
|
function getAccountInfo(csna, accountContractId) {
|
3267
3267
|
return __async(this, null, function* () {
|
3268
|
-
const accountInfo = yield nearCall(accountContractId, "get_account", {
|
3268
|
+
const accountInfo = yield nearCall(accountContractId, "get_account", {
|
3269
|
+
account_id: csna
|
3270
|
+
});
|
3269
3271
|
console.log("get_account accountInfo:", accountInfo);
|
3270
3272
|
return accountInfo;
|
3271
3273
|
});
|
@@ -3285,23 +3287,25 @@ function checkGasTokenBalance(csna, gasToken, minAmount, env) {
|
|
3285
3287
|
}
|
3286
3288
|
});
|
3287
3289
|
}
|
3288
|
-
function checkGasTokenArrears(
|
3290
|
+
function checkGasTokenArrears(accountInfo, env, autoDeposit) {
|
3289
3291
|
return __async(this, null, function* () {
|
3290
|
-
|
3292
|
+
var _a, _b, _c, _d;
|
3293
|
+
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))
|
3291
3294
|
return;
|
3292
3295
|
const config = yield getConfig(env);
|
3293
|
-
const
|
3294
|
-
|
3296
|
+
const arrearsType = accountInfo.debt_info.transfer_amount ? "Deposit" : ((_c = accountInfo.relayer_fee) == null ? void 0 : _c.amount) ? "RelayerFee" : void 0;
|
3297
|
+
const transferAmount = arrearsType === "Deposit" ? accountInfo.debt_info.transfer_amount : (_d = accountInfo.relayer_fee) == null ? void 0 : _d.amount;
|
3298
|
+
console.log("get_account:", accountInfo);
|
3295
3299
|
const action = {
|
3296
3300
|
receiver_id: config.accountContractId,
|
3297
3301
|
amount: transferAmount,
|
3298
|
-
msg: JSON.stringify(
|
3302
|
+
msg: JSON.stringify(arrearsType)
|
3299
3303
|
};
|
3300
3304
|
if (!autoDeposit)
|
3301
3305
|
return action;
|
3302
3306
|
const confirmed = yield Dialog.confirm({
|
3303
|
-
title: "Has gas token arrears",
|
3304
|
-
message: "You have gas token arrears, please deposit gas token to continue."
|
3307
|
+
title: arrearsType === "Deposit" ? "Has gas token arrears" : "Has relayer fee arrears",
|
3308
|
+
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."
|
3305
3309
|
});
|
3306
3310
|
if (confirmed) {
|
3307
3311
|
yield executeBTCDepositAndAction({ action, env });
|
@@ -3443,16 +3447,16 @@ function executeBTCDepositAndAction(_0) {
|
|
3443
3447
|
});
|
3444
3448
|
const accountInfo = yield getAccountInfo(csna, config.accountContractId);
|
3445
3449
|
const newActions = [];
|
3446
|
-
const
|
3447
|
-
if (
|
3448
|
-
newActions.push(__spreadProps(__spreadValues({},
|
3450
|
+
const arrearsAction = yield checkGasTokenArrears(accountInfo, env, false);
|
3451
|
+
if (arrearsAction) {
|
3452
|
+
newActions.push(__spreadProps(__spreadValues({}, arrearsAction), {
|
3449
3453
|
gas: GAS_LIMIT
|
3450
3454
|
}));
|
3451
3455
|
}
|
3452
3456
|
if (action || !action && new import_big.default((accountInfo == null ? void 0 : accountInfo.gas_token[config.token]) || 0).lt(MINIMUM_DEPOSIT_AMOUNT_BASE)) {
|
3453
3457
|
newActions.push(
|
3454
3458
|
action ? __spreadProps(__spreadValues({}, action), {
|
3455
|
-
amount: (
|
3459
|
+
amount: (arrearsAction == null ? void 0 : arrearsAction.amount) && !fixedAmount ? new import_big.default(receiveAmount).minus(arrearsAction.amount).toString() : receiveAmount.toString(),
|
3456
3460
|
gas: GAS_LIMIT
|
3457
3461
|
}) : {
|
3458
3462
|
receiver_id: config.accountContractId,
|
@@ -3494,7 +3498,7 @@ function executeBTCDepositAndAction(_0) {
|
|
3494
3498
|
{ deposit_msg: depositMsg }
|
3495
3499
|
);
|
3496
3500
|
const _feeRate = feeRate || (yield getBtcGasPrice());
|
3497
|
-
const sendAmount = (
|
3501
|
+
const sendAmount = (arrearsAction == null ? void 0 : arrearsAction.amount) && fixedAmount ? new import_big.default(depositAmount).plus((arrearsAction == null ? void 0 : arrearsAction.amount) || 0).toString() : depositAmount;
|
3498
3502
|
console.log("user deposit address:", userDepositAddress);
|
3499
3503
|
console.log("send amount:", sendAmount);
|
3500
3504
|
console.log("fee rate:", _feeRate);
|
@@ -3743,7 +3747,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3743
3747
|
const btcContext = window.btcContext;
|
3744
3748
|
const accountId = state.getAccount();
|
3745
3749
|
const accountInfo = yield getAccountInfo(accountId, currentConfig.accountContractId);
|
3746
|
-
yield checkGasTokenArrears(accountInfo
|
3750
|
+
yield checkGasTokenArrears(accountInfo, env, true);
|
3747
3751
|
const trans = [...params.transactions];
|
3748
3752
|
console.log("raw trans:", trans);
|
3749
3753
|
const gasTokenBalance = (accountInfo == null ? void 0 : accountInfo.gas_token[currentConfig.token]) || "0";
|
@@ -4001,7 +4005,7 @@ function setupBTCWallet({
|
|
4001
4005
|
|
4002
4006
|
// src/index.ts
|
4003
4007
|
var getVersion = () => {
|
4004
|
-
return "0.3.
|
4008
|
+
return "0.3.30";
|
4005
4009
|
};
|
4006
4010
|
if (typeof window !== "undefined") {
|
4007
4011
|
window.__BTC_WALLET_VERSION = getVersion();
|