From 5837a1acaa002c88b1d9af63912d742b2bf9fdb2 Mon Sep 17 00:00:00 2001 From: Evren Ceyhan Date: Sat, 2 Sep 2023 14:41:52 +0300 Subject: [PATCH 01/27] api assets moved to their own module --- src/server/api.ts | 19 ------------------- src/server/api/assets.ts | 29 +++++++++++++++++++++++++++++ src/server/api/index.ts | 1 + src/server/utils.ts | 8 -------- 4 files changed, 30 insertions(+), 27 deletions(-) delete mode 100644 src/server/api.ts create mode 100644 src/server/api/assets.ts create mode 100644 src/server/api/index.ts diff --git a/src/server/api.ts b/src/server/api.ts deleted file mode 100644 index ba1180e..0000000 --- a/src/server/api.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { Asset } from './types'; -import { fetchCollectApi, makeCode } from './utils'; - -export const getFiatAssets = async () => { - const assets = await fetchCollectApi('/allCurrency'); - - // limit to 5 assets - return assets.slice(0, 5); -}; - -export const getGoldAssets = async () => { - const assets = await fetchCollectApi('/goldPrice'); - - // limit to 5 assets - return assets.slice(0, 5).map((asset) => ({ - ...asset, - code: makeCode(asset.name), - })); -}; diff --git a/src/server/api/assets.ts b/src/server/api/assets.ts new file mode 100644 index 0000000..96cbc9f --- /dev/null +++ b/src/server/api/assets.ts @@ -0,0 +1,29 @@ +import { Asset } from '../types'; +import { fetchCollectApi } from '../utils'; + +export const getFiatAssets = async () => { + const assets = await fetchCollectApi('/allCurrency'); + + // limit to 5 assets + return assets.slice(0, 5); +}; + +export const getGoldAssets = async () => { + const assets = await fetchCollectApi('/goldPrice'); + + // limit to 5 assets + return assets.slice(0, 5).map((asset) => ({ + ...asset, + code: makeCode(asset.name), + })); +}; + +// HELPERS ///////////////////////////////////////////////////////////////////////////////////////// + +function makeCode(name: string) { + // make code from first & last letter of the first word + // and first letter of the second word in uppercase + const [first, second] = name.split(' '); + + return `${first[0]}${first.at(-1)}${second[0]}`.toUpperCase(); +} diff --git a/src/server/api/index.ts b/src/server/api/index.ts new file mode 100644 index 0000000..df64466 --- /dev/null +++ b/src/server/api/index.ts @@ -0,0 +1 @@ +export * from './assets'; diff --git a/src/server/utils.ts b/src/server/utils.ts index b4f8879..57160b7 100644 --- a/src/server/utils.ts +++ b/src/server/utils.ts @@ -19,11 +19,3 @@ export async function fetchCollectApi(path: string): Promise { return (await response.json()).result; } - -export function makeCode(name: string) { - // make code from first & last letter of the first word - // and first letter of the second word in uppercase - const [first, second] = name.split(' '); - - return `${first[0]}${first.at(-1)}${second[0]}`.toUpperCase(); -} From 6575991d36e0efe528b4c8989206ca5ff599244c Mon Sep 17 00:00:00 2001 From: Evren Ceyhan Date: Sat, 2 Sep 2023 15:32:25 +0300 Subject: [PATCH 02/27] auth moved to composables --- src/App.vue | 3 ++- src/{store => composables}/auth.ts | 17 +++++++++++++---- src/router.ts | 2 +- src/server/db.ts | 2 +- 4 files changed, 17 insertions(+), 7 deletions(-) rename src/{store => composables}/auth.ts (65%) diff --git a/src/App.vue b/src/App.vue index 1d6647a..85bd4ac 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,5 +1,5 @@ @@ -29,19 +21,11 @@ onMounted(async () => load()); - + Fiat - + Gold diff --git a/src/store/assets.ts b/src/store/assets.ts index 95a572d..22265bd 100644 --- a/src/store/assets.ts +++ b/src/store/assets.ts @@ -2,27 +2,27 @@ import { computed, ref } from 'vue'; import { Asset } from '../server/types'; import { getFiatAssets, getGoldAssets } from '../server/api'; -const fiatAssets = ref([]); -const goldAssets = ref([]); +type Category = 'fiat' | 'gold'; -const assets = computed(() => [ - ...fiatAssets.value, - ...goldAssets.value, -]); +const category = ref('fiat'); +const assets = ref([]); const assetMap = computed>(() => assets.value.reduce((acc, cur) => ({ ...acc, [cur.code]: cur }), {} as any) ); const load = async () => { - fiatAssets.value = await getFiatAssets(); - goldAssets.value = await getGoldAssets(); + const fetch = { + fiat: getFiatAssets, + gold: getGoldAssets, + }; + + assets.value = await fetch[category.value](); }; export const useAssets = () => ({ + category, assets, assetMap, - fiatAssets, - goldAssets, load, }); From fda3bc3ea2f53f2a8defe6a77d3d612ff0391869 Mon Sep 17 00:00:00 2001 From: Evren Ceyhan Date: Sun, 3 Sep 2023 00:47:10 +0300 Subject: [PATCH 15/27] obsolete assetMap removed --- src/store/assets.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/store/assets.ts b/src/store/assets.ts index 22265bd..32e164a 100644 --- a/src/store/assets.ts +++ b/src/store/assets.ts @@ -1,4 +1,4 @@ -import { computed, ref } from 'vue'; +import { ref } from 'vue'; import { Asset } from '../server/types'; import { getFiatAssets, getGoldAssets } from '../server/api'; @@ -7,10 +7,6 @@ type Category = 'fiat' | 'gold'; const category = ref('fiat'); const assets = ref([]); -const assetMap = computed>(() => - assets.value.reduce((acc, cur) => ({ ...acc, [cur.code]: cur }), {} as any) -); - const load = async () => { const fetch = { fiat: getFiatAssets, @@ -23,6 +19,5 @@ const load = async () => { export const useAssets = () => ({ category, assets, - assetMap, load, }); From 97f8b651ba4ab0acef590e9241d66cb8b06e87d8 Mon Sep 17 00:00:00 2001 From: Evren Ceyhan Date: Sun, 3 Sep 2023 00:51:57 +0300 Subject: [PATCH 16/27] assets page logic cleanup --- src/pages/Assets.vue | 9 +-------- src/store/assets.ts | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/pages/Assets.vue b/src/pages/Assets.vue index 1437e9c..ca279a2 100644 --- a/src/pages/Assets.vue +++ b/src/pages/Assets.vue @@ -1,17 +1,10 @@