Skip to content

Open source personal finance application

chore(Amount): rename methods

ilkome3b9c94be1f72
diff --git a/components/amount/Amount.vue b/components/amount/Amount.vue
index c58cf9de..0d10020d 100644
--- a/components/amount/Amount.vue
+++ b/components/amount/Amount.vue
@@ -14,7 +14,7 @@ const props = withDefaults(defineProps<{
isShowSign: true,
})
-const { baseCurrency, formatAmount, getCurrencySymbol, getAmountInBaseCurrency } = useAmount()
+const { baseCurrency, formatAmount, getCurrencySymbol, getAmountInBaseRate } = useAmount()
const sign = props.type === 0 ? '-' : '+'
const alignClasses = computed(() => ({
@@ -51,7 +51,7 @@ const amountClasses = computed(() => ([{
:class="alignClasses"
)
.text-xs.leading-none(v-if="isShowSign && sign === '-'") {{ sign }}
- .text-xs.leading-none {{ getAmountInBaseCurrency({ amount, currency }) }}
+ .text-xs.leading-none {{ getAmountInBaseRate({ amount, currency }) }}
.text-2xs.leading-none {{ getCurrencySymbol(baseCurrency) }}
//- 0
diff --git a/components/amount/useAmount.ts b/components/amount/useAmount.ts
index 48171814..540cfc83 100644
--- a/components/amount/useAmount.ts
+++ b/components/amount/useAmount.ts
@@ -1,7 +1,7 @@
import currencyjs from 'currency.js'
import { currencies } from '~/components/currencies/currencies'
import type { CurrencyCode } from '~/components/currencies/types'
-import { getAmountInBaseRate } from '~/components/trns/getTotal'
+import { getAmountInRate } from '~/components/trns/getTotal'
function getCurrencySymbol(currencyCode?: CurrencyCode) {
const currencySettings = currencies.find(c => c.code === currencyCode)
@@ -29,7 +29,7 @@ function formatAmount(amount: number, currencyCode?: CurrencyCode) {
export default function useAmount() {
const { $store } = useNuxtApp()
- function getAmountInBaseCurrency({ amount, currency, noFormat }: {
+ function getAmountInBaseRate({ amount, currency, noFormat }: {
amount: number
currency: string // TODO: add typings
noFormat?: boolean
@@ -37,7 +37,7 @@ export default function useAmount() {
const rates = $store.state.currencies.rates
const baseRate = $store.state.currencies.base
- const amountInBaseRate = getAmountInBaseRate({
+ const amountInBaseRate = getAmountInRate({
amount,
currency,
rates,
@@ -57,6 +57,6 @@ export default function useAmount() {
formatAmount,
getCurrencySymbol,
- getAmountInBaseCurrency,
+ getAmountInBaseRate,
}
}
diff --git a/components/trns/getTotal.ts b/components/trns/getTotal.ts
index beb1020d..15bd429b 100644
--- a/components/trns/getTotal.ts
+++ b/components/trns/getTotal.ts
@@ -3,8 +3,7 @@ import type { TrnID, TrnItem } from '~/components/trns/types'
import type { WalletID, WalletItem } from '~/components/wallets/types'
import { TrnType } from '~/components/trns/types'
-// TODO: why is getAmountInBaseRate and getAmountInBaseCurrency
-export function getAmountInBaseRate({
+export function getAmountInRate({
amount,
currency,
baseRate,
@@ -41,8 +40,7 @@ export function getTotal({
walletsIds?: WalletID[]
walletsItems: Record<WalletID, WalletItem>
}) {
- // TODO: rename getformattedAmount
- function getformattedAmount(amount: number, currency: string) {
+ function getFormattedAmount(amount: number, currency: string) {
return getAmountInRate({
amount,
baseRate,
@@ -68,7 +66,7 @@ export function getTotal({
if (trn.type === TrnType.Income || trn.type === TrnType.Expense) {
const isTransferCategory = transferCategoriesIds?.includes(trn.categoryId)
const wallet = walletsItems[trn.walletId]
- const sum = getformattedAmount(trn.amount, wallet.currency)
+ const sum = getFormattedAmount(trn.amount, wallet.currency)
// Income
if (trn.type === TrnType.Income) {
@@ -89,8 +87,8 @@ export function getTotal({
else if (trn.type === TrnType.Transfer && 'incomeWalletId' in trn) {
const incomeWallet = walletsItems[trn.incomeWalletId]
const expenseWallet = walletsItems[trn.expenseWalletId]
- const incomeAmount = getformattedAmount(trn.incomeAmount, incomeWallet.currency)
- const expenseAmount = getformattedAmount(trn.expenseAmount, expenseWallet.currency)
+ const incomeAmount = getFormattedAmount(trn.incomeAmount, incomeWallet.currency)
+ const expenseAmount = getFormattedAmount(trn.expenseAmount, expenseWallet.currency)
// Include only selected wallets
if (walletsIds && walletsIds.length > 0) {
@@ -114,8 +112,8 @@ export function getTotal({
else if (trn.type === TrnType.Transfer && 'walletFromId' in trn) {
const incomeWallet = walletsItems[trn.walletToId]
const expenseWallet = walletsItems[trn.walletFromId]
- const incomeAmount = getformattedAmount(trn.amountTo, incomeWallet.currency)
- const expenseAmount = getformattedAmount(trn.amountFrom, expenseWallet.currency)
+ const incomeAmount = getFormattedAmount(trn.amountTo, incomeWallet.currency)
+ const expenseAmount = getFormattedAmount(trn.amountFrom, expenseWallet.currency)
// Include only selected wallets
if (walletsIds && walletsIds.length > 0) {
diff --git a/components/wallets/Total.vue b/components/wallets/Total.vue
index 9af30889..df7d3f7f 100644
--- a/components/wallets/Total.vue
+++ b/components/wallets/Total.vue
@@ -2,7 +2,7 @@
import useAmount from '~/components/amount/useAmount'
const { $store } = useNuxtApp()
-const { getAmountInBaseCurrency } = useAmount()
+const { getAmountInBaseRate } = useAmount()
const totalInWallets = computed(() => {
const walletsItems = $store.state.wallets.items
@@ -19,7 +19,7 @@ const totalInWallets = computed(() => {
walletTotal = walletsTotal[walletId].base
}
else {
- walletTotal = getAmountInBaseCurrency({
+ walletTotal = getAmountInBaseRate({
amount: walletsTotal[walletId].base,
currency: walletsItems[walletId].currency,
noFormat: true,
diff --git a/tests/getAmount.test.ts b/tests/getAmount.test.ts
index df9cd45d..215b6aef 100644
--- a/tests/getAmount.test.ts
+++ b/tests/getAmount.test.ts
@@ -1,10 +1,10 @@
import { describe, expect, it } from 'vitest'
-import { getAmountInBaseRate } from '~/components/trns/getTotal'
+import { getAmountInRate } from '~/components/trns/getTotal'
import { ratesBasedOnUsd as rates } from '~/tests/rates.mock'
describe('Get amount', () => {
it('Get amount in same rate as base rate', () => {
- const amountInBaseRate = getAmountInBaseRate({
+ const amountInBaseRate = getAmountInRate({
amount: 40,
currency: 'USD',
rates,
@@ -15,7 +15,7 @@ describe('Get amount', () => {
})
it('Get amount in RUB when base rate is USD', () => {
- const amountInBaseRate = getAmountInBaseRate({
+ const amountInBaseRate = getAmountInRate({
amount: 70,
currency: 'RUB',
rates,
@@ -26,7 +26,7 @@ describe('Get amount', () => {
})
it('Get amount in RUB when base rate is EUR', () => {
- const amountInBaseRate = getAmountInBaseRate({
+ const amountInBaseRate = getAmountInRate({
amount: 70,
currency: 'RUB',
rates,