Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
implement selecting dynamic currency options
Browse files Browse the repository at this point in the history
  • Loading branch information
hay-kot committed Jan 5, 2024
1 parent fa676d6 commit b4151f0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
4 changes: 4 additions & 0 deletions backend/app/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ func run(cfg *config.Config) error {
}

if cfg.CurrencyConfig != "" {
log.Info().
Str("path", cfg.CurrencyConfig).
Msg("loading currency config file")

content, err := os.ReadFile(cfg.CurrencyConfig)
if err != nil {
log.Fatal().
Expand Down
14 changes: 13 additions & 1 deletion frontend/lib/api/classes/group.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { BaseAPI, route } from "../base";
import { Group, GroupInvitation, GroupInvitationCreate, GroupUpdate } from "../types/data-contracts";
import {
CurrenciesCurrency,
Group,
GroupInvitation,
GroupInvitationCreate,
GroupUpdate,
} from "../types/data-contracts";

export class GroupApi extends BaseAPI {
createInvitation(data: GroupInvitationCreate) {
Expand All @@ -21,4 +27,10 @@ export class GroupApi extends BaseAPI {
url: route("/groups"),
});
}

currencies() {
return this.http.get<CurrenciesCurrency[]>({
url: route("/currencies"),
});
}
}
21 changes: 17 additions & 4 deletions frontend/pages/profile.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<script setup lang="ts">
import { Detail } from "~~/components/global/DetailsSection/types";
import { themes } from "~~/lib/data/themes";
import { currencies, Currency } from "~~/lib/data/currency";
import { NotifierCreate, NotifierOut } from "~~/lib/api/types/data-contracts";
definePageMeta({
Expand All @@ -15,9 +14,23 @@
const confirm = useConfirm();
const notify = useNotifier();
// Currency Selection
const currency = ref<Currency>(currencies[0]);
const currencies = computedAsync(async () => {
const resp = await api.group.currencies();
if (resp.error) {
notify.error("Failed to get currencies");
return [];
}
return resp.data;
});
// Currency Selection
const currency = ref<typeof currencies.value[number]>({
code: "USD",
name: "United States Dollar",
local: "en-US",
symbol: "$",
});
watch(currency, () => {
if (group.value) {
group.value.currency = currency.value.code;
Expand Down Expand Up @@ -45,7 +58,7 @@
}
// @ts-expect-error - typescript is stupid, it should know group.value is not null
const found = currencies.find(c => c.code === group.value.currency);
const found = currencies.value.find(c => c.code === group.value.currency);
if (found) {
currency.value = found;
}
Expand Down

0 comments on commit b4151f0

Please sign in to comment.