Skip to content

Open source personal finance application

refactor(wallets): remove credit available/debt view toggle

Ilya Komichev2dda394acf88
diff --git a/app/app/components/layout/Sidebar.vue b/app/app/components/layout/Sidebar.vue
index 2ba36f70..0c132c4f 100644
--- a/app/app/components/layout/Sidebar.vue
+++ b/app/app/components/layout/Sidebar.vue
@@ -24,9 +24,7 @@ const isShowLogoMenu = ref(false)
const walletMenu = useWalletMenuItems()
function getWalletContextMenuItems(walletId: WalletId) {
- const cv = walletMenu.creditView(walletId)
return [
- ...(cv ? [[cv]] : []),
[walletMenu.edit(walletId)],
]
}
diff --git a/app/app/components/wallets/ItemBody.vue b/app/app/components/wallets/ItemBody.vue
index 150c4072..9f59cb4e 100644
--- a/app/app/components/wallets/ItemBody.vue
+++ b/app/app/components/wallets/ItemBody.vue
@@ -3,7 +3,6 @@ import type { WalletId, WalletItemComputed } from '~/components/wallets/types'
import { useCurrenciesStore } from '~/components/currencies/useCurrenciesStore'
import { getCreditAvailable } from '~/components/wallets/types'
-import { useWalletCreditView } from '~/components/wallets/useWalletCreditView'
const props = defineProps<{
activeItemId?: WalletId | null
@@ -36,22 +35,9 @@ const classes = computed(() => ([
},
]))
-const { view: activeCreditView } = useWalletCreditView(props.walletId)
-
const walletCreditLimit = computed(() =>
props.wallet.type === 'credit' ? props.wallet.creditLimit : 0,
)
-
-const creditAmount = computed(() => {
- switch (activeCreditView.value) {
- case 'debt':
- return props.wallet?.amount
- case 'summary':
- return getCreditAvailable(walletCreditLimit.value, props.wallet.amount)
- default:
- return 0
- }
-})
</script>
<template>
@@ -130,7 +116,7 @@ const creditAmount = computed(() => {
<div class="pr-1">
<Amount
v-if="walletCreditLimit"
- :amount="creditAmount"
+ :amount="wallet.amount"
:currencyCode="wallet.currency"
:isShowBaseRate="props.isShowBaseRate"
variant="sm"
@@ -155,7 +141,7 @@ const creditAmount = computed(() => {
<div v-if="!isSort">
<Amount
v-if="walletCreditLimit"
- :amount="creditAmount"
+ :amount="wallet.amount"
:currencyCode="wallet.currency"
:isShowBaseRate="false"
:isShowMinus="false"
diff --git a/app/app/components/wallets/constants.ts b/app/app/components/wallets/constants.ts
index a10cf705..c64933b7 100644
--- a/app/app/components/wallets/constants.ts
+++ b/app/app/components/wallets/constants.ts
@@ -1,7 +1,6 @@
export const WALLET_STORAGE_KEYS = {
activeCurrency: 'finapp-wallets-active-currency',
activeType: 'finapp-wallets-active-type',
- creditViewPrefix: 'finapp-wallets-credit-view-',
groupedBy: 'finapp-wallets-groupedBy',
groupedBySecondary: 'finapp-wallets-groupedBySecondary',
includeArchivedInStats: 'finapp-wallets-include-archived-in-stats',
diff --git a/app/app/components/wallets/page/ListItem.vue b/app/app/components/wallets/page/ListItem.vue
index ae826610..6c3a0e19 100644
--- a/app/app/components/wallets/page/ListItem.vue
+++ b/app/app/components/wallets/page/ListItem.vue
@@ -15,14 +15,10 @@ const emit = defineEmits<{
const walletsStore = useWalletsStore()
const m = useWalletMenuItems()
-const contextMenuItems = computed(() => {
- const cv = m.creditView(props.walletId)
- return [
- ...(cv ? [[cv]] : []),
- [m.edit(props.walletId)],
- [m.delete(props.walletId, id => emit('delete', id))],
- ]
-})
+const contextMenuItems = computed(() => [
+ [m.edit(props.walletId)],
+ [m.delete(props.walletId, id => emit('delete', id))],
+])
</script>
<template>
diff --git a/app/app/components/wallets/useWalletCreditView.ts b/app/app/components/wallets/useWalletCreditView.ts
deleted file mode 100644
index 45a98b2e..00000000
--- a/app/app/components/wallets/useWalletCreditView.ts
+++ /dev/null
@@ -1,33 +0,0 @@
-import type { RemovableRef } from '@vueuse/core'
-
-import { useStorage } from '@vueuse/core'
-
-import type { WalletId } from '~/components/wallets/types'
-
-import { WALLET_STORAGE_KEYS } from '~/components/wallets/constants'
-
-export const CREDIT_VIEWS = ['debt', 'summary'] as const
-export type CreditView = typeof CREDIT_VIEWS[number]
-
-// Cache one ref per walletId so multiple consumers in the same tab share
-// reactive updates. useStorage creates a fresh ref on each call and only
-// syncs across tabs via storage events, not within the same document.
-const cache = new Map<WalletId, RemovableRef<CreditView>>()
-
-export function useWalletCreditView(walletId: WalletId) {
- let view = cache.get(walletId)
- if (!view) {
- view = useStorage<CreditView>(
- `${WALLET_STORAGE_KEYS.creditViewPrefix}${walletId}`,
- 'debt',
- )
- cache.set(walletId, view)
- }
-
- function cycle() {
- const i = CREDIT_VIEWS.findIndex(v => v === view!.value)
- view!.value = CREDIT_VIEWS[(i + 1) % CREDIT_VIEWS.length]!
- }
-
- return { cycle, view }
-}
diff --git a/app/app/components/wallets/useWalletMenuItems.ts b/app/app/components/wallets/useWalletMenuItems.ts
index 6482c3b3..7765f46b 100644
--- a/app/app/components/wallets/useWalletMenuItems.ts
+++ b/app/app/components/wallets/useWalletMenuItems.ts
@@ -1,30 +1,12 @@
import type { WalletId } from '~/components/wallets/types'
-import { useWalletCreditView } from '~/components/wallets/useWalletCreditView'
-import { useWalletsStore } from '~/components/wallets/useWalletsStore'
-
type Item = { color?: 'error', icon: string, label: string, onSelect: () => void }
export function useWalletMenuItems() {
const { t } = useI18n()
const router = useRouter()
- const walletsStore = useWalletsStore()
return {
- creditView(walletId: WalletId): Item | null {
- const wallet = walletsStore.itemsComputed[walletId]
- if (!wallet || wallet.type !== 'credit' || wallet.creditLimit <= 0)
- return null
- const { cycle, view } = useWalletCreditView(walletId)
- return {
- icon: view.value === 'debt' ? 'lucide:wallet' : 'lucide:credit-card',
- label: view.value === 'debt'
- ? t('wallets.creditView.showAvailable')
- : t('wallets.creditView.showDebt'),
- onSelect: cycle,
- }
- },
-
delete(walletId: WalletId, onDelete: (id: WalletId) => void): Item {
return {
color: 'error',
diff --git a/app/i18n/locales/en-US.js b/app/i18n/locales/en-US.js
index 0348e31a..96a314c1 100644
--- a/app/i18n/locales/en-US.js
+++ b/app/i18n/locales/en-US.js
@@ -468,10 +468,6 @@ export default {
wallets: {
ariaSwitch: 'Switch wallets',
createNewTitle: 'New wallet',
- creditView: {
- showAvailable: 'Show available credit',
- showDebt: 'Show current debt',
- },
errors: {
deleteFailed: 'Failed to delete wallet',
orderFailed: 'Failed to save wallet order',
diff --git a/app/i18n/locales/ru-RU.js b/app/i18n/locales/ru-RU.js
index c00d0c94..3bfeb07d 100644
--- a/app/i18n/locales/ru-RU.js
+++ b/app/i18n/locales/ru-RU.js
@@ -468,10 +468,6 @@ export default {
wallets: {
ariaSwitch: 'Поменять кошельки',
createNewTitle: 'Добавление кошелька',
- creditView: {
- showAvailable: 'Показать доступный лимит',
- showDebt: 'Показать текущий долг',
- },
errors: {
deleteFailed: 'Не удалось удалить кошелек',
orderFailed: 'Не удалось сохранить порядок кошельков',