@pioneer-platform/pioneer-sdk 8.15.34 → 8.15.40

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 CHANGED
@@ -472,6 +472,14 @@ function processPortfolioBalance(balance, primaryAddress, context, blockchains)
472
472
  valueUsd: balance.valueUsd.toString(),
473
473
  updated: new Date().getTime()
474
474
  };
475
+ if (balance.caip === "cosmos:cosmoshub-4/slip44:118" || balance.caip === "cosmos:osmosis-1/slip44:118") {
476
+ console.log(tag2, `\uD83D\uDCCA [CHART CREATED] ${assetInfo?.symbol || balance.symbol}:`, {
477
+ caip: balance.caip,
478
+ decimal: chartBalance.decimal,
479
+ decimals: chartBalance.decimals,
480
+ precision: chartBalance.precision
481
+ });
482
+ }
475
483
  if (balance.display) {
476
484
  chartBalance.icon = ["multi", chartBalance.icon, balance.display.toString()].toString();
477
485
  }
@@ -4463,6 +4471,13 @@ function enrichBalancesWithAssetInfo(balances, assetsMap, caipToNetworkId7) {
4463
4471
  valueUsd: balance.valueUsd,
4464
4472
  priceUsd: balance.priceUsd
4465
4473
  });
4474
+ if (balance.caip === "cosmos:cosmoshub-4/slip44:118" || balance.caip === "cosmos:osmosis-1/slip44:118") {
4475
+ console.log(tag, `✅ [DEBUG] Enriched ${balance.symbol}:`, {
4476
+ caip: balance.caip,
4477
+ decimals: balance.decimals,
4478
+ precision: balance.precision
4479
+ });
4480
+ }
4466
4481
  enrichedBalances.push(balance);
4467
4482
  }
4468
4483
  if (enrichedBalances.length < balances.length) {
@@ -4837,14 +4852,17 @@ class SDK {
4837
4852
  this.getUnifiedPortfolio = async function() {
4838
4853
  const tag6 = `${TAG12} | getUnifiedPortfolio | `;
4839
4854
  try {
4855
+ console.log(tag6, " checkpoint 4.0 - getUnifiedPortfolio start");
4840
4856
  const startTime = performance.now();
4841
4857
  try {
4842
4858
  const baseUrl = this.keepkeyEndpoint?.baseUrl || "kkapi://";
4843
4859
  const portfolioUrl = `${baseUrl}/api/portfolio`;
4860
+ console.log(tag6, " checkpoint 4.1 - Fetching portfolio from:", portfolioUrl);
4844
4861
  const portfolioResponse = await fetch(portfolioUrl, {
4845
4862
  method: "GET",
4846
4863
  signal: AbortSignal.timeout(2000)
4847
4864
  });
4865
+ console.log(tag6, " checkpoint 4.2 - Portfolio fetch returned, status:", portfolioResponse.status);
4848
4866
  if (!portfolioResponse.ok) {
4849
4867
  console.warn(tag6, "Portfolio endpoint returned", portfolioResponse.status);
4850
4868
  return null;
@@ -4957,7 +4975,9 @@ class SDK {
4957
4975
  };
4958
4976
  console.log("\uD83D\uDD11 [INIT] Initializing KeepKey SDK...");
4959
4977
  const keepKeySdk = await import_keepkey_sdk.KeepKeySdk.create(configKeepKey);
4978
+ console.log(tag6, " checkpoint 1.1 - KeepKeySdk created");
4960
4979
  const features = await keepKeySdk.system.info.getFeatures();
4980
+ console.log(tag6, " checkpoint 1.2 - features retrieved:", features);
4961
4981
  this.keepkeyApiKey = configKeepKey.apiKey;
4962
4982
  this.keepKeySdk = keepKeySdk;
4963
4983
  this.context = "keepkey:" + features.label + ".json";
@@ -4971,14 +4991,18 @@ class SDK {
4971
4991
  console.log("\uD83D\uDC41️ [VIEW-ONLY] Skipping vault endpoint detection");
4972
4992
  this.keepkeyEndpoint = null;
4973
4993
  }
4994
+ console.log(tag6, " checkpoint 2 - Starting WebSocket initialization");
4974
4995
  let configWss = {
4975
4996
  username: this.username,
4976
4997
  queryKey: this.queryKey,
4977
4998
  wss: this.wss
4978
4999
  };
4979
5000
  let clientEvents = new import_pioneer_events.Events(configWss);
5001
+ console.log(tag6, " checkpoint 2.1 - Events created, calling init()");
4980
5002
  await clientEvents.init();
5003
+ console.log(tag6, " checkpoint 2.2 - Events init complete, setting username");
4981
5004
  await clientEvents.setUsername(this.username);
5005
+ console.log(tag6, " checkpoint 2.3 - Username set, WebSocket ready");
4982
5006
  clientEvents.events.on("message", (request) => {
4983
5007
  this.events.emit("message", request);
4984
5008
  });
@@ -5044,11 +5068,14 @@ class SDK {
5044
5068
  }
5045
5069
  });
5046
5070
  this.events.emit("SET_STATUS", "init");
5071
+ console.log(tag6, " checkpoint 3 - Starting fast portfolio check");
5047
5072
  if (this.keepKeySdk && !skipSync) {
5048
5073
  console.log("⚡ [FAST PORTFOLIO] Attempting fast load...");
5074
+ console.log(tag6, " checkpoint 3.1 - Calling getUnifiedPortfolio()");
5049
5075
  const fastStart = performance.now();
5050
5076
  try {
5051
5077
  const unifiedResult = await this.getUnifiedPortfolio();
5078
+ console.log(tag6, " checkpoint 3.2 - getUnifiedPortfolio() returned");
5052
5079
  console.log("unifiedResult: ", unifiedResult);
5053
5080
  if (unifiedResult && unifiedResult.cached && unifiedResult.totalValueUsd > 0) {
5054
5081
  console.log(`✅ [FAST PORTFOLIO] Loaded in ${(performance.now() - fastStart).toFixed(0)}ms`);
@@ -5813,7 +5840,7 @@ class SDK {
5813
5840
  const { getCharts: getChartsModular } = await Promise.resolve().then(() => (init_charts(), exports_charts));
5814
5841
  const newBalances = await getChartsModular(this.blockchains, this.pioneer, this.pubkeys, this.context);
5815
5842
  console.log(tag6, `Modular charts returned ${newBalances.length} balances (native + tokens + staking)`);
5816
- const uniqueBalances = new Map([...this.balances, ...newBalances].map((balance) => [
5843
+ const uniqueBalances = new Map([...newBalances, ...this.balances].map((balance) => [
5817
5844
  balance.identifier || `${balance.caip}:${balance.pubkey}`,
5818
5845
  {
5819
5846
  ...balance,
@@ -5979,7 +6006,16 @@ class SDK {
5979
6006
  const networkId2 = import_pioneer_caip8.caipToNetworkId(asset.caip || asset.networkId);
5980
6007
  const currentContextValid = this.pubkeyContext?.networks?.includes(networkId2);
5981
6008
  if (!this.pubkeyContext || !currentContextValid) {
5982
- this.pubkeyContext = assetPubkeys[0];
6009
+ let preferredPubkey = assetPubkeys[0];
6010
+ const isBitcoin = networkId2?.includes("bip122:000000000019d6689c085ae165831e93") || asset.symbol === "BTC" || asset.name?.toLowerCase().includes("bitcoin");
6011
+ if (isBitcoin) {
6012
+ const nativeSegwitPubkey = assetPubkeys.find((pk) => pk.script_type === "p2wpkh" || pk.scriptType === "p2wpkh" || pk.note?.toLowerCase().includes("native") && pk.note?.toLowerCase().includes("segwit") || pk.pathMaster?.includes("84'"));
6013
+ if (nativeSegwitPubkey) {
6014
+ preferredPubkey = nativeSegwitPubkey;
6015
+ console.log(tag6, "Preferring Native Segwit (Bech32) for Bitcoin");
6016
+ }
6017
+ }
6018
+ this.pubkeyContext = preferredPubkey;
5983
6019
  console.log(tag6, "Auto-set pubkey context for network:", this.pubkeyContext.address || this.pubkeyContext.pubkey);
5984
6020
  } else {
5985
6021
  console.log(tag6, "Preserving existing pubkey context for network:", this.pubkeyContext.address || this.pubkeyContext.pubkey, `(addressNList: [${(this.pubkeyContext.addressNList || this.pubkeyContext.addressNListMaster).join(", ")}])`);
package/dist/index.es.js CHANGED
@@ -463,6 +463,14 @@ function processPortfolioBalance(balance, primaryAddress, context, blockchains)
463
463
  valueUsd: balance.valueUsd.toString(),
464
464
  updated: new Date().getTime()
465
465
  };
466
+ if (balance.caip === "cosmos:cosmoshub-4/slip44:118" || balance.caip === "cosmos:osmosis-1/slip44:118") {
467
+ console.log(tag2, `\uD83D\uDCCA [CHART CREATED] ${assetInfo?.symbol || balance.symbol}:`, {
468
+ caip: balance.caip,
469
+ decimal: chartBalance.decimal,
470
+ decimals: chartBalance.decimals,
471
+ precision: chartBalance.precision
472
+ });
473
+ }
466
474
  if (balance.display) {
467
475
  chartBalance.icon = ["multi", chartBalance.icon, balance.display.toString()].toString();
468
476
  }
@@ -4647,6 +4655,13 @@ function enrichBalancesWithAssetInfo(balances, assetsMap, caipToNetworkId7) {
4647
4655
  valueUsd: balance.valueUsd,
4648
4656
  priceUsd: balance.priceUsd
4649
4657
  });
4658
+ if (balance.caip === "cosmos:cosmoshub-4/slip44:118" || balance.caip === "cosmos:osmosis-1/slip44:118") {
4659
+ console.log(tag, `✅ [DEBUG] Enriched ${balance.symbol}:`, {
4660
+ caip: balance.caip,
4661
+ decimals: balance.decimals,
4662
+ precision: balance.precision
4663
+ });
4664
+ }
4650
4665
  enrichedBalances.push(balance);
4651
4666
  }
4652
4667
  if (enrichedBalances.length < balances.length) {
@@ -5021,14 +5036,17 @@ class SDK {
5021
5036
  this.getUnifiedPortfolio = async function() {
5022
5037
  const tag6 = `${TAG12} | getUnifiedPortfolio | `;
5023
5038
  try {
5039
+ console.log(tag6, " checkpoint 4.0 - getUnifiedPortfolio start");
5024
5040
  const startTime = performance.now();
5025
5041
  try {
5026
5042
  const baseUrl = this.keepkeyEndpoint?.baseUrl || "kkapi://";
5027
5043
  const portfolioUrl = `${baseUrl}/api/portfolio`;
5044
+ console.log(tag6, " checkpoint 4.1 - Fetching portfolio from:", portfolioUrl);
5028
5045
  const portfolioResponse = await fetch(portfolioUrl, {
5029
5046
  method: "GET",
5030
5047
  signal: AbortSignal.timeout(2000)
5031
5048
  });
5049
+ console.log(tag6, " checkpoint 4.2 - Portfolio fetch returned, status:", portfolioResponse.status);
5032
5050
  if (!portfolioResponse.ok) {
5033
5051
  console.warn(tag6, "Portfolio endpoint returned", portfolioResponse.status);
5034
5052
  return null;
@@ -5141,7 +5159,9 @@ class SDK {
5141
5159
  };
5142
5160
  console.log("\uD83D\uDD11 [INIT] Initializing KeepKey SDK...");
5143
5161
  const keepKeySdk = await KeepKeySdk.create(configKeepKey);
5162
+ console.log(tag6, " checkpoint 1.1 - KeepKeySdk created");
5144
5163
  const features = await keepKeySdk.system.info.getFeatures();
5164
+ console.log(tag6, " checkpoint 1.2 - features retrieved:", features);
5145
5165
  this.keepkeyApiKey = configKeepKey.apiKey;
5146
5166
  this.keepKeySdk = keepKeySdk;
5147
5167
  this.context = "keepkey:" + features.label + ".json";
@@ -5155,14 +5175,18 @@ class SDK {
5155
5175
  console.log("\uD83D\uDC41️ [VIEW-ONLY] Skipping vault endpoint detection");
5156
5176
  this.keepkeyEndpoint = null;
5157
5177
  }
5178
+ console.log(tag6, " checkpoint 2 - Starting WebSocket initialization");
5158
5179
  let configWss = {
5159
5180
  username: this.username,
5160
5181
  queryKey: this.queryKey,
5161
5182
  wss: this.wss
5162
5183
  };
5163
5184
  let clientEvents = new Events(configWss);
5185
+ console.log(tag6, " checkpoint 2.1 - Events created, calling init()");
5164
5186
  await clientEvents.init();
5187
+ console.log(tag6, " checkpoint 2.2 - Events init complete, setting username");
5165
5188
  await clientEvents.setUsername(this.username);
5189
+ console.log(tag6, " checkpoint 2.3 - Username set, WebSocket ready");
5166
5190
  clientEvents.events.on("message", (request) => {
5167
5191
  this.events.emit("message", request);
5168
5192
  });
@@ -5228,11 +5252,14 @@ class SDK {
5228
5252
  }
5229
5253
  });
5230
5254
  this.events.emit("SET_STATUS", "init");
5255
+ console.log(tag6, " checkpoint 3 - Starting fast portfolio check");
5231
5256
  if (this.keepKeySdk && !skipSync) {
5232
5257
  console.log("⚡ [FAST PORTFOLIO] Attempting fast load...");
5258
+ console.log(tag6, " checkpoint 3.1 - Calling getUnifiedPortfolio()");
5233
5259
  const fastStart = performance.now();
5234
5260
  try {
5235
5261
  const unifiedResult = await this.getUnifiedPortfolio();
5262
+ console.log(tag6, " checkpoint 3.2 - getUnifiedPortfolio() returned");
5236
5263
  console.log("unifiedResult: ", unifiedResult);
5237
5264
  if (unifiedResult && unifiedResult.cached && unifiedResult.totalValueUsd > 0) {
5238
5265
  console.log(`✅ [FAST PORTFOLIO] Loaded in ${(performance.now() - fastStart).toFixed(0)}ms`);
@@ -5997,7 +6024,7 @@ class SDK {
5997
6024
  const { getCharts: getChartsModular } = await Promise.resolve().then(() => (init_charts(), exports_charts));
5998
6025
  const newBalances = await getChartsModular(this.blockchains, this.pioneer, this.pubkeys, this.context);
5999
6026
  console.log(tag6, `Modular charts returned ${newBalances.length} balances (native + tokens + staking)`);
6000
- const uniqueBalances = new Map([...this.balances, ...newBalances].map((balance) => [
6027
+ const uniqueBalances = new Map([...newBalances, ...this.balances].map((balance) => [
6001
6028
  balance.identifier || `${balance.caip}:${balance.pubkey}`,
6002
6029
  {
6003
6030
  ...balance,
@@ -6163,7 +6190,16 @@ class SDK {
6163
6190
  const networkId2 = caipToNetworkId7(asset.caip || asset.networkId);
6164
6191
  const currentContextValid = this.pubkeyContext?.networks?.includes(networkId2);
6165
6192
  if (!this.pubkeyContext || !currentContextValid) {
6166
- this.pubkeyContext = assetPubkeys[0];
6193
+ let preferredPubkey = assetPubkeys[0];
6194
+ const isBitcoin = networkId2?.includes("bip122:000000000019d6689c085ae165831e93") || asset.symbol === "BTC" || asset.name?.toLowerCase().includes("bitcoin");
6195
+ if (isBitcoin) {
6196
+ const nativeSegwitPubkey = assetPubkeys.find((pk) => pk.script_type === "p2wpkh" || pk.scriptType === "p2wpkh" || pk.note?.toLowerCase().includes("native") && pk.note?.toLowerCase().includes("segwit") || pk.pathMaster?.includes("84'"));
6197
+ if (nativeSegwitPubkey) {
6198
+ preferredPubkey = nativeSegwitPubkey;
6199
+ console.log(tag6, "Preferring Native Segwit (Bech32) for Bitcoin");
6200
+ }
6201
+ }
6202
+ this.pubkeyContext = preferredPubkey;
6167
6203
  console.log(tag6, "Auto-set pubkey context for network:", this.pubkeyContext.address || this.pubkeyContext.pubkey);
6168
6204
  } else {
6169
6205
  console.log(tag6, "Preserving existing pubkey context for network:", this.pubkeyContext.address || this.pubkeyContext.pubkey, `(addressNList: [${(this.pubkeyContext.addressNList || this.pubkeyContext.addressNListMaster).join(", ")}])`);
package/dist/index.js CHANGED
@@ -463,6 +463,14 @@ function processPortfolioBalance(balance, primaryAddress, context, blockchains)
463
463
  valueUsd: balance.valueUsd.toString(),
464
464
  updated: new Date().getTime()
465
465
  };
466
+ if (balance.caip === "cosmos:cosmoshub-4/slip44:118" || balance.caip === "cosmos:osmosis-1/slip44:118") {
467
+ console.log(tag2, `\uD83D\uDCCA [CHART CREATED] ${assetInfo?.symbol || balance.symbol}:`, {
468
+ caip: balance.caip,
469
+ decimal: chartBalance.decimal,
470
+ decimals: chartBalance.decimals,
471
+ precision: chartBalance.precision
472
+ });
473
+ }
466
474
  if (balance.display) {
467
475
  chartBalance.icon = ["multi", chartBalance.icon, balance.display.toString()].toString();
468
476
  }
@@ -4647,6 +4655,13 @@ function enrichBalancesWithAssetInfo(balances, assetsMap, caipToNetworkId7) {
4647
4655
  valueUsd: balance.valueUsd,
4648
4656
  priceUsd: balance.priceUsd
4649
4657
  });
4658
+ if (balance.caip === "cosmos:cosmoshub-4/slip44:118" || balance.caip === "cosmos:osmosis-1/slip44:118") {
4659
+ console.log(tag, `✅ [DEBUG] Enriched ${balance.symbol}:`, {
4660
+ caip: balance.caip,
4661
+ decimals: balance.decimals,
4662
+ precision: balance.precision
4663
+ });
4664
+ }
4650
4665
  enrichedBalances.push(balance);
4651
4666
  }
4652
4667
  if (enrichedBalances.length < balances.length) {
@@ -5021,14 +5036,17 @@ class SDK {
5021
5036
  this.getUnifiedPortfolio = async function() {
5022
5037
  const tag6 = `${TAG12} | getUnifiedPortfolio | `;
5023
5038
  try {
5039
+ console.log(tag6, " checkpoint 4.0 - getUnifiedPortfolio start");
5024
5040
  const startTime = performance.now();
5025
5041
  try {
5026
5042
  const baseUrl = this.keepkeyEndpoint?.baseUrl || "kkapi://";
5027
5043
  const portfolioUrl = `${baseUrl}/api/portfolio`;
5044
+ console.log(tag6, " checkpoint 4.1 - Fetching portfolio from:", portfolioUrl);
5028
5045
  const portfolioResponse = await fetch(portfolioUrl, {
5029
5046
  method: "GET",
5030
5047
  signal: AbortSignal.timeout(2000)
5031
5048
  });
5049
+ console.log(tag6, " checkpoint 4.2 - Portfolio fetch returned, status:", portfolioResponse.status);
5032
5050
  if (!portfolioResponse.ok) {
5033
5051
  console.warn(tag6, "Portfolio endpoint returned", portfolioResponse.status);
5034
5052
  return null;
@@ -5141,7 +5159,9 @@ class SDK {
5141
5159
  };
5142
5160
  console.log("\uD83D\uDD11 [INIT] Initializing KeepKey SDK...");
5143
5161
  const keepKeySdk = await KeepKeySdk.create(configKeepKey);
5162
+ console.log(tag6, " checkpoint 1.1 - KeepKeySdk created");
5144
5163
  const features = await keepKeySdk.system.info.getFeatures();
5164
+ console.log(tag6, " checkpoint 1.2 - features retrieved:", features);
5145
5165
  this.keepkeyApiKey = configKeepKey.apiKey;
5146
5166
  this.keepKeySdk = keepKeySdk;
5147
5167
  this.context = "keepkey:" + features.label + ".json";
@@ -5155,14 +5175,18 @@ class SDK {
5155
5175
  console.log("\uD83D\uDC41️ [VIEW-ONLY] Skipping vault endpoint detection");
5156
5176
  this.keepkeyEndpoint = null;
5157
5177
  }
5178
+ console.log(tag6, " checkpoint 2 - Starting WebSocket initialization");
5158
5179
  let configWss = {
5159
5180
  username: this.username,
5160
5181
  queryKey: this.queryKey,
5161
5182
  wss: this.wss
5162
5183
  };
5163
5184
  let clientEvents = new Events(configWss);
5185
+ console.log(tag6, " checkpoint 2.1 - Events created, calling init()");
5164
5186
  await clientEvents.init();
5187
+ console.log(tag6, " checkpoint 2.2 - Events init complete, setting username");
5165
5188
  await clientEvents.setUsername(this.username);
5189
+ console.log(tag6, " checkpoint 2.3 - Username set, WebSocket ready");
5166
5190
  clientEvents.events.on("message", (request) => {
5167
5191
  this.events.emit("message", request);
5168
5192
  });
@@ -5228,11 +5252,14 @@ class SDK {
5228
5252
  }
5229
5253
  });
5230
5254
  this.events.emit("SET_STATUS", "init");
5255
+ console.log(tag6, " checkpoint 3 - Starting fast portfolio check");
5231
5256
  if (this.keepKeySdk && !skipSync) {
5232
5257
  console.log("⚡ [FAST PORTFOLIO] Attempting fast load...");
5258
+ console.log(tag6, " checkpoint 3.1 - Calling getUnifiedPortfolio()");
5233
5259
  const fastStart = performance.now();
5234
5260
  try {
5235
5261
  const unifiedResult = await this.getUnifiedPortfolio();
5262
+ console.log(tag6, " checkpoint 3.2 - getUnifiedPortfolio() returned");
5236
5263
  console.log("unifiedResult: ", unifiedResult);
5237
5264
  if (unifiedResult && unifiedResult.cached && unifiedResult.totalValueUsd > 0) {
5238
5265
  console.log(`✅ [FAST PORTFOLIO] Loaded in ${(performance.now() - fastStart).toFixed(0)}ms`);
@@ -5997,7 +6024,7 @@ class SDK {
5997
6024
  const { getCharts: getChartsModular } = await Promise.resolve().then(() => (init_charts(), exports_charts));
5998
6025
  const newBalances = await getChartsModular(this.blockchains, this.pioneer, this.pubkeys, this.context);
5999
6026
  console.log(tag6, `Modular charts returned ${newBalances.length} balances (native + tokens + staking)`);
6000
- const uniqueBalances = new Map([...this.balances, ...newBalances].map((balance) => [
6027
+ const uniqueBalances = new Map([...newBalances, ...this.balances].map((balance) => [
6001
6028
  balance.identifier || `${balance.caip}:${balance.pubkey}`,
6002
6029
  {
6003
6030
  ...balance,
@@ -6163,7 +6190,16 @@ class SDK {
6163
6190
  const networkId2 = caipToNetworkId7(asset.caip || asset.networkId);
6164
6191
  const currentContextValid = this.pubkeyContext?.networks?.includes(networkId2);
6165
6192
  if (!this.pubkeyContext || !currentContextValid) {
6166
- this.pubkeyContext = assetPubkeys[0];
6193
+ let preferredPubkey = assetPubkeys[0];
6194
+ const isBitcoin = networkId2?.includes("bip122:000000000019d6689c085ae165831e93") || asset.symbol === "BTC" || asset.name?.toLowerCase().includes("bitcoin");
6195
+ if (isBitcoin) {
6196
+ const nativeSegwitPubkey = assetPubkeys.find((pk) => pk.script_type === "p2wpkh" || pk.scriptType === "p2wpkh" || pk.note?.toLowerCase().includes("native") && pk.note?.toLowerCase().includes("segwit") || pk.pathMaster?.includes("84'"));
6197
+ if (nativeSegwitPubkey) {
6198
+ preferredPubkey = nativeSegwitPubkey;
6199
+ console.log(tag6, "Preferring Native Segwit (Bech32) for Bitcoin");
6200
+ }
6201
+ }
6202
+ this.pubkeyContext = preferredPubkey;
6167
6203
  console.log(tag6, "Auto-set pubkey context for network:", this.pubkeyContext.address || this.pubkeyContext.pubkey);
6168
6204
  } else {
6169
6205
  console.log(tag6, "Preserving existing pubkey context for network:", this.pubkeyContext.address || this.pubkeyContext.pubkey, `(addressNList: [${(this.pubkeyContext.addressNList || this.pubkeyContext.addressNListMaster).join(", ")}])`);
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "author": "highlander",
3
3
  "name": "@pioneer-platform/pioneer-sdk",
4
- "version": "8.15.34",
4
+ "version": "8.15.40",
5
5
  "dependencies": {
6
6
  "@keepkey/keepkey-sdk": "^0.2.62",
7
- "@pioneer-platform/pioneer-caip": "^9.10.11",
8
- "@pioneer-platform/pioneer-client": "^9.10.17",
9
- "@pioneer-platform/pioneer-coins": "^9.11.11",
10
- "@pioneer-platform/pioneer-discovery": "^8.15.34",
11
- "@pioneer-platform/pioneer-events": "^8.12.6",
7
+ "@pioneer-platform/pioneer-caip": "^9.10.17",
8
+ "@pioneer-platform/pioneer-client": "^9.10.23",
9
+ "@pioneer-platform/pioneer-coins": "^9.11.17",
10
+ "@pioneer-platform/pioneer-discovery": "^8.15.40",
11
+ "@pioneer-platform/pioneer-events": "^8.12.12",
12
12
  "coinselect": "^3.1.13",
13
13
  "eventemitter3": "^5.0.1",
14
14
  "neotraverse": "^0.6.8",
package/src/charts/evm.ts CHANGED
@@ -120,6 +120,7 @@ export async function getEvmCharts(params: ChartParams): Promise<ChartBalance[]>
120
120
 
121
121
  for (const token of portfolio.tokens) {
122
122
  const processedToken = processPortfolioToken(token, primaryAddress, context, blockchains);
123
+
123
124
  if (processedToken && !checkDuplicateBalance(balances, processedToken.caip, processedToken.pubkey)) {
124
125
  balances.push(processedToken);
125
126
  }
@@ -224,6 +225,16 @@ function processPortfolioBalance(
224
225
  updated: new Date().getTime(),
225
226
  };
226
227
 
228
+ // DEBUG: Log ATOM and OSMO chart balance creation
229
+ if (balance.caip === 'cosmos:cosmoshub-4/slip44:118' || balance.caip === 'cosmos:osmosis-1/slip44:118') {
230
+ console.log(tag, `📊 [CHART CREATED] ${assetInfo?.symbol || balance.symbol}:`, {
231
+ caip: balance.caip,
232
+ decimal: chartBalance.decimal,
233
+ decimals: chartBalance.decimals,
234
+ precision: chartBalance.precision,
235
+ });
236
+ }
237
+
227
238
  // Handle display icon for multi-asset icons
228
239
  if (balance.display) {
229
240
  chartBalance.icon = ['multi', chartBalance.icon, balance.display.toString()].toString();
@@ -15,6 +15,8 @@ export interface ChartBalance {
15
15
  type: string;
16
16
  token?: boolean; // Indicates if this is a token balance
17
17
  decimal?: number;
18
+ decimals?: number; // Number of decimal places (NEW standard)
19
+ precision?: number; // Precision for the asset (alias for decimals)
18
20
  balance: string;
19
21
  priceUsd: number;
20
22
  valueUsd: number | string;
package/src/index.ts CHANGED
@@ -333,6 +333,7 @@ export class SDK {
333
333
  this.getUnifiedPortfolio = async function () {
334
334
  const tag = `${TAG} | getUnifiedPortfolio | `;
335
335
  try {
336
+ console.log(tag,' checkpoint 4.0 - getUnifiedPortfolio start')
336
337
  const startTime = performance.now();
337
338
 
338
339
  // Check if kkapi is available and use the detected endpoint
@@ -340,11 +341,13 @@ export class SDK {
340
341
  // Use the detected endpoint instead of hardcoded kkapi://
341
342
  const baseUrl = this.keepkeyEndpoint?.baseUrl || 'kkapi://';
342
343
  const portfolioUrl = `${baseUrl}/api/portfolio`;
344
+ console.log(tag,' checkpoint 4.1 - Fetching portfolio from:', portfolioUrl)
343
345
 
344
346
  const portfolioResponse = await fetch(portfolioUrl, {
345
347
  method: 'GET',
346
348
  signal: AbortSignal.timeout(2000), // 2 second timeout
347
349
  });
350
+ console.log(tag,' checkpoint 4.2 - Portfolio fetch returned, status:', portfolioResponse.status)
348
351
 
349
352
  if (!portfolioResponse.ok) {
350
353
  console.warn(tag, 'Portfolio endpoint returned', portfolioResponse.status);
@@ -495,8 +498,9 @@ export class SDK {
495
498
 
496
499
  console.log('🔑 [INIT] Initializing KeepKey SDK...');
497
500
  const keepKeySdk = await KeepKeySdk.create(configKeepKey);
501
+ console.log(tag,' checkpoint 1.1 - KeepKeySdk created')
498
502
  const features = await keepKeySdk.system.info.getFeatures();
499
-
503
+ console.log(tag,' checkpoint 1.2 - features retrieved:', features)
500
504
  this.keepkeyApiKey = configKeepKey.apiKey;
501
505
  this.keepKeySdk = keepKeySdk;
502
506
  this.context = 'keepkey:' + features.label + '.json';
@@ -512,6 +516,7 @@ export class SDK {
512
516
  }
513
517
 
514
518
  // Initialize WebSocket events
519
+ console.log(tag,' checkpoint 2 - Starting WebSocket initialization')
515
520
  let configWss = {
516
521
  username: this.username,
517
522
  queryKey: this.queryKey,
@@ -519,8 +524,11 @@ export class SDK {
519
524
  };
520
525
 
521
526
  let clientEvents = new Events(configWss);
527
+ console.log(tag,' checkpoint 2.1 - Events created, calling init()')
522
528
  await clientEvents.init();
529
+ console.log(tag,' checkpoint 2.2 - Events init complete, setting username')
523
530
  await clientEvents.setUsername(this.username);
531
+ console.log(tag,' checkpoint 2.3 - Username set, WebSocket ready')
524
532
 
525
533
  clientEvents.events.on('message', (request) => {
526
534
  this.events.emit('message', request);
@@ -620,12 +628,15 @@ export class SDK {
620
628
  this.events.emit('SET_STATUS', 'init');
621
629
 
622
630
  // Fast Portfolio Pattern: Try unified portfolio first, then sync if needed
631
+ console.log(tag,' checkpoint 3 - Starting fast portfolio check')
623
632
  if (this.keepKeySdk && !skipSync) {
624
633
  console.log('⚡ [FAST PORTFOLIO] Attempting fast load...');
634
+ console.log(tag,' checkpoint 3.1 - Calling getUnifiedPortfolio()')
625
635
  const fastStart = performance.now();
626
636
 
627
637
  try {
628
638
  const unifiedResult = await this.getUnifiedPortfolio();
639
+ console.log(tag,' checkpoint 3.2 - getUnifiedPortfolio() returned')
629
640
  console.log('unifiedResult: ', unifiedResult);
630
641
 
631
642
  if (unifiedResult && unifiedResult.cached && unifiedResult.totalValueUsd > 0) {
@@ -1744,8 +1755,10 @@ export class SDK {
1744
1755
  console.log(tag, `Modular charts returned ${newBalances.length} balances (native + tokens + staking)`);
1745
1756
 
1746
1757
  // Deduplicate balances using a Map with `identifier` as the key
1758
+ // CRITICAL: Put newBalances FIRST so this.balances (with enriched data) override incomplete newBalances
1759
+ // When Map is constructed from an array with duplicate keys, the LAST occurrence wins
1747
1760
  const uniqueBalances = new Map(
1748
- [...this.balances, ...newBalances].map((balance: any) => [
1761
+ [...newBalances, ...this.balances].map((balance: any) => [
1749
1762
  balance.identifier || `${balance.caip}:${balance.pubkey}`,
1750
1763
  {
1751
1764
  ...balance,
@@ -1976,8 +1989,30 @@ export class SDK {
1976
1989
  const currentContextValid = this.pubkeyContext?.networks?.includes(networkId);
1977
1990
 
1978
1991
  if (!this.pubkeyContext || !currentContextValid) {
1979
- // No context or wrong network - auto-set to first matching pubkey
1980
- this.pubkeyContext = assetPubkeys[0];
1992
+ // No context or wrong network - auto-set to preferred pubkey
1993
+ // For Bitcoin, prefer Native Segwit (Bech32) over legacy
1994
+ let preferredPubkey = assetPubkeys[0];
1995
+
1996
+ const isBitcoin = networkId?.includes('bip122:000000000019d6689c085ae165831e93') ||
1997
+ asset.symbol === 'BTC' ||
1998
+ asset.name?.toLowerCase().includes('bitcoin');
1999
+
2000
+ if (isBitcoin) {
2001
+ // Find Native Segwit pubkey (script_type: 'p2wpkh', path includes 84')
2002
+ const nativeSegwitPubkey = assetPubkeys.find((pk: any) =>
2003
+ pk.script_type === 'p2wpkh' ||
2004
+ pk.scriptType === 'p2wpkh' ||
2005
+ (pk.note?.toLowerCase().includes('native') && pk.note?.toLowerCase().includes('segwit')) ||
2006
+ pk.pathMaster?.includes("84'")
2007
+ );
2008
+
2009
+ if (nativeSegwitPubkey) {
2010
+ preferredPubkey = nativeSegwitPubkey;
2011
+ console.log(tag, 'Preferring Native Segwit (Bech32) for Bitcoin');
2012
+ }
2013
+ }
2014
+
2015
+ this.pubkeyContext = preferredPubkey;
1981
2016
  console.log(
1982
2017
  tag,
1983
2018
  'Auto-set pubkey context for network:',
@@ -376,6 +376,15 @@ export function enrichBalancesWithAssetInfo(
376
376
  priceUsd: balance.priceUsd,
377
377
  });
378
378
 
379
+ // DEBUG: Verify ATOM and OSMO after enrichment
380
+ if (balance.caip === 'cosmos:cosmoshub-4/slip44:118' || balance.caip === 'cosmos:osmosis-1/slip44:118') {
381
+ console.log(tag, `✅ [DEBUG] Enriched ${balance.symbol}:`, {
382
+ caip: balance.caip,
383
+ decimals: balance.decimals,
384
+ precision: balance.precision,
385
+ });
386
+ }
387
+
379
388
  enrichedBalances.push(balance);
380
389
  }
381
390