@pioneer-platform/helpers 4.0.1 → 4.0.3
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/__tests__/test-module.js +31 -0
- package/lib/modules/assetValue.js +10 -2
- package/package.json +2 -2
- package/src/modules/assetValue.ts +94 -38
@@ -0,0 +1,31 @@
|
|
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
|
+
}catch(e){
|
27
|
+
console.error(e)
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
run_test()
|
@@ -309,14 +309,21 @@ var AssetValue = /** @class */ (function (_super) {
|
|
309
309
|
switch (_b.label) {
|
310
310
|
case 0:
|
311
311
|
_b.trys.push([0, 2, , 3]);
|
312
|
+
console.log("Starting to load static assets...");
|
312
313
|
return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require('@coinmasters/tokens')); })];
|
313
314
|
case 1:
|
314
315
|
_a = _b.sent(), _ThorchainList = _a.ThorchainList, NativeList = _a.NativeList, tokensPackage = __rest(_a, ["ThorchainList", "NativeList"]);
|
316
|
+
console.log("Successfully imported @coinmasters/tokens package.");
|
315
317
|
tokensMap = __spreadArray([NativeList], Object.values(tokensPackage), true).reduce(
|
316
318
|
//@ts-ignore
|
317
319
|
function (acc, _a) {
|
320
|
+
var _b;
|
318
321
|
var tokens = _a.tokens;
|
319
|
-
|
322
|
+
if (!tokens) {
|
323
|
+
console.warn("No tokens found in the current package, skipping.");
|
324
|
+
return acc;
|
325
|
+
}
|
326
|
+
console.log("Processing tokens for chain ".concat(((_b = tokens[0]) === null || _b === void 0 ? void 0 : _b.chain) || 'unknown'));
|
320
327
|
tokens.forEach(function (_a) {
|
321
328
|
var identifier = _a.identifier, chain = _a.chain, rest = __rest(_a, ["identifier", "chain"]);
|
322
329
|
//@ts-ignore
|
@@ -325,12 +332,13 @@ var AssetValue = /** @class */ (function (_super) {
|
|
325
332
|
});
|
326
333
|
return acc;
|
327
334
|
}, new Map());
|
335
|
+
console.log("Tokens map successfully created:", tokensMap);
|
328
336
|
staticTokensMap = tokensMap;
|
329
337
|
resolve({ ok: true });
|
330
338
|
return [3 /*break*/, 3];
|
331
339
|
case 2:
|
332
340
|
error_1 = _b.sent();
|
333
|
-
console.error(error_1);
|
341
|
+
console.error("Error loading static assets:", error_1);
|
334
342
|
reject({
|
335
343
|
ok: false,
|
336
344
|
error: error_1,
|
package/package.json
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
{
|
2
2
|
"name": "@pioneer-platform/helpers",
|
3
|
-
"version": "4.0.
|
3
|
+
"version": "4.0.3",
|
4
4
|
"main": "./lib/index.js",
|
5
|
-
"types": "./lib/
|
5
|
+
"types": "./lib/index.d.ts",
|
6
6
|
"scripts": {
|
7
7
|
"npm": "npm i",
|
8
8
|
"test": "npm run build && node __tests__/test-module.js",
|
@@ -263,48 +263,104 @@ 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
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
//
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
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
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
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
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
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
|
}
|
319
|
+
|
320
|
+
// static async loadStaticAssets() {
|
321
|
+
// return new Promise<{ ok: true } | { ok: false; message: string; error: any }>(
|
322
|
+
// async (resolve, reject) => {
|
323
|
+
// try {
|
324
|
+
// // @ts-ignore
|
325
|
+
// const {
|
326
|
+
// // Omit ThorchainList from import to avoid decimals conflict (TC uses 8 for all)
|
327
|
+
// // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
328
|
+
// ThorchainList: _ThorchainList,
|
329
|
+
// NativeList,
|
330
|
+
// ...tokensPackage
|
331
|
+
// //@ts-ignore
|
332
|
+
// } = await import('@coinmasters/tokens');
|
333
|
+
// const tokensMap = [NativeList, ...Object.values(tokensPackage)].reduce(
|
334
|
+
// //@ts-ignore
|
335
|
+
// (acc, { tokens }) => {
|
336
|
+
// // @ts-ignore
|
337
|
+
// tokens.forEach(({ identifier, chain, ...rest }) => {
|
338
|
+
// //@ts-ignore
|
339
|
+
// const decimal = 'decimals' in rest ? rest.decimals : BaseDecimal[chain as Chain];
|
340
|
+
//
|
341
|
+
// acc.set(identifier as TokenNames, { identifier, decimal });
|
342
|
+
// });
|
343
|
+
//
|
344
|
+
// return acc;
|
345
|
+
// },
|
346
|
+
// new Map<TokenNames, { decimal: number; identifier: string }>(),
|
347
|
+
// );
|
348
|
+
//
|
349
|
+
// staticTokensMap = tokensMap;
|
350
|
+
//
|
351
|
+
// resolve({ ok: true });
|
352
|
+
// } catch (error) {
|
353
|
+
// console.error(error);
|
354
|
+
// reject({
|
355
|
+
// ok: false,
|
356
|
+
// error,
|
357
|
+
// message:
|
358
|
+
// "Couldn't load static assets. Ensure you have installed @coinmasters/tokens package",
|
359
|
+
// });
|
360
|
+
// }
|
361
|
+
// },
|
362
|
+
// );
|
363
|
+
// }
|
308
364
|
}
|
309
365
|
|
310
366
|
export const getMinAmountByChain = (chain: Chain) => {
|