btc-wallet 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.js +45 -20
- package/dist/index.js.map +3 -3
- package/dist/utils/index.d.ts +4 -0
- package/esm/index.js +45 -20
- package/esm/index.js.map +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -523,7 +523,7 @@ var _network2, _event2;
|
|
523
523
|
var MagicEdenConnector = class extends BaseConnector {
|
524
524
|
constructor() {
|
525
525
|
super();
|
526
|
-
__privateAdd(this, _network2, "
|
526
|
+
__privateAdd(this, _network2, "Mainnet");
|
527
527
|
__privateAdd(this, _event2, new import_events2.default());
|
528
528
|
this.metadata = {
|
529
529
|
id: "magicEden",
|
@@ -1362,6 +1362,27 @@ var checkBTCVersion = (accountContracts, accountContractKey, version) => {
|
|
1362
1362
|
return accountContracts[accountContractKey].some((item) => item.version === version);
|
1363
1363
|
};
|
1364
1364
|
var delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
1365
|
+
function retryOperation(_0, _1) {
|
1366
|
+
return __async(this, arguments, function* (operation, shouldStop, {
|
1367
|
+
maxRetries = 3,
|
1368
|
+
delayMs = 1e3
|
1369
|
+
} = {}) {
|
1370
|
+
let retries = 0;
|
1371
|
+
while (retries <= maxRetries) {
|
1372
|
+
const result = yield operation();
|
1373
|
+
if (shouldStop(result)) {
|
1374
|
+
return result;
|
1375
|
+
}
|
1376
|
+
if (retries === maxRetries) {
|
1377
|
+
console.warn("Max retries reached");
|
1378
|
+
return result;
|
1379
|
+
}
|
1380
|
+
retries++;
|
1381
|
+
yield delay(delayMs);
|
1382
|
+
}
|
1383
|
+
throw new Error("Unexpected execution path");
|
1384
|
+
});
|
1385
|
+
}
|
1365
1386
|
|
1366
1387
|
// src/utils/ethereumUtils.ts
|
1367
1388
|
var import_util2 = require("@ethereumjs/util");
|
@@ -2768,7 +2789,7 @@ function request(url, options) {
|
|
2768
2789
|
body,
|
2769
2790
|
method
|
2770
2791
|
});
|
2771
|
-
const
|
2792
|
+
const retryCount = (_a = options == null ? void 0 : options.retryCount) != null ? _a : 1;
|
2772
2793
|
const controller = new AbortController();
|
2773
2794
|
const timeout = (options == null ? void 0 : options.timeout) || 2e4;
|
2774
2795
|
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
@@ -2791,16 +2812,16 @@ function request(url, options) {
|
|
2791
2812
|
return data;
|
2792
2813
|
} catch (err) {
|
2793
2814
|
console.error(err);
|
2794
|
-
if (
|
2795
|
-
console.log(`Retrying... attempts left: ${
|
2796
|
-
return request(url, __spreadProps(__spreadValues({}, options), { retryCount:
|
2815
|
+
if (retryCount > 0) {
|
2816
|
+
console.log(`Retrying... attempts left: ${retryCount}`);
|
2817
|
+
return request(url, __spreadProps(__spreadValues({}, options), { retryCount: retryCount - 1 }));
|
2797
2818
|
} else if ((options == null ? void 0 : options.pollingInterval) && (options == null ? void 0 : options.maxPollingAttempts)) {
|
2798
2819
|
if (options.maxPollingAttempts > 0) {
|
2799
2820
|
console.log(`Polling... attempts left: ${options.maxPollingAttempts}`);
|
2800
2821
|
yield new Promise((resolve) => setTimeout(resolve, options.pollingInterval));
|
2801
2822
|
return request(url, __spreadProps(__spreadValues({}, options), {
|
2802
2823
|
maxPollingAttempts: options.maxPollingAttempts - 1,
|
2803
|
-
retryCount
|
2824
|
+
retryCount
|
2804
2825
|
}));
|
2805
2826
|
}
|
2806
2827
|
}
|
@@ -2951,8 +2972,15 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2951
2972
|
}
|
2952
2973
|
];
|
2953
2974
|
}
|
2954
|
-
|
2955
|
-
const btcPublicKey = yield btcContext.getPublicKey()
|
2975
|
+
yield btcContext.login();
|
2976
|
+
const btcPublicKey = yield retryOperation(btcContext.getPublicKey, (res) => !!res, {
|
2977
|
+
maxRetries: 40,
|
2978
|
+
delayMs: 3e3
|
2979
|
+
});
|
2980
|
+
console.log("btcPublicKey:", btcPublicKey);
|
2981
|
+
if (!btcPublicKey) {
|
2982
|
+
throw new Error("No connected BTC wallet, please connect your BTC wallet first.");
|
2983
|
+
}
|
2956
2984
|
const { nearTempAddress, nearTempPublicKey } = yield getNearAccountByBtcPublicKey(btcPublicKey);
|
2957
2985
|
return [
|
2958
2986
|
{
|
@@ -3274,24 +3302,21 @@ function getBtcGasPrice() {
|
|
3274
3302
|
}
|
3275
3303
|
});
|
3276
3304
|
}
|
3277
|
-
var retryCount = 0;
|
3278
3305
|
function getBtcBalance() {
|
3279
3306
|
return __async(this, null, function* () {
|
3280
|
-
|
3307
|
+
var _a;
|
3308
|
+
const { account } = yield retryOperation(getBtcProvider, (res2) => !!res2.account);
|
3281
3309
|
if (!account) {
|
3282
|
-
|
3283
|
-
|
3284
|
-
throw new Error("BTC Account is not available.");
|
3285
|
-
}
|
3286
|
-
yield delay(1e3);
|
3287
|
-
return getBtcBalance();
|
3310
|
+
console.error("BTC Account is not available.");
|
3311
|
+
return { rawBalance: 0, balance: 0 };
|
3288
3312
|
}
|
3289
|
-
retryCount = 0;
|
3290
3313
|
const btcRpcUrl = yield getBtcRpcUrl();
|
3291
3314
|
const res = yield fetch(`${btcRpcUrl}/address/${account}/utxo`).then((res2) => res2.json());
|
3292
|
-
const rawBalance = res.
|
3315
|
+
const rawBalance = (_a = res.filter((item) => {
|
3316
|
+
var _a2;
|
3317
|
+
return (_a2 = item == null ? void 0 : item.status) == null ? void 0 : _a2.confirmed;
|
3318
|
+
})) == null ? void 0 : _a.reduce((acc, cur) => acc + cur.value, 0);
|
3293
3319
|
const balance = rawBalance / __pow(10, 8);
|
3294
|
-
console.log("btc balance:", balance);
|
3295
3320
|
return { rawBalance, balance };
|
3296
3321
|
});
|
3297
3322
|
}
|
@@ -3333,7 +3358,7 @@ function executeBurrowSupply(_0) {
|
|
3333
3358
|
|
3334
3359
|
// src/index.ts
|
3335
3360
|
var getVersion = () => {
|
3336
|
-
return "0.3.
|
3361
|
+
return "0.3.5";
|
3337
3362
|
};
|
3338
3363
|
if (typeof window !== "undefined") {
|
3339
3364
|
window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();
|