@pioneer-platform/pioneer-sdk 4.20.5 → 4.20.7

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
@@ -3531,8 +3531,62 @@ function buildDashboardFromBalances(balances, blockchains, assetsMap) {
3531
3531
  return dashboardData;
3532
3532
  }
3533
3533
 
3534
+ // src/utils/sync-market.ts
3535
+ var TAG8 = " | sync-market | ";
3536
+ async function syncMarket(balances, pioneer) {
3537
+ const tag5 = `${TAG8} | syncMarket | `;
3538
+ try {
3539
+ const invalidBalances = balances.filter((b2) => !b2 || !b2.caip || typeof b2.caip !== "string" || !b2.caip.includes(":"));
3540
+ if (invalidBalances.length > 0) {
3541
+ console.warn(tag5, `Found ${invalidBalances.length} balances with invalid CAIPs:`, invalidBalances.map((b2) => ({
3542
+ caip: b2?.caip,
3543
+ type: typeof b2?.caip,
3544
+ symbol: b2?.symbol,
3545
+ balance: b2?.balance
3546
+ })));
3547
+ }
3548
+ let allCaips = balances.filter((b2) => b2 && b2.caip && typeof b2.caip === "string" && b2.caip.trim().length > 0).map((b2) => b2.caip);
3549
+ allCaips = [...new Set(allCaips)];
3550
+ allCaips = allCaips.filter((caip) => caip && typeof caip === "string" && caip.trim().length > 0 && caip.includes(":"));
3551
+ console.log("GetMarketInfo: payload: ", allCaips);
3552
+ console.log("GetMarketInfo: payload type: ", typeof allCaips);
3553
+ console.log("GetMarketInfo: payload length: ", allCaips.length);
3554
+ const invalidEntries = allCaips.filter((caip) => typeof caip !== "string");
3555
+ if (invalidEntries.length > 0) {
3556
+ console.error(tag5, "CRITICAL: Invalid entries detected in allCaips:", invalidEntries);
3557
+ throw new Error("Invalid CAIP entries detected - aborting market sync");
3558
+ }
3559
+ if (allCaips && allCaips.length > 0) {
3560
+ try {
3561
+ let allPrices = await pioneer.GetMarketInfo(allCaips);
3562
+ console.log("GetMarketInfo: response: ", allPrices);
3563
+ const priceMap = {};
3564
+ if (allPrices && allPrices.data) {
3565
+ for (let i = 0;i < allCaips.length && i < allPrices.data.length; i++) {
3566
+ priceMap[allCaips[i]] = allPrices.data[i];
3567
+ }
3568
+ }
3569
+ for (let balance of balances) {
3570
+ if (balance && balance.caip && priceMap[balance.caip] !== undefined) {
3571
+ balance.price = priceMap[balance.caip];
3572
+ balance.priceUsd = priceMap[balance.caip];
3573
+ balance.valueUsd = balance.price * (balance.balance || 0);
3574
+ }
3575
+ }
3576
+ } catch (apiError) {
3577
+ console.error(tag5, "API error fetching market info:", apiError);
3578
+ console.warn(tag5, "Continuing without market prices");
3579
+ }
3580
+ }
3581
+ return true;
3582
+ } catch (e) {
3583
+ console.error(tag5, "e:", e);
3584
+ throw e;
3585
+ }
3586
+ }
3587
+
3534
3588
  // src/index.ts
3535
- var TAG8 = " | Pioneer-sdk | ";
3589
+ var TAG9 = " | Pioneer-sdk | ";
3536
3590
 
3537
3591
  class SDK {
3538
3592
  status;
@@ -3696,7 +3750,7 @@ class SDK {
3696
3750
  return true;
3697
3751
  };
3698
3752
  this.setPubkeys = (newPubkeys) => {
3699
- const tag5 = `${TAG8} | setPubkeys | `;
3753
+ const tag5 = `${TAG9} | setPubkeys | `;
3700
3754
  this.pubkeys = [];
3701
3755
  this.pubkeySet.clear();
3702
3756
  let added = 0;
@@ -3707,7 +3761,7 @@ class SDK {
3707
3761
  }
3708
3762
  };
3709
3763
  this.getUnifiedPortfolio = async function() {
3710
- const tag5 = `${TAG8} | getUnifiedPortfolio | `;
3764
+ const tag5 = `${TAG9} | getUnifiedPortfolio | `;
3711
3765
  try {
3712
3766
  const startTime = performance.now();
3713
3767
  try {
@@ -3815,7 +3869,7 @@ class SDK {
3815
3869
  }
3816
3870
  };
3817
3871
  this.init = async function(walletsVerbose, setup) {
3818
- const tag5 = `${TAG8} | init | `;
3872
+ const tag5 = `${TAG9} | init | `;
3819
3873
  try {
3820
3874
  if (!this.username)
3821
3875
  throw Error("username required!");
@@ -3906,58 +3960,10 @@ class SDK {
3906
3960
  return buildDashboardFromBalances(this.balances, this.blockchains, this.assetsMap);
3907
3961
  };
3908
3962
  this.syncMarket = async function() {
3909
- const tag5 = `${TAG8} | syncMarket | `;
3910
- try {
3911
- const invalidBalances = this.balances.filter((b2) => !b2 || !b2.caip || typeof b2.caip !== "string" || !b2.caip.includes(":"));
3912
- if (invalidBalances.length > 0) {
3913
- console.warn(tag5, `Found ${invalidBalances.length} balances with invalid CAIPs:`, invalidBalances.map((b2) => ({
3914
- caip: b2?.caip,
3915
- type: typeof b2?.caip,
3916
- symbol: b2?.symbol,
3917
- balance: b2?.balance
3918
- })));
3919
- }
3920
- let allCaips = this.balances.filter((b2) => b2 && b2.caip && typeof b2.caip === "string" && b2.caip.trim().length > 0).map((b2) => b2.caip);
3921
- allCaips = [...new Set(allCaips)];
3922
- allCaips = allCaips.filter((caip) => caip && typeof caip === "string" && caip.trim().length > 0 && caip.includes(":"));
3923
- console.log("GetMarketInfo: payload: ", allCaips);
3924
- console.log("GetMarketInfo: payload type: ", typeof allCaips);
3925
- console.log("GetMarketInfo: payload length: ", allCaips.length);
3926
- const invalidEntries = allCaips.filter((caip) => typeof caip !== "string");
3927
- if (invalidEntries.length > 0) {
3928
- console.error(tag5, "CRITICAL: Invalid entries detected in allCaips:", invalidEntries);
3929
- throw new Error("Invalid CAIP entries detected - aborting market sync");
3930
- }
3931
- if (allCaips && allCaips.length > 0) {
3932
- try {
3933
- let allPrices = await this.pioneer.GetMarketInfo(allCaips);
3934
- console.log("GetMarketInfo: response: ", allPrices);
3935
- const priceMap = {};
3936
- if (allPrices && allPrices.data) {
3937
- for (let i = 0;i < allCaips.length && i < allPrices.data.length; i++) {
3938
- priceMap[allCaips[i]] = allPrices.data[i];
3939
- }
3940
- }
3941
- for (let balance of this.balances) {
3942
- if (balance && balance.caip && priceMap[balance.caip] !== undefined) {
3943
- balance.price = priceMap[balance.caip];
3944
- balance.priceUsd = priceMap[balance.caip];
3945
- balance.valueUsd = balance.price * (balance.balance || 0);
3946
- }
3947
- }
3948
- } catch (apiError) {
3949
- console.error(tag5, "API error fetching market info:", apiError);
3950
- console.warn(tag5, "Continuing without market prices");
3951
- }
3952
- }
3953
- return true;
3954
- } catch (e) {
3955
- console.error(tag5, "e:", e);
3956
- throw e;
3957
- }
3963
+ return syncMarket(this.balances, this.pioneer);
3958
3964
  };
3959
3965
  this.sync = async function() {
3960
- const tag5 = `${TAG8} | sync | `;
3966
+ const tag5 = `${TAG9} | sync | `;
3961
3967
  try {
3962
3968
  const matchesNetwork = (item, networkId) => {
3963
3969
  if (!item.networks || !Array.isArray(item.networks))
@@ -4110,7 +4116,7 @@ class SDK {
4110
4116
  }
4111
4117
  };
4112
4118
  this.buildTx = async function(sendPayload) {
4113
- let tag5 = TAG8 + " | buildTx | ";
4119
+ let tag5 = TAG9 + " | buildTx | ";
4114
4120
  try {
4115
4121
  const transactionDependencies = {
4116
4122
  context: this.context,
@@ -4132,7 +4138,7 @@ class SDK {
4132
4138
  }
4133
4139
  };
4134
4140
  this.buildDelegateTx = async function(caip, params) {
4135
- let tag5 = TAG8 + " | buildDelegateTx | ";
4141
+ let tag5 = TAG9 + " | buildDelegateTx | ";
4136
4142
  try {
4137
4143
  const delegateParams = {
4138
4144
  ...params,
@@ -4147,7 +4153,7 @@ class SDK {
4147
4153
  }
4148
4154
  };
4149
4155
  this.buildUndelegateTx = async function(caip, params) {
4150
- let tag5 = TAG8 + " | buildUndelegateTx | ";
4156
+ let tag5 = TAG9 + " | buildUndelegateTx | ";
4151
4157
  try {
4152
4158
  const undelegateParams = {
4153
4159
  ...params,
@@ -4162,7 +4168,7 @@ class SDK {
4162
4168
  }
4163
4169
  };
4164
4170
  this.buildClaimRewardsTx = async function(caip, params) {
4165
- let tag5 = TAG8 + " | buildClaimRewardsTx | ";
4171
+ let tag5 = TAG9 + " | buildClaimRewardsTx | ";
4166
4172
  try {
4167
4173
  const claimParams = {
4168
4174
  ...params,
@@ -4177,7 +4183,7 @@ class SDK {
4177
4183
  }
4178
4184
  };
4179
4185
  this.buildClaimAllRewardsTx = async function(caip, params) {
4180
- let tag5 = TAG8 + " | buildClaimAllRewardsTx | ";
4186
+ let tag5 = TAG9 + " | buildClaimAllRewardsTx | ";
4181
4187
  try {
4182
4188
  const claimAllParams = {
4183
4189
  ...params,
@@ -4191,7 +4197,7 @@ class SDK {
4191
4197
  }
4192
4198
  };
4193
4199
  this.signTx = async function(unsignedTx) {
4194
- let tag5 = TAG8 + " | signTx | ";
4200
+ let tag5 = TAG9 + " | signTx | ";
4195
4201
  try {
4196
4202
  const transactionDependencies = {
4197
4203
  context: this.context,
@@ -4212,7 +4218,7 @@ class SDK {
4212
4218
  }
4213
4219
  };
4214
4220
  this.broadcastTx = async function(caip, signedTx) {
4215
- let tag5 = TAG8 + " | broadcastTx | ";
4221
+ let tag5 = TAG9 + " | broadcastTx | ";
4216
4222
  try {
4217
4223
  const transactionDependencies = {
4218
4224
  context: this.context,
@@ -4236,7 +4242,7 @@ class SDK {
4236
4242
  }
4237
4243
  };
4238
4244
  this.swap = async function(swapPayload) {
4239
- let tag5 = `${TAG8} | swap | `;
4245
+ let tag5 = `${TAG9} | swap | `;
4240
4246
  try {
4241
4247
  if (!swapPayload)
4242
4248
  throw Error("swapPayload required!");
@@ -4371,7 +4377,7 @@ class SDK {
4371
4377
  }
4372
4378
  };
4373
4379
  this.transfer = async function(sendPayload) {
4374
- let tag5 = `${TAG8} | transfer | `;
4380
+ let tag5 = `${TAG9} | transfer | `;
4375
4381
  try {
4376
4382
  if (!sendPayload)
4377
4383
  throw Error("sendPayload required!");
@@ -4466,7 +4472,7 @@ class SDK {
4466
4472
  }
4467
4473
  };
4468
4474
  this.setBlockchains = async function(blockchains) {
4469
- const tag5 = `${TAG8} | setBlockchains | `;
4475
+ const tag5 = `${TAG9} | setBlockchains | `;
4470
4476
  try {
4471
4477
  if (!blockchains)
4472
4478
  throw Error("blockchains required!");
@@ -4482,7 +4488,7 @@ class SDK {
4482
4488
  }
4483
4489
  };
4484
4490
  this.addAsset = async function(caip, data) {
4485
- let tag5 = TAG8 + " | addAsset | ";
4491
+ let tag5 = TAG9 + " | addAsset | ";
4486
4492
  try {
4487
4493
  let success = false;
4488
4494
  if (!caip)
@@ -4520,7 +4526,7 @@ class SDK {
4520
4526
  }
4521
4527
  };
4522
4528
  this.clearWalletState = async function() {
4523
- const tag5 = `${TAG8} | clearWalletState | `;
4529
+ const tag5 = `${TAG9} | clearWalletState | `;
4524
4530
  try {
4525
4531
  this.context = null;
4526
4532
  this.paths = [];
@@ -4535,7 +4541,7 @@ class SDK {
4535
4541
  }
4536
4542
  };
4537
4543
  this.addPath = async function(path) {
4538
- const tag5 = `${TAG8} | addPath | `;
4544
+ const tag5 = `${TAG9} | addPath | `;
4539
4545
  try {
4540
4546
  this.paths.push(path);
4541
4547
  const pubkey = await getPubkey(path.networks[0], path, this.keepKeySdk, this.context);
@@ -4549,7 +4555,7 @@ class SDK {
4549
4555
  }
4550
4556
  };
4551
4557
  this.addPaths = async function(paths) {
4552
- const tag5 = `${TAG8} | addPaths | `;
4558
+ const tag5 = `${TAG9} | addPaths | `;
4553
4559
  try {
4554
4560
  console.log(tag5, `Adding ${paths.length} paths in batch mode...`);
4555
4561
  this.paths.push(...paths);
@@ -4585,7 +4591,7 @@ class SDK {
4585
4591
  return this.getGasAssets();
4586
4592
  };
4587
4593
  this.getGasAssets = async function() {
4588
- const tag5 = `${TAG8} | getGasAssets | `;
4594
+ const tag5 = `${TAG9} | getGasAssets | `;
4589
4595
  try {
4590
4596
  for (let i = 0;i < this.blockchains.length; i++) {
4591
4597
  let networkId = this.blockchains[i];
@@ -4628,7 +4634,7 @@ class SDK {
4628
4634
  }
4629
4635
  };
4630
4636
  this.getPubkeys = async function() {
4631
- const tag5 = `${TAG8} | getPubkeys | `;
4637
+ const tag5 = `${TAG9} | getPubkeys | `;
4632
4638
  try {
4633
4639
  if (this.paths.length === 0)
4634
4640
  throw new Error("No paths found!");
@@ -4649,7 +4655,7 @@ class SDK {
4649
4655
  }
4650
4656
  };
4651
4657
  this.getBalancesForNetworks = async function(networkIds) {
4652
- const tag5 = `${TAG8} | getBalancesForNetworks | `;
4658
+ const tag5 = `${TAG9} | getBalancesForNetworks | `;
4653
4659
  try {
4654
4660
  if (!this.pioneer) {
4655
4661
  console.error(tag5, "ERROR: Pioneer client not initialized! this.pioneer is:", this.pioneer);
@@ -4704,7 +4710,7 @@ class SDK {
4704
4710
  }
4705
4711
  };
4706
4712
  this.getBalances = async function() {
4707
- const tag5 = `${TAG8} | getBalances | `;
4713
+ const tag5 = `${TAG9} | getBalances | `;
4708
4714
  try {
4709
4715
  return await this.getBalancesForNetworks(this.blockchains);
4710
4716
  } catch (e) {
@@ -4713,7 +4719,7 @@ class SDK {
4713
4719
  }
4714
4720
  };
4715
4721
  this.getBalance = async function(networkId) {
4716
- const tag5 = `${TAG8} | getBalance | `;
4722
+ const tag5 = `${TAG9} | getBalance | `;
4717
4723
  try {
4718
4724
  const results = await this.getBalancesForNetworks([networkId]);
4719
4725
  const filtered = results.filter(async (b2) => b2.networkId === await import_pioneer_caip7.networkIdToCaip(networkId));
@@ -4724,7 +4730,7 @@ class SDK {
4724
4730
  }
4725
4731
  };
4726
4732
  this.getFees = async function(networkId) {
4727
- const tag5 = `${TAG8} | getFees | `;
4733
+ const tag5 = `${TAG9} | getFees | `;
4728
4734
  try {
4729
4735
  if (!this.pioneer) {
4730
4736
  throw new Error("Pioneer client not initialized. Call init() first.");
@@ -4739,7 +4745,7 @@ class SDK {
4739
4745
  return estimateTransactionFee(feeRate, unit, networkType, txSize);
4740
4746
  };
4741
4747
  this.getCharts = async function() {
4742
- const tag5 = `${TAG8} | getCharts | `;
4748
+ const tag5 = `${TAG9} | getCharts | `;
4743
4749
  try {
4744
4750
  console.log(tag5, "Fetching charts");
4745
4751
  const newBalances = await getCharts(this.blockchains, this.pioneer, this.pubkeys, this.context);
@@ -4761,7 +4767,7 @@ class SDK {
4761
4767
  }
4762
4768
  };
4763
4769
  this.setContext = async (context) => {
4764
- const tag5 = `${TAG8} | setContext | `;
4770
+ const tag5 = `${TAG9} | setContext | `;
4765
4771
  try {
4766
4772
  if (!context)
4767
4773
  throw Error("context required!");
@@ -4774,7 +4780,7 @@ class SDK {
4774
4780
  }
4775
4781
  };
4776
4782
  this.setContextType = async (contextType) => {
4777
- const tag5 = `${TAG8} | setContextType | `;
4783
+ const tag5 = `${TAG9} | setContextType | `;
4778
4784
  try {
4779
4785
  if (!contextType)
4780
4786
  throw Error("contextType required!");
@@ -4787,7 +4793,7 @@ class SDK {
4787
4793
  }
4788
4794
  };
4789
4795
  this.refresh = async () => {
4790
- const tag5 = `${TAG8} | refresh | `;
4796
+ const tag5 = `${TAG9} | refresh | `;
4791
4797
  try {
4792
4798
  await this.sync();
4793
4799
  return this.balances;
@@ -4797,7 +4803,7 @@ class SDK {
4797
4803
  }
4798
4804
  };
4799
4805
  this.setAssetContext = async function(asset) {
4800
- const tag5 = `${TAG8} | setAssetContext | `;
4806
+ const tag5 = `${TAG9} | setAssetContext | `;
4801
4807
  try {
4802
4808
  if (!asset) {
4803
4809
  this.assetContext = null;
@@ -4996,7 +5002,7 @@ class SDK {
4996
5002
  }
4997
5003
  };
4998
5004
  this.setPubkeyContext = async function(pubkey) {
4999
- let tag5 = `${TAG8} | setPubkeyContext | `;
5005
+ let tag5 = `${TAG9} | setPubkeyContext | `;
5000
5006
  try {
5001
5007
  if (!pubkey)
5002
5008
  throw Error("pubkey is required");
@@ -5015,7 +5021,7 @@ class SDK {
5015
5021
  }
5016
5022
  };
5017
5023
  this.setOutboundAssetContext = async function(asset) {
5018
- const tag5 = `${TAG8} | setOutputAssetContext | `;
5024
+ const tag5 = `${TAG9} | setOutputAssetContext | `;
5019
5025
  try {
5020
5026
  console.log(tag5, "0. asset: ", asset);
5021
5027
  if (!asset) {