@pioneer-platform/pioneer-sdk 8.15.15 → 8.15.16
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.cjs +162 -36
- package/dist/index.es.js +163 -37
- package/dist/index.js +163 -37
- package/package.json +2 -3
- package/src/index.ts +2 -1
- package/src/utils/logger.ts +21 -0
- package/src/utils/path-discovery.ts +1 -2
- package/src/utils/portfolio-helpers.ts +1 -1
- package/src/utils/pubkey-sync.ts +1 -2
- package/src/utils/sync-state.ts +1 -1
package/dist/index.cjs
CHANGED
|
@@ -41,6 +41,117 @@ var __export = (target, all) => {
|
|
|
41
41
|
};
|
|
42
42
|
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
43
43
|
|
|
44
|
+
// ../../support/loggerdog/lib/index.js
|
|
45
|
+
var require_lib = __commonJS((exports2, module2) => {
|
|
46
|
+
var __spreadArray = exports2 && exports2.__spreadArray || function(to, from, pack) {
|
|
47
|
+
if (pack || arguments.length === 2)
|
|
48
|
+
for (var i = 0, l = from.length, ar;i < l; i++) {
|
|
49
|
+
if (ar || !(i in from)) {
|
|
50
|
+
if (!ar)
|
|
51
|
+
ar = Array.prototype.slice.call(from, 0, i);
|
|
52
|
+
ar[i] = from[i];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
56
|
+
};
|
|
57
|
+
var LOG_LEVELS = {
|
|
58
|
+
TEST: { val: 0, label: "TEST", color: "color: cyan" },
|
|
59
|
+
EMERG: { val: 0, label: "EMERG", color: "color: magenta" },
|
|
60
|
+
ALERT: { val: 1, label: "ALERT", color: "color: magenta" },
|
|
61
|
+
CRIT: { val: 2, label: "CRIT", color: "color: red" },
|
|
62
|
+
ERROR: { val: 3, label: "ERROR", color: "color: red" },
|
|
63
|
+
WARN: { val: 4, label: "WARN", color: "color: orange" },
|
|
64
|
+
NOTICE: { val: 5, label: "NOTICE", color: "color: yellow" },
|
|
65
|
+
VERBOSE: { val: 6, label: "VERBOSE", color: "color: cyan" },
|
|
66
|
+
INFO: { val: 6, label: "INFO", color: "color: cyan" },
|
|
67
|
+
DEBUG: { val: 7, label: "DEBUG", color: "color: green" },
|
|
68
|
+
DEBUGV: { val: 8, label: "DEBUG", color: "color: green" },
|
|
69
|
+
DEBUGVV: { val: 9, label: "DEBUG", color: "color: green" }
|
|
70
|
+
};
|
|
71
|
+
var DEFAULT_LOG_LEVEL = typeof process !== "undefined" ? process.env["DEFAULT_LOG_LEVEL"] || "INFO" : "INFO";
|
|
72
|
+
function _extractContext(stack, depth) {
|
|
73
|
+
try {
|
|
74
|
+
var arr = stack.split(`
|
|
75
|
+
`);
|
|
76
|
+
var chunks = arr[depth].split("/");
|
|
77
|
+
var business = chunks[chunks.length - 1];
|
|
78
|
+
var matches = business.match(/^([^:]+):(\d+):(\d+)/i) || "";
|
|
79
|
+
var filename = matches[1];
|
|
80
|
+
var line = matches[2];
|
|
81
|
+
var pos = matches[3];
|
|
82
|
+
return { filename, line, pos };
|
|
83
|
+
} catch (ex) {
|
|
84
|
+
return { filename: "unknown" };
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function _getContextString() {
|
|
88
|
+
var stack = new Error().stack || "";
|
|
89
|
+
var _a = _extractContext(stack, 3), filename = _a.filename, line = _a.line, pos = _a.pos;
|
|
90
|
+
return "[".concat(filename, ":").concat(line, ":").concat(pos, "]");
|
|
91
|
+
}
|
|
92
|
+
var Logger = function() {
|
|
93
|
+
function Logger2() {
|
|
94
|
+
var stack = new Error().stack || "";
|
|
95
|
+
var ctx = _extractContext(stack, 3);
|
|
96
|
+
this._tag = ctx.filename || "";
|
|
97
|
+
for (var lvl in LOG_LEVELS) {
|
|
98
|
+
this[lvl.toLowerCase()] = this._log.bind(this, lvl);
|
|
99
|
+
}
|
|
100
|
+
this._setLogLevel();
|
|
101
|
+
}
|
|
102
|
+
Logger2.prototype._setLogLevel = function() {
|
|
103
|
+
var tag = this._tag.split(".")[0];
|
|
104
|
+
tag = tag.toUpperCase().replace("-", "_");
|
|
105
|
+
var level = typeof process !== "undefined" ? process.env["LOG_LEVEL_" + tag] || null : null;
|
|
106
|
+
if (level && LOG_LEVELS[level] !== undefined) {
|
|
107
|
+
this._level = LOG_LEVELS[level].val;
|
|
108
|
+
} else {
|
|
109
|
+
this._level = LOG_LEVELS[DEFAULT_LOG_LEVEL].val;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
Logger2.prototype._log = function(level) {
|
|
113
|
+
var args = [];
|
|
114
|
+
for (var _i = 1;_i < arguments.length; _i++) {
|
|
115
|
+
args[_i - 1] = arguments[_i];
|
|
116
|
+
}
|
|
117
|
+
if (this._level >= LOG_LEVELS[level].val) {
|
|
118
|
+
var dt = new Date().toISOString().replace("T", " ");
|
|
119
|
+
var ctx = _getContextString();
|
|
120
|
+
var label = LOG_LEVELS[level].label;
|
|
121
|
+
var color = LOG_LEVELS[level].color;
|
|
122
|
+
var message = undefined;
|
|
123
|
+
if (typeof process !== "undefined" && process.env["STRUCTURED_LOGGING"]) {
|
|
124
|
+
message = {};
|
|
125
|
+
var tag = args[0];
|
|
126
|
+
var param = args[1];
|
|
127
|
+
var value = args[2];
|
|
128
|
+
if (typeof args === "object") {
|
|
129
|
+
message.loggerdog = true;
|
|
130
|
+
message.label = label;
|
|
131
|
+
message.param = param;
|
|
132
|
+
message.value = value;
|
|
133
|
+
message.ctx = ctx;
|
|
134
|
+
message.dt = dt;
|
|
135
|
+
message.tag = tag.toString();
|
|
136
|
+
message.raw = args.toString();
|
|
137
|
+
} else {
|
|
138
|
+
message.raw = args;
|
|
139
|
+
}
|
|
140
|
+
console.log("%c " + dt, color, label, ctx, message);
|
|
141
|
+
} else {
|
|
142
|
+
console.log.apply(console, __spreadArray(["%c " + dt, color, label, ctx], args, false));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
return Logger2;
|
|
147
|
+
}();
|
|
148
|
+
var getLogger = function() {
|
|
149
|
+
return new Logger;
|
|
150
|
+
};
|
|
151
|
+
exports2.default = getLogger;
|
|
152
|
+
module2.exports = getLogger;
|
|
153
|
+
});
|
|
154
|
+
|
|
44
155
|
// ../../../node_modules/coinselect/utils.js
|
|
45
156
|
var require_utils = __commonJS((exports2, module2) => {
|
|
46
157
|
var TX_EMPTY_SIZE = 4 + 1 + 1 + 4;
|
|
@@ -798,7 +909,7 @@ var import_pioneer_caip8 = require("@pioneer-platform/pioneer-caip");
|
|
|
798
909
|
|
|
799
910
|
// ../pioneer-client/lib/index.js
|
|
800
911
|
var import_swagger_client = __toESM(require("swagger-client"));
|
|
801
|
-
var import_loggerdog = __toESM(
|
|
912
|
+
var import_loggerdog = __toESM(require_lib());
|
|
802
913
|
var log = typeof window === "undefined" ? import_loggerdog.default() : {
|
|
803
914
|
debug: (...args) => console.debug(...args),
|
|
804
915
|
info: (...args) => console.info(...args),
|
|
@@ -949,6 +1060,25 @@ var import_pioneer_discovery2 = require("@pioneer-platform/pioneer-discovery");
|
|
|
949
1060
|
var import_pioneer_events = require("@pioneer-platform/pioneer-events");
|
|
950
1061
|
var import_events = __toESM(require("events"));
|
|
951
1062
|
|
|
1063
|
+
// src/utils/logger.ts
|
|
1064
|
+
var DEBUG = process.env.DEBUG === "true" || typeof window !== "undefined" && window.DEBUG;
|
|
1065
|
+
var logger = {
|
|
1066
|
+
info: (tag, ...args) => {
|
|
1067
|
+
console.log(`[INFO] ${tag}`, ...args);
|
|
1068
|
+
},
|
|
1069
|
+
debug: (tag, ...args) => {
|
|
1070
|
+
if (DEBUG) {
|
|
1071
|
+
console.log(`[DEBUG] ${tag}`, ...args);
|
|
1072
|
+
}
|
|
1073
|
+
},
|
|
1074
|
+
warn: (tag, ...args) => {
|
|
1075
|
+
console.warn(`[WARN] ${tag}`, ...args);
|
|
1076
|
+
},
|
|
1077
|
+
error: (tag, ...args) => {
|
|
1078
|
+
console.error(`[ERROR] ${tag}`, ...args);
|
|
1079
|
+
}
|
|
1080
|
+
};
|
|
1081
|
+
|
|
952
1082
|
// src/getPubkey.ts
|
|
953
1083
|
var import_pioneer_caip = require("@pioneer-platform/pioneer-caip");
|
|
954
1084
|
var import_pioneer_coins = require("@pioneer-platform/pioneer-coins");
|
|
@@ -4059,7 +4189,6 @@ function filterPubkeysForAsset(pubkeys, caip, caipToNetworkId7) {
|
|
|
4059
4189
|
}
|
|
4060
4190
|
|
|
4061
4191
|
// src/utils/portfolio-helpers.ts
|
|
4062
|
-
var log2 = require("@pioneer-platform/loggerdog")();
|
|
4063
4192
|
var TAG9 = " | portfolio-helpers | ";
|
|
4064
4193
|
function isCacheDataValid(portfolioData) {
|
|
4065
4194
|
if (!portfolioData.networks || !Array.isArray(portfolioData.networks)) {
|
|
@@ -4082,22 +4211,22 @@ async function fetchMarketPrice(pioneer, caip) {
|
|
|
4082
4211
|
const tag = TAG9 + " | fetchMarketPrice | ";
|
|
4083
4212
|
try {
|
|
4084
4213
|
if (!caip || typeof caip !== "string" || !caip.includes(":")) {
|
|
4085
|
-
|
|
4214
|
+
logger.warn(tag, "Invalid or missing CAIP, skipping market price fetch:", caip);
|
|
4086
4215
|
return 0;
|
|
4087
4216
|
}
|
|
4088
|
-
|
|
4217
|
+
logger.debug(tag, "Fetching fresh market price for:", caip);
|
|
4089
4218
|
const marketData = await pioneer.GetMarketInfo([caip]);
|
|
4090
|
-
|
|
4219
|
+
logger.debug(tag, "Market data response:", marketData);
|
|
4091
4220
|
if (marketData && marketData.data && marketData.data.length > 0) {
|
|
4092
4221
|
const price = marketData.data[0];
|
|
4093
|
-
|
|
4222
|
+
logger.debug(tag, "✅ Fresh market price:", price);
|
|
4094
4223
|
return price;
|
|
4095
4224
|
} else {
|
|
4096
|
-
|
|
4225
|
+
logger.warn(tag, "No market data returned for:", caip);
|
|
4097
4226
|
return 0;
|
|
4098
4227
|
}
|
|
4099
4228
|
} catch (marketError) {
|
|
4100
|
-
|
|
4229
|
+
logger.error(tag, "Error fetching market price:", marketError);
|
|
4101
4230
|
return 0;
|
|
4102
4231
|
}
|
|
4103
4232
|
}
|
|
@@ -4111,7 +4240,7 @@ function extractPriceFromBalances(balances) {
|
|
|
4111
4240
|
const valueUsd = parseFloat(balances[0].valueUsd);
|
|
4112
4241
|
if (balance > 0 && valueUsd > 0) {
|
|
4113
4242
|
priceValue = valueUsd / balance;
|
|
4114
|
-
|
|
4243
|
+
logger.debug(tag, "Calculated priceUsd from valueUsd/balance:", priceValue);
|
|
4115
4244
|
}
|
|
4116
4245
|
}
|
|
4117
4246
|
return priceValue || 0;
|
|
@@ -4120,15 +4249,15 @@ function aggregateBalances(balances, caip) {
|
|
|
4120
4249
|
const tag = TAG9 + " | aggregateBalances | ";
|
|
4121
4250
|
let totalBalance = 0;
|
|
4122
4251
|
let totalValueUsd = 0;
|
|
4123
|
-
|
|
4252
|
+
logger.debug(tag, `Aggregating ${balances.length} balance entries for ${caip}`);
|
|
4124
4253
|
for (const balanceEntry of balances) {
|
|
4125
4254
|
const balance = parseFloat(balanceEntry.balance) || 0;
|
|
4126
4255
|
const valueUsd = parseFloat(balanceEntry.valueUsd) || 0;
|
|
4127
4256
|
totalBalance += balance;
|
|
4128
4257
|
totalValueUsd += valueUsd;
|
|
4129
|
-
|
|
4258
|
+
logger.debug(tag, ` Balance entry: ${balance} (${valueUsd} USD)`);
|
|
4130
4259
|
}
|
|
4131
|
-
|
|
4260
|
+
logger.debug(tag, `Aggregated balance: ${totalBalance} (${totalValueUsd.toFixed(2)} USD)`);
|
|
4132
4261
|
return { totalBalance, totalValueUsd };
|
|
4133
4262
|
}
|
|
4134
4263
|
function updateBalancesWithPrice(balances, freshPriceUsd) {
|
|
@@ -4139,7 +4268,7 @@ function updateBalancesWithPrice(balances, freshPriceUsd) {
|
|
|
4139
4268
|
const balanceAmount = parseFloat(balance.balance || 0);
|
|
4140
4269
|
balance.valueUsd = (balanceAmount * freshPriceUsd).toString();
|
|
4141
4270
|
}
|
|
4142
|
-
|
|
4271
|
+
logger.debug(tag, "Updated all balances with fresh price data");
|
|
4143
4272
|
}
|
|
4144
4273
|
function buildDashboardFromPortfolioData(portfolioData) {
|
|
4145
4274
|
const cacheAge = portfolioData.lastUpdated ? Math.floor((Date.now() - portfolioData.lastUpdated) / 1000) : 0;
|
|
@@ -4197,19 +4326,18 @@ function enrichBalancesWithAssetInfo(balances, assetsMap, caipToNetworkId7) {
|
|
|
4197
4326
|
}
|
|
4198
4327
|
|
|
4199
4328
|
// src/utils/sync-state.ts
|
|
4200
|
-
var log3 = require("@pioneer-platform/loggerdog")();
|
|
4201
4329
|
var TAG10 = " | sync-state | ";
|
|
4202
4330
|
function resolveAssetInfo(assetsMap, assetData, asset) {
|
|
4203
4331
|
const tag = TAG10 + " | resolveAssetInfo | ";
|
|
4204
4332
|
let assetInfo = assetsMap.get(asset.caip.toLowerCase());
|
|
4205
|
-
|
|
4333
|
+
logger.debug(tag, "assetInfo from assetsMap:", assetInfo);
|
|
4206
4334
|
const assetInfoDiscovery = assetData[asset.caip];
|
|
4207
|
-
|
|
4335
|
+
logger.debug(tag, "assetInfoDiscovery:", assetInfoDiscovery);
|
|
4208
4336
|
if (assetInfoDiscovery) {
|
|
4209
4337
|
assetInfo = assetInfoDiscovery;
|
|
4210
4338
|
}
|
|
4211
4339
|
if (!assetInfo) {
|
|
4212
|
-
|
|
4340
|
+
logger.debug(tag, "Building placeholder asset for", asset.caip);
|
|
4213
4341
|
assetInfo = {
|
|
4214
4342
|
caip: asset.caip.toLowerCase(),
|
|
4215
4343
|
networkId: asset.networkId,
|
|
@@ -4331,19 +4459,18 @@ function validatePubkeysNetworks(pubkeys, tag = "") {
|
|
|
4331
4459
|
|
|
4332
4460
|
// src/utils/path-discovery.ts
|
|
4333
4461
|
var import_pioneer_coins4 = require("@pioneer-platform/pioneer-coins");
|
|
4334
|
-
var log4 = require("@pioneer-platform/loggerdog")();
|
|
4335
4462
|
async function ensurePathsForBlockchains(blockchains, currentPaths, tag) {
|
|
4336
4463
|
let allPaths = [...currentPaths];
|
|
4337
4464
|
for (const blockchain of blockchains) {
|
|
4338
4465
|
const networkId = normalizeNetworkId(blockchain);
|
|
4339
4466
|
const existingPaths = allPaths.filter((path) => matchesNetwork(path, networkId));
|
|
4340
4467
|
if (existingPaths.length === 0) {
|
|
4341
|
-
|
|
4468
|
+
logger.info(tag, `Discovering paths for ${networkId}...`);
|
|
4342
4469
|
const newPaths = import_pioneer_coins4.getPaths([networkId]);
|
|
4343
4470
|
if (!newPaths || newPaths.length === 0) {
|
|
4344
4471
|
throw new Error(`Path discovery failed for ${networkId}. ` + `Available blockchains: ${blockchains.join(", ")}`);
|
|
4345
4472
|
}
|
|
4346
|
-
|
|
4473
|
+
logger.debug(tag, `Added ${newPaths.length} paths for ${networkId}`);
|
|
4347
4474
|
allPaths = allPaths.concat(newPaths);
|
|
4348
4475
|
}
|
|
4349
4476
|
}
|
|
@@ -4352,7 +4479,6 @@ async function ensurePathsForBlockchains(blockchains, currentPaths, tag) {
|
|
|
4352
4479
|
|
|
4353
4480
|
// src/utils/pubkey-sync.ts
|
|
4354
4481
|
var import_pioneer_coins5 = require("@pioneer-platform/pioneer-coins");
|
|
4355
|
-
var log5 = require("@pioneer-platform/loggerdog")();
|
|
4356
4482
|
async function syncPubkeysForBlockchains(blockchains, paths, existingPubkeys, keepKeySdk, context, getPubkeyFn, addPubkeyCallback, tag) {
|
|
4357
4483
|
for (const blockchain of blockchains) {
|
|
4358
4484
|
const networkId = normalizeNetworkId(blockchain);
|
|
@@ -4361,22 +4487,22 @@ async function syncPubkeysForBlockchains(blockchains, paths, existingPubkeys, ke
|
|
|
4361
4487
|
const availablePaths = paths.map((p) => p.note || p.path || "unnamed").join(", ");
|
|
4362
4488
|
throw new Error(`No paths found for ${networkId}. ` + `Available paths: ${availablePaths || "none"}`);
|
|
4363
4489
|
}
|
|
4364
|
-
|
|
4490
|
+
logger.info(tag, `Syncing ${pathsForChain.length} pubkeys for ${networkId}...`);
|
|
4365
4491
|
for (const path of pathsForChain) {
|
|
4366
4492
|
const pathBip32 = import_pioneer_coins5.addressNListToBIP32(path.addressNListMaster);
|
|
4367
4493
|
const existingPubkey = existingPubkeys.find((p) => p.pathMaster === pathBip32);
|
|
4368
4494
|
if (!existingPubkey) {
|
|
4369
|
-
|
|
4495
|
+
logger.debug(tag, `Fetching pubkey for path ${pathBip32}...`);
|
|
4370
4496
|
const newPubkey = await getPubkeyFn(blockchain, path, keepKeySdk, context);
|
|
4371
4497
|
if (!newPubkey) {
|
|
4372
4498
|
throw new Error(`Pubkey fetch failed for ${networkId} at path ${pathBip32}. ` + `Ensure hardware wallet is connected and unlocked.`);
|
|
4373
4499
|
}
|
|
4374
4500
|
addPubkeyCallback(newPubkey);
|
|
4375
|
-
|
|
4501
|
+
logger.debug(tag, `✓ Added pubkey for ${pathBip32}`);
|
|
4376
4502
|
}
|
|
4377
4503
|
}
|
|
4378
4504
|
}
|
|
4379
|
-
|
|
4505
|
+
logger.info(tag, `✅ Pubkey sync complete. Total pubkeys: ${existingPubkeys.length}`);
|
|
4380
4506
|
}
|
|
4381
4507
|
|
|
4382
4508
|
// src/index.ts
|
|
@@ -4797,48 +4923,48 @@ class SDK {
|
|
|
4797
4923
|
};
|
|
4798
4924
|
this.sync = async function() {
|
|
4799
4925
|
const tag6 = `${TAG12} | sync | `;
|
|
4800
|
-
const
|
|
4926
|
+
const log2 = logger;
|
|
4801
4927
|
try {
|
|
4802
4928
|
this.syncState = {
|
|
4803
4929
|
...createInitialSyncState(this.blockchains.length),
|
|
4804
4930
|
syncProgress: 10
|
|
4805
4931
|
};
|
|
4806
4932
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
4807
|
-
|
|
4933
|
+
log2.info(tag6, "Fetching initial pubkeys...");
|
|
4808
4934
|
await this.getPubkeys();
|
|
4809
4935
|
this.syncState.syncProgress = 20;
|
|
4810
4936
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
4811
|
-
|
|
4937
|
+
log2.info(tag6, "Discovering paths for blockchains...");
|
|
4812
4938
|
this.paths = await ensurePathsForBlockchains(this.blockchains, this.paths, tag6);
|
|
4813
4939
|
this.syncState.syncProgress = 30;
|
|
4814
4940
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
4815
|
-
|
|
4941
|
+
log2.info(tag6, "Synchronizing pubkeys...");
|
|
4816
4942
|
await syncPubkeysForBlockchains(this.blockchains, this.paths, this.pubkeys, this.keepKeySdk, this.context, getPubkey, (pubkey) => this.addPubkey(pubkey), tag6);
|
|
4817
4943
|
this.syncState.syncProgress = 50;
|
|
4818
4944
|
this.syncState.syncedChains = this.blockchains.length;
|
|
4819
4945
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
4820
|
-
|
|
4946
|
+
log2.info(tag6, "Fetching balances...");
|
|
4821
4947
|
await this.getBalances();
|
|
4822
4948
|
this.syncState.syncProgress = 70;
|
|
4823
4949
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
4824
|
-
|
|
4950
|
+
log2.info(tag6, "Loading charts (tokens + portfolio)...");
|
|
4825
4951
|
await this.getCharts();
|
|
4826
|
-
|
|
4952
|
+
log2.info(tag6, `Charts loaded. Total balances: ${this.balances.length}`);
|
|
4827
4953
|
this.syncState.syncProgress = 85;
|
|
4828
4954
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
4829
|
-
|
|
4955
|
+
log2.info(tag6, "Syncing market prices...");
|
|
4830
4956
|
await this.syncMarket();
|
|
4831
4957
|
this.syncState.syncProgress = 95;
|
|
4832
4958
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
4833
|
-
|
|
4959
|
+
log2.info(tag6, "Building dashboard...");
|
|
4834
4960
|
this.dashboard = buildDashboardFromBalances(this.balances, [...new Set(this.blockchains)], this.assetsMap);
|
|
4835
4961
|
this.syncState = createFreshSyncState(this.blockchains.length);
|
|
4836
4962
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
4837
4963
|
this.events.emit("SYNC_COMPLETE", this.syncState);
|
|
4838
|
-
|
|
4964
|
+
log2.info(tag6, "✅ Sync complete!");
|
|
4839
4965
|
return true;
|
|
4840
4966
|
} catch (e) {
|
|
4841
|
-
|
|
4967
|
+
log2.error(tag6, "Sync failed:", e);
|
|
4842
4968
|
this.syncState = {
|
|
4843
4969
|
...this.syncState,
|
|
4844
4970
|
isSynced: false,
|
package/dist/index.es.js
CHANGED
|
@@ -33,6 +33,117 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
33
33
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
+
// ../../support/loggerdog/lib/index.js
|
|
37
|
+
var require_lib = __commonJS((exports, module) => {
|
|
38
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from, pack) {
|
|
39
|
+
if (pack || arguments.length === 2)
|
|
40
|
+
for (var i = 0, l = from.length, ar;i < l; i++) {
|
|
41
|
+
if (ar || !(i in from)) {
|
|
42
|
+
if (!ar)
|
|
43
|
+
ar = Array.prototype.slice.call(from, 0, i);
|
|
44
|
+
ar[i] = from[i];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
48
|
+
};
|
|
49
|
+
var LOG_LEVELS = {
|
|
50
|
+
TEST: { val: 0, label: "TEST", color: "color: cyan" },
|
|
51
|
+
EMERG: { val: 0, label: "EMERG", color: "color: magenta" },
|
|
52
|
+
ALERT: { val: 1, label: "ALERT", color: "color: magenta" },
|
|
53
|
+
CRIT: { val: 2, label: "CRIT", color: "color: red" },
|
|
54
|
+
ERROR: { val: 3, label: "ERROR", color: "color: red" },
|
|
55
|
+
WARN: { val: 4, label: "WARN", color: "color: orange" },
|
|
56
|
+
NOTICE: { val: 5, label: "NOTICE", color: "color: yellow" },
|
|
57
|
+
VERBOSE: { val: 6, label: "VERBOSE", color: "color: cyan" },
|
|
58
|
+
INFO: { val: 6, label: "INFO", color: "color: cyan" },
|
|
59
|
+
DEBUG: { val: 7, label: "DEBUG", color: "color: green" },
|
|
60
|
+
DEBUGV: { val: 8, label: "DEBUG", color: "color: green" },
|
|
61
|
+
DEBUGVV: { val: 9, label: "DEBUG", color: "color: green" }
|
|
62
|
+
};
|
|
63
|
+
var DEFAULT_LOG_LEVEL = typeof process !== "undefined" ? process.env["DEFAULT_LOG_LEVEL"] || "INFO" : "INFO";
|
|
64
|
+
function _extractContext(stack, depth) {
|
|
65
|
+
try {
|
|
66
|
+
var arr = stack.split(`
|
|
67
|
+
`);
|
|
68
|
+
var chunks = arr[depth].split("/");
|
|
69
|
+
var business = chunks[chunks.length - 1];
|
|
70
|
+
var matches = business.match(/^([^:]+):(\d+):(\d+)/i) || "";
|
|
71
|
+
var filename = matches[1];
|
|
72
|
+
var line = matches[2];
|
|
73
|
+
var pos = matches[3];
|
|
74
|
+
return { filename, line, pos };
|
|
75
|
+
} catch (ex) {
|
|
76
|
+
return { filename: "unknown" };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function _getContextString() {
|
|
80
|
+
var stack = new Error().stack || "";
|
|
81
|
+
var _a = _extractContext(stack, 3), filename = _a.filename, line = _a.line, pos = _a.pos;
|
|
82
|
+
return "[".concat(filename, ":").concat(line, ":").concat(pos, "]");
|
|
83
|
+
}
|
|
84
|
+
var Logger = function() {
|
|
85
|
+
function Logger2() {
|
|
86
|
+
var stack = new Error().stack || "";
|
|
87
|
+
var ctx = _extractContext(stack, 3);
|
|
88
|
+
this._tag = ctx.filename || "";
|
|
89
|
+
for (var lvl in LOG_LEVELS) {
|
|
90
|
+
this[lvl.toLowerCase()] = this._log.bind(this, lvl);
|
|
91
|
+
}
|
|
92
|
+
this._setLogLevel();
|
|
93
|
+
}
|
|
94
|
+
Logger2.prototype._setLogLevel = function() {
|
|
95
|
+
var tag = this._tag.split(".")[0];
|
|
96
|
+
tag = tag.toUpperCase().replace("-", "_");
|
|
97
|
+
var level = typeof process !== "undefined" ? process.env["LOG_LEVEL_" + tag] || null : null;
|
|
98
|
+
if (level && LOG_LEVELS[level] !== undefined) {
|
|
99
|
+
this._level = LOG_LEVELS[level].val;
|
|
100
|
+
} else {
|
|
101
|
+
this._level = LOG_LEVELS[DEFAULT_LOG_LEVEL].val;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
Logger2.prototype._log = function(level) {
|
|
105
|
+
var args = [];
|
|
106
|
+
for (var _i = 1;_i < arguments.length; _i++) {
|
|
107
|
+
args[_i - 1] = arguments[_i];
|
|
108
|
+
}
|
|
109
|
+
if (this._level >= LOG_LEVELS[level].val) {
|
|
110
|
+
var dt = new Date().toISOString().replace("T", " ");
|
|
111
|
+
var ctx = _getContextString();
|
|
112
|
+
var label = LOG_LEVELS[level].label;
|
|
113
|
+
var color = LOG_LEVELS[level].color;
|
|
114
|
+
var message = undefined;
|
|
115
|
+
if (typeof process !== "undefined" && process.env["STRUCTURED_LOGGING"]) {
|
|
116
|
+
message = {};
|
|
117
|
+
var tag = args[0];
|
|
118
|
+
var param = args[1];
|
|
119
|
+
var value = args[2];
|
|
120
|
+
if (typeof args === "object") {
|
|
121
|
+
message.loggerdog = true;
|
|
122
|
+
message.label = label;
|
|
123
|
+
message.param = param;
|
|
124
|
+
message.value = value;
|
|
125
|
+
message.ctx = ctx;
|
|
126
|
+
message.dt = dt;
|
|
127
|
+
message.tag = tag.toString();
|
|
128
|
+
message.raw = args.toString();
|
|
129
|
+
} else {
|
|
130
|
+
message.raw = args;
|
|
131
|
+
}
|
|
132
|
+
console.log("%c " + dt, color, label, ctx, message);
|
|
133
|
+
} else {
|
|
134
|
+
console.log.apply(console, __spreadArray(["%c " + dt, color, label, ctx], args, false));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
return Logger2;
|
|
139
|
+
}();
|
|
140
|
+
var getLogger = function() {
|
|
141
|
+
return new Logger;
|
|
142
|
+
};
|
|
143
|
+
exports.default = getLogger;
|
|
144
|
+
module.exports = getLogger;
|
|
145
|
+
});
|
|
146
|
+
|
|
36
147
|
// ../../../node_modules/coinselect/utils.js
|
|
37
148
|
var require_utils = __commonJS((exports, module) => {
|
|
38
149
|
var TX_EMPTY_SIZE = 4 + 1 + 1 + 4;
|
|
@@ -782,9 +893,9 @@ import { KeepKeySdk } from "@keepkey/keepkey-sdk";
|
|
|
782
893
|
import { caipToNetworkId as caipToNetworkId7, networkIdToCaip as networkIdToCaip2 } from "@pioneer-platform/pioneer-caip";
|
|
783
894
|
|
|
784
895
|
// ../pioneer-client/lib/index.js
|
|
896
|
+
var import_loggerdog = __toESM(require_lib(), 1);
|
|
785
897
|
import SwaggerClient from "swagger-client";
|
|
786
|
-
|
|
787
|
-
var log = typeof window === "undefined" ? loggerdog() : {
|
|
898
|
+
var log = typeof window === "undefined" ? import_loggerdog.default() : {
|
|
788
899
|
debug: (...args) => console.debug(...args),
|
|
789
900
|
info: (...args) => console.info(...args),
|
|
790
901
|
warn: (...args) => console.warn(...args),
|
|
@@ -1129,6 +1240,25 @@ function R(t) {
|
|
|
1129
1240
|
var A = o;
|
|
1130
1241
|
var P = o.prototype;
|
|
1131
1242
|
|
|
1243
|
+
// src/utils/logger.ts
|
|
1244
|
+
var DEBUG = process.env.DEBUG === "true" || typeof window !== "undefined" && window.DEBUG;
|
|
1245
|
+
var logger = {
|
|
1246
|
+
info: (tag, ...args) => {
|
|
1247
|
+
console.log(`[INFO] ${tag}`, ...args);
|
|
1248
|
+
},
|
|
1249
|
+
debug: (tag, ...args) => {
|
|
1250
|
+
if (DEBUG) {
|
|
1251
|
+
console.log(`[DEBUG] ${tag}`, ...args);
|
|
1252
|
+
}
|
|
1253
|
+
},
|
|
1254
|
+
warn: (tag, ...args) => {
|
|
1255
|
+
console.warn(`[WARN] ${tag}`, ...args);
|
|
1256
|
+
},
|
|
1257
|
+
error: (tag, ...args) => {
|
|
1258
|
+
console.error(`[ERROR] ${tag}`, ...args);
|
|
1259
|
+
}
|
|
1260
|
+
};
|
|
1261
|
+
|
|
1132
1262
|
// src/getPubkey.ts
|
|
1133
1263
|
import { NetworkIdToChain } from "@pioneer-platform/pioneer-caip";
|
|
1134
1264
|
import {
|
|
@@ -4243,7 +4373,6 @@ function filterPubkeysForAsset(pubkeys, caip, caipToNetworkId7) {
|
|
|
4243
4373
|
}
|
|
4244
4374
|
|
|
4245
4375
|
// src/utils/portfolio-helpers.ts
|
|
4246
|
-
var log2 = __require("@pioneer-platform/loggerdog")();
|
|
4247
4376
|
var TAG9 = " | portfolio-helpers | ";
|
|
4248
4377
|
function isCacheDataValid(portfolioData) {
|
|
4249
4378
|
if (!portfolioData.networks || !Array.isArray(portfolioData.networks)) {
|
|
@@ -4266,22 +4395,22 @@ async function fetchMarketPrice(pioneer, caip) {
|
|
|
4266
4395
|
const tag = TAG9 + " | fetchMarketPrice | ";
|
|
4267
4396
|
try {
|
|
4268
4397
|
if (!caip || typeof caip !== "string" || !caip.includes(":")) {
|
|
4269
|
-
|
|
4398
|
+
logger.warn(tag, "Invalid or missing CAIP, skipping market price fetch:", caip);
|
|
4270
4399
|
return 0;
|
|
4271
4400
|
}
|
|
4272
|
-
|
|
4401
|
+
logger.debug(tag, "Fetching fresh market price for:", caip);
|
|
4273
4402
|
const marketData = await pioneer.GetMarketInfo([caip]);
|
|
4274
|
-
|
|
4403
|
+
logger.debug(tag, "Market data response:", marketData);
|
|
4275
4404
|
if (marketData && marketData.data && marketData.data.length > 0) {
|
|
4276
4405
|
const price = marketData.data[0];
|
|
4277
|
-
|
|
4406
|
+
logger.debug(tag, "✅ Fresh market price:", price);
|
|
4278
4407
|
return price;
|
|
4279
4408
|
} else {
|
|
4280
|
-
|
|
4409
|
+
logger.warn(tag, "No market data returned for:", caip);
|
|
4281
4410
|
return 0;
|
|
4282
4411
|
}
|
|
4283
4412
|
} catch (marketError) {
|
|
4284
|
-
|
|
4413
|
+
logger.error(tag, "Error fetching market price:", marketError);
|
|
4285
4414
|
return 0;
|
|
4286
4415
|
}
|
|
4287
4416
|
}
|
|
@@ -4295,7 +4424,7 @@ function extractPriceFromBalances(balances) {
|
|
|
4295
4424
|
const valueUsd = parseFloat(balances[0].valueUsd);
|
|
4296
4425
|
if (balance > 0 && valueUsd > 0) {
|
|
4297
4426
|
priceValue = valueUsd / balance;
|
|
4298
|
-
|
|
4427
|
+
logger.debug(tag, "Calculated priceUsd from valueUsd/balance:", priceValue);
|
|
4299
4428
|
}
|
|
4300
4429
|
}
|
|
4301
4430
|
return priceValue || 0;
|
|
@@ -4304,15 +4433,15 @@ function aggregateBalances(balances, caip) {
|
|
|
4304
4433
|
const tag = TAG9 + " | aggregateBalances | ";
|
|
4305
4434
|
let totalBalance = 0;
|
|
4306
4435
|
let totalValueUsd = 0;
|
|
4307
|
-
|
|
4436
|
+
logger.debug(tag, `Aggregating ${balances.length} balance entries for ${caip}`);
|
|
4308
4437
|
for (const balanceEntry of balances) {
|
|
4309
4438
|
const balance = parseFloat(balanceEntry.balance) || 0;
|
|
4310
4439
|
const valueUsd = parseFloat(balanceEntry.valueUsd) || 0;
|
|
4311
4440
|
totalBalance += balance;
|
|
4312
4441
|
totalValueUsd += valueUsd;
|
|
4313
|
-
|
|
4442
|
+
logger.debug(tag, ` Balance entry: ${balance} (${valueUsd} USD)`);
|
|
4314
4443
|
}
|
|
4315
|
-
|
|
4444
|
+
logger.debug(tag, `Aggregated balance: ${totalBalance} (${totalValueUsd.toFixed(2)} USD)`);
|
|
4316
4445
|
return { totalBalance, totalValueUsd };
|
|
4317
4446
|
}
|
|
4318
4447
|
function updateBalancesWithPrice(balances, freshPriceUsd) {
|
|
@@ -4323,7 +4452,7 @@ function updateBalancesWithPrice(balances, freshPriceUsd) {
|
|
|
4323
4452
|
const balanceAmount = parseFloat(balance.balance || 0);
|
|
4324
4453
|
balance.valueUsd = (balanceAmount * freshPriceUsd).toString();
|
|
4325
4454
|
}
|
|
4326
|
-
|
|
4455
|
+
logger.debug(tag, "Updated all balances with fresh price data");
|
|
4327
4456
|
}
|
|
4328
4457
|
function buildDashboardFromPortfolioData(portfolioData) {
|
|
4329
4458
|
const cacheAge = portfolioData.lastUpdated ? Math.floor((Date.now() - portfolioData.lastUpdated) / 1000) : 0;
|
|
@@ -4381,19 +4510,18 @@ function enrichBalancesWithAssetInfo(balances, assetsMap, caipToNetworkId7) {
|
|
|
4381
4510
|
}
|
|
4382
4511
|
|
|
4383
4512
|
// src/utils/sync-state.ts
|
|
4384
|
-
var log3 = __require("@pioneer-platform/loggerdog")();
|
|
4385
4513
|
var TAG10 = " | sync-state | ";
|
|
4386
4514
|
function resolveAssetInfo(assetsMap, assetData, asset) {
|
|
4387
4515
|
const tag = TAG10 + " | resolveAssetInfo | ";
|
|
4388
4516
|
let assetInfo = assetsMap.get(asset.caip.toLowerCase());
|
|
4389
|
-
|
|
4517
|
+
logger.debug(tag, "assetInfo from assetsMap:", assetInfo);
|
|
4390
4518
|
const assetInfoDiscovery = assetData[asset.caip];
|
|
4391
|
-
|
|
4519
|
+
logger.debug(tag, "assetInfoDiscovery:", assetInfoDiscovery);
|
|
4392
4520
|
if (assetInfoDiscovery) {
|
|
4393
4521
|
assetInfo = assetInfoDiscovery;
|
|
4394
4522
|
}
|
|
4395
4523
|
if (!assetInfo) {
|
|
4396
|
-
|
|
4524
|
+
logger.debug(tag, "Building placeholder asset for", asset.caip);
|
|
4397
4525
|
assetInfo = {
|
|
4398
4526
|
caip: asset.caip.toLowerCase(),
|
|
4399
4527
|
networkId: asset.networkId,
|
|
@@ -4515,19 +4643,18 @@ function validatePubkeysNetworks(pubkeys, tag = "") {
|
|
|
4515
4643
|
|
|
4516
4644
|
// src/utils/path-discovery.ts
|
|
4517
4645
|
import { getPaths } from "@pioneer-platform/pioneer-coins";
|
|
4518
|
-
var log4 = __require("@pioneer-platform/loggerdog")();
|
|
4519
4646
|
async function ensurePathsForBlockchains(blockchains, currentPaths, tag) {
|
|
4520
4647
|
let allPaths = [...currentPaths];
|
|
4521
4648
|
for (const blockchain of blockchains) {
|
|
4522
4649
|
const networkId = normalizeNetworkId(blockchain);
|
|
4523
4650
|
const existingPaths = allPaths.filter((path) => matchesNetwork(path, networkId));
|
|
4524
4651
|
if (existingPaths.length === 0) {
|
|
4525
|
-
|
|
4652
|
+
logger.info(tag, `Discovering paths for ${networkId}...`);
|
|
4526
4653
|
const newPaths = getPaths([networkId]);
|
|
4527
4654
|
if (!newPaths || newPaths.length === 0) {
|
|
4528
4655
|
throw new Error(`Path discovery failed for ${networkId}. ` + `Available blockchains: ${blockchains.join(", ")}`);
|
|
4529
4656
|
}
|
|
4530
|
-
|
|
4657
|
+
logger.debug(tag, `Added ${newPaths.length} paths for ${networkId}`);
|
|
4531
4658
|
allPaths = allPaths.concat(newPaths);
|
|
4532
4659
|
}
|
|
4533
4660
|
}
|
|
@@ -4536,7 +4663,6 @@ async function ensurePathsForBlockchains(blockchains, currentPaths, tag) {
|
|
|
4536
4663
|
|
|
4537
4664
|
// src/utils/pubkey-sync.ts
|
|
4538
4665
|
import { addressNListToBIP32 as addressNListToBIP322 } from "@pioneer-platform/pioneer-coins";
|
|
4539
|
-
var log5 = __require("@pioneer-platform/loggerdog")();
|
|
4540
4666
|
async function syncPubkeysForBlockchains(blockchains, paths, existingPubkeys, keepKeySdk, context, getPubkeyFn, addPubkeyCallback, tag) {
|
|
4541
4667
|
for (const blockchain of blockchains) {
|
|
4542
4668
|
const networkId = normalizeNetworkId(blockchain);
|
|
@@ -4545,22 +4671,22 @@ async function syncPubkeysForBlockchains(blockchains, paths, existingPubkeys, ke
|
|
|
4545
4671
|
const availablePaths = paths.map((p) => p.note || p.path || "unnamed").join(", ");
|
|
4546
4672
|
throw new Error(`No paths found for ${networkId}. ` + `Available paths: ${availablePaths || "none"}`);
|
|
4547
4673
|
}
|
|
4548
|
-
|
|
4674
|
+
logger.info(tag, `Syncing ${pathsForChain.length} pubkeys for ${networkId}...`);
|
|
4549
4675
|
for (const path of pathsForChain) {
|
|
4550
4676
|
const pathBip32 = addressNListToBIP322(path.addressNListMaster);
|
|
4551
4677
|
const existingPubkey = existingPubkeys.find((p) => p.pathMaster === pathBip32);
|
|
4552
4678
|
if (!existingPubkey) {
|
|
4553
|
-
|
|
4679
|
+
logger.debug(tag, `Fetching pubkey for path ${pathBip32}...`);
|
|
4554
4680
|
const newPubkey = await getPubkeyFn(blockchain, path, keepKeySdk, context);
|
|
4555
4681
|
if (!newPubkey) {
|
|
4556
4682
|
throw new Error(`Pubkey fetch failed for ${networkId} at path ${pathBip32}. ` + `Ensure hardware wallet is connected and unlocked.`);
|
|
4557
4683
|
}
|
|
4558
4684
|
addPubkeyCallback(newPubkey);
|
|
4559
|
-
|
|
4685
|
+
logger.debug(tag, `✓ Added pubkey for ${pathBip32}`);
|
|
4560
4686
|
}
|
|
4561
4687
|
}
|
|
4562
4688
|
}
|
|
4563
|
-
|
|
4689
|
+
logger.info(tag, `✅ Pubkey sync complete. Total pubkeys: ${existingPubkeys.length}`);
|
|
4564
4690
|
}
|
|
4565
4691
|
|
|
4566
4692
|
// src/index.ts
|
|
@@ -4981,48 +5107,48 @@ class SDK {
|
|
|
4981
5107
|
};
|
|
4982
5108
|
this.sync = async function() {
|
|
4983
5109
|
const tag6 = `${TAG12} | sync | `;
|
|
4984
|
-
const
|
|
5110
|
+
const log2 = logger;
|
|
4985
5111
|
try {
|
|
4986
5112
|
this.syncState = {
|
|
4987
5113
|
...createInitialSyncState(this.blockchains.length),
|
|
4988
5114
|
syncProgress: 10
|
|
4989
5115
|
};
|
|
4990
5116
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
4991
|
-
|
|
5117
|
+
log2.info(tag6, "Fetching initial pubkeys...");
|
|
4992
5118
|
await this.getPubkeys();
|
|
4993
5119
|
this.syncState.syncProgress = 20;
|
|
4994
5120
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
4995
|
-
|
|
5121
|
+
log2.info(tag6, "Discovering paths for blockchains...");
|
|
4996
5122
|
this.paths = await ensurePathsForBlockchains(this.blockchains, this.paths, tag6);
|
|
4997
5123
|
this.syncState.syncProgress = 30;
|
|
4998
5124
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
4999
|
-
|
|
5125
|
+
log2.info(tag6, "Synchronizing pubkeys...");
|
|
5000
5126
|
await syncPubkeysForBlockchains(this.blockchains, this.paths, this.pubkeys, this.keepKeySdk, this.context, getPubkey, (pubkey) => this.addPubkey(pubkey), tag6);
|
|
5001
5127
|
this.syncState.syncProgress = 50;
|
|
5002
5128
|
this.syncState.syncedChains = this.blockchains.length;
|
|
5003
5129
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
5004
|
-
|
|
5130
|
+
log2.info(tag6, "Fetching balances...");
|
|
5005
5131
|
await this.getBalances();
|
|
5006
5132
|
this.syncState.syncProgress = 70;
|
|
5007
5133
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
5008
|
-
|
|
5134
|
+
log2.info(tag6, "Loading charts (tokens + portfolio)...");
|
|
5009
5135
|
await this.getCharts();
|
|
5010
|
-
|
|
5136
|
+
log2.info(tag6, `Charts loaded. Total balances: ${this.balances.length}`);
|
|
5011
5137
|
this.syncState.syncProgress = 85;
|
|
5012
5138
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
5013
|
-
|
|
5139
|
+
log2.info(tag6, "Syncing market prices...");
|
|
5014
5140
|
await this.syncMarket();
|
|
5015
5141
|
this.syncState.syncProgress = 95;
|
|
5016
5142
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
5017
|
-
|
|
5143
|
+
log2.info(tag6, "Building dashboard...");
|
|
5018
5144
|
this.dashboard = buildDashboardFromBalances(this.balances, [...new Set(this.blockchains)], this.assetsMap);
|
|
5019
5145
|
this.syncState = createFreshSyncState(this.blockchains.length);
|
|
5020
5146
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
5021
5147
|
this.events.emit("SYNC_COMPLETE", this.syncState);
|
|
5022
|
-
|
|
5148
|
+
log2.info(tag6, "✅ Sync complete!");
|
|
5023
5149
|
return true;
|
|
5024
5150
|
} catch (e) {
|
|
5025
|
-
|
|
5151
|
+
log2.error(tag6, "Sync failed:", e);
|
|
5026
5152
|
this.syncState = {
|
|
5027
5153
|
...this.syncState,
|
|
5028
5154
|
isSynced: false,
|
package/dist/index.js
CHANGED
|
@@ -33,6 +33,117 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
33
33
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
+
// ../../support/loggerdog/lib/index.js
|
|
37
|
+
var require_lib = __commonJS((exports, module) => {
|
|
38
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from, pack) {
|
|
39
|
+
if (pack || arguments.length === 2)
|
|
40
|
+
for (var i = 0, l = from.length, ar;i < l; i++) {
|
|
41
|
+
if (ar || !(i in from)) {
|
|
42
|
+
if (!ar)
|
|
43
|
+
ar = Array.prototype.slice.call(from, 0, i);
|
|
44
|
+
ar[i] = from[i];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
48
|
+
};
|
|
49
|
+
var LOG_LEVELS = {
|
|
50
|
+
TEST: { val: 0, label: "TEST", color: "color: cyan" },
|
|
51
|
+
EMERG: { val: 0, label: "EMERG", color: "color: magenta" },
|
|
52
|
+
ALERT: { val: 1, label: "ALERT", color: "color: magenta" },
|
|
53
|
+
CRIT: { val: 2, label: "CRIT", color: "color: red" },
|
|
54
|
+
ERROR: { val: 3, label: "ERROR", color: "color: red" },
|
|
55
|
+
WARN: { val: 4, label: "WARN", color: "color: orange" },
|
|
56
|
+
NOTICE: { val: 5, label: "NOTICE", color: "color: yellow" },
|
|
57
|
+
VERBOSE: { val: 6, label: "VERBOSE", color: "color: cyan" },
|
|
58
|
+
INFO: { val: 6, label: "INFO", color: "color: cyan" },
|
|
59
|
+
DEBUG: { val: 7, label: "DEBUG", color: "color: green" },
|
|
60
|
+
DEBUGV: { val: 8, label: "DEBUG", color: "color: green" },
|
|
61
|
+
DEBUGVV: { val: 9, label: "DEBUG", color: "color: green" }
|
|
62
|
+
};
|
|
63
|
+
var DEFAULT_LOG_LEVEL = typeof process !== "undefined" ? process.env["DEFAULT_LOG_LEVEL"] || "INFO" : "INFO";
|
|
64
|
+
function _extractContext(stack, depth) {
|
|
65
|
+
try {
|
|
66
|
+
var arr = stack.split(`
|
|
67
|
+
`);
|
|
68
|
+
var chunks = arr[depth].split("/");
|
|
69
|
+
var business = chunks[chunks.length - 1];
|
|
70
|
+
var matches = business.match(/^([^:]+):(\d+):(\d+)/i) || "";
|
|
71
|
+
var filename = matches[1];
|
|
72
|
+
var line = matches[2];
|
|
73
|
+
var pos = matches[3];
|
|
74
|
+
return { filename, line, pos };
|
|
75
|
+
} catch (ex) {
|
|
76
|
+
return { filename: "unknown" };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function _getContextString() {
|
|
80
|
+
var stack = new Error().stack || "";
|
|
81
|
+
var _a = _extractContext(stack, 3), filename = _a.filename, line = _a.line, pos = _a.pos;
|
|
82
|
+
return "[".concat(filename, ":").concat(line, ":").concat(pos, "]");
|
|
83
|
+
}
|
|
84
|
+
var Logger = function() {
|
|
85
|
+
function Logger2() {
|
|
86
|
+
var stack = new Error().stack || "";
|
|
87
|
+
var ctx = _extractContext(stack, 3);
|
|
88
|
+
this._tag = ctx.filename || "";
|
|
89
|
+
for (var lvl in LOG_LEVELS) {
|
|
90
|
+
this[lvl.toLowerCase()] = this._log.bind(this, lvl);
|
|
91
|
+
}
|
|
92
|
+
this._setLogLevel();
|
|
93
|
+
}
|
|
94
|
+
Logger2.prototype._setLogLevel = function() {
|
|
95
|
+
var tag = this._tag.split(".")[0];
|
|
96
|
+
tag = tag.toUpperCase().replace("-", "_");
|
|
97
|
+
var level = typeof process !== "undefined" ? process.env["LOG_LEVEL_" + tag] || null : null;
|
|
98
|
+
if (level && LOG_LEVELS[level] !== undefined) {
|
|
99
|
+
this._level = LOG_LEVELS[level].val;
|
|
100
|
+
} else {
|
|
101
|
+
this._level = LOG_LEVELS[DEFAULT_LOG_LEVEL].val;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
Logger2.prototype._log = function(level) {
|
|
105
|
+
var args = [];
|
|
106
|
+
for (var _i = 1;_i < arguments.length; _i++) {
|
|
107
|
+
args[_i - 1] = arguments[_i];
|
|
108
|
+
}
|
|
109
|
+
if (this._level >= LOG_LEVELS[level].val) {
|
|
110
|
+
var dt = new Date().toISOString().replace("T", " ");
|
|
111
|
+
var ctx = _getContextString();
|
|
112
|
+
var label = LOG_LEVELS[level].label;
|
|
113
|
+
var color = LOG_LEVELS[level].color;
|
|
114
|
+
var message = undefined;
|
|
115
|
+
if (typeof process !== "undefined" && process.env["STRUCTURED_LOGGING"]) {
|
|
116
|
+
message = {};
|
|
117
|
+
var tag = args[0];
|
|
118
|
+
var param = args[1];
|
|
119
|
+
var value = args[2];
|
|
120
|
+
if (typeof args === "object") {
|
|
121
|
+
message.loggerdog = true;
|
|
122
|
+
message.label = label;
|
|
123
|
+
message.param = param;
|
|
124
|
+
message.value = value;
|
|
125
|
+
message.ctx = ctx;
|
|
126
|
+
message.dt = dt;
|
|
127
|
+
message.tag = tag.toString();
|
|
128
|
+
message.raw = args.toString();
|
|
129
|
+
} else {
|
|
130
|
+
message.raw = args;
|
|
131
|
+
}
|
|
132
|
+
console.log("%c " + dt, color, label, ctx, message);
|
|
133
|
+
} else {
|
|
134
|
+
console.log.apply(console, __spreadArray(["%c " + dt, color, label, ctx], args, false));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
return Logger2;
|
|
139
|
+
}();
|
|
140
|
+
var getLogger = function() {
|
|
141
|
+
return new Logger;
|
|
142
|
+
};
|
|
143
|
+
exports.default = getLogger;
|
|
144
|
+
module.exports = getLogger;
|
|
145
|
+
});
|
|
146
|
+
|
|
36
147
|
// ../../../node_modules/coinselect/utils.js
|
|
37
148
|
var require_utils = __commonJS((exports, module) => {
|
|
38
149
|
var TX_EMPTY_SIZE = 4 + 1 + 1 + 4;
|
|
@@ -782,9 +893,9 @@ import { KeepKeySdk } from "@keepkey/keepkey-sdk";
|
|
|
782
893
|
import { caipToNetworkId as caipToNetworkId7, networkIdToCaip as networkIdToCaip2 } from "@pioneer-platform/pioneer-caip";
|
|
783
894
|
|
|
784
895
|
// ../pioneer-client/lib/index.js
|
|
896
|
+
var import_loggerdog = __toESM(require_lib(), 1);
|
|
785
897
|
import SwaggerClient from "swagger-client";
|
|
786
|
-
|
|
787
|
-
var log = typeof window === "undefined" ? loggerdog() : {
|
|
898
|
+
var log = typeof window === "undefined" ? import_loggerdog.default() : {
|
|
788
899
|
debug: (...args) => console.debug(...args),
|
|
789
900
|
info: (...args) => console.info(...args),
|
|
790
901
|
warn: (...args) => console.warn(...args),
|
|
@@ -1129,6 +1240,25 @@ function R(t) {
|
|
|
1129
1240
|
var A = o;
|
|
1130
1241
|
var P = o.prototype;
|
|
1131
1242
|
|
|
1243
|
+
// src/utils/logger.ts
|
|
1244
|
+
var DEBUG = process.env.DEBUG === "true" || typeof window !== "undefined" && window.DEBUG;
|
|
1245
|
+
var logger = {
|
|
1246
|
+
info: (tag, ...args) => {
|
|
1247
|
+
console.log(`[INFO] ${tag}`, ...args);
|
|
1248
|
+
},
|
|
1249
|
+
debug: (tag, ...args) => {
|
|
1250
|
+
if (DEBUG) {
|
|
1251
|
+
console.log(`[DEBUG] ${tag}`, ...args);
|
|
1252
|
+
}
|
|
1253
|
+
},
|
|
1254
|
+
warn: (tag, ...args) => {
|
|
1255
|
+
console.warn(`[WARN] ${tag}`, ...args);
|
|
1256
|
+
},
|
|
1257
|
+
error: (tag, ...args) => {
|
|
1258
|
+
console.error(`[ERROR] ${tag}`, ...args);
|
|
1259
|
+
}
|
|
1260
|
+
};
|
|
1261
|
+
|
|
1132
1262
|
// src/getPubkey.ts
|
|
1133
1263
|
import { NetworkIdToChain } from "@pioneer-platform/pioneer-caip";
|
|
1134
1264
|
import {
|
|
@@ -4243,7 +4373,6 @@ function filterPubkeysForAsset(pubkeys, caip, caipToNetworkId7) {
|
|
|
4243
4373
|
}
|
|
4244
4374
|
|
|
4245
4375
|
// src/utils/portfolio-helpers.ts
|
|
4246
|
-
var log2 = __require("@pioneer-platform/loggerdog")();
|
|
4247
4376
|
var TAG9 = " | portfolio-helpers | ";
|
|
4248
4377
|
function isCacheDataValid(portfolioData) {
|
|
4249
4378
|
if (!portfolioData.networks || !Array.isArray(portfolioData.networks)) {
|
|
@@ -4266,22 +4395,22 @@ async function fetchMarketPrice(pioneer, caip) {
|
|
|
4266
4395
|
const tag = TAG9 + " | fetchMarketPrice | ";
|
|
4267
4396
|
try {
|
|
4268
4397
|
if (!caip || typeof caip !== "string" || !caip.includes(":")) {
|
|
4269
|
-
|
|
4398
|
+
logger.warn(tag, "Invalid or missing CAIP, skipping market price fetch:", caip);
|
|
4270
4399
|
return 0;
|
|
4271
4400
|
}
|
|
4272
|
-
|
|
4401
|
+
logger.debug(tag, "Fetching fresh market price for:", caip);
|
|
4273
4402
|
const marketData = await pioneer.GetMarketInfo([caip]);
|
|
4274
|
-
|
|
4403
|
+
logger.debug(tag, "Market data response:", marketData);
|
|
4275
4404
|
if (marketData && marketData.data && marketData.data.length > 0) {
|
|
4276
4405
|
const price = marketData.data[0];
|
|
4277
|
-
|
|
4406
|
+
logger.debug(tag, "✅ Fresh market price:", price);
|
|
4278
4407
|
return price;
|
|
4279
4408
|
} else {
|
|
4280
|
-
|
|
4409
|
+
logger.warn(tag, "No market data returned for:", caip);
|
|
4281
4410
|
return 0;
|
|
4282
4411
|
}
|
|
4283
4412
|
} catch (marketError) {
|
|
4284
|
-
|
|
4413
|
+
logger.error(tag, "Error fetching market price:", marketError);
|
|
4285
4414
|
return 0;
|
|
4286
4415
|
}
|
|
4287
4416
|
}
|
|
@@ -4295,7 +4424,7 @@ function extractPriceFromBalances(balances) {
|
|
|
4295
4424
|
const valueUsd = parseFloat(balances[0].valueUsd);
|
|
4296
4425
|
if (balance > 0 && valueUsd > 0) {
|
|
4297
4426
|
priceValue = valueUsd / balance;
|
|
4298
|
-
|
|
4427
|
+
logger.debug(tag, "Calculated priceUsd from valueUsd/balance:", priceValue);
|
|
4299
4428
|
}
|
|
4300
4429
|
}
|
|
4301
4430
|
return priceValue || 0;
|
|
@@ -4304,15 +4433,15 @@ function aggregateBalances(balances, caip) {
|
|
|
4304
4433
|
const tag = TAG9 + " | aggregateBalances | ";
|
|
4305
4434
|
let totalBalance = 0;
|
|
4306
4435
|
let totalValueUsd = 0;
|
|
4307
|
-
|
|
4436
|
+
logger.debug(tag, `Aggregating ${balances.length} balance entries for ${caip}`);
|
|
4308
4437
|
for (const balanceEntry of balances) {
|
|
4309
4438
|
const balance = parseFloat(balanceEntry.balance) || 0;
|
|
4310
4439
|
const valueUsd = parseFloat(balanceEntry.valueUsd) || 0;
|
|
4311
4440
|
totalBalance += balance;
|
|
4312
4441
|
totalValueUsd += valueUsd;
|
|
4313
|
-
|
|
4442
|
+
logger.debug(tag, ` Balance entry: ${balance} (${valueUsd} USD)`);
|
|
4314
4443
|
}
|
|
4315
|
-
|
|
4444
|
+
logger.debug(tag, `Aggregated balance: ${totalBalance} (${totalValueUsd.toFixed(2)} USD)`);
|
|
4316
4445
|
return { totalBalance, totalValueUsd };
|
|
4317
4446
|
}
|
|
4318
4447
|
function updateBalancesWithPrice(balances, freshPriceUsd) {
|
|
@@ -4323,7 +4452,7 @@ function updateBalancesWithPrice(balances, freshPriceUsd) {
|
|
|
4323
4452
|
const balanceAmount = parseFloat(balance.balance || 0);
|
|
4324
4453
|
balance.valueUsd = (balanceAmount * freshPriceUsd).toString();
|
|
4325
4454
|
}
|
|
4326
|
-
|
|
4455
|
+
logger.debug(tag, "Updated all balances with fresh price data");
|
|
4327
4456
|
}
|
|
4328
4457
|
function buildDashboardFromPortfolioData(portfolioData) {
|
|
4329
4458
|
const cacheAge = portfolioData.lastUpdated ? Math.floor((Date.now() - portfolioData.lastUpdated) / 1000) : 0;
|
|
@@ -4381,19 +4510,18 @@ function enrichBalancesWithAssetInfo(balances, assetsMap, caipToNetworkId7) {
|
|
|
4381
4510
|
}
|
|
4382
4511
|
|
|
4383
4512
|
// src/utils/sync-state.ts
|
|
4384
|
-
var log3 = __require("@pioneer-platform/loggerdog")();
|
|
4385
4513
|
var TAG10 = " | sync-state | ";
|
|
4386
4514
|
function resolveAssetInfo(assetsMap, assetData, asset) {
|
|
4387
4515
|
const tag = TAG10 + " | resolveAssetInfo | ";
|
|
4388
4516
|
let assetInfo = assetsMap.get(asset.caip.toLowerCase());
|
|
4389
|
-
|
|
4517
|
+
logger.debug(tag, "assetInfo from assetsMap:", assetInfo);
|
|
4390
4518
|
const assetInfoDiscovery = assetData[asset.caip];
|
|
4391
|
-
|
|
4519
|
+
logger.debug(tag, "assetInfoDiscovery:", assetInfoDiscovery);
|
|
4392
4520
|
if (assetInfoDiscovery) {
|
|
4393
4521
|
assetInfo = assetInfoDiscovery;
|
|
4394
4522
|
}
|
|
4395
4523
|
if (!assetInfo) {
|
|
4396
|
-
|
|
4524
|
+
logger.debug(tag, "Building placeholder asset for", asset.caip);
|
|
4397
4525
|
assetInfo = {
|
|
4398
4526
|
caip: asset.caip.toLowerCase(),
|
|
4399
4527
|
networkId: asset.networkId,
|
|
@@ -4515,19 +4643,18 @@ function validatePubkeysNetworks(pubkeys, tag = "") {
|
|
|
4515
4643
|
|
|
4516
4644
|
// src/utils/path-discovery.ts
|
|
4517
4645
|
import { getPaths } from "@pioneer-platform/pioneer-coins";
|
|
4518
|
-
var log4 = __require("@pioneer-platform/loggerdog")();
|
|
4519
4646
|
async function ensurePathsForBlockchains(blockchains, currentPaths, tag) {
|
|
4520
4647
|
let allPaths = [...currentPaths];
|
|
4521
4648
|
for (const blockchain of blockchains) {
|
|
4522
4649
|
const networkId = normalizeNetworkId(blockchain);
|
|
4523
4650
|
const existingPaths = allPaths.filter((path) => matchesNetwork(path, networkId));
|
|
4524
4651
|
if (existingPaths.length === 0) {
|
|
4525
|
-
|
|
4652
|
+
logger.info(tag, `Discovering paths for ${networkId}...`);
|
|
4526
4653
|
const newPaths = getPaths([networkId]);
|
|
4527
4654
|
if (!newPaths || newPaths.length === 0) {
|
|
4528
4655
|
throw new Error(`Path discovery failed for ${networkId}. ` + `Available blockchains: ${blockchains.join(", ")}`);
|
|
4529
4656
|
}
|
|
4530
|
-
|
|
4657
|
+
logger.debug(tag, `Added ${newPaths.length} paths for ${networkId}`);
|
|
4531
4658
|
allPaths = allPaths.concat(newPaths);
|
|
4532
4659
|
}
|
|
4533
4660
|
}
|
|
@@ -4536,7 +4663,6 @@ async function ensurePathsForBlockchains(blockchains, currentPaths, tag) {
|
|
|
4536
4663
|
|
|
4537
4664
|
// src/utils/pubkey-sync.ts
|
|
4538
4665
|
import { addressNListToBIP32 as addressNListToBIP322 } from "@pioneer-platform/pioneer-coins";
|
|
4539
|
-
var log5 = __require("@pioneer-platform/loggerdog")();
|
|
4540
4666
|
async function syncPubkeysForBlockchains(blockchains, paths, existingPubkeys, keepKeySdk, context, getPubkeyFn, addPubkeyCallback, tag) {
|
|
4541
4667
|
for (const blockchain of blockchains) {
|
|
4542
4668
|
const networkId = normalizeNetworkId(blockchain);
|
|
@@ -4545,22 +4671,22 @@ async function syncPubkeysForBlockchains(blockchains, paths, existingPubkeys, ke
|
|
|
4545
4671
|
const availablePaths = paths.map((p) => p.note || p.path || "unnamed").join(", ");
|
|
4546
4672
|
throw new Error(`No paths found for ${networkId}. ` + `Available paths: ${availablePaths || "none"}`);
|
|
4547
4673
|
}
|
|
4548
|
-
|
|
4674
|
+
logger.info(tag, `Syncing ${pathsForChain.length} pubkeys for ${networkId}...`);
|
|
4549
4675
|
for (const path of pathsForChain) {
|
|
4550
4676
|
const pathBip32 = addressNListToBIP322(path.addressNListMaster);
|
|
4551
4677
|
const existingPubkey = existingPubkeys.find((p) => p.pathMaster === pathBip32);
|
|
4552
4678
|
if (!existingPubkey) {
|
|
4553
|
-
|
|
4679
|
+
logger.debug(tag, `Fetching pubkey for path ${pathBip32}...`);
|
|
4554
4680
|
const newPubkey = await getPubkeyFn(blockchain, path, keepKeySdk, context);
|
|
4555
4681
|
if (!newPubkey) {
|
|
4556
4682
|
throw new Error(`Pubkey fetch failed for ${networkId} at path ${pathBip32}. ` + `Ensure hardware wallet is connected and unlocked.`);
|
|
4557
4683
|
}
|
|
4558
4684
|
addPubkeyCallback(newPubkey);
|
|
4559
|
-
|
|
4685
|
+
logger.debug(tag, `✓ Added pubkey for ${pathBip32}`);
|
|
4560
4686
|
}
|
|
4561
4687
|
}
|
|
4562
4688
|
}
|
|
4563
|
-
|
|
4689
|
+
logger.info(tag, `✅ Pubkey sync complete. Total pubkeys: ${existingPubkeys.length}`);
|
|
4564
4690
|
}
|
|
4565
4691
|
|
|
4566
4692
|
// src/index.ts
|
|
@@ -4981,48 +5107,48 @@ class SDK {
|
|
|
4981
5107
|
};
|
|
4982
5108
|
this.sync = async function() {
|
|
4983
5109
|
const tag6 = `${TAG12} | sync | `;
|
|
4984
|
-
const
|
|
5110
|
+
const log2 = logger;
|
|
4985
5111
|
try {
|
|
4986
5112
|
this.syncState = {
|
|
4987
5113
|
...createInitialSyncState(this.blockchains.length),
|
|
4988
5114
|
syncProgress: 10
|
|
4989
5115
|
};
|
|
4990
5116
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
4991
|
-
|
|
5117
|
+
log2.info(tag6, "Fetching initial pubkeys...");
|
|
4992
5118
|
await this.getPubkeys();
|
|
4993
5119
|
this.syncState.syncProgress = 20;
|
|
4994
5120
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
4995
|
-
|
|
5121
|
+
log2.info(tag6, "Discovering paths for blockchains...");
|
|
4996
5122
|
this.paths = await ensurePathsForBlockchains(this.blockchains, this.paths, tag6);
|
|
4997
5123
|
this.syncState.syncProgress = 30;
|
|
4998
5124
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
4999
|
-
|
|
5125
|
+
log2.info(tag6, "Synchronizing pubkeys...");
|
|
5000
5126
|
await syncPubkeysForBlockchains(this.blockchains, this.paths, this.pubkeys, this.keepKeySdk, this.context, getPubkey, (pubkey) => this.addPubkey(pubkey), tag6);
|
|
5001
5127
|
this.syncState.syncProgress = 50;
|
|
5002
5128
|
this.syncState.syncedChains = this.blockchains.length;
|
|
5003
5129
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
5004
|
-
|
|
5130
|
+
log2.info(tag6, "Fetching balances...");
|
|
5005
5131
|
await this.getBalances();
|
|
5006
5132
|
this.syncState.syncProgress = 70;
|
|
5007
5133
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
5008
|
-
|
|
5134
|
+
log2.info(tag6, "Loading charts (tokens + portfolio)...");
|
|
5009
5135
|
await this.getCharts();
|
|
5010
|
-
|
|
5136
|
+
log2.info(tag6, `Charts loaded. Total balances: ${this.balances.length}`);
|
|
5011
5137
|
this.syncState.syncProgress = 85;
|
|
5012
5138
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
5013
|
-
|
|
5139
|
+
log2.info(tag6, "Syncing market prices...");
|
|
5014
5140
|
await this.syncMarket();
|
|
5015
5141
|
this.syncState.syncProgress = 95;
|
|
5016
5142
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
5017
|
-
|
|
5143
|
+
log2.info(tag6, "Building dashboard...");
|
|
5018
5144
|
this.dashboard = buildDashboardFromBalances(this.balances, [...new Set(this.blockchains)], this.assetsMap);
|
|
5019
5145
|
this.syncState = createFreshSyncState(this.blockchains.length);
|
|
5020
5146
|
this.events.emit("SYNC_STATE_CHANGED", this.syncState);
|
|
5021
5147
|
this.events.emit("SYNC_COMPLETE", this.syncState);
|
|
5022
|
-
|
|
5148
|
+
log2.info(tag6, "✅ Sync complete!");
|
|
5023
5149
|
return true;
|
|
5024
5150
|
} catch (e) {
|
|
5025
|
-
|
|
5151
|
+
log2.error(tag6, "Sync failed:", e);
|
|
5026
5152
|
this.syncState = {
|
|
5027
5153
|
...this.syncState,
|
|
5028
5154
|
isSynced: false,
|
package/package.json
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "highlander",
|
|
3
3
|
"name": "@pioneer-platform/pioneer-sdk",
|
|
4
|
-
"version": "8.15.
|
|
4
|
+
"version": "8.15.16",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@keepkey/keepkey-sdk": "^0.2.62",
|
|
7
|
-
"@pioneer-platform/loggerdog": "^8.11.0",
|
|
8
7
|
"@pioneer-platform/pioneer-caip": "^9.10.2",
|
|
9
8
|
"@pioneer-platform/pioneer-client": "^9.10.11",
|
|
10
9
|
"@pioneer-platform/pioneer-coins": "^9.11.2",
|
|
11
|
-
"@pioneer-platform/pioneer-discovery": "^8.15.
|
|
10
|
+
"@pioneer-platform/pioneer-discovery": "^8.15.16",
|
|
12
11
|
"@pioneer-platform/pioneer-events": "^8.12.0",
|
|
13
12
|
"coinselect": "^3.1.13",
|
|
14
13
|
"eventemitter3": "^5.0.1",
|
package/src/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ import EventEmitter from 'events';
|
|
|
8
8
|
|
|
9
9
|
import { getCharts } from './charts/index.js';
|
|
10
10
|
//internal
|
|
11
|
+
import { logger } from './utils/logger.js';
|
|
11
12
|
import { getPubkey } from './getPubkey.js';
|
|
12
13
|
import { optimizedGetPubkeys } from './kkapi-batch-client.js';
|
|
13
14
|
import { OfflineClient } from './offline-client.js';
|
|
@@ -660,7 +661,7 @@ export class SDK {
|
|
|
660
661
|
};
|
|
661
662
|
this.sync = async function () {
|
|
662
663
|
const tag = `${TAG} | sync | `;
|
|
663
|
-
const log =
|
|
664
|
+
const log = logger;
|
|
664
665
|
|
|
665
666
|
try {
|
|
666
667
|
// Update sync state: starting
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Simple client-side logger for Pioneer SDK
|
|
2
|
+
// Replaces server-side loggerdog dependency
|
|
3
|
+
|
|
4
|
+
const DEBUG = process.env.DEBUG === 'true' || typeof window !== 'undefined' && (window as any).DEBUG;
|
|
5
|
+
|
|
6
|
+
export const logger = {
|
|
7
|
+
info: (tag: string, ...args: any[]) => {
|
|
8
|
+
console.log(`[INFO] ${tag}`, ...args);
|
|
9
|
+
},
|
|
10
|
+
debug: (tag: string, ...args: any[]) => {
|
|
11
|
+
if (DEBUG) {
|
|
12
|
+
console.log(`[DEBUG] ${tag}`, ...args);
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
warn: (tag: string, ...args: any[]) => {
|
|
16
|
+
console.warn(`[WARN] ${tag}`, ...args);
|
|
17
|
+
},
|
|
18
|
+
error: (tag: string, ...args: any[]) => {
|
|
19
|
+
console.error(`[ERROR] ${tag}`, ...args);
|
|
20
|
+
},
|
|
21
|
+
};
|
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { getPaths } from '@pioneer-platform/pioneer-coins';
|
|
4
4
|
import { matchesNetwork, normalizeNetworkId } from './network-helpers.js';
|
|
5
|
-
|
|
6
|
-
const log = require('@pioneer-platform/loggerdog')();
|
|
5
|
+
import { logger as log } from './logger.js';
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* Ensure paths exist for all blockchains
|
package/src/utils/pubkey-sync.ts
CHANGED
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { addressNListToBIP32 } from '@pioneer-platform/pioneer-coins';
|
|
4
4
|
import { matchesNetwork, normalizeNetworkId } from './network-helpers.js';
|
|
5
|
-
|
|
6
|
-
const log = require('@pioneer-platform/loggerdog')();
|
|
5
|
+
import { logger as log } from './logger.js';
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* Synchronize pubkeys for all blockchains
|