btc-wallet 0.5.78-beta → 0.5.80-beta
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/index.js +44 -30
- package/dist/index.js.map +2 -2
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/satoshi.d.ts +4 -8
- package/esm/index.js +44 -30
- package/esm/index.js.map +2 -2
- package/package.json +1 -1
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/satoshi.d.ts
CHANGED
@@ -18,17 +18,13 @@ interface ReceiveDepositMsgParams {
|
|
18
18
|
depositType?: number;
|
19
19
|
postActions?: string;
|
20
20
|
extraMsg?: string;
|
21
|
+
userDepositAddress?: string;
|
21
22
|
}
|
22
|
-
export declare function preReceiveDepositMsg({ env, btcPublicKey, depositType, postActions, extraMsg, }: Omit<ReceiveDepositMsgParams, 'txHash'>): Promise<any>;
|
23
|
+
export declare function preReceiveDepositMsg({ env, btcPublicKey, depositType, postActions, extraMsg, userDepositAddress, }: Omit<ReceiveDepositMsgParams, 'txHash'>): Promise<any>;
|
23
24
|
export declare function receiveDepositMsg({ env, btcPublicKey, txHash, depositType, postActions, extraMsg, }: ReceiveDepositMsgParams): Promise<any>;
|
24
|
-
export declare function
|
25
|
+
export declare function hasBridgeTransaction({ env }: {
|
25
26
|
env: ENV;
|
26
|
-
|
27
|
-
fromChainId?: number;
|
28
|
-
fromAddress?: string;
|
29
|
-
page?: number;
|
30
|
-
pageSize?: number;
|
31
|
-
}): Promise<any[]>;
|
27
|
+
}): Promise<boolean>;
|
32
28
|
export declare function checkBridgeTransactionStatus({ txHash, fromChain, env, }: {
|
33
29
|
txHash: string;
|
34
30
|
fromChain?: 'BTC' | 'NEAR';
|
package/esm/index.js
CHANGED
@@ -209,6 +209,26 @@ function storageStore(namespace, options) {
|
|
209
209
|
}
|
210
210
|
};
|
211
211
|
}
|
212
|
+
var getUrlQuery = (url) => {
|
213
|
+
var _a;
|
214
|
+
try {
|
215
|
+
const search = url ? (_a = url.split("?")[1]) == null ? void 0 : _a.split("#")[0] : window.location.search.substring(1).split("#")[0];
|
216
|
+
const urlSearchParams = new URLSearchParams(search);
|
217
|
+
const entries = urlSearchParams.entries();
|
218
|
+
const query = {};
|
219
|
+
for (const [key, value] of entries) {
|
220
|
+
if (query[key]) {
|
221
|
+
query[key] = Array.isArray(query[key]) ? [...query[key], value] : [query[key], value];
|
222
|
+
} else {
|
223
|
+
query[key] = value;
|
224
|
+
}
|
225
|
+
}
|
226
|
+
return query;
|
227
|
+
} catch (error) {
|
228
|
+
console.error("getUrlQuery", error);
|
229
|
+
return {};
|
230
|
+
}
|
231
|
+
};
|
212
232
|
|
213
233
|
// src/utils/Dialog.ts
|
214
234
|
var Dialog = class {
|
@@ -3309,14 +3329,15 @@ function preReceiveDepositMsg(_0) {
|
|
3309
3329
|
btcPublicKey,
|
3310
3330
|
depositType = 1,
|
3311
3331
|
postActions,
|
3312
|
-
extraMsg
|
3332
|
+
extraMsg,
|
3333
|
+
userDepositAddress
|
3313
3334
|
}) {
|
3314
3335
|
const config = getWalletConfig(env);
|
3315
3336
|
const { result_code, result_message, result_data } = yield request(
|
3316
3337
|
`${config.base_url}/v1/preReceiveDepositMsg`,
|
3317
3338
|
{
|
3318
3339
|
method: "POST",
|
3319
|
-
body: { btcPublicKey, depositType, postActions, extraMsg }
|
3340
|
+
body: { btcPublicKey, depositType, postActions, extraMsg, userDepositAddress }
|
3320
3341
|
}
|
3321
3342
|
);
|
3322
3343
|
console.log("preReceiveDepositMsg resp:", { result_code, result_message, result_data });
|
@@ -3350,23 +3371,19 @@ function receiveDepositMsg(_0) {
|
|
3350
3371
|
return result_data;
|
3351
3372
|
});
|
3352
3373
|
}
|
3353
|
-
function
|
3354
|
-
return __async(this, arguments, function* ({
|
3355
|
-
|
3356
|
-
fromChainId = 0,
|
3357
|
-
fromAddress,
|
3358
|
-
page = 1,
|
3359
|
-
pageSize = 10
|
3360
|
-
}) {
|
3374
|
+
function hasBridgeTransaction(_0) {
|
3375
|
+
return __async(this, arguments, function* ({ env }) {
|
3376
|
+
var _a, _b;
|
3361
3377
|
try {
|
3362
3378
|
const config = getWalletConfig(env);
|
3379
|
+
const btcAccount = ((_a = window.btcContext) == null ? void 0 : _a.account) || ((_b = getUrlQuery()) == null ? void 0 : _b.originalAccountId);
|
3363
3380
|
const { result_data = [] } = yield request(
|
3364
|
-
`${config.base_url}/v1/history?fromChainId
|
3381
|
+
`${config.base_url}/v1/history?fromChainId=0&fromAddress=${btcAccount}&page=1&pageSize=1`
|
3365
3382
|
);
|
3366
|
-
return result_data;
|
3383
|
+
return (result_data == null ? void 0 : result_data.length) > 0;
|
3367
3384
|
} catch (error) {
|
3368
|
-
console.error("
|
3369
|
-
return
|
3385
|
+
console.error("hasBridgeTransaction error:", error);
|
3386
|
+
return false;
|
3370
3387
|
}
|
3371
3388
|
});
|
3372
3389
|
}
|
@@ -3771,10 +3788,10 @@ var NEAR_STORAGE_DEPOSIT_AMOUNT = "1250000000000000000000";
|
|
3771
3788
|
var NBTC_STORAGE_DEPOSIT_AMOUNT = 800;
|
3772
3789
|
var NEW_ACCOUNT_MIN_DEPOSIT_AMOUNT = 1e3;
|
3773
3790
|
function getBtcProvider() {
|
3774
|
-
if (typeof window === "undefined" || !
|
3791
|
+
if (typeof window === "undefined" || !window.btcContext) {
|
3775
3792
|
throw new Error("BTC Provider is not initialized.");
|
3776
3793
|
}
|
3777
|
-
return window.btcContext
|
3794
|
+
return window.btcContext;
|
3778
3795
|
}
|
3779
3796
|
function getNetwork() {
|
3780
3797
|
return __async(this, null, function* () {
|
@@ -3806,14 +3823,10 @@ function checkGasTokenDebt(csna, env, autoDeposit) {
|
|
3806
3823
|
return __async(this, null, function* () {
|
3807
3824
|
var _a, _b, _c;
|
3808
3825
|
const accountInfo = yield getAccountInfo({ csna, env });
|
3809
|
-
const
|
3810
|
-
|
3811
|
-
env,
|
3812
|
-
fromAddress: account,
|
3813
|
-
page: 1,
|
3814
|
-
pageSize: 1
|
3826
|
+
const bridgeTransactions = yield hasBridgeTransaction({
|
3827
|
+
env
|
3815
3828
|
});
|
3816
|
-
const isNewAccount = !(accountInfo == null ? void 0 : accountInfo.nonce) && bridgeTransactions
|
3829
|
+
const isNewAccount = !(accountInfo == null ? void 0 : accountInfo.nonce) && !bridgeTransactions;
|
3817
3830
|
const debtAmount = new Big2(((_a = accountInfo == null ? void 0 : accountInfo.debt_info) == null ? void 0 : _a.near_gas_debt_amount) || 0).plus(((_b = accountInfo == null ? void 0 : accountInfo.debt_info) == null ? void 0 : _b.protocol_fee_debt_amount) || 0).toString();
|
3818
3831
|
const relayerFeeAmount = isNewAccount ? NBTC_STORAGE_DEPOSIT_AMOUNT : ((_c = accountInfo == null ? void 0 : accountInfo.relayer_fee) == null ? void 0 : _c.amount) || 0;
|
3819
3832
|
const hasDebtArrears = new Big2(debtAmount).gt(0);
|
@@ -4079,11 +4092,11 @@ function executeBTCDepositAndAction(_0) {
|
|
4079
4092
|
const _feeRate = feeRate || (yield getBtcGasPrice());
|
4080
4093
|
console.table({
|
4081
4094
|
"User Deposit Address": userDepositAddress,
|
4082
|
-
"Deposit Amount": depositAmount,
|
4083
|
-
"Protocol Fee": protocolFee,
|
4084
|
-
"Repay Amount": repayAmount,
|
4085
|
-
"Receive Amount": receiveAmount,
|
4086
|
-
"Fee Rate": _feeRate
|
4095
|
+
"Deposit Amount": Number(depositAmount),
|
4096
|
+
"Protocol Fee": Number(protocolFee),
|
4097
|
+
"Repay Amount": Number(repayAmount),
|
4098
|
+
"Receive Amount": Number(receiveAmount),
|
4099
|
+
"Fee Rate": Number(_feeRate)
|
4087
4100
|
});
|
4088
4101
|
const postActionsStr = newActions.length > 0 ? JSON.stringify(newActions) : void 0;
|
4089
4102
|
yield preReceiveDepositMsg({
|
@@ -4091,7 +4104,8 @@ function executeBTCDepositAndAction(_0) {
|
|
4091
4104
|
btcPublicKey,
|
4092
4105
|
depositType: postActionsStr || depositMsg.extra_msg ? 1 : 0,
|
4093
4106
|
postActions: postActionsStr,
|
4094
|
-
extraMsg: depositMsg.extra_msg
|
4107
|
+
extraMsg: depositMsg.extra_msg,
|
4108
|
+
userDepositAddress
|
4095
4109
|
});
|
4096
4110
|
const txHash = yield sendBitcoin(userDepositAddress, depositAmount, _feeRate);
|
4097
4111
|
yield receiveDepositMsg({
|
@@ -5326,7 +5340,7 @@ function getGroup(state) {
|
|
5326
5340
|
|
5327
5341
|
// src/index.ts
|
5328
5342
|
var getVersion = () => {
|
5329
|
-
return "0.5.
|
5343
|
+
return "0.5.80-beta";
|
5330
5344
|
};
|
5331
5345
|
if (typeof window !== "undefined") {
|
5332
5346
|
window.__BTC_WALLET_VERSION = getVersion();
|