Skip to content

Open source personal finance application

Fix init default currency Set currency based on first created wallet currency

Ilya Komicheva2ca88a43eaf
diff --git a/src/components/wallets/form/WalletForm.vue b/src/components/wallets/form/WalletForm.vue
index 3e9b9928..5813f5e2 100644
--- a/src/components/wallets/form/WalletForm.vue
+++ b/src/components/wallets/form/WalletForm.vue
@@ -74,7 +74,6 @@ export default {
handleSubmit () {
if (this.validateForm()) {
- const uid = this.$store.state.user.user.uid
const id = this.walletId || createId()
const walletsValues = {
@@ -82,11 +81,10 @@ export default {
countTotal: this.wallet.countTotal,
currency: this.wallet.currency,
name: this.wallet.name,
- order: parseInt(this.wallet.order) || 1
+ order: this.wallet.order
}
- db.ref(`users/${uid}/accounts/${id}`).set(walletsValues)
-
+ this.$store.dispatch('addWallet', { id, values: walletsValues })
this.$store.commit('setWalletEditId', null)
this.$store.dispatch('setActiveTab', 'wallets')
diff --git a/src/components/wallets/store/actions.js b/src/components/wallets/store/actions.js
index 0f07c359..33a36263 100644
--- a/src/components/wallets/store/actions.js
+++ b/src/components/wallets/store/actions.js
@@ -2,6 +2,26 @@ import localforage from 'localforage'
import { db } from '@/firebase'
export default {
+ addWallet ({ dispatch, rootState, getters }, { id, values }) {
+ const uid = rootState.user.user.uid
+
+ const formatedValues = {
+ color: values.color,
+ countTotal: values.countTotal,
+ currency: values.currency,
+ name: values.name,
+ order: parseInt(values.order) || 1
+ }
+
+ // set default currency based on first created wallet
+ if (!getters.hasWallets) {
+ db.ref(`users/${uid}/settings/baseCurrency`).set(values.currency)
+ dispatch('initCurrencies')
+ }
+
+ db.ref(`users/${uid}/accounts/${id}`).set(formatedValues)
+ },
+
initWallets ({ dispatch, rootState }) {
const uid = rootState.user.user.uid
diff --git a/src/components/welcome/Welcome.vue b/src/components/welcome/Welcome.vue
index 0a2d6f2f..bbb211ed 100644
--- a/src/components/welcome/Welcome.vue
+++ b/src/components/welcome/Welcome.vue
@@ -15,6 +15,13 @@ export default {
showCategoryForm: false,
showWalletForm: false
}
+ },
+
+ methods: {
+ categoryCreatedCallback () {
+ this.showCategoryForm = false
+ this.$store.dispatch('setActiveTab', 'stat')
+ }
}
}
</script>
@@ -57,7 +64,7 @@ export default {
.tab(v-if="showCategoryForm")
.tab__content
CategoryForm(
- v-on:callback="showCategoryForm = false")
+ v-on:callback="categoryCreatedCallback")
a(href="https://ilko.me").welcome__copy.login__copy
| Made with
@@ -101,7 +108,6 @@ export default {
padding 0
.welcome
-
.login__copy
color var(--c-font-4)