Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sort) option to disable sorting #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions helper/calculateNetworth.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { calculateEssence } = require('../calculators/essenceCalculator');
const { calculateItem } = require('../calculators/itemCalculator');
const { getPetLevel } = require('../constants/pets');

const calculateNetworth = (items, purseBalance, bankBalance, prices, onlyNetworth, returnItemData) => {
const calculateNetworth = (items, purseBalance, bankBalance, prices, onlyNetworth, returnItemData, sortData) => {
const categories = {};

for (const [category, categoryItems] of Object.entries(items)) {
Expand All @@ -27,7 +27,7 @@ const calculateNetworth = (items, purseBalance, bankBalance, prices, onlyNetwort
}

// Sort items by price
if (!onlyNetworth && categories[category].items.length > 0) {
if (sortData && !onlyNetworth && categories[category].items.length > 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also disables combining items like if you have 10 stacks of enchanted hay bales it will shows each stack instead of combining. See .reduce below.

categories[category].items = categories[category].items
.sort((a, b) => b.price - a.price)
.reduce((r, a) => {
Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const getNetworth = async (profileData, bankBalance, options) => {
const purse = profileData.coin_purse;
const prices = await parsePrices(options?.prices, options?.cache);
const items = await parseItems(profileData);
return calculateNetworth(items, purse, bankBalance, prices, options?.onlyNetworth, options?.returnItemData);
return calculateNetworth(items, purse, bankBalance, prices, options?.onlyNetworth, options?.returnItemData, options?.sortData ?? true);
};

/**
Expand Down Expand Up @@ -83,7 +83,7 @@ const getPrices = async (cache) => {
if (cachedPrices?.lastCache > Date.now() - 1000 * 60 * 5 && cache !== false) {
return cachedPrices.prices; // Cache for 5 minutes
}

if (isLoadingPrices) {
while (isLoadingPrices) {
await new Promise(r => setTimeout(r, 100)) //re-check if prices have loaded yet in 100ms
Expand Down Expand Up @@ -134,7 +134,7 @@ const checkForUpdate = async () => {
if (latestVersion !== currentVersion) {
console.log(`[SKYHELPER-NETWORTH] An update is available! Current version: ${currentVersion}, Latest version: ${latestVersion}`);
}
} catch (err) {}
} catch (err) { }
};
checkForUpdate();
let interval;
Expand Down