Skip to content

Commit

Permalink
dont initially show unsupported currencies (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
MauserBitfly authored Jun 6, 2024
1 parent eaab739 commit 912d245
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions frontend/composables/useCurrency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export function useCurrency () {
const showInDevelopment = Boolean(useRuntimeConfig().public.showInDevelopment)

const selectedCurrency = useCookie<Currency>(COOKIE_KEY.CURRENCY, { default: () => 'NAT' })
const currency = readonly(selectedCurrency)
function setCurrency (newCurrency: Currency) {
selectedCurrency.value = newCurrency
}
Expand All @@ -32,16 +31,18 @@ export function useCurrency () {
return list.concat((latestState.value?.exchange_rates || []).map(r => r.code as Currency))
})

const currency = computed(() => selectedCurrency.value && available.value.includes(selectedCurrency.value) ? selectedCurrency.value : available.value[0])

const withLabel = computed(() => {
return available.value?.map(currency => ({
currency,
label: $t(`currency.label.${currency}`, {}, rates.value?.[currency]?.currency || currency)
}))
})

watch([latestState, currency], () => {
watch([latestState, selectedCurrency], () => {
// once we loaded our latestState and see that we don't support the currency we switch back to the first item
if (latestState.value && !available.value.includes(currency.value)) {
if (latestState.value && !available.value.includes(selectedCurrency.value)) {
selectedCurrency.value = available.value[0]
}
})
Expand Down

0 comments on commit 912d245

Please sign in to comment.