Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into dev
  • Loading branch information
viktorgullmark committed Aug 21, 2022
2 parents e647f93 + 7b4ecc4 commit 94df295
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,22 @@ const ItemTableFilterSubtotal = ({ array }: ItemTableFilterSubtotalProps) => {

let value = array.map((i) => i.total).reduce((a, b) => a + b, 0);

if (settingStore.showPriceInExalt) {
if (settingStore.currency === 'exalt') {
if (priceStore.exaltedPrice) {
value = value / priceStore.exaltedPrice;
} else {
value = 0;
}
}

if (settingStore.currency === 'divine') {
if (priceStore.divinePrice) {
value = value / priceStore.divinePrice;
} else {
value = 0;
}
}

// FIXME: remove unnecessary .map()
const sumString =
' ' +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const useStyles = makeStyles((theme) => ({
color: currencyChangeColors.negative,
},
tooltip: {
maxWidth: 170,
maxWidth: 220,
},
clearBtn: {
color: theme.palette.text.secondary,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ const OverviewWidgetContent = ({
const classes = useStyles();
const { t } = useTranslation();
const { settingStore, priceStore } = useStores();

const toggleCurrency = () => {
// cycle over current setting and choose next
const chooseCurrency = () => {
switch (settingStore.currency) {
case 'exalt':
return 'divine';
case 'divine':
return 'chaos';
case 'chaos':
return 'exalt';
}
};
settingStore.setCurrencyDisplay(chooseCurrency());
};
return (
<>
<Grid container className={classes.topContent}>
Expand Down Expand Up @@ -78,7 +93,8 @@ const OverviewWidgetContent = ({
title={
<>
<Typography variant="subtitle1" color="inherit" gutterBottom>
1 ex = {priceStore.exaltedPrice?.toFixed(1)} chaos
1 ex = {priceStore.exaltedPrice?.toFixed(1)} c
<br />1 divine = {priceStore.divinePrice?.toFixed(1)} c
</Typography>
<em>{t('action.currency_switch')}</em>
</>
Expand All @@ -90,7 +106,7 @@ const OverviewWidgetContent = ({
data-tour-elem="currencySwitch"
size="small"
className={classes.adornmentIcon}
onClick={() => settingStore.setShowPriceInExalt(!settingStore.showPriceInExalt)}
onClick={() => toggleCurrency()}
>
<ChangeCircleIcon />
</IconButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ const NetWorthSettings = () => {
const { settingStore } = useStores();
return (
<Grid container spacing={5}>
<Grid item>
<CheckboxSetting
value={settingStore!.showPriceInExalt}
handleChange={(value: boolean) => settingStore!.setShowPriceInExalt(value)}
translationKey="price_in_exalt"
/>
</Grid>
<Grid item>
<CheckboxSetting
value={settingStore!.lowConfidencePricing}
Expand Down
4 changes: 1 addition & 3 deletions ExilenceNextApp/src/components/toolbar/ToolbarContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ const ToolbarContainer = () => {
};

const activeCurrency = () => {
return settingStore?.showPriceInExalt
? { name: 'exalted', short: 'ex' }
: { name: 'chaos', short: 'c' };
return settingStore?.activeCurrency;
};

const handleOverlay = () => {
Expand Down
5 changes: 4 additions & 1 deletion ExilenceNextApp/src/routes/net-worth/NetWorth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,12 @@ const NetWorth = () => {
};

const getExaltedValue = (value: number) => {
if (settingStore.showPriceInExalt && priceStore.exaltedPrice) {
if (settingStore.currency === 'exalt' && priceStore.exaltedPrice) {
value = value / priceStore.exaltedPrice;
}
if (settingStore.currency === 'divine' && priceStore.divinePrice) {
value = value / priceStore.divinePrice;
}
return value;
};

Expand Down
2 changes: 1 addition & 1 deletion ExilenceNextApp/src/store/domains/account.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AxiosError } from 'axios';
import { action, computed, makeObservable, observable, runInAction, toJS } from 'mobx';
import { action, computed, makeObservable, observable, runInAction } from 'mobx';
import { persist } from 'mobx-persist';
import { fromStream } from 'mobx-utils';
import { of, Subject, throwError, timer } from 'rxjs';
Expand Down
11 changes: 9 additions & 2 deletions ExilenceNextApp/src/store/domains/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,14 @@ export class Group implements IApiGroup {

let newNetworth = getValueForSnapshotsTabs(this.latestGroupSnapshots);

if (rootStore.settingStore.showPriceInExalt && rootStore.priceStore.exaltedPrice) {
if (rootStore.settingStore.currency === 'exalt' && rootStore.priceStore.exaltedPrice) {
newNetworth = newNetworth / rootStore.priceStore.exaltedPrice;
previousNetworth = previousNetworth / rootStore.priceStore.exaltedPrice;
}
if (rootStore.settingStore.currency === 'divine' && rootStore.priceStore.divinePrice) {
newNetworth = newNetworth / rootStore.priceStore.divinePrice;
previousNetworth = previousNetworth / rootStore.priceStore.divinePrice;
}
return newNetworth - previousNetworth;
}

Expand Down Expand Up @@ -161,9 +165,12 @@ export class Group implements IApiGroup {
return 0;
}
let calculatedValue = calculateNetWorth(this.latestGroupSnapshots);
if (rootStore.settingStore.showPriceInExalt && rootStore.priceStore.exaltedPrice) {
if (rootStore.settingStore.currency === 'exalt' && rootStore.priceStore.exaltedPrice) {
calculatedValue = calculatedValue / rootStore.priceStore.exaltedPrice;
}
if (rootStore.settingStore.currency === 'divine' && rootStore.priceStore.divinePrice) {
calculatedValue = calculatedValue / rootStore.priceStore.divinePrice;
}
return calculatedValue;
}

Expand Down
21 changes: 15 additions & 6 deletions ExilenceNextApp/src/store/domains/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,12 @@ export class Profile {
return 0;
}
let calculatedValue = calculateNetWorth([mapSnapshotToApiSnapshot(this.snapshots[0])]);
if (rootStore.settingStore.showPriceInExalt && rootStore.priceStore.exaltedPrice) {
if (rootStore.settingStore.currency === 'exalt' && rootStore.priceStore.exaltedPrice) {
calculatedValue = calculatedValue / rootStore.priceStore.exaltedPrice;
}
if (rootStore.settingStore.currency === 'divine' && rootStore.priceStore.divinePrice) {
calculatedValue = calculatedValue / rootStore.priceStore.divinePrice;
}
return calculatedValue;
}

Expand All @@ -142,10 +145,14 @@ export class Profile {
mapSnapshotToApiSnapshot(this.snapshots[1]),
]);

if (rootStore.settingStore.showPriceInExalt && rootStore.priceStore.exaltedPrice) {
if (rootStore.settingStore.currency === 'exalt' && rootStore.priceStore.exaltedPrice) {
lastSnapshotNetWorth = lastSnapshotNetWorth / rootStore.priceStore.exaltedPrice;
previousSnapshotNetWorth = previousSnapshotNetWorth / rootStore.priceStore.exaltedPrice;
}
if (rootStore.settingStore.currency === 'divine' && rootStore.priceStore.divinePrice) {
lastSnapshotNetWorth = lastSnapshotNetWorth / rootStore.priceStore.divinePrice;
previousSnapshotNetWorth = previousSnapshotNetWorth / rootStore.priceStore.divinePrice;
}
return lastSnapshotNetWorth - previousSnapshotNetWorth;
}

Expand Down Expand Up @@ -400,18 +407,20 @@ export class Profile {

@action
updateNetWorthOverlay() {
const activeCurrency = rootStore.settingStore.showPriceInExalt
? { name: 'exalted', short: 'ex' }
: { name: 'chaos', short: 'c' };
const activeCurrency = rootStore.settingStore.activeCurrency;

let income = rootStore.signalrStore.activeGroup
? rootStore.signalrStore.activeGroup.income
: rootStore.accountStore.getSelectedAccount!.activeProfile!.income;

if (rootStore.settingStore.showPriceInExalt && rootStore.priceStore.exaltedPrice) {
if (rootStore.settingStore.currency === 'exalt' && rootStore.priceStore.exaltedPrice) {
income = income / rootStore.priceStore.exaltedPrice;
}

if (rootStore.settingStore.currency === 'divine' && rootStore.priceStore.divinePrice) {
income = income / rootStore.priceStore.divinePrice;
}

const formattedIncome = formatValue(
income,
activeCurrency.short,
Expand Down
7 changes: 7 additions & 0 deletions ExilenceNextApp/src/store/priceStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ export class PriceStore {
: exaltedOrbPrice?.calculated;
}

@computed get divinePrice() {
const divineOrbPrice = this.activePricesWithCustomValues?.find((p) => p.name === 'Divine Orb');
return divineOrbPrice?.customPrice && divineOrbPrice.customPrice > 0
? divineOrbPrice?.customPrice
: divineOrbPrice?.calculated;
}

@computed get customPricesTableData() {
const selectedLeagueId = this.rootStore.uiStateStore.selectedPriceTableLeagueId;
const activeLeagueId = this.rootStore.accountStore.getSelectedAccount.activePriceLeague?.id;
Expand Down
16 changes: 12 additions & 4 deletions ExilenceNextApp/src/store/settingStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { electronService } from '../services/electron.service';
import { RootStore } from './rootStore';

export type ReleaseChannel = 'latest' | 'beta';
export type Currency = 'chaos' | 'exalt' | 'divine';
export type AppExitTypes = 'minimize-to-tray' | 'exit';

export class SettingStore {
Expand All @@ -18,7 +19,7 @@ export class SettingStore {
electronService.localSettings?.releaseChannel || 'latest';
@persist @observable priceThreshold: number = 0;
@persist @observable totalPriceThreshold: number = 0;
@persist @observable showPriceInExalt = false;
@persist @observable currency: Currency = 'chaos';
@persist @observable autoSnapshotInterval: number = 60 * 20 * 1000; // default to 20 minutes
@persist @observable uiScale: number = electronService.webFrame.getZoomFactor() * 100;
@persist @observable logPath: string =
Expand All @@ -31,7 +32,14 @@ export class SettingStore {
}

@computed get activeCurrency(): ICurrency {
return this.showPriceInExalt ? { name: 'exalted', short: 'ex' } : { name: 'chaos', short: 'c' };
switch (this.currency) {
case 'exalt':
return { name: 'exalted', short: 'ex' };
case 'chaos':
return { name: 'chaos', short: 'c' };
case 'divine':
return { name: 'divine', short: 'div' };
}
}

@action
Expand All @@ -47,8 +55,8 @@ export class SettingStore {
}

@action
setShowPriceInExalt(value: boolean) {
this.showPriceInExalt = value;
setCurrencyDisplay(value: Currency) {
this.currency = value;
rootStore.accountStore.getSelectedAccount?.activeProfile?.updateNetWorthOverlay();
}

Expand Down

0 comments on commit 94df295

Please sign in to comment.