Skip to content

Open source personal finance application

create transfer transaction unit

ilkome898a30a8deff
diff --git a/components/categories/modal/CategoryModal.vue b/components/categories/modal/CategoryModal.vue
index 40777e05..f231b5cc 100644
--- a/components/categories/modal/CategoryModal.vue
+++ b/components/categories/modal/CategoryModal.vue
@@ -121,6 +121,7 @@ Portal(
template(slot="btns")
ModalButton(
+ v-if="categoryId !== 'transfer'"
:name="$t('base.delete')"
icon="mdi mdi-delete"
@onClick="handleDeleteClick"
diff --git a/components/trnForm/TrnForm.vue b/components/trnForm/TrnForm.vue
index a6ff1257..f5710201 100644
--- a/components/trnForm/TrnForm.vue
+++ b/components/trnForm/TrnForm.vue
@@ -80,6 +80,8 @@ export default {
show: {
// @ts-ignore
handler (show) {
+ const { clearExpression } = useCalculator()
+
if (show) {
// @ts-ignore
this.$nextTick(() => {
@@ -106,6 +108,9 @@ export default {
}
})
}
+ else {
+ clearExpression()
+ }
},
immediate: true
},
@@ -127,16 +132,15 @@ export default {
handleSubmitForm () {
try {
const { validate } = useTrnFormValidate()
- const { getResult } = useCalculator()
+ // @ts-ignore
+ const { id, values } = this.prepeareValues(this.isTransfer)
const validateStatus = validate({
+ ...values,
// @ts-ignore
- ...this.$store.state.trnForm.values,
- amount: getResult.value,
- // @ts-ignore
- walletFrom: this.$store.getters['wallets/getWalletWithId'](this.$store.state.trnForm.transfer.from),
+ walletFrom: this.$store.getters['wallets/getWalletWithId'](this.$store.state.trnForm.values.walletFromId),
// @ts-ignore
- walletTo: this.$store.getters['wallets/getWalletWithId'](this.$store.state.trnForm.transfer.to)
+ walletTo: this.$store.getters['wallets/getWalletWithId'](this.$store.state.trnForm.values.walletToId)
})
// @ts-ignore
@@ -149,84 +153,16 @@ export default {
// @ts-ignore
text: validateStatus.error.text
})
-
return
}
- else {
- this.showSuccess()
- // @ts-ignore
- this.isTransfer
- // @ts-ignore
- ? this.handleSubmitTrnasfer()
- // @ts-ignore
- : this.handleSubmitTrn()
- }
- }
- catch (e) {
- console.log(e)
- }
- },
-
- handleSubmitTrn () {
- const { getResult } = useCalculator()
- // @ts-ignore
- const values = {
+ this.showSuccess()
// @ts-ignore
- ...this.$store.state.trnForm.values,
- amount: getResult.value
+ this.$store.dispatch('trns/addTrn', { id, values })
}
-
- // @ts-ignore
- const id = values.trnId || generateId(this.$day().valueOf())
-
- // @ts-ignore
- this.$store.dispatch('trns/addTrn', {
- id,
- values
- })
- },
-
- handleSubmitTrnasfer () {
- const { getResult } = useCalculator()
-
- const values = {
- // @ts-ignore
- amount: getResult.value,
- // @ts-ignore
- categoryId: this.$store.getters['categories/transferCategoryId'],
- // @ts-ignore
- date: this.$day(this.$store.state.trnForm.values.date).valueOf()
+ catch (e) {
+ console.log(e)
}
-
- // @ts-ignore
- const id = generateId(this.$day().valueOf())
-
- // Income
- // @ts-ignore
- this.$store.dispatch('trns/addTrn', {
- // @ts-ignore
- id: id + 'incomes',
- values: {
- ...values,
- // @ts-ignore
- walletId: this.$store.state.trnForm.transfer.to,
- amountType: 1
- }
- })
-
- // Expense
- // @ts-ignore
- this.$store.dispatch('trns/addTrn', {
- // @ts-ignore
- id: id + 'expenses',
- values: {
- ...values,
- // @ts-ignore
- walletId: this.$store.state.trnForm.transfer.from,
- amountType: 0
- }
- })
},
setTrnFormHeight () {
@@ -252,6 +188,69 @@ export default {
text: 'Excellent transaction!',
title: emo
})
+ },
+
+ prepeareValues (isTransfer: boolean): any {
+ let normalizedValues
+ // @ts-ignore
+ const id = this.$store.state.trnForm.values.trnId || generateId(this.$day().valueOf())
+ const { getResult } = useCalculator()
+
+ // Simple
+ if (!isTransfer) {
+ normalizedValues = {
+ // @ts-ignore
+ amount: getResult.value,
+ // @ts-ignore
+ amountFrom: getResult.value,
+ // @ts-ignore
+ amountTo: getResult.value,
+ // @ts-ignore
+ categoryId: this.$store.state.trnForm.values.categoryId,
+ // @ts-ignore
+ date: this.$day(this.$store.state.trnForm.values.date).valueOf(),
+ // @ts-ignore
+ description: this.$store.state.trnForm.values.description || null,
+ // @ts-ignore
+ groups: this.$store.state.trnForm.values.groups || null,
+ // @ts-ignore
+ type: Number(this.$store.state.trnForm.values.amountType) || 0,
+ // @ts-ignore
+ walletId: this.$store.state.trnForm.values.walletFromId
+ }
+ }
+
+ // Transfer
+ if (isTransfer) {
+ normalizedValues = {
+ // @ts-ignore
+ amount: getResult.value,
+ // @ts-ignore
+ // @ts-ignore
+ amountFrom: getResult.value,
+ // @ts-ignore
+ amountTo: getResult.value,
+ categoryId: 'transfer',
+ // @ts-ignore
+ date: this.$day(this.$store.state.trnForm.values.date).valueOf(),
+ // @ts-ignore
+ walletId: this.$store.state.trnForm.values.walletFromId,
+ // @ts-ignore
+ walletToId: this.$store.state.trnForm.values.walletToId,
+ // @ts-ignore
+ walletFromId: this.$store.state.trnForm.values.walletFromId,
+ type: 2,
+ // @ts-ignore
+ description: this.$store.state.trnForm.values.description || null,
+ // @ts-ignore
+ groups: this.$store.state.trnForm.values.groups || null
+ }
+ }
+
+ return {
+ id,
+ values: normalizedValues
+ }
}
}
}
diff --git a/components/trnForm/TrnFormHeaderTransfer.vue b/components/trnForm/TrnFormHeaderTransfer.vue
index 26784981..fb9a45f3 100644
--- a/components/trnForm/TrnFormHeaderTransfer.vue
+++ b/components/trnForm/TrnFormHeaderTransfer.vue
@@ -1,25 +1,33 @@
<script>
export default {
fetch () {
- this.$store.commit('trnForm/setTrnFormTransfer', {
- tranferType: 'from',
- walletId: this.walletFromId
- })
- this.$store.commit('trnForm/setTrnFormTransfer', {
- tranferType: 'to',
- walletId: this.walletToId
- })
+ if (this.$store.state.trnForm.values.amountType === 2) {
+ this.$store.commit('trnForm/setTrnFormValues', {
+ walletFromId: this.walletFromId,
+ walletToId: this.walletToId
+ })
+ }
+ else {
+ this.$store.commit('trnForm/setTrnFormTransfer', {
+ tranferType: 'from',
+ walletId: this.walletFromId
+ })
+ this.$store.commit('trnForm/setTrnFormTransfer', {
+ tranferType: 'to',
+ walletId: this.walletToId
+ })
+ }
},
computed: {
walletFromId () {
- return this.$store.state.trnForm.transfer.from || this.$store.state.trnForm.values.walletId || this.$store.getters['wallets/walletsSortedIds'][0]
+ return this.$store.state.trnForm.values.walletFromId || this.$store.state.trnForm.values.walletId || this.$store.getters['wallets/walletsSortedIds'][0]
},
walletFrom () {
return this.$store.state.wallets.items[this.walletFromId]
},
walletToId () {
- return this.$store.state.trnForm.transfer.to || this.$store.getters['wallets/walletsSortedIds'][1] || this.$store.state.trnForm.values.walletId
+ return this.$store.state.trnForm.values.walletToId || this.$store.getters['wallets/walletsSortedIds'][1] || this.$store.state.trnForm.values.walletId
},
walletTo () {
return this.$store.state.wallets.items[this.walletToId]
diff --git a/components/trnForm/TrnFormModalTransferFrom.vue b/components/trnForm/TrnFormModalTransferFrom.vue
index 9c14cfa3..9babfe5c 100644
--- a/components/trnForm/TrnFormModalTransferFrom.vue
+++ b/components/trnForm/TrnFormModalTransferFrom.vue
@@ -3,8 +3,8 @@ export default {
methods: {
handleSetWallet (walletId) {
this.$store.commit('trnForm/toogleTrnFormModal', 'transferFrom')
- this.$store.commit('trnForm/setTrnFormTransfer', {
- tranferType: 'from',
+ this.$store.commit('trnForm/setTrnFormValues', {
+ walletFromId: walletId,
walletId
})
}
diff --git a/components/trnForm/TrnFormModalTransferTo.vue b/components/trnForm/TrnFormModalTransferTo.vue
index 5e23e0f7..bd56d1b6 100644
--- a/components/trnForm/TrnFormModalTransferTo.vue
+++ b/components/trnForm/TrnFormModalTransferTo.vue
@@ -3,8 +3,8 @@ export default {
methods: {
handleSetWallet (walletId) {
this.$store.commit('trnForm/toogleTrnFormModal', 'transferTo')
- this.$store.commit('trnForm/setTrnFormTransfer', {
- tranferType: 'to',
+ this.$store.commit('trnForm/setTrnFormValues', {
+ walletToId: walletId,
walletId
})
}
diff --git a/components/trnForm/useTrnFormValidate.ts b/components/trnForm/useTrnFormValidate.ts
index 571acaec..d3cfdc53 100644
--- a/components/trnForm/useTrnFormValidate.ts
+++ b/components/trnForm/useTrnFormValidate.ts
@@ -49,7 +49,7 @@ export default function useTrnFormValidate () {
// Transfer
if (values.amountType === 2) {
- if (values.walletFrom.id === values.walletTo.id) {
+ if (values.walletFromId === values.walletToId) {
return {
error: {
title: errorTitle,
diff --git a/components/trns/item/TrnItem.vue b/components/trns/item/TrnItem.vue
index 1e2767fa..4ac7b76c 100644
--- a/components/trns/item/TrnItem.vue
+++ b/components/trns/item/TrnItem.vue
@@ -105,8 +105,8 @@ export default {
template(v-if="ui === 'detailed'")
.trnItem__categoryIcon
Icon(
- background="var(--c-bg-3)"
- icon="mdi mdi-repeat"
+ :background="category.color"
+ :icon="category.icon"
big
round
)
@@ -114,60 +114,57 @@ export default {
.trnItem__date {{ formatedDate }}
.trnItem__wallet
WalletItem(
- :id="trn.fromWalletId"
+ :id="trn.walletFromId"
ui="tile"
)
.trnFormHeaderSeparator: .mdi.mdi-chevron-right
WalletItem(
- :id="trn.toWalletId"
+ :id="trn.walletToId"
ui="tile"
)
-
- .trnItem__desc(v-if="trn.description") {{ trn.description }}
-
.trnItem__amount(@click.stop="setTrnEdit")
Amount(
- :currency="$store.state.wallets.items[trn.fromWalletId].currency"
- :value="trn.fromAmount"
- :type="trn.type"
+ :currency="$store.state.wallets.items[trn.walletFromId].currency"
+ :value="trn.amountFrom"
+ :type="2"
vertical="center"
size="xl"
)
+ .trnItem__desc(v-if="trn.description") {{ trn.description }}
+
//- Transfer: History
//-------------------------------------------------------------------------
template(v-else)
- .trnItem__categoryIcon
- Icon(
- background="var(--c-bg-3)"
- icon="mdi mdi-repeat"
- round
- )
+ .trnItem__left
+ .trnItem__categoryIcon
+ Icon(
+ :background="category.color"
+ :icon="category.icon"
+ round
+ )
- .trnItem__categoryName
- div {{ $t('trnForm.transferTitle') }}
- .transfer
- div {{ $t('trnForm.transfer.fromShort') }}: {{ $store.state.wallets.items[trn.fromWalletId].name }}
- div {{ $t('trnForm.transfer.toShort') }}: {{ $store.state.wallets.items[trn.toWalletId].name }}
+ .trnItem__center
+ .trnItem__categoryName
+ div {{ $t('trnForm.transferTitle') }}
+ .transfer
+ div
+ span {{ $t('trnForm.transfer.from') }}:
+ | {{ $store.state.wallets.items[trn.walletFromId].name }}
+ div
+ span {{ $t('trnForm.transfer.to') }}:
+ | {{ $store.state.wallets.items[trn.walletToId].name }}
- .trnItem__amount(@click.stop="setTrnEdit")
- Amount(
- :currency="$store.state.wallets.items[trn.fromWalletId].currency"
- :isColorize="false"
- :type="0"
- :value="trn.fromAmount"
- isShowPrefix
- )
- Amount(
- :currency="$store.state.wallets.items[trn.toWalletId].currency"
- :isColorize="false"
- :type="1"
- :value="trn.toAmount"
- isShowPrefix
- )
+ .trnItem__desc(v-if="trn.description") {{ trn.description }}
- .trnItem__desc
- div(v-if="trn.description") {{ trn.description }}
+ .trnItem__right
+ .trnItem__amount(@click.stop="setTrnEdit")
+ Amount(
+ :currency="$store.state.wallets.items[trn.walletFromId].currency"
+ :isColorize="false"
+ :type="2"
+ :value="trn.amountFrom"
+ )
//- Transaction
//---------------------------------------------------------------------------
@@ -178,8 +175,8 @@ export default {
.trnItem__categoryIcon
Icon(
:background="category.color"
- big
:icon="category.icon"
+ big
round
)
.trnItem__categoryName {{ category.name }}
@@ -276,6 +273,11 @@ export default {
padding-top $m5
font-size 14px
+ span
+ padding-right 2px
+ color var(--c-font-3)
+ font-size 11px
+
.trnFormHeaderSeparator
color var(--c-font-1)
font-size 32px
diff --git a/locales/en-US.js b/locales/en-US.js
index 6c3285c5..1732e671 100644
--- a/locales/en-US.js
+++ b/locales/en-US.js
@@ -32,6 +32,10 @@ export default {
description: {
title: 'Description',
placeholder: 'Write description...'
+ },
+ transfer: {
+ from: 'From',
+ to: 'To'
}
},
diff --git a/locales/ru-RU.js b/locales/ru-RU.js
index 951d50b7..071208a8 100644
--- a/locales/ru-RU.js
+++ b/locales/ru-RU.js
@@ -33,6 +33,10 @@ export default {
description: {
title: 'Описание',
placeholder: 'Напишите описание...'
+ },
+ transfer: {
+ from: 'Из',
+ to: 'В'
}
},
diff --git a/store/categories/getters.js b/store/categories/getters.js
index b0e0a51b..90bc7f62 100644
--- a/store/categories/getters.js
+++ b/store/categories/getters.js
@@ -17,7 +17,7 @@ export default {
if (!getters.hasCategories) { return [] }
return Object.keys(state.items)
- .filter(key => state.items[key].parentId === 0)
+ .filter(id => state.items[id].parentId === 0)
.sort((a, b) => {
if (state.items[a].order < state.items[b].order) { return -1 }
if (state.items[a].order > state.items[b].order) { return 1 }
@@ -31,6 +31,7 @@ export default {
const categoriesForBeParent = []
for (const categoryId of categoriesRootIds) {
+ if (categoryId === 'transfer') { break }
let isTrns = false
for (const trnId in trns) {
if (trns[trnId].categoryId === categoryId) {
@@ -101,8 +102,8 @@ export default {
if (state.items[a] && state.items[b]) {
if (state.items[a].name < state.items[b].name) { return -1 }
if (state.items[a].name > state.items[b].name) { return 1 }
- return 0
}
+ return 0
})
}
},
@@ -123,6 +124,6 @@ export default {
if (!getters.hasCategories) { return null }
return Object.keys(state.items)
- .find(id => state.items[id].name === 'Перевод' || state.items[id].name === 'Transfer') || false
+ .find(id => state.items[id].name === 'Перевод' || state.items[id].name === 'Transfer') || state.items.transfer || false
}
}
diff --git a/store/categories/mutations.js b/store/categories/mutations.js
index 77c46680..b2c459b1 100644
--- a/store/categories/mutations.js
+++ b/store/categories/mutations.js
@@ -6,7 +6,19 @@ export default {
freezedItems[itemId] = Object.freeze(items[itemId])
}
}
- state.items = freezedItems
+ state.items = {
+ ...freezedItems,
+ transfer: {
+ color: 'var(--c-blue-1)',
+ icon: 'mdi mdi-mdi mdi-repeat',
+ name: 'Transfer',
+ order: 0,
+ parentId: 0,
+ showInLastUsed: false,
+ showInQuickSelector: false,
+ showStat: false
+ }
+ }
},
showCategoryModal (state) {
diff --git a/store/trnForm/actions.js b/store/trnForm/actions.js
index c16ff6f5..29fdd644 100644
--- a/store/trnForm/actions.js
+++ b/store/trnForm/actions.js
@@ -4,8 +4,7 @@ export default {
closeTrnForm ({ commit }) {
commit('closeTrnForm')
commit('setTrnFormValues', {
- trnId: null,
- amountEvaluation: null
+ trnId: null
})
},
@@ -17,7 +16,6 @@ export default {
const lastTrn = rootState.trns.items[rootGetters['trns/lastCreatedTrnId']]
commit('setTrnFormValues', {
amount: '0',
- amountEvaluation: null,
amountType: 0,
categoryId: lastTrn.categoryId,
date: dayjs().valueOf(),
@@ -33,7 +31,6 @@ export default {
const walletId = walletsIds[0]
commit('setTrnFormValues', {
amount: '0',
- amountEvaluation: null,
amountType: 0,
categoryId,
date: dayjs().valueOf(),
@@ -47,17 +44,37 @@ export default {
case 'edit':
if (trnId && rootGetters['trns/hasTrns']) {
const trn = rootState.trns.items[trnId]
- commit('setTrnFormValues', {
- ...trn,
- amount: trn.amount,
- amountEvaluation: null,
- amountType: trn.type,
- categoryId: trn.categoryId,
- date: trn.date,
- description: trn.description || null,
- trnId,
- walletId: trn.walletId
- })
+
+ // Transfer
+ if (trn.type === 2) {
+ commit('setTrnFormValues', {
+ ...trn,
+ amount: trn.amount,
+ amountFrom: trn.amount,
+ amountTo: trn.amount,
+ amountType: trn.type,
+ categoryId: trn.categoryId,
+ date: trn.date,
+ description: trn.description || null,
+ trnId,
+ walletId: trn.walletId,
+ walletFromId: trn.walletFromId,
+ walletToId: trn.walletToId
+ })
+ }
+ // Simple
+ else {
+ commit('setTrnFormValues', {
+ ...trn,
+ amount: trn.amount,
+ amountType: trn.type,
+ categoryId: trn.categoryId,
+ date: trn.date,
+ description: trn.description || null,
+ trnId,
+ walletId: trn.walletId
+ })
+ }
}
break
@@ -66,7 +83,6 @@ export default {
const trn = rootState.trns.items[trnId]
commit('setTrnFormValues', {
...trn,
- amountEvaluation: null,
amountType: trn.type,
categoryId: trn.categoryId,
date: dayjs().valueOf(),
diff --git a/store/trns/actions.js b/store/trns/actions.js
index 9f77e762..8331d0ef 100644
--- a/store/trns/actions.js
+++ b/store/trns/actions.js
@@ -23,24 +23,17 @@ export default {
addTrn ({ commit, rootState }, { id, values }) {
const uid = rootState.user.user.uid
const trns = rootState.trns.items
- let isTrnSavedOnline = false
-
- const formatedTrnValues = {
- amount: values.amount,
- categoryId: values.categoryId,
- date: dayjs(values.date).valueOf(),
- description: values.description || null,
- edited: dayjs().valueOf(),
- groups: values.groups || null,
- type: Number(values.amountType) || 0,
- walletId: values.walletId
+ const valuesWithEditDate = {
+ ...values,
+ edited: dayjs().valueOf()
}
+ let isTrnSavedOnline = false
- localforage.setItem('finapp.trns', { ...trns, [id]: formatedTrnValues })
- commit('setTrns', Object.freeze({ ...trns, [id]: formatedTrnValues }))
+ localforage.setItem('finapp.trns', { ...trns, [id]: valuesWithEditDate })
+ commit('setTrns', Object.freeze({ ...trns, [id]: valuesWithEditDate }))
db.ref(`users/${uid}/trns/${id}`)
- .set(formatedTrnValues)
+ .set(valuesWithEditDate)
.then(() => {
isTrnSavedOnline = true
removeTrnToAddLaterLocal(id)
diff --git a/store/trns/getters.js b/store/trns/getters.js
index 0ecee8dd..b03c1e06 100644
--- a/store/trns/getters.js
+++ b/store/trns/getters.js
@@ -20,7 +20,7 @@ export default {
* @return {String} return.incomes
* @return {String} return.total
*/
- getTotalOfTrnsIds: (state, getters, rootState, rootGetters) => (trnsIds, inculdeTrnasfers = false) => {
+ getTotalOfTrnsIds: (state, getters, rootState, rootGetters) => (trnsIds, inculdeTrnasfers = false, isConvertToBase = true, walletId) => {
const trns = rootState.trns.items
const currencies = rootState.currencies.rates
const wallets = rootState.wallets.items
@@ -33,17 +33,29 @@ export default {
for (const key of trnsIds) {
const trn = trns[key]
if (trn && (inculdeTrnasfers || trn.categoryId !== transferCategoryId)) {
- const wallet = wallets[trn.walletId]
- if (wallet && currencies) {
- let amount = 0
- if (wallet.currency !== baseCurrency) {
- amount = Math.abs(trn.amount / currencies[wallet.currency])
+ // Simple
+ if (trn.type !== 2) {
+ const wallet = wallets[trn.walletId]
+ if (wallet && currencies) {
+ let amount = 0
+ if (isConvertToBase && wallet.currency !== baseCurrency) {
+ amount = Math.abs(trn.amount / currencies[wallet.currency])
+ }
+ else {
+ amount = trn.amount
+ }
+ if (trn.type === 1) { incomes = incomes + amount }
+ else { expenses = expenses + amount }
}
- else {
- amount = trn.amount
+ }
+
+ if (trn.type === 2 && inculdeTrnasfers) {
+ if (walletId === trn.walletFromId) {
+ expenses = expenses + trn.amountFrom
+ }
+ if (walletId === trn.walletToId) {
+ incomes = incomes + trn.amountTo
}
- if (trn.type === 1) { incomes = incomes + amount }
- else { expenses = expenses + amount }
}
}
}
@@ -59,7 +71,7 @@ export default {
const trns = rootState.trns.items
const trnsIds = []
for (const trnId in trns) {
- if (trns[trnId] && trns[trnId].walletId === walletId) {
+ if (trns[trnId] && (trns[trnId].walletId === walletId || trns[trnId].walletFromId === walletId || trns[trnId].walletToId === walletId)) {
trnsIds.push(trnId)
}
}
@@ -109,7 +121,7 @@ export default {
// filter wallet
if (filterWalletId) {
- trnsIds = trnsIds.filter(trnId => trns[trnId].walletId === filterWalletId)
+ trnsIds = trnsIds.filter(trnId => trns[trnId].walletId === filterWalletId || trns[trnId].walletToId === filterWalletId || trns[trnId].walletFromId === filterWalletId)
}
// filter category
@@ -218,7 +230,7 @@ export default {
// filter wallet
if (filterWalletId) {
- trnsIds = trnsIds.filter(trnId => trns[trnId].walletId === filterWalletId)
+ trnsIds = trnsIds.filter(trnId => trns[trnId].walletId === filterWalletId || trns[trnId].walletToId === filterWalletId || trns[trnId].walletFromId === filterWalletId)
}
// filter category
@@ -230,6 +242,7 @@ export default {
for (const categoryId of childCategoriesIds) {
if (trnCategoryId === categoryId) { return true }
}
+ return false
})
}
else {
@@ -280,7 +293,7 @@ export default {
// filter wallet
if (filterWalletId) {
- trnsIds = trnsIds.filter(trnId => trns[trnId].walletId === filterWalletId)
+ trnsIds = trnsIds.filter(trnId => trns[trnId].walletId === filterWalletId || trns[trnId].walletToId === filterWalletId || trns[trnId].walletFromId === filterWalletId)
}
// filter category
diff --git a/store/wallets/getters.js b/store/wallets/getters.js
index c7d5abdc..da4c6ad4 100644
--- a/store/wallets/getters.js
+++ b/store/wallets/getters.js
@@ -14,20 +14,9 @@ export default {
// getWalletAmount
getWalletAmount: (state, getters, rootState, rootGetters) => (walletId) => {
- const trns = rootState.trns.items
- let amount = 0
const trnsIds = rootGetters['trns/getTrnsIdsInWallet'](walletId)
- for (const trnId of trnsIds) {
- if (trns[trnId]) {
- if (trns[trnId].type === 0) {
- amount = amount - trns[trnId].amount
- }
- else {
- amount = amount + trns[trnId].amount
- }
- }
- }
- return amount
+ const { total } = rootGetters['trns/getTotalOfTrnsIds'](trnsIds, true, false, walletId)
+ return total || 0
},
walletsTotal (state, getters, rootState, rootGetters) {
@@ -36,18 +25,9 @@ export default {
const wallets = rootState.wallets.items
const getWalletAmount = (walletId) => {
- const trns = rootState.trns.items
- let amount = 0
const trnsIds = rootGetters['trns/getTrnsIdsInWallet'](walletId)
- for (const trnId of trnsIds) {
- if (trns[trnId].type === 0) {
- amount = amount - trns[trnId].amount
- }
- else {
- amount = amount + trns[trnId].amount
- }
- }
- return amount || 0
+ const { total } = rootGetters['trns/getTotalOfTrnsIds'](trnsIds, true, false, walletId)
+ return total || 0
}
Object.keys(wallets).forEach((id) => {