@pioneer-platform/pioneer-sdk 4.20.6 → 4.20.8

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,12 +1,12 @@
1
1
  {
2
2
  "author": "highlander",
3
3
  "name": "@pioneer-platform/pioneer-sdk",
4
- "version": "4.20.6",
4
+ "version": "4.20.8",
5
5
  "dependencies": {
6
6
  "@keepkey/keepkey-sdk": "^0.2.62",
7
7
  "@pioneer-platform/loggerdog": "^8.11.0",
8
8
  "@pioneer-platform/pioneer-caip": "^9.10.0",
9
- "@pioneer-platform/pioneer-client": "^9.10.2",
9
+ "@pioneer-platform/pioneer-client": "^9.10.3",
10
10
  "@pioneer-platform/pioneer-coins": "^9.11.0",
11
11
  "@pioneer-platform/pioneer-discovery": "^0.8.0",
12
12
  "@pioneer-platform/pioneer-events": "^8.11.0",
@@ -48,8 +48,6 @@
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",
53
51
  "scripts": {
54
52
  "build": "bash scripts/build.sh",
55
53
  "build:watch": "nodemon --watch src --exec 'bun run build'",
@@ -57,5 +55,7 @@
57
55
  "lint": "eslint ./ --ext .ts,.tsx --fix; tsc --noEmit",
58
56
  "test": "echo 'vitest --run'",
59
57
  "test:coverage": "echo 'vitest run --coverage'"
60
- }
61
- }
58
+ },
59
+ "type": "module",
60
+ "types": "./dist/index.d.ts"
61
+ }
package/src/index.ts CHANGED
@@ -19,6 +19,7 @@ import { getFees, estimateTransactionFee, type NormalizedFeeRates, type FeeEstim
19
19
  import { detectKkApiAvailability } from './utils/kkapi-detection.js';
20
20
  import { formatTime } from './utils/format-time.js';
21
21
  import { buildDashboardFromBalances } from './utils/build-dashboard.js';
22
+ import { syncMarket } from './utils/sync-market.js';
22
23
 
23
24
  const TAG = ' | Pioneer-sdk | ';
24
25
 
@@ -572,86 +573,8 @@ export class SDK {
572
573
  this.buildDashboardFromBalances = function () {
573
574
  return buildDashboardFromBalances(this.balances, this.blockchains, this.assetsMap);
574
575
  };
575
-
576
576
  this.syncMarket = async function () {
577
- const tag = `${TAG} | syncMarket | `;
578
- try {
579
- // Log balances with invalid CAIPs for debugging
580
- const invalidBalances = this.balances.filter(b =>
581
- !b || !b.caip || typeof b.caip !== 'string' || !b.caip.includes(':')
582
- );
583
- if (invalidBalances.length > 0) {
584
- console.warn(tag, `Found ${invalidBalances.length} balances with invalid CAIPs:`,
585
- invalidBalances.map(b => ({
586
- caip: b?.caip,
587
- type: typeof b?.caip,
588
- symbol: b?.symbol,
589
- balance: b?.balance
590
- }))
591
- );
592
- }
593
-
594
- // Extract all CAIP identifiers from balances, filtering out invalid entries
595
- let allCaips = this.balances
596
- .filter(b => b && b.caip && typeof b.caip === 'string' && b.caip.trim().length > 0)
597
- .map((b) => b.caip);
598
-
599
- // Remove duplicates
600
- allCaips = [...new Set(allCaips)];
601
-
602
- // CRITICAL: Double-check all elements are valid strings after Set deduplication
603
- // Filter out any non-string or empty values that might have slipped through
604
- allCaips = allCaips.filter(caip =>
605
- caip &&
606
- typeof caip === 'string' &&
607
- caip.trim().length > 0 &&
608
- caip.includes(':') // CAIP format always has a colon
609
- );
610
-
611
- // Fetch market prices for all CAIPs
612
- console.log('GetMarketInfo: payload: ', allCaips);
613
- console.log('GetMarketInfo: payload type: ', typeof allCaips);
614
- console.log('GetMarketInfo: payload length: ', allCaips.length);
615
-
616
- // Additional validation log to catch issues
617
- const invalidEntries = allCaips.filter(caip => typeof caip !== 'string');
618
- if (invalidEntries.length > 0) {
619
- console.error(tag, 'CRITICAL: Invalid entries detected in allCaips:', invalidEntries);
620
- throw new Error('Invalid CAIP entries detected - aborting market sync');
621
- }
622
-
623
- if (allCaips && allCaips.length > 0) {
624
- try {
625
- let allPrices = await this.pioneer.GetMarketInfo(allCaips);
626
- console.log('GetMarketInfo: response: ', allPrices);
627
-
628
- // Create a map of CAIP to price for easier lookup
629
- const priceMap = {};
630
- if (allPrices && allPrices.data) {
631
- for (let i = 0; i < allCaips.length && i < allPrices.data.length; i++) {
632
- priceMap[allCaips[i]] = allPrices.data[i];
633
- }
634
- }
635
-
636
- // Update each balance with the corresponding price and value
637
- for (let balance of this.balances) {
638
- if (balance && balance.caip && priceMap[balance.caip] !== undefined) {
639
- balance.price = priceMap[balance.caip];
640
- balance.priceUsd = priceMap[balance.caip]; // Also set priceUsd for compatibility
641
- balance.valueUsd = balance.price * (balance.balance || 0);
642
- }
643
- }
644
- } catch (apiError) {
645
- console.error(tag, 'API error fetching market info:', apiError);
646
- // Don't throw - just log and continue without prices
647
- console.warn(tag, 'Continuing without market prices');
648
- }
649
- }
650
- return true;
651
- } catch (e) {
652
- console.error(tag, 'e:', e);
653
- throw e;
654
- }
577
+ return syncMarket(this.balances, this.pioneer);
655
578
  };
656
579
  this.sync = async function () {
657
580
  const tag = `${TAG} | sync | `;
@@ -0,0 +1,86 @@
1
+ // Market data synchronization utility
2
+ const TAG = ' | sync-market | ';
3
+
4
+ export async function syncMarket(balances: any[], pioneer: any): Promise<boolean> {
5
+ const tag = `${TAG} | syncMarket | `;
6
+ try {
7
+ // Log balances with invalid CAIPs for debugging
8
+ const invalidBalances = balances.filter(
9
+ (b) => !b || !b.caip || typeof b.caip !== 'string' || !b.caip.includes(':'),
10
+ );
11
+ if (invalidBalances.length > 0) {
12
+ console.warn(
13
+ tag,
14
+ `Found ${invalidBalances.length} balances with invalid CAIPs:`,
15
+ invalidBalances.map((b) => ({
16
+ caip: b?.caip,
17
+ type: typeof b?.caip,
18
+ symbol: b?.symbol,
19
+ balance: b?.balance,
20
+ })),
21
+ );
22
+ }
23
+
24
+ // Extract all CAIP identifiers from balances, filtering out invalid entries
25
+ let allCaips = balances
26
+ .filter((b) => b && b.caip && typeof b.caip === 'string' && b.caip.trim().length > 0)
27
+ .map((b) => b.caip);
28
+
29
+ // Remove duplicates
30
+ allCaips = [...new Set(allCaips)];
31
+
32
+ // CRITICAL: Double-check all elements are valid strings after Set deduplication
33
+ // Filter out any non-string or empty values that might have slipped through
34
+ allCaips = allCaips.filter(
35
+ (caip) =>
36
+ caip &&
37
+ typeof caip === 'string' &&
38
+ caip.trim().length > 0 &&
39
+ caip.includes(':'), // CAIP format always has a colon
40
+ );
41
+
42
+ // Fetch market prices for all CAIPs
43
+ console.log('GetMarketInfo: payload: ', allCaips);
44
+ console.log('GetMarketInfo: payload type: ', typeof allCaips);
45
+ console.log('GetMarketInfo: payload length: ', allCaips.length);
46
+
47
+ // Additional validation log to catch issues
48
+ const invalidEntries = allCaips.filter((caip) => typeof caip !== 'string');
49
+ if (invalidEntries.length > 0) {
50
+ console.error(tag, 'CRITICAL: Invalid entries detected in allCaips:', invalidEntries);
51
+ throw new Error('Invalid CAIP entries detected - aborting market sync');
52
+ }
53
+
54
+ if (allCaips && allCaips.length > 0) {
55
+ try {
56
+ let allPrices = await pioneer.GetMarketInfo(allCaips);
57
+ console.log('GetMarketInfo: response: ', allPrices);
58
+
59
+ // Create a map of CAIP to price for easier lookup
60
+ const priceMap: Record<string, number> = {};
61
+ if (allPrices && allPrices.data) {
62
+ for (let i = 0; i < allCaips.length && i < allPrices.data.length; i++) {
63
+ priceMap[allCaips[i]] = allPrices.data[i];
64
+ }
65
+ }
66
+
67
+ // Update each balance with the corresponding price and value
68
+ for (let balance of balances) {
69
+ if (balance && balance.caip && priceMap[balance.caip] !== undefined) {
70
+ balance.price = priceMap[balance.caip];
71
+ balance.priceUsd = priceMap[balance.caip]; // Also set priceUsd for compatibility
72
+ balance.valueUsd = balance.price * (balance.balance || 0);
73
+ }
74
+ }
75
+ } catch (apiError) {
76
+ console.error(tag, 'API error fetching market info:', apiError);
77
+ // Don't throw - just log and continue without prices
78
+ console.warn(tag, 'Continuing without market prices');
79
+ }
80
+ }
81
+ return true;
82
+ } catch (e) {
83
+ console.error(tag, 'e:', e);
84
+ throw e;
85
+ }
86
+ }