mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-18 16:54:25 +08:00
code refactor
This commit is contained in:
+1
-1
@@ -68,7 +68,7 @@ export default {
|
|||||||
|
|
||||||
// auto refresh exchange rates data
|
// auto refresh exchange rates data
|
||||||
if (this.$settings.isAutoUpdateExchangeRatesData()) {
|
if (this.$settings.isAutoUpdateExchangeRatesData()) {
|
||||||
this.$services.autoRefreshLatestExchangeRates();
|
this.$store.dispatch('getLatestExchangeRates', { silent: true, force: false });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,54 +0,0 @@
|
|||||||
import utils from './utils.js';
|
|
||||||
|
|
||||||
const exchangeRatesLocalStorageKey = 'lab_app_exchange_rates';
|
|
||||||
|
|
||||||
function getExchangeRates() {
|
|
||||||
const storageData = localStorage.getItem(exchangeRatesLocalStorageKey) || '{}';
|
|
||||||
return JSON.parse(storageData);
|
|
||||||
}
|
|
||||||
|
|
||||||
function setExchangeRates(value) {
|
|
||||||
const storageData = JSON.stringify(value);
|
|
||||||
localStorage.setItem(exchangeRatesLocalStorageKey, storageData);
|
|
||||||
}
|
|
||||||
|
|
||||||
function clearExchangeRates() {
|
|
||||||
localStorage.removeItem(exchangeRatesLocalStorageKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getExchangeRate(fromCurrency, toCurrency) {
|
|
||||||
const exchangeRates = getExchangeRates().exchangeRates;
|
|
||||||
const exchangeRateMap = {};
|
|
||||||
|
|
||||||
for (let i = 0; i < exchangeRates.length; i++) {
|
|
||||||
const exchangeRate = exchangeRates[i];
|
|
||||||
exchangeRateMap[exchangeRate.currency] = exchangeRate;
|
|
||||||
}
|
|
||||||
|
|
||||||
const fromCurrencyExchangeRate = exchangeRateMap[fromCurrency];
|
|
||||||
const toCurrencyExchangeRate = exchangeRateMap[toCurrency];
|
|
||||||
|
|
||||||
if (!fromCurrencyExchangeRate || !toCurrencyExchangeRate) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return parseFloat(toCurrencyExchangeRate.rate) / parseFloat(fromCurrencyExchangeRate.rate);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getOtherCurrencyAmount(amount, fromCurrency, toCurrency) {
|
|
||||||
const exchangeRate = getExchangeRate(fromCurrency, toCurrency);
|
|
||||||
|
|
||||||
if (!utils.isNumber(exchangeRate)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return amount * exchangeRate;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default {
|
|
||||||
getExchangeRates,
|
|
||||||
setExchangeRates,
|
|
||||||
clearExchangeRates,
|
|
||||||
getExchangeRate,
|
|
||||||
getOtherCurrencyAmount,
|
|
||||||
};
|
|
||||||
+3
-21
@@ -1,7 +1,6 @@
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import moment from 'moment';
|
|
||||||
import userState from "./userstate.js";
|
import userState from "./userstate.js";
|
||||||
import exchangeRates from "./exchangeRates.js";
|
|
||||||
|
|
||||||
const baseUrlPath = '/api';
|
const baseUrlPath = '/api';
|
||||||
|
|
||||||
@@ -330,26 +329,9 @@ export default {
|
|||||||
id
|
id
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getLatestExchangeRates: () => {
|
getLatestExchangeRates: ({ ignoreError }) => {
|
||||||
return axios.get('v1/exchange_rates/latest.json');
|
|
||||||
},
|
|
||||||
autoRefreshLatestExchangeRates: () => {
|
|
||||||
const currentExchangeRateData = exchangeRates.getExchangeRates();
|
|
||||||
|
|
||||||
if (currentExchangeRateData && currentExchangeRateData.date === moment().format('YYYY-MM-DD')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
return axios.get('v1/exchange_rates/latest.json', {
|
return axios.get('v1/exchange_rates/latest.json', {
|
||||||
ignoreError: true
|
ignoreError: !!ignoreError
|
||||||
}).then(response => {
|
|
||||||
const data = response.data;
|
|
||||||
|
|
||||||
if (data && data.success && data.result && data.result.exchangeRates) {
|
|
||||||
exchangeRates.setExchangeRates(data.result);
|
|
||||||
}
|
|
||||||
|
|
||||||
return data.result;
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import logger from './lib/logger.js';
|
|||||||
import settings from './lib/settings.js';
|
import settings from './lib/settings.js';
|
||||||
import services from './lib/services.js';
|
import services from './lib/services.js';
|
||||||
import userstate from './lib/userstate.js';
|
import userstate from './lib/userstate.js';
|
||||||
import exchangeRates from './lib/exchangeRates.js';
|
|
||||||
import webauthn from './lib/webauthn.js';
|
import webauthn from './lib/webauthn.js';
|
||||||
import utils from './lib/utils.js';
|
import utils from './lib/utils.js';
|
||||||
import stores from './store/index.js';
|
import stores from './store/index.js';
|
||||||
@@ -211,7 +210,6 @@ Vue.prototype.$hideLoading = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Vue.prototype.$services = services;
|
Vue.prototype.$services = services;
|
||||||
Vue.prototype.$exchangeRates = exchangeRates;
|
|
||||||
Vue.prototype.$user = userstate;
|
Vue.prototype.$user = userstate;
|
||||||
|
|
||||||
Vue.filter('itemFieldContent', (value, fieldName, defaultValue, translate) => itemFieldContentFilter({ i18n }, value, fieldName, defaultValue, translate));
|
Vue.filter('itemFieldContent', (value, fieldName, defaultValue, translate) => itemFieldContentFilter({ i18n }, value, fieldName, defaultValue, translate));
|
||||||
|
|||||||
@@ -0,0 +1,115 @@
|
|||||||
|
import services from '../lib/services.js';
|
||||||
|
import logger from '../lib/logger.js';
|
||||||
|
import utils from '../lib/utils.js';
|
||||||
|
|
||||||
|
import {
|
||||||
|
STORE_LATEST_EXCHANGE_RATES
|
||||||
|
} from './mutations.js';
|
||||||
|
|
||||||
|
const exchangeRatesLocalStorageKey = 'lab_app_exchange_rates';
|
||||||
|
|
||||||
|
function getLatestExchangeRates(context, { silent, force }) {
|
||||||
|
const currentExchangeRateData = context.state.latestExchangeRates;
|
||||||
|
const now = new Date();
|
||||||
|
|
||||||
|
if (!force) {
|
||||||
|
if (currentExchangeRateData && currentExchangeRateData.time && currentExchangeRateData.data &&
|
||||||
|
currentExchangeRateData.data.date === utils.formatDate(now, 'YYYY-MM-DD')) {
|
||||||
|
return currentExchangeRateData.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentExchangeRateData && currentExchangeRateData.time && currentExchangeRateData.data &&
|
||||||
|
utils.formatUnixTime(currentExchangeRateData.time, 'YYYY-MM-DD HH') === utils.formatDate(now, 'YYYY-MM-DD HH')) {
|
||||||
|
return currentExchangeRateData.data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
services.getLatestExchangeRates({
|
||||||
|
ignoreError: silent
|
||||||
|
}).then(response => {
|
||||||
|
const data = response.data;
|
||||||
|
|
||||||
|
if (!data || !data.success || !data.result) {
|
||||||
|
reject({ message: 'Unable to get exchange rates data' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
context.commit(STORE_LATEST_EXCHANGE_RATES, {
|
||||||
|
time: utils.getUnixTime(now),
|
||||||
|
data: data.result
|
||||||
|
});
|
||||||
|
|
||||||
|
resolve(data.result);
|
||||||
|
}).catch(error => {
|
||||||
|
logger.error('failed to get latest exchange rates data', error);
|
||||||
|
|
||||||
|
if (error && error.processed) {
|
||||||
|
reject(error);
|
||||||
|
} else if (error.response && error.response.data && error.response.data.errorMessage) {
|
||||||
|
reject({ error: error.response.data });
|
||||||
|
} else {
|
||||||
|
reject({ message: 'Unable to get exchange rates data' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function exchangeRatesLastUpdateDate(state) {
|
||||||
|
const exchangeRates = state.latestExchangeRates || {};
|
||||||
|
return exchangeRates && exchangeRates.data ? exchangeRates.data.date : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getExchangedAmount(state) {
|
||||||
|
return (amount, fromCurrency, toCurrency) => {
|
||||||
|
if (!state.latestExchangeRates || !state.latestExchangeRates.data || !state.latestExchangeRates.data.exchangeRates) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const exchangeRates = state.latestExchangeRates.data.exchangeRates;
|
||||||
|
const exchangeRateMap = {};
|
||||||
|
|
||||||
|
for (let i = 0; i < exchangeRates.length; i++) {
|
||||||
|
const exchangeRate = exchangeRates[i];
|
||||||
|
exchangeRateMap[exchangeRate.currency] = exchangeRate;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fromCurrencyExchangeRate = exchangeRateMap[fromCurrency];
|
||||||
|
const toCurrencyExchangeRate = exchangeRateMap[toCurrency];
|
||||||
|
|
||||||
|
if (!fromCurrencyExchangeRate || !toCurrencyExchangeRate) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const exchangeRate = parseFloat(toCurrencyExchangeRate.rate) / parseFloat(fromCurrencyExchangeRate.rate);
|
||||||
|
|
||||||
|
if (!utils.isNumber(exchangeRate)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return amount * exchangeRate;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function getExchangeRatesFromLocalStorage() {
|
||||||
|
const storageData = localStorage.getItem(exchangeRatesLocalStorageKey) || '{}';
|
||||||
|
return JSON.parse(storageData);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setExchangeRatesToLocalStorage(value) {
|
||||||
|
const storageData = JSON.stringify(value);
|
||||||
|
localStorage.setItem(exchangeRatesLocalStorageKey, storageData);
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearExchangeRatesFromLocalStorage() {
|
||||||
|
localStorage.removeItem(exchangeRatesLocalStorageKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
getLatestExchangeRates,
|
||||||
|
exchangeRatesLastUpdateDate,
|
||||||
|
getExchangedAmount,
|
||||||
|
getExchangeRatesFromLocalStorage,
|
||||||
|
setExchangeRatesToLocalStorage,
|
||||||
|
clearExchangeRatesFromLocalStorage,
|
||||||
|
}
|
||||||
@@ -7,6 +7,8 @@ import {
|
|||||||
STORE_USER_INFO,
|
STORE_USER_INFO,
|
||||||
CLEAR_USER_INFO,
|
CLEAR_USER_INFO,
|
||||||
|
|
||||||
|
STORE_LATEST_EXCHANGE_RATES,
|
||||||
|
|
||||||
LOAD_ACCOUNT_LIST,
|
LOAD_ACCOUNT_LIST,
|
||||||
ADD_ACCOUNT_TO_ACCOUNT_LIST,
|
ADD_ACCOUNT_TO_ACCOUNT_LIST,
|
||||||
SAVE_ACCOUNT_IN_ACCOUNT_LIST,
|
SAVE_ACCOUNT_IN_ACCOUNT_LIST,
|
||||||
@@ -28,6 +30,7 @@ import {
|
|||||||
|
|
||||||
import user from './user.js';
|
import user from './user.js';
|
||||||
import token from './token.js';
|
import token from './token.js';
|
||||||
|
import exchangeRates from './exchangeRates.js';
|
||||||
import account from './account.js';
|
import account from './account.js';
|
||||||
import transactionTag from './transactionTag.js';
|
import transactionTag from './transactionTag.js';
|
||||||
|
|
||||||
@@ -35,6 +38,7 @@ const stores = {
|
|||||||
strict: process.env.NODE_ENV !== 'production',
|
strict: process.env.NODE_ENV !== 'production',
|
||||||
state: {
|
state: {
|
||||||
currentUserInfo: userState.getUserInfo(),
|
currentUserInfo: userState.getUserInfo(),
|
||||||
|
latestExchangeRates: exchangeRates.getExchangeRatesFromLocalStorage(),
|
||||||
allAccounts: [],
|
allAccounts: [],
|
||||||
allAccountsMap: {},
|
allAccountsMap: {},
|
||||||
allCategorizedAccounts: {},
|
allCategorizedAccounts: {},
|
||||||
@@ -49,11 +53,14 @@ const stores = {
|
|||||||
getters: {
|
getters: {
|
||||||
currentUserNickname: user.currentUserNickname,
|
currentUserNickname: user.currentUserNickname,
|
||||||
currentUserDefaultCurrency: user.currentUserDefaultCurrency,
|
currentUserDefaultCurrency: user.currentUserDefaultCurrency,
|
||||||
|
exchangeRatesLastUpdateDate: exchangeRates.exchangeRatesLastUpdateDate,
|
||||||
|
getExchangedAmount: exchangeRates.getExchangedAmount,
|
||||||
allAvailableAccountsCount: account.allAvailableAccountsCount,
|
allAvailableAccountsCount: account.allAvailableAccountsCount,
|
||||||
allVisibleAccountsCount: account.allVisibleAccountsCount,
|
allVisibleAccountsCount: account.allVisibleAccountsCount,
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
[RESET_STATE] (state) {
|
[RESET_STATE] (state) {
|
||||||
|
state.latestExchangeRates = {};
|
||||||
state.allAccounts = [];
|
state.allAccounts = [];
|
||||||
state.allAccountsMap = {};
|
state.allAccountsMap = {};
|
||||||
state.allCategorizedAccounts = {};
|
state.allCategorizedAccounts = {};
|
||||||
@@ -64,6 +71,8 @@ const stores = {
|
|||||||
state.allTransactionTagsMap = {};
|
state.allTransactionTagsMap = {};
|
||||||
state.transactionTagListStateInvalid = true;
|
state.transactionTagListStateInvalid = true;
|
||||||
state.transactions = [];
|
state.transactions = [];
|
||||||
|
|
||||||
|
exchangeRates.clearExchangeRatesFromLocalStorage();
|
||||||
},
|
},
|
||||||
[STORE_USER_INFO] (state, userInfo) {
|
[STORE_USER_INFO] (state, userInfo) {
|
||||||
state.currentUserInfo = userInfo;
|
state.currentUserInfo = userInfo;
|
||||||
@@ -73,6 +82,10 @@ const stores = {
|
|||||||
state.currentUserInfo = null;
|
state.currentUserInfo = null;
|
||||||
userState.clearUserInfo();
|
userState.clearUserInfo();
|
||||||
},
|
},
|
||||||
|
[STORE_LATEST_EXCHANGE_RATES] (state, latestExchangeRates) {
|
||||||
|
state.latestExchangeRates = latestExchangeRates;
|
||||||
|
exchangeRates.setExchangeRatesToLocalStorage(latestExchangeRates);
|
||||||
|
},
|
||||||
[LOAD_ACCOUNT_LIST] (state, accounts) {
|
[LOAD_ACCOUNT_LIST] (state, accounts) {
|
||||||
state.allAccounts = accounts;
|
state.allAccounts = accounts;
|
||||||
state.allAccountsMap = {};
|
state.allAccountsMap = {};
|
||||||
@@ -250,10 +263,12 @@ const stores = {
|
|||||||
getCurrentUserProfile: user.getCurrentUserProfile,
|
getCurrentUserProfile: user.getCurrentUserProfile,
|
||||||
updateUserProfile: user.updateUserProfile,
|
updateUserProfile: user.updateUserProfile,
|
||||||
clearUserInfoState: user.clearUserInfoState,
|
clearUserInfoState: user.clearUserInfoState,
|
||||||
|
resetState: user.resetState,
|
||||||
getAllTokens: token.getAllTokens,
|
getAllTokens: token.getAllTokens,
|
||||||
refreshTokenAndRevokeOldToken: token.refreshTokenAndRevokeOldToken,
|
refreshTokenAndRevokeOldToken: token.refreshTokenAndRevokeOldToken,
|
||||||
revokeToken: token.revokeToken,
|
revokeToken: token.revokeToken,
|
||||||
revokeAllTokens: token.revokeAllTokens,
|
revokeAllTokens: token.revokeAllTokens,
|
||||||
|
getLatestExchangeRates: exchangeRates.getLatestExchangeRates,
|
||||||
loadAllAccounts: account.loadAllAccounts,
|
loadAllAccounts: account.loadAllAccounts,
|
||||||
saveAccount: account.saveAccount,
|
saveAccount: account.saveAccount,
|
||||||
getAccount: account.getAccount,
|
getAccount: account.getAccount,
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ export const RESET_STATE = 'RESET_STATE';
|
|||||||
export const STORE_USER_INFO = 'STORE_USER_INFO';
|
export const STORE_USER_INFO = 'STORE_USER_INFO';
|
||||||
export const CLEAR_USER_INFO = 'CLEAR_USER_INFO';
|
export const CLEAR_USER_INFO = 'CLEAR_USER_INFO';
|
||||||
|
|
||||||
|
export const STORE_LATEST_EXCHANGE_RATES = 'STORE_LATEST_EXCHANGE_RATES';
|
||||||
|
|
||||||
export const LOAD_ACCOUNT_LIST = 'LOAD_ACCOUNT_LIST';
|
export const LOAD_ACCOUNT_LIST = 'LOAD_ACCOUNT_LIST';
|
||||||
export const ADD_ACCOUNT_TO_ACCOUNT_LIST = 'ADD_ACCOUNT_TO_ACCOUNT_LIST';
|
export const ADD_ACCOUNT_TO_ACCOUNT_LIST = 'ADD_ACCOUNT_TO_ACCOUNT_LIST';
|
||||||
export const SAVE_ACCOUNT_IN_ACCOUNT_LIST = 'SAVE_ACCOUNT_IN_ACCOUNT_LIST';
|
export const SAVE_ACCOUNT_IN_ACCOUNT_LIST = 'SAVE_ACCOUNT_IN_ACCOUNT_LIST';
|
||||||
|
|||||||
@@ -264,6 +264,10 @@ function clearUserInfoState(context) {
|
|||||||
context.commit(CLEAR_USER_INFO);
|
context.commit(CLEAR_USER_INFO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resetState(context) {
|
||||||
|
context.commit(RESET_STATE);
|
||||||
|
}
|
||||||
|
|
||||||
function currentUserNickname(state) {
|
function currentUserNickname(state) {
|
||||||
const userInfo = state.currentUserInfo || {};
|
const userInfo = state.currentUserInfo || {};
|
||||||
return userInfo.nickname || userInfo.username || null;
|
return userInfo.nickname || userInfo.username || null;
|
||||||
@@ -282,6 +286,7 @@ export default {
|
|||||||
getCurrentUserProfile,
|
getCurrentUserProfile,
|
||||||
updateUserProfile,
|
updateUserProfile,
|
||||||
clearUserInfoState,
|
clearUserInfoState,
|
||||||
|
resetState,
|
||||||
currentUserNickname,
|
currentUserNickname,
|
||||||
currentUserDefaultCurrency
|
currentUserDefaultCurrency
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
</f7-navbar>
|
</f7-navbar>
|
||||||
|
|
||||||
<f7-card>
|
<f7-card>
|
||||||
<f7-card-content class="no-safe-areas" :padding="false" v-if="exchangeRatesData.exchangeRates && exchangeRatesData.exchangeRates.length">
|
<f7-card-content class="no-safe-areas" :padding="false" v-if="exchangeRatesData && exchangeRatesData.exchangeRates && exchangeRatesData.exchangeRates.length">
|
||||||
<f7-list>
|
<f7-list>
|
||||||
<f7-list-item
|
<f7-list-item
|
||||||
:title="$t('Base Currency')"
|
:title="$t('Base Currency')"
|
||||||
@@ -25,12 +25,12 @@
|
|||||||
</f7-card>
|
</f7-card>
|
||||||
|
|
||||||
<f7-card>
|
<f7-card>
|
||||||
<f7-card-content class="no-safe-areas" :padding="false" v-if="!exchangeRatesData.exchangeRates || !exchangeRatesData.exchangeRates.length">
|
<f7-card-content class="no-safe-areas" :padding="false" v-if="!exchangeRatesData || !exchangeRatesData.exchangeRates || !exchangeRatesData.exchangeRates.length">
|
||||||
<f7-list>
|
<f7-list>
|
||||||
<f7-list-item :title="$t('No exchange rates data')"></f7-list-item>
|
<f7-list-item :title="$t('No exchange rates data')"></f7-list-item>
|
||||||
</f7-list>
|
</f7-list>
|
||||||
</f7-card-content>
|
</f7-card-content>
|
||||||
<f7-card-content class="no-safe-areas" :padding="false" v-if="exchangeRatesData.exchangeRates && exchangeRatesData.exchangeRates.length">
|
<f7-card-content class="no-safe-areas" :padding="false" v-if="exchangeRatesData && exchangeRatesData.exchangeRates && exchangeRatesData.exchangeRates.length">
|
||||||
<f7-list>
|
<f7-list>
|
||||||
<f7-list-item v-for="exchangeRate in availableExchangeRates" :key="exchangeRate.currencyCode"
|
<f7-list-item v-for="exchangeRate in availableExchangeRates" :key="exchangeRate.currencyCode"
|
||||||
:title="exchangeRate.currencyDisplayName"
|
:title="exchangeRate.currencyDisplayName"
|
||||||
@@ -56,11 +56,13 @@ export default {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
baseCurrency: self.$store.getters.currentUserDefaultCurrency || self.$t('default.currency'),
|
baseCurrency: self.$store.getters.currentUserDefaultCurrency || self.$t('default.currency'),
|
||||||
exchangeRatesData: self.$exchangeRates.getExchangeRates(),
|
|
||||||
updating: false
|
updating: false
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
exchangeRatesData() {
|
||||||
|
return this.$store.state.latestExchangeRates.data;
|
||||||
|
},
|
||||||
availableExchangeRates() {
|
availableExchangeRates() {
|
||||||
if (!this.exchangeRatesData || !this.exchangeRatesData.exchangeRates) {
|
if (!this.exchangeRatesData || !this.exchangeRatesData.exchangeRates) {
|
||||||
return [];
|
return [];
|
||||||
@@ -117,7 +119,10 @@ export default {
|
|||||||
self.$showLoading();
|
self.$showLoading();
|
||||||
}
|
}
|
||||||
|
|
||||||
self.$services.getLatestExchangeRates().then(response => {
|
self.$store.dispatch('getLatestExchangeRates', {
|
||||||
|
silent: false,
|
||||||
|
force: true
|
||||||
|
}).then(() => {
|
||||||
if (done) {
|
if (done) {
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
@@ -125,20 +130,8 @@ export default {
|
|||||||
self.updating = false;
|
self.updating = false;
|
||||||
self.$hideLoading();
|
self.$hideLoading();
|
||||||
|
|
||||||
const data = response.data;
|
|
||||||
|
|
||||||
if (!data || !data.success || !data.result) {
|
|
||||||
self.$toast('Unable to get exchange rates data');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.exchangeRatesData = data.result;
|
|
||||||
self.$exchangeRates.setExchangeRates(data.result);
|
|
||||||
|
|
||||||
self.$toast('Exchange rates data has been updated');
|
self.$toast('Exchange rates data has been updated');
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
self.$logger.error('failed to get latest exchange rates data', error);
|
|
||||||
|
|
||||||
if (done) {
|
if (done) {
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
@@ -146,10 +139,8 @@ export default {
|
|||||||
self.updating = false;
|
self.updating = false;
|
||||||
self.$hideLoading();
|
self.$hideLoading();
|
||||||
|
|
||||||
if (error.response && error.response.data && error.response.data.errorMessage) {
|
if (!error.processed) {
|
||||||
self.$toast({ error: error.response.data });
|
self.$toast(error.message || error);
|
||||||
} else if (!error.processed) {
|
|
||||||
self.$toast('Unable to get exchange rates data');
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (self.$settings.isAutoUpdateExchangeRatesData()) {
|
if (self.$settings.isAutoUpdateExchangeRatesData()) {
|
||||||
self.$services.autoRefreshLatestExchangeRates();
|
self.$store.dispatch('getLatestExchangeRates', { silent: true, force: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
router.refreshPage();
|
router.refreshPage();
|
||||||
@@ -239,7 +239,7 @@ export default {
|
|||||||
self.$hideLoading();
|
self.$hideLoading();
|
||||||
|
|
||||||
if (self.$settings.isAutoUpdateExchangeRatesData()) {
|
if (self.$settings.isAutoUpdateExchangeRatesData()) {
|
||||||
self.$services.autoRefreshLatestExchangeRates();
|
self.$store.dispatch('getLatestExchangeRates', { silent: true, force: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
self.show2faSheet = false;
|
self.show2faSheet = false;
|
||||||
|
|||||||
@@ -86,8 +86,7 @@ export default {
|
|||||||
const self = this;
|
const self = this;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isEnableApplicationLock: this.$settings.isEnableApplicationLock(),
|
isEnableApplicationLock: self.$settings.isEnableApplicationLock(),
|
||||||
exchangeRatesLastUpdateDate: self.getExchangeRatesLastUpdateDate(),
|
|
||||||
logouting: false
|
logouting: false
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@@ -104,7 +103,6 @@ export default {
|
|||||||
},
|
},
|
||||||
set: function (value) {
|
set: function (value) {
|
||||||
this.$locale.setLanguage(value);
|
this.$locale.setLanguage(value);
|
||||||
this.exchangeRatesLastUpdateDate = this.getExchangeRatesLastUpdateDate();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
currentNickName() {
|
currentNickName() {
|
||||||
@@ -113,6 +111,10 @@ export default {
|
|||||||
isDataExportingEnabled() {
|
isDataExportingEnabled() {
|
||||||
return this.$settings.isDataExportingEnabled();
|
return this.$settings.isDataExportingEnabled();
|
||||||
},
|
},
|
||||||
|
exchangeRatesLastUpdateDate() {
|
||||||
|
const exchangeRatesLastUpdateDate = this.$store.getters.exchangeRatesLastUpdateDate;
|
||||||
|
return exchangeRatesLastUpdateDate ? this.$utilities.formatDate(exchangeRatesLastUpdateDate, this.$t('format.date.long')) : '';
|
||||||
|
},
|
||||||
isAutoUpdateExchangeRatesData: {
|
isAutoUpdateExchangeRatesData: {
|
||||||
get: function () {
|
get: function () {
|
||||||
return this.$settings.isAutoUpdateExchangeRatesData();
|
return this.$settings.isAutoUpdateExchangeRatesData();
|
||||||
@@ -171,11 +173,6 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
onPageAfterIn() {
|
onPageAfterIn() {
|
||||||
this.isEnableApplicationLock = this.$settings.isEnableApplicationLock();
|
this.isEnableApplicationLock = this.$settings.isEnableApplicationLock();
|
||||||
this.exchangeRatesLastUpdateDate = this.getExchangeRatesLastUpdateDate();
|
|
||||||
},
|
|
||||||
getExchangeRatesLastUpdateDate() {
|
|
||||||
const exchangeRates = this.$exchangeRates.getExchangeRates();
|
|
||||||
return exchangeRates && exchangeRates.date ? this.$moment(exchangeRates.date).format(this.$t('format.date.long')) : '';
|
|
||||||
},
|
},
|
||||||
logout() {
|
logout() {
|
||||||
const self = this;
|
const self = this;
|
||||||
@@ -189,7 +186,6 @@ export default {
|
|||||||
self.logouting = false;
|
self.logouting = false;
|
||||||
self.$hideLoading();
|
self.$hideLoading();
|
||||||
|
|
||||||
self.$exchangeRates.clearExchangeRates();
|
|
||||||
self.$settings.clearSettings();
|
self.$settings.clearSettings();
|
||||||
self.$locale.init();
|
self.$locale.init();
|
||||||
|
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ export default {
|
|||||||
|
|
||||||
if (self.$user.isUserLogined()) {
|
if (self.$user.isUserLogined()) {
|
||||||
if (self.$settings.isAutoUpdateExchangeRatesData()) {
|
if (self.$settings.isAutoUpdateExchangeRatesData()) {
|
||||||
self.$services.autoRefreshLatestExchangeRates();
|
self.$store.dispatch('getLatestExchangeRates', { silent: true, force: false });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ export default {
|
|||||||
self.$store.dispatch('refreshTokenAndRevokeOldToken');
|
self.$store.dispatch('refreshTokenAndRevokeOldToken');
|
||||||
|
|
||||||
if (self.$settings.isAutoUpdateExchangeRatesData()) {
|
if (self.$settings.isAutoUpdateExchangeRatesData()) {
|
||||||
self.$services.autoRefreshLatestExchangeRates();
|
self.$store.dispatch('getLatestExchangeRates', { silent: true, force: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
router.refreshPage();
|
router.refreshPage();
|
||||||
@@ -104,7 +104,7 @@ export default {
|
|||||||
this.$store.dispatch('refreshTokenAndRevokeOldToken');
|
this.$store.dispatch('refreshTokenAndRevokeOldToken');
|
||||||
|
|
||||||
if (this.$settings.isAutoUpdateExchangeRatesData()) {
|
if (this.$settings.isAutoUpdateExchangeRatesData()) {
|
||||||
this.$services.autoRefreshLatestExchangeRates();
|
this.$store.dispatch('getLatestExchangeRates', { silent: true, force: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
router.refreshPage();
|
router.refreshPage();
|
||||||
@@ -121,7 +121,7 @@ export default {
|
|||||||
self.$user.clearTokenAndUserInfo(true);
|
self.$user.clearTokenAndUserInfo(true);
|
||||||
self.$user.clearWebAuthnConfig();
|
self.$user.clearWebAuthnConfig();
|
||||||
self.$store.dispatch('clearUserInfoState');
|
self.$store.dispatch('clearUserInfoState');
|
||||||
self.$exchangeRates.clearExchangeRates();
|
self.$store.dispatch('resetState');
|
||||||
self.$settings.clearSettings();
|
self.$settings.clearSettings();
|
||||||
self.$locale.init();
|
self.$locale.init();
|
||||||
|
|
||||||
|
|||||||
@@ -245,7 +245,7 @@ export default {
|
|||||||
if (accountsBalance[i].currency === this.defaultCurrency) {
|
if (accountsBalance[i].currency === this.defaultCurrency) {
|
||||||
netAssets += accountsBalance[i].balance;
|
netAssets += accountsBalance[i].balance;
|
||||||
} else {
|
} else {
|
||||||
const balance = this.$exchangeRates.getOtherCurrencyAmount(accountsBalance[i].balance, accountsBalance[i].currency, this.defaultCurrency);
|
const balance = this.$store.getters.getExchangedAmount(accountsBalance[i].balance, accountsBalance[i].currency, this.defaultCurrency);
|
||||||
|
|
||||||
if (!this.$utilities.isNumber(balance)) {
|
if (!this.$utilities.isNumber(balance)) {
|
||||||
hasUnCalculatedAmount = true;
|
hasUnCalculatedAmount = true;
|
||||||
@@ -275,7 +275,7 @@ export default {
|
|||||||
if (accountsBalance[i].currency === this.defaultCurrency) {
|
if (accountsBalance[i].currency === this.defaultCurrency) {
|
||||||
totalAssets += accountsBalance[i].balance;
|
totalAssets += accountsBalance[i].balance;
|
||||||
} else {
|
} else {
|
||||||
const balance = this.$exchangeRates.getOtherCurrencyAmount(accountsBalance[i].balance, accountsBalance[i].currency, this.defaultCurrency);
|
const balance = this.$store.getters.getExchangedAmount(accountsBalance[i].balance, accountsBalance[i].currency, this.defaultCurrency);
|
||||||
|
|
||||||
if (!this.$utilities.isNumber(balance)) {
|
if (!this.$utilities.isNumber(balance)) {
|
||||||
hasUnCalculatedAmount = true;
|
hasUnCalculatedAmount = true;
|
||||||
@@ -305,7 +305,7 @@ export default {
|
|||||||
if (accountsBalance[i].currency === this.defaultCurrency) {
|
if (accountsBalance[i].currency === this.defaultCurrency) {
|
||||||
totalLiabilities -= accountsBalance[i].balance;
|
totalLiabilities -= accountsBalance[i].balance;
|
||||||
} else {
|
} else {
|
||||||
const balance = this.$exchangeRates.getOtherCurrencyAmount(accountsBalance[i].balance, accountsBalance[i].currency, this.defaultCurrency);
|
const balance = this.$store.getters.getExchangedAmount(accountsBalance[i].balance, accountsBalance[i].currency, this.defaultCurrency);
|
||||||
|
|
||||||
if (!this.$utilities.isNumber(balance)) {
|
if (!this.$utilities.isNumber(balance)) {
|
||||||
hasUnCalculatedAmount = true;
|
hasUnCalculatedAmount = true;
|
||||||
@@ -431,7 +431,7 @@ export default {
|
|||||||
totalBalance += accountsBalance[i].balance;
|
totalBalance += accountsBalance[i].balance;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const balance = this.$exchangeRates.getOtherCurrencyAmount(accountsBalance[i].balance, accountsBalance[i].currency, this.defaultCurrency);
|
const balance = this.$store.getters.getExchangedAmount(accountsBalance[i].balance, accountsBalance[i].currency, this.defaultCurrency);
|
||||||
|
|
||||||
if (!this.$utilities.isNumber(balance)) {
|
if (!this.$utilities.isNumber(balance)) {
|
||||||
hasUnCalculatedAmount = true;
|
hasUnCalculatedAmount = true;
|
||||||
|
|||||||
@@ -369,8 +369,8 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sourceAccount && destinationAccount && sourceAccount.currency !== destinationAccount.currency) {
|
if (sourceAccount && destinationAccount && sourceAccount.currency !== destinationAccount.currency) {
|
||||||
const exchangedOldValue = this.$exchangeRates.getOtherCurrencyAmount(oldValue, sourceAccount.currency, destinationAccount.currency);
|
const exchangedOldValue = this.$store.getters.getExchangedAmount(oldValue, sourceAccount.currency, destinationAccount.currency);
|
||||||
const exchangedNewValue = this.$exchangeRates.getOtherCurrencyAmount(newValue, sourceAccount.currency, destinationAccount.currency);
|
const exchangedNewValue = this.$store.getters.getExchangedAmount(newValue, sourceAccount.currency, destinationAccount.currency);
|
||||||
|
|
||||||
if (this.$utilities.isNumber(exchangedOldValue)) {
|
if (this.$utilities.isNumber(exchangedOldValue)) {
|
||||||
oldValue = Math.floor(exchangedOldValue);
|
oldValue = Math.floor(exchangedOldValue);
|
||||||
@@ -704,7 +704,7 @@ export default {
|
|||||||
totalBalance += accountsBalance[i].balance;
|
totalBalance += accountsBalance[i].balance;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const balance = this.$exchangeRates.getOtherCurrencyAmount(accountsBalance[i].balance, accountsBalance[i].currency, this.defaultCurrency);
|
const balance = this.$store.getters.getExchangedAmount(accountsBalance[i].balance, accountsBalance[i].currency, this.defaultCurrency);
|
||||||
|
|
||||||
if (!this.$utilities.isNumber(balance)) {
|
if (!this.$utilities.isNumber(balance)) {
|
||||||
hasUnCalculatedAmount = true;
|
hasUnCalculatedAmount = true;
|
||||||
|
|||||||
@@ -888,7 +888,7 @@ export default {
|
|||||||
let amount = transaction.sourceAmount;
|
let amount = transaction.sourceAmount;
|
||||||
|
|
||||||
if (transaction.sourceAccount.currency !== this.defaultCurrency) {
|
if (transaction.sourceAccount.currency !== this.defaultCurrency) {
|
||||||
const balance = this.$exchangeRates.getOtherCurrencyAmount(amount, transaction.sourceAccount.currency, this.defaultCurrency);
|
const balance = this.$store.getters.getExchangedAmount(amount, transaction.sourceAccount.currency, this.defaultCurrency);
|
||||||
|
|
||||||
if (!this.$utilities.isNumber(balance)) {
|
if (!this.$utilities.isNumber(balance)) {
|
||||||
if (transaction.type === this.$constants.transaction.allTransactionTypes.Expense) {
|
if (transaction.type === this.$constants.transaction.allTransactionTypes.Expense) {
|
||||||
|
|||||||
Reference in New Issue
Block a user