Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add currency code in record list #199

Merged
merged 4 commits into from
Jul 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 52 additions & 14 deletions src/components/fields/input-field.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,34 @@
</template>
</template>

<input
v-bind="computedAttrs"
:type="type"
:value="modelValue"
:style="inputFieldStyles"
:disabled="disabled"
:tabindex="tabindex"
:min="minValue"
class="input-field__input"
autocomplete="off"
autocorrect="off"
autocapitalize="off"
spellcheck="false"
>
<div class="input-field__wrapper">
<template v-if="isLeadingIconExist">
<div class="input-field__leading-icon">
<slot name="iconLeading" />
</div>
</template>

<input
v-bind="computedAttrs"
:type="type"
:value="modelValue"
:style="inputFieldStyles"
:disabled="disabled"
:tabindex="tabindex"
:min="minValue"
class="input-field__input"
autocomplete="off"
autocorrect="off"
autocapitalize="off"
spellcheck="false"
>

<template v-if="isTrailIconExist">
<div class="input-field__trailing-icon">
<slot name="iconTrailing" />
</div>
</template>
</div>
</FieldLabel>

<template v-if="isSubLabelExist">
Expand Down Expand Up @@ -121,10 +135,16 @@ export default defineComponent({

const isSubLabelExist = computed(() => !!slots.subLabel);

const isTrailIconExist = computed(() => !!slots.iconTrailing);

const isLeadingIconExist = computed(() => !!slots.iconLeading);

return {
minValue,
computedAttrs,
isSubLabelExist,
isTrailIconExist,
isLeadingIconExist,
};
},
});
Expand All @@ -135,6 +155,14 @@ export default defineComponent({
position: relative;
width: 100%;
flex: 1;
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
-webkit-appearance: none;
margin: 0;
}
input[type="number"] {
-moz-appearance: textfield;
}
}
.input-field--disabled {
opacity: 0.6;
Expand All @@ -155,6 +183,9 @@ export default defineComponent({

@include placeholder-custom(rgba(var(--app-on-surface-color-rgb), 0.6));
}
.input-field__wrapper {
position: relative;
}
.input-fields__sublabel {
position: absolute;
right: 0;
Expand All @@ -168,4 +199,11 @@ export default defineComponent({
text-decoration: none;
}
}
.input-field__leading-icon,
.input-field__trailing-icon {
position: absolute;
top: 0;
right: 0;
padding: 12px 24px;
}
</style>
25 changes: 22 additions & 3 deletions src/components/modals/system-tx-form/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
type="number"
only-positive
placeholder="Amount"
/>
>
<template #iconTrailing>
<span>{{ currencyCode }}</span>
</template>
</input-field>
</form-row>

<account-field
Expand Down Expand Up @@ -123,6 +127,7 @@ import {
ref,
watch,
computed,
onMounted,
} from 'vue';
import { storeToRefs } from 'pinia';
import {
Expand Down Expand Up @@ -204,9 +209,9 @@ export default defineComponent({
const accountsStore = useAccountsStore();
const categoriesStore = useCategoriesStore();
const currenciesStore = useCurrenciesStore();
const { getCurrency } = useCurrenciesStore();
const { getCurrency, currenciesMap } = useCurrenciesStore();

const { accountsRecord } = storeToRefs(accountsStore);
const { accountsRecord, accounts } = storeToRefs(accountsStore);
const { currencies } = storeToRefs(currenciesStore);
const { categories, rawCategories } = storeToRefs(categoriesStore);

Expand Down Expand Up @@ -246,6 +251,14 @@ export default defineComponent({

return form.value.account.currencyId !== form.value.toAccount.currencyId;
});

const currencyCode = computed(() => {
if (form.value.account?.currencyId) {
return currenciesMap[form.value.account.currencyId].code;
}
return undefined;
});

const targetCurrency = computed(() => {
if (form.value.toAccount?.currencyId) {
return getCurrency(form.value.toAccount.currencyId);
Expand Down Expand Up @@ -400,11 +413,17 @@ export default defineComponent({
if (!disabled) form.value.type = type;
};

onMounted(() => {
form.value.account = accounts.value[0];
});

return {
FORM_TYPES,
TRANSACTION_TYPES,
PAYMENT_TYPES,
form,
currencyCode,
currenciesMap,
currencies,
isCurrenciesDifferent,
targetCurrency,
Expand Down
11 changes: 8 additions & 3 deletions src/components/transactions-list/mono-transaction.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<div class="transaction__right">
<div class="transaction__amount">
{{ formatAmount(tx.amount) }}
<!-- {{ tx.account.currency.asset }} -->
{{ currenciesMap[tx.currencyId].code }}
</div>
<div class="transaction__time">
{{ formateDate(tx.time) }}
Expand All @@ -26,9 +26,10 @@

<script lang="ts">
import { format } from 'date-fns';
import { storeToRefs } from 'pinia';
import { defineComponent, PropType, computed } from 'vue';
import { MonobankTrasnactionModel } from 'shared-types';
import { useCategoriesStore } from '@/stores';
import { useCategoriesStore, useCurrenciesStore } from '@/stores';
import { MODAL_TYPES, useModalCenter } from '@/components/modal-center/index';
import { formatAmount } from '@/js/helpers';

Expand All @@ -41,7 +42,11 @@ export default defineComponent({
},
setup(props) {
const { getCategoryTypeById } = useCategoriesStore();
const currenciesStore = useCurrenciesStore();
const { addModal } = useModalCenter();

const { currenciesMap } = storeToRefs(currenciesStore);

const category = computed(
() => getCategoryTypeById(props.tx.categoryId),
);
Expand All @@ -57,7 +62,7 @@ export default defineComponent({

return {
formatAmount,

currenciesMap,
category,
formateDate,
editTransaction,
Expand Down
8 changes: 8 additions & 0 deletions src/stores/currencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ export const useCurrenciesStore = defineStore('currencies', () => {
}, [] as CurrencyRecord[]),
);

const currenciesMap = computed(
() => currencies.value.reduce((acc, curr) => {
acc[curr.currencyId] = curr;
return acc;
}, {}),
);

const loadCurrencies = async () => {
currencies.value = await loadUserCurrencies();

Expand Down Expand Up @@ -58,6 +65,7 @@ export const useCurrenciesStore = defineStore('currencies', () => {
currencies,
baseCurrency,
systemCurrencies,
currenciesMap,
systemCurrenciesAssociatedWithUser,
isBaseCurrencyExists,
loadCurrencies,
Expand Down