|
@@ -1,6 +1,7 @@
|
|
import {
|
|
import {
|
|
SET_CURRENCIES,
|
|
SET_CURRENCIES,
|
|
- SET_LOADING_CURRENCIES
|
|
|
|
|
|
+ SET_LOADING_CURRENCIES,
|
|
|
|
+ AUTOSELECT_CURRENCY
|
|
} from '@/constants/mutationTypes'
|
|
} from '@/constants/mutationTypes'
|
|
|
|
|
|
import {
|
|
import {
|
|
@@ -10,12 +11,14 @@ import {
|
|
|
|
|
|
const initialState = {
|
|
const initialState = {
|
|
currencies: [],
|
|
currencies: [],
|
|
- loadingCurrencies: false
|
|
|
|
|
|
+ loadingCurrencies: false,
|
|
|
|
+ selectedCurrency: null
|
|
}
|
|
}
|
|
|
|
|
|
const state = {
|
|
const state = {
|
|
currencies: initialState.currencies,
|
|
currencies: initialState.currencies,
|
|
- loadingCurrencies: !initialState.currencies
|
|
|
|
|
|
+ loadingCurrencies: !initialState.currencies,
|
|
|
|
+ selectedCurrency: initialState.selectedCurrency
|
|
}
|
|
}
|
|
|
|
|
|
const getters = {
|
|
const getters = {
|
|
@@ -32,6 +35,13 @@ const getters = {
|
|
*/
|
|
*/
|
|
loadingCurrencies(state) {
|
|
loadingCurrencies(state) {
|
|
return state.loadingCurrencies
|
|
return state.loadingCurrencies
|
|
|
|
+ },
|
|
|
|
+ /**
|
|
|
|
+ *
|
|
|
|
+ * @param {*} state
|
|
|
|
+ */
|
|
|
|
+ selectedCurrency(state) {
|
|
|
|
+ return state.selectedCurrency
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -51,6 +61,13 @@ const mutations = {
|
|
*/
|
|
*/
|
|
[SET_LOADING_CURRENCIES] (state, payload) {
|
|
[SET_LOADING_CURRENCIES] (state, payload) {
|
|
state.loadingCurrencies = !!payload
|
|
state.loadingCurrencies = !!payload
|
|
|
|
+ },
|
|
|
|
+ /**
|
|
|
|
+ *
|
|
|
|
+ * @param {*} state
|
|
|
|
+ */
|
|
|
|
+ [AUTOSELECT_CURRENCY] (state) {
|
|
|
|
+ state.selectedCurrency = state.currencies.find(item => item.base === true)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -62,6 +79,7 @@ const actions = {
|
|
*/
|
|
*/
|
|
[INIT_CURRENCIES] ({ commit }, payload) {
|
|
[INIT_CURRENCIES] ({ commit }, payload) {
|
|
commit(SET_CURRENCIES, payload)
|
|
commit(SET_CURRENCIES, payload)
|
|
|
|
+ commit(AUTOSELECT_CURRENCY)
|
|
commit(SET_LOADING_CURRENCIES)
|
|
commit(SET_LOADING_CURRENCIES)
|
|
},
|
|
},
|
|
/**
|
|
/**
|