UNPKG

@qso-soft/shared

Version:

Shared library for QSO-soft

47 lines 2.13 kB
import { prepareModulesWithOptions } from '../modules'; import { limitArray, shuffleArray } from '../utils'; import { getRangedByIdWallets, getWalletsFromKeys } from './get-filtered-wallets'; export const prepareWallets = async (params) => { const { routeSettings, shouldShuffleWallets, jsonWallets, projectName } = params; const logTemplate = { action: 'prepareWallets', }; let wallets = getWalletsFromKeys(params.logger, jsonWallets, projectName); if (shouldShuffleWallets) { wallets = shuffleArray(wallets); } const limitWalletsToUse = routeSettings.limitWalletsToUse; const shouldLimitWallets = limitWalletsToUse > 0; if (shouldLimitWallets) { params.logger.success(`Limit of [${limitWalletsToUse}] has been applied. Total wallets before limit [${wallets.length}]`, { ...logTemplate }); wallets = limitArray(wallets, limitWalletsToUse); } params.logger.success(`We are starting to work on [${wallets.length}] wallets`, { ...logTemplate }); return wallets; }; export const prepareWalletsWithModules = async (params) => { const { shouldShuffleModules, getUpdatedModulesCallback } = params; const wallets = await prepareWallets(params); if (!wallets?.length) { params.logger.error('Wallets not found', { status: 'failed' }); return; } const filteredWallets = getRangedByIdWallets(wallets, QsoGlobal.settings.idFilter, params.logger); return filteredWallets.map((wallet) => ({ wallet, modules: prepareModulesWithOptions({ routeSettings: params.routeSettings, shouldShuffleModules, defaultModuleConfigs: QsoGlobal.defaultModuleConfigs, getUpdatedModulesCallback, }), })); }; export const prepareSavedWalletsWithModules = (savedModules) => savedModules.walletsWithModules?.reduce((acc, cur) => { const currentModules = cur.modules.filter((module) => module.count > 0); if (currentModules.length) { return [...acc, { ...cur, modules: currentModules }]; } return acc; }, []); //# sourceMappingURL=prepare-wallets.js.map