@pioneer-platform/helpers 4.0.2 → 4.0.4

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.
@@ -0,0 +1,39 @@
1
+ /*
2
+ Test Module
3
+
4
+ */
5
+
6
+
7
+ require("dotenv").config({path:'./../../.env'})
8
+ require("dotenv").config({path:'../../../.env'})
9
+ require("dotenv").config({path:'../../../../.env'})
10
+
11
+ let helpers = require("../lib")
12
+
13
+
14
+ let run_test = async function(){
15
+ try{
16
+
17
+ await helpers.AssetValue.loadStaticAssets();
18
+
19
+ // let assetValue = helpers.AssetValue.fromChainOrSignature(
20
+ // 'BASE',
21
+ // 0,
22
+ // );
23
+ // console.log("assetValue: ",assetValue)
24
+ // console.log("assetValue: ",assetValue.getValue('string'))
25
+
26
+ //formatBigIntToSafeValue
27
+ let value = helpers.formatBigIntToSafeValue({
28
+ value: 45354402190799130n,
29
+ decimal: 18,
30
+ })
31
+ console.log("value: ",value)
32
+
33
+
34
+ }catch(e){
35
+ console.error(e)
36
+ }
37
+ }
38
+
39
+ run_test()
@@ -144,7 +144,7 @@ var AssetValue = /** @class */ (function (_super) {
144
144
  function AssetValue(params) {
145
145
  var _this = this;
146
146
  var identifier = 'identifier' in params ? params.identifier : "".concat(params.chain, ".").concat(params.symbol);
147
- console.log('identifier: ', identifier);
147
+ // console.log('identifier: ', identifier);
148
148
  var value;
149
149
  if (params.value instanceof bigIntArithmetics_1.BigIntArithmetics) {
150
150
  value = params.value;
@@ -152,7 +152,7 @@ var AssetValue = /** @class */ (function (_super) {
152
152
  else {
153
153
  value = { decimal: params.decimal, value: params.value };
154
154
  }
155
- console.log('value: ', value);
155
+ // console.log('value: ', value);
156
156
  _this = _super.call(this, value) || this;
157
157
  _this.isGasAsset = false;
158
158
  _this.isSynthetic = false;
@@ -162,7 +162,7 @@ var AssetValue = /** @class */ (function (_super) {
162
162
  // : { decimal: params.decimal, value: params.value },
163
163
  // );
164
164
  var assetInfo = getAssetInfo(identifier);
165
- console.log('assetInfo: ', assetInfo);
165
+ // console.log('assetInfo: ', assetInfo);
166
166
  _this.type = (0, asset_1.getAssetType)(assetInfo);
167
167
  _this.chain = assetInfo.chain;
168
168
  _this.ticker = assetInfo.ticker;
@@ -245,13 +245,13 @@ var AssetValue = /** @class */ (function (_super) {
245
245
  AssetValue.fromStringSync = function (assetString, value) {
246
246
  if (value === void 0) { value = 0; }
247
247
  var _a = getAssetInfo(assetString), isSynthetic = _a.isSynthetic, symbol = _a.symbol, chain = _a.chain, isGasAsset = _a.isGasAsset, ticker = _a.ticker, address = _a.address;
248
- console.log('getAssetInfo: ', { isSynthetic: isSynthetic, symbol: symbol, chain: chain, isGasAsset: isGasAsset, ticker: ticker, address: address });
248
+ //console.log('getAssetInfo: ', { isSynthetic, symbol, chain, isGasAsset, ticker, address });
249
249
  var _b = getStaticToken(assetString), tax = _b.tax, decimal = _b.decimal, tokenIdentifier = _b.identifier;
250
- console.log('getStaticToken: ', { tax: tax, decimal: decimal, tokenIdentifier: tokenIdentifier });
251
- console.log('value: ', value);
252
- console.log('decimal: ', decimal);
250
+ // console.log('getStaticToken: ', { tax, decimal, tokenIdentifier });
251
+ // console.log('value: ', value);
252
+ // console.log('decimal: ', decimal);
253
253
  var parsedValue = safeValue(value, decimal);
254
- console.log('parsedValue: ', parsedValue);
254
+ // console.log('parsedValue: ', parsedValue);
255
255
  var asset;
256
256
  if (tokenIdentifier) {
257
257
  console.log('tokenIdentifier is truthy'); // Indicates tokenIdentifier has a value considered true in a boolean context
@@ -316,7 +316,11 @@ var AssetValue = /** @class */ (function (_super) {
316
316
  //@ts-ignore
317
317
  function (acc, _a) {
318
318
  var tokens = _a.tokens;
319
- // @ts-ignore
319
+ if (!tokens) {
320
+ console.warn("No tokens found in the current package, skipping.");
321
+ return acc;
322
+ }
323
+ // console.log(`Processing tokens for chain ${tokens[0]?.chain || 'unknown'}`);
320
324
  tokens.forEach(function (_a) {
321
325
  var identifier = _a.identifier, chain = _a.chain, rest = __rest(_a, ["identifier", "chain"]);
322
326
  //@ts-ignore
@@ -325,12 +329,13 @@ var AssetValue = /** @class */ (function (_super) {
325
329
  });
326
330
  return acc;
327
331
  }, new Map());
332
+ // console.log("Tokens map successfully created:", tokensMap);
328
333
  staticTokensMap = tokensMap;
329
334
  resolve({ ok: true });
330
335
  return [3 /*break*/, 3];
331
336
  case 2:
332
337
  error_1 = _b.sent();
333
- console.error(error_1);
338
+ console.error("Error loading static assets:", error_1);
334
339
  reject({
335
340
  ok: false,
336
341
  error: error_1,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pioneer-platform/helpers",
3
- "version": "4.0.2",
3
+ "version": "4.0.4",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "scripts": {
@@ -102,7 +102,7 @@ export class AssetValue extends BigIntArithmetics {
102
102
  constructor(params: AssetValueParams) {
103
103
  const identifier =
104
104
  'identifier' in params ? params.identifier : `${params.chain}.${params.symbol}`;
105
- console.log('identifier: ', identifier);
105
+ // console.log('identifier: ', identifier);
106
106
 
107
107
  let value;
108
108
  if (params.value instanceof BigIntArithmetics) {
@@ -110,7 +110,7 @@ export class AssetValue extends BigIntArithmetics {
110
110
  } else {
111
111
  value = { decimal: params.decimal, value: params.value };
112
112
  }
113
- console.log('value: ', value);
113
+ // console.log('value: ', value);
114
114
  super(value);
115
115
 
116
116
  // super(
@@ -120,7 +120,7 @@ export class AssetValue extends BigIntArithmetics {
120
120
  // );
121
121
 
122
122
  const assetInfo = getAssetInfo(identifier);
123
- console.log('assetInfo: ', assetInfo);
123
+ // console.log('assetInfo: ', assetInfo);
124
124
  this.type = getAssetType(assetInfo);
125
125
  this.chain = assetInfo.chain;
126
126
  this.ticker = assetInfo.ticker;
@@ -202,17 +202,17 @@ export class AssetValue extends BigIntArithmetics {
202
202
 
203
203
  static fromStringSync(assetString: string, value: NumberPrimitives = 0) {
204
204
  const { isSynthetic, symbol, chain, isGasAsset, ticker, address } = getAssetInfo(assetString);
205
- console.log('getAssetInfo: ', { isSynthetic, symbol, chain, isGasAsset, ticker, address });
205
+ //console.log('getAssetInfo: ', { isSynthetic, symbol, chain, isGasAsset, ticker, address });
206
206
  const {
207
207
  tax,
208
208
  decimal,
209
209
  identifier: tokenIdentifier,
210
210
  } = getStaticToken(assetString as unknown as TokenNames);
211
- console.log('getStaticToken: ', { tax, decimal, tokenIdentifier });
212
- console.log('value: ', value);
213
- console.log('decimal: ', decimal);
211
+ // console.log('getStaticToken: ', { tax, decimal, tokenIdentifier });
212
+ // console.log('value: ', value);
213
+ // console.log('decimal: ', decimal);
214
214
  const parsedValue = safeValue(value, decimal);
215
- console.log('parsedValue: ', parsedValue);
215
+ // console.log('parsedValue: ', parsedValue);
216
216
  let asset: AssetValue | undefined;
217
217
 
218
218
  if (tokenIdentifier) {
@@ -263,46 +263,57 @@ export class AssetValue extends BigIntArithmetics {
263
263
 
264
264
  static async loadStaticAssets() {
265
265
  return new Promise<{ ok: true } | { ok: false; message: string; error: any }>(
266
- async (resolve, reject) => {
267
- try {
268
- // @ts-ignore
269
- const {
270
- // Omit ThorchainList from import to avoid decimals conflict (TC uses 8 for all)
271
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
272
- ThorchainList: _ThorchainList,
273
- NativeList,
274
- ...tokensPackage
266
+ async (resolve, reject) => {
267
+ try {
268
+ // console.log("Starting to load static assets...");
269
+
270
+ // @ts-ignore
271
+ const {
272
+ // Omit ThorchainList from import to avoid decimals conflict (TC uses 8 for all)
273
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
274
+ ThorchainList: _ThorchainList,
275
+ NativeList,
276
+ ...tokensPackage
275
277
  //@ts-ignore
276
- } = await import('@coinmasters/tokens');
277
- const tokensMap = [NativeList, ...Object.values(tokensPackage)].reduce(
278
- //@ts-ignore
279
- (acc, { tokens }) => {
280
- // @ts-ignore
281
- tokens.forEach(({ identifier, chain, ...rest }) => {
278
+ } = await import('@coinmasters/tokens');
279
+
280
+ // console.log("Successfully imported @coinmasters/tokens package.");
281
+
282
+ const tokensMap = [NativeList, ...Object.values(tokensPackage)].reduce(
282
283
  //@ts-ignore
283
- const decimal = 'decimals' in rest ? rest.decimals : BaseDecimal[chain as Chain];
284
-
285
- acc.set(identifier as TokenNames, { identifier, decimal });
286
- });
287
-
288
- return acc;
289
- },
290
- new Map<TokenNames, { decimal: number; identifier: string }>(),
291
- );
292
-
293
- staticTokensMap = tokensMap;
294
-
295
- resolve({ ok: true });
296
- } catch (error) {
297
- console.error(error);
298
- reject({
299
- ok: false,
300
- error,
301
- message:
302
- "Couldn't load static assets. Ensure you have installed @coinmasters/tokens package",
303
- });
304
- }
305
- },
284
+ (acc, { tokens }) => {
285
+ if (!tokens) {
286
+ console.warn("No tokens found in the current package, skipping.");
287
+ return acc;
288
+ }
289
+ // console.log(`Processing tokens for chain ${tokens[0]?.chain || 'unknown'}`);
290
+
291
+ tokens.forEach(({ identifier, chain, ...rest }:any) => {
292
+ //@ts-ignore
293
+ const decimal = 'decimals' in rest ? rest.decimals : BaseDecimal[chain as Chain];
294
+
295
+ acc.set(identifier as TokenNames, { identifier, decimal });
296
+ });
297
+
298
+ return acc;
299
+ },
300
+ new Map<TokenNames, { decimal: number; identifier: string }>(),
301
+ );
302
+
303
+ // console.log("Tokens map successfully created:", tokensMap);
304
+
305
+ staticTokensMap = tokensMap;
306
+
307
+ resolve({ ok: true });
308
+ } catch (error) {
309
+ console.error("Error loading static assets:", error);
310
+ reject({
311
+ ok: false,
312
+ error,
313
+ message: "Couldn't load static assets. Ensure you have installed @coinmasters/tokens package",
314
+ });
315
+ }
316
+ },
306
317
  );
307
318
  }
308
319
  }