Account for renamed variable.

This commit is contained in:
James Cole
2025-03-23 15:04:38 +01:00
parent 5e1ecb2b11
commit a46f8430df
10 changed files with 111 additions and 108 deletions

View File

@@ -31,7 +31,7 @@ export default () => ({
billBox: {paid: [], unpaid: []},
leftBox: {left: [], perDay: []},
netBox: {net: []},
autoConversion: false,
convertToNative: false,
loading: false,
boxData: null,
boxOptions: null,
@@ -42,8 +42,9 @@ export default () => ({
const boxesCacheKey = getCacheKey('ds_boxes_data', {start: start, end: end});
cleanupCache();
const cacheValid = window.store.get('cacheValid');
//const cacheValid = window.store.get('cacheValid');
let cachedData = window.store.get(boxesCacheKey);
const cacheValid = false; // force refresh
if (cacheValid && typeof cachedData !== 'undefined') {
this.boxData = cachedData;
@@ -76,7 +77,8 @@ export default () => ({
}
let key = current.key;
// native (auto conversion):
if (this.autoConversion) {
if (this.convertToNative) {
console.error('convertToNative does not work in boxes.');
if (key.startsWith('balance-in-native')) {
this.balanceBox.amounts.push(formatMoney(current.value, current.currency_code));
// prep subtitles (for later)
@@ -132,9 +134,10 @@ export default () => ({
}
}
// not native
if (!this.autoConversion && !key.endsWith('native')) {
if (!this.convertToNative && !key.endsWith('native')) {
console.log('NOT NATIVE');
if (key.startsWith('balance-in-')) {
this.balanceBox.amounts.push(formatMoney(current.value, current.currency_code));
this.balanceBox.amounts.push(formatMoney(current.monetary_value , current.currency_code));
continue;
}
// spent info is used in subtitle:
@@ -146,7 +149,7 @@ export default () => ({
// append the amount spent.
subtitles[current.currency_code] =
subtitles[current.currency_code] +
formatMoney(current.value, current.currency_code);
formatMoney(current.monetary_value , current.currency_code);
continue;
}
// earned info is used in subtitle:
@@ -157,30 +160,30 @@ export default () => ({
}
// prepend the amount earned.
subtitles[current.currency_code] =
formatMoney(current.value, current.currency_code) + ' + ' +
formatMoney(current.monetary_value , current.currency_code) + ' + ' +
subtitles[current.currency_code];
continue;
}
if (key.startsWith('bills-unpaid-in-')) {
this.billBox.unpaid.push(formatMoney(current.value, current.currency_code));
this.billBox.unpaid.push(formatMoney(current.monetary_value , current.currency_code));
continue;
}
if (key.startsWith('bills-paid-in-')) {
this.billBox.paid.push(formatMoney(current.value, current.currency_code));
this.billBox.paid.push(formatMoney(current.monetary_value , current.currency_code));
continue;
}
if (key.startsWith('left-to-spend-in-')) {
this.leftBox.left.push(formatMoney(current.value, current.currency_code));
this.leftBox.left.push(formatMoney(current.monetary_value , current.currency_code));
continue;
}
if (key.startsWith('left-per-day-to-spend-in-')) {
this.leftBox.perDay.push(formatMoney(current.value, current.currency_code));
this.leftBox.perDay.push(formatMoney(current.monetary_value , current.currency_code));
continue;
}
if (key.startsWith('net-worth-in-')) {
this.netBox.net.push(formatMoney(current.value, current.currency_code));
this.netBox.net.push(formatMoney(current.monetary_value , current.currency_code));
}
}
@@ -210,10 +213,10 @@ export default () => ({
init() {
// console.log('boxes init');
// TODO can be replaced by "getVariables"
Promise.all([getVariable('viewRange'), getVariable('autoConversion', false)]).then((values) => {
Promise.all([getVariable('viewRange'), getVariable('convertToNative', false)]).then((values) => {
// console.log('boxes after promises');
afterPromises = true;
this.autoConversion = values[1];
this.convertToNative = values[1];
this.loadBoxes();
});
window.store.observe('end', () => {
@@ -224,12 +227,12 @@ export default () => ({
this.boxData = null;
this.loadBoxes();
});
window.store.observe('autoConversion', (newValue) => {
window.store.observe('convertToNative', (newValue) => {
if (!afterPromises) {
return;
}
// console.log('boxes observe autoConversion');
this.autoConversion = newValue;
// console.log('boxes observe convertToNative');
this.convertToNative = newValue;
this.loadBoxes();
});
},