@pioneer-platform/pioneer-sdk 4.21.11 → 4.21.13

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "highlander",
3
3
  "name": "@pioneer-platform/pioneer-sdk",
4
- "version": "4.21.11",
4
+ "version": "4.21.13",
5
5
  "dependencies": {
6
6
  "@keepkey/keepkey-sdk": "^0.2.62",
7
7
  "@pioneer-platform/loggerdog": "^8.11.0",
@@ -48,6 +48,8 @@
48
48
  },
49
49
  "react-native": "./src/index.ts",
50
50
  "repository": "https://github.com/thorswap/SwapKit.git",
51
+ "type": "module",
52
+ "types": "./dist/index.d.ts",
51
53
  "scripts": {
52
54
  "build": "bash scripts/build.sh",
53
55
  "build:watch": "nodemon --watch src --exec 'bun run build'",
@@ -55,7 +57,5 @@
55
57
  "lint": "eslint ./ --ext .ts,.tsx --fix; tsc --noEmit",
56
58
  "test": "echo 'vitest --run'",
57
59
  "test:coverage": "echo 'vitest run --coverage'"
58
- },
59
- "type": "module",
60
- "types": "./dist/index.d.ts"
61
- }
60
+ }
61
+ }
@@ -45,9 +45,34 @@ export class TransactionManager {
45
45
  this.events = events;
46
46
  }
47
47
 
48
- async classifyCaip(caip: string): Promise<string> {
48
+ async classifyCaip(caip: any): Promise<string> {
49
49
  // Ensure caip is a string (handle case where it might be an object)
50
- const caipString = typeof caip === 'string' ? caip : String(caip);
50
+ let caipString: string;
51
+
52
+ if (typeof caip === 'string') {
53
+ caipString = caip;
54
+ } else if (caip && typeof caip === 'object') {
55
+ // If it's an object, try to extract the caip string
56
+ // It might have a 'caip' property, or we need to stringify it
57
+ if (caip.caip && typeof caip.caip === 'string') {
58
+ caipString = caip.caip;
59
+ } else if (caip.toString && typeof caip.toString === 'function') {
60
+ caipString = caip.toString();
61
+ // If toString() returned "[object Object]", it's not helpful
62
+ if (caipString === '[object Object]') {
63
+ // Try to construct from chainId and network properties if they exist
64
+ if (caip.chainId && caip.network) {
65
+ caipString = `${caip.chainId}:${caip.network}`;
66
+ } else {
67
+ throw new Error(`Cannot extract CAIP string from object: ${JSON.stringify(caip)}`);
68
+ }
69
+ }
70
+ } else {
71
+ throw new Error(`Cannot extract CAIP string from object: ${JSON.stringify(caip)}`);
72
+ }
73
+ } else {
74
+ throw new Error(`Invalid CAIP parameter: ${caip}`);
75
+ }
51
76
 
52
77
  if (SUPPORTED_CAIPS.UTXO.includes(caipString)) return 'UTXO';
53
78
  if (SUPPORTED_CAIPS.TENDERMINT.includes(caipString)) return 'TENDERMINT';
package/src/fees/index.ts CHANGED
@@ -246,7 +246,7 @@ function normalizeFeeData(
246
246
  averageValue = feeData.average.toString();
247
247
  fastestValue = feeData.fastest.toString();
248
248
  } else if (hasAverageFastFastest) {
249
- // Map API format to UI format
249
+ // EVM API format: {average, fast, fastest}
250
250
  slowValue = feeData.average.toString();
251
251
  averageValue = feeData.fast.toString();
252
252
  fastestValue = feeData.fastest.toString();
package/src/getPubkey.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Chain, NetworkIdToChain } from '@coinmasters/types';
1
+ import { Chain, NetworkIdToChain } from '@pioneer-platform/pioneer-caip';
2
2
  import {
3
3
  addressNListToBIP32,
4
4
  //@ts-ignore
@@ -160,7 +160,7 @@ export const getPubkey = async (networkId: string, path: any, sdk: any, context:
160
160
  throw new Error(`FAIL FAST - xpub retrieval failed for ${networkId} at ${addressNListToBIP32(path.addressNList)}: ${xpubError.message}`);
161
161
  }
162
162
  } else {
163
- console.log('🔑 [PUBKEY] Non-xpub path (address-based), using address as pubkey');
163
+ // Non-xpub path (address-based chains like ETH, Cosmos, etc.) - using address as pubkey
164
164
  pubkey.pubkey = address;
165
165
  pubkey.path = addressNListToBIP32(path.addressNList);
166
166
  pubkey.pathMaster = addressNListToBIP32(path.addressNListMaster);
package/src/index.ts CHANGED
@@ -662,7 +662,6 @@ export class SDK {
662
662
 
663
663
  // Deduplicate blockchains before calculation to prevent double-counting
664
664
  const uniqueBlockchains = [...new Set(this.blockchains)];
665
- console.log(tag, 'uniqueBlockchains: ', uniqueBlockchains);
666
665
 
667
666
  // Calculate totals for each blockchain
668
667
  for (const blockchain of uniqueBlockchains) {
@@ -674,26 +673,12 @@ export class SDK {
674
673
  );
675
674
  });
676
675
 
677
- console.log(tag, `Filtering for blockchain: ${blockchain}`);
678
- console.log(tag, `Found ${filteredBalances.length} balances before deduplication`);
679
-
680
- // Log each balance to see what's different
681
- filteredBalances.forEach((balance, idx) => {
682
- console.log(tag, `Balance[${idx}]:`, {
683
- caip: balance.caip,
684
- pubkey: balance.pubkey,
685
- balance: balance.balance,
686
- valueUsd: balance.valueUsd,
687
- });
688
- });
689
-
690
676
  // Deduplicate balances based on caip + pubkey combination
691
677
  const balanceMap = new Map();
692
678
 
693
679
  // Special handling for Bitcoin to work around API bug
694
680
  const isBitcoin = blockchain.includes('bip122:000000000019d6689c085ae165831e93');
695
681
  if (isBitcoin) {
696
- console.log(tag, 'Bitcoin network detected - checking for duplicate balances');
697
682
  // Group Bitcoin balances by value to detect duplicates
698
683
  const bitcoinByValue = new Map();
699
684
  filteredBalances.forEach((balance) => {
@@ -707,10 +692,6 @@ export class SDK {
707
692
  // Check if all three address types have the same non-zero balance (API bug)
708
693
  for (const [valueKey, balances] of bitcoinByValue.entries()) {
709
694
  if (balances.length === 3 && parseFloat(balances[0].valueUsd || '0') > 0) {
710
- console.log(
711
- tag,
712
- 'BITCOIN API BUG DETECTED: All 3 address types have same balance, keeping only xpub',
713
- );
714
695
  // Keep only the xpub (or first one if no xpub)
715
696
  const xpubBalance =
716
697
  balances.find((b) => b.pubkey?.startsWith('xpub')) || balances[0];
@@ -741,9 +722,6 @@ export class SDK {
741
722
 
742
723
  const networkBalances = Array.from(balanceMap.values());
743
724
 
744
- console.log(tag, 'networkBalances (deduplicated): ', networkBalances);
745
- console.log(tag, 'networkBalances count: ', networkBalances.length);
746
-
747
725
  // Ensure we're working with numbers for calculations
748
726
  const networkTotal = networkBalances.reduce((sum, balance, idx) => {
749
727
  const valueUsd =
@@ -751,35 +729,9 @@ export class SDK {
751
729
  ? parseFloat(balance.valueUsd)
752
730
  : balance.valueUsd || 0;
753
731
 
754
- console.log(
755
- tag,
756
- `[${idx}] valueUsd:`,
757
- balance.valueUsd,
758
- '→ parsed:',
759
- valueUsd,
760
- '| running sum:',
761
- sum + valueUsd,
762
- );
763
-
764
- if (blockchain.includes('bip122:000000000019d6689c085ae165831e93')) {
765
- console.log(
766
- tag,
767
- `[BITCOIN DEBUG ${idx}] pubkey:`,
768
- balance.pubkey?.substring(0, 10) + '...',
769
- '| balance:',
770
- balance.balance,
771
- '| valueUsd:',
772
- balance.valueUsd,
773
- '→ parsed:',
774
- valueUsd,
775
- );
776
- }
777
-
778
732
  return sum + valueUsd;
779
733
  }, 0);
780
734
 
781
- console.log('Final networkTotal:', networkTotal);
782
-
783
735
  // Get native asset for this blockchain
784
736
  const nativeAssetCaip = networkIdToCaip(blockchain);
785
737
  const gasAsset = networkBalances.find((b) => b.caip === nativeAssetCaip);
@@ -1611,12 +1563,6 @@ export class SDK {
1611
1563
 
1612
1564
  let balances = marketInfo.data;
1613
1565
 
1614
- const bitcoinBalances = balances.filter(
1615
- (b: any) => b.caip === 'bip122:000000000019d6689c085ae165831e93/slip44:0',
1616
- );
1617
- if (bitcoinBalances.length > 0) {
1618
- }
1619
-
1620
1566
  // Enrich balances with asset info
1621
1567
  for (let balance of balances) {
1622
1568
  const assetInfo = this.assetsMap.get(balance.caip);
@@ -1626,10 +1572,9 @@ export class SDK {
1626
1572
  networkId: caipToNetworkId(balance.caip),
1627
1573
  icon: assetInfo.icon || 'https://pioneers.dev/coins/etherum.png',
1628
1574
  identifier: `${balance.caip}:${balance.pubkey}`,
1575
+ updated: Date.now(), // Add timestamp for worker validation
1629
1576
  });
1630
1577
  }
1631
- console.log(tag, 'balances: ', balances);
1632
-
1633
1578
  this.balances = balances;
1634
1579
  this.events.emit('SET_BALANCES', this.balances);
1635
1580
  return this.balances;
@@ -4,8 +4,6 @@ const TAG = ' | build-dashboard | ';
4
4
 
5
5
  // Build dashboard from cached balances (no Pioneer API calls)
6
6
  export function buildDashboardFromBalances(balances: any[], blockchains: string[], assetsMap: Map<string, any>) {
7
- console.log(TAG, '[DASHBOARD] Building dashboard from cached balances...');
8
-
9
7
  const dashboardData: {
10
8
  networks: {
11
9
  networkId: string;
@@ -37,8 +35,6 @@ export function buildDashboardFromBalances(balances: any[], blockchains: string[
37
35
  totalNativeBalance: string;
38
36
  }[] = [];
39
37
 
40
- console.log(TAG, 'balances: ', balances);
41
-
42
38
  // Calculate totals for each blockchain
43
39
  for (const blockchain of blockchains) {
44
40
  const filteredBalances = balances.filter((b) => {
@@ -55,7 +51,6 @@ export function buildDashboardFromBalances(balances: any[], blockchains: string[
55
51
  // Special handling for Bitcoin to work around API bug
56
52
  const isBitcoin = blockchain.includes('bip122:000000000019d6689c085ae165831e93');
57
53
  if (isBitcoin) {
58
- console.log(TAG, 'Bitcoin network detected - checking for duplicate balances');
59
54
  // Group Bitcoin balances by value to detect duplicates
60
55
  const bitcoinByValue = new Map();
61
56
  filteredBalances.forEach((balance) => {
@@ -69,10 +64,6 @@ export function buildDashboardFromBalances(balances: any[], blockchains: string[
69
64
  // Check if all three address types have the same non-zero balance (API bug)
70
65
  for (const [valueKey, balances] of bitcoinByValue.entries()) {
71
66
  if (balances.length === 3 && parseFloat(balances[0].valueUsd || '0') > 0) {
72
- console.log(
73
- TAG,
74
- 'BITCOIN API BUG DETECTED: All 3 address types have same balance, keeping only xpub',
75
- );
76
67
  // Keep only the xpub (or first one if no xpub)
77
68
  const xpubBalance = balances.find((b) => b.pubkey?.startsWith('xpub')) || balances[0];
78
69
  const key = `${xpubBalance.caip}_${xpubBalance.pubkey || 'default'}`;
@@ -108,22 +99,6 @@ export function buildDashboardFromBalances(balances: any[], blockchains: string[
108
99
  ? parseFloat(balance.valueUsd)
109
100
  : balance.valueUsd || 0;
110
101
 
111
- if (blockchain.includes('bip122:000000000019d6689c085ae165831e93')) {
112
- console.log(
113
- TAG,
114
- `[BITCOIN DEBUG ${idx}] pubkey:`,
115
- balance.pubkey?.substring(0, 10) + '...',
116
- '| balance:',
117
- balance.balance,
118
- '| valueUsd:',
119
- balance.valueUsd,
120
- '→ parsed:',
121
- valueUsd,
122
- '| running sum:',
123
- sum + valueUsd,
124
- );
125
- }
126
-
127
102
  return sum + valueUsd;
128
103
  }, 0);
129
104
 
@@ -146,13 +121,6 @@ export function buildDashboardFromBalances(balances: any[], blockchains: string[
146
121
  // Get colors from assetMap since balances don't have them
147
122
  const assetInfo = nativeAssetCaip ? assetsMap.get(nativeAssetCaip) : null;
148
123
 
149
- // Debug logging
150
- console.log(TAG, `[DEBUG] Network: ${blockchain}`);
151
- console.log(TAG, `[DEBUG] nativeAssetCaip: ${nativeAssetCaip}`);
152
- console.log(TAG, `[DEBUG] assetInfo:`, assetInfo);
153
- console.log(TAG, `[DEBUG] gasAsset:`, gasAsset);
154
- console.log(TAG, `[DEBUG] Resolved name: ${gasAsset?.name || assetInfo?.name || 'NO NAME'}`);
155
-
156
124
  networksTemp.push({
157
125
  networkId: blockchain,
158
126
  totalValueUsd: networkTotal,
@@ -33,7 +33,6 @@ export async function syncPortfolio(context: {
33
33
  if (paths.length === 0) {
34
34
  //get paths for chain
35
35
  const pathsForChain = getPaths([networkId]);
36
- console.log(tag, 'pathsForChain: ', pathsForChain);
37
36
  for (let j = 0; j < pathsForChain.length; j++) {
38
37
  const path = pathsForChain[j];
39
38
  if (!context.paths.find((p) => p.note === path.note)) {
@@ -45,7 +44,6 @@ export async function syncPortfolio(context: {
45
44
 
46
45
  //get balances for paths
47
46
  await context.getPubkeys();
48
- console.log(tag, 'context.pubkeys: ', context.pubkeys);
49
47
  await context.getBalances();
50
48
 
51
49
  // Get market data with cache support
@@ -82,7 +80,14 @@ export async function syncPortfolio(context: {
82
80
  if (balance && balance.caip && priceMap[balance.caip] !== undefined) {
83
81
  balance.price = priceMap[balance.caip];
84
82
  balance.priceUsd = priceMap[balance.caip];
85
- balance.valueUsd = balance.price * (balance.balance || 0);
83
+
84
+ // Parse balance to number (it comes as a string from API)
85
+ const balanceNum = typeof balance.balance === 'string'
86
+ ? parseFloat(balance.balance)
87
+ : (balance.balance || 0);
88
+
89
+ balance.valueUsd = balance.price * balanceNum;
90
+ balance.updated = Date.now(); // Update timestamp when prices are refreshed
86
91
  }
87
92
  }
88
93
  } catch (apiError) {