Skip to content

Commit

Permalink
fix: Env typed and default values provided
Browse files Browse the repository at this point in the history
  • Loading branch information
RezaRahemtola committed Oct 24, 2024
1 parent 3e85abc commit d96a834
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 8 deletions.
6 changes: 4 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

# APIs
LTAI_SUBSCRIPTIONS_API_URL=http://localhost:8000
LTAI_BASE_ADDRESS=92e1d72210429Ce7eE8a0d64D526D4b9752801FF
LTAI_PUBLISHER_ADDRESS=0xae92Dc50115dbBb1CF0BA848e83842daf00CE129
WALLET_CONNECT_PROJECT_ID=

# Blockchain addresses (change in development)
# LTAI_BASE_ADDRESS=0x92e1d72210429Ce7eE8a0d64D526D4b9752801FF
# LTAI_PUBLISHER_ADDRESS=0xae92Dc50115dbBb1CF0BA848e83842daf00CE129
4 changes: 2 additions & 2 deletions src/apis/subscriptions/services.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { createClient, createConfig, type Options } from '@hey-api/client-axios';
import type { GetUserSubscriptionsSubscriptionsGetData, GetUserSubscriptionsSubscriptionsGetError, GetUserSubscriptionsSubscriptionsGetResponse, SubscribeHoldSubscriptionPostData, SubscribeHoldSubscriptionPostError, SubscribeHoldSubscriptionPostResponse, UnsubscribeHoldSubscriptionDeleteData, UnsubscribeHoldSubscriptionDeleteError, UnsubscribeHoldSubscriptionDeleteResponse, RefreshActiveHoldSubscriptionsHoldRefreshPostError, RefreshActiveHoldSubscriptionsHoldRefreshPostResponse, HoldSubscriptionMessagesHoldMessageGetData, HoldSubscriptionMessagesHoldMessageGetError, HoldSubscriptionMessagesHoldMessageGetResponse, RefreshSubsRefreshPostError, RefreshSubsRefreshPostResponse, SubscribeVouchersSubscriptionPostData, SubscribeVouchersSubscriptionPostError, SubscribeVouchersSubscriptionPostResponse, CancelVouchersSubscriptionsVouchersSubscriptionDeleteData, CancelVouchersSubscriptionsVouchersSubscriptionDeleteError, CancelVouchersSubscriptionsVouchersSubscriptionDeleteResponse, RefreshActiveVouchersSubscriptionsVouchersRefreshPostError, RefreshActiveVouchersSubscriptionsVouchersRefreshPostResponse } from './types.gen';

export const client = createClient(createConfig({baseURL: process.env.LTAI_SUBSCRIPTIONS_API_UR}));
export const client = createClient(createConfig());

/**
* Get User Subscriptions
Expand Down Expand Up @@ -83,4 +83,4 @@ export const cancelVouchersSubscriptionsVouchersSubscriptionDelete = <ThrowOnErr
export const refreshActiveVouchersSubscriptionsVouchersRefreshPost = <ThrowOnError extends boolean = false>(options?: Options<unknown, ThrowOnError>) => { return (options?.client ?? client).post<RefreshActiveVouchersSubscriptionsVouchersRefreshPostResponse, RefreshActiveVouchersSubscriptionsVouchersRefreshPostError, ThrowOnError>({
...options,
url: '/vouchers/refresh'
}); };
}); };
13 changes: 13 additions & 0 deletions src/config/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { z } from 'zod';

const envSchema = z.object({
ALEPH_API_URL: z.string().optional(),
LTAI_SUBSCRIPTIONS_API_URL: z.string(),
WALLET_CONNECT_PROJECT_ID: z.string(),
LTAI_BASE_ADDRESS: z.string().startsWith('0x').optional().default('0xF8B1b47AA748F5C7b5D0e80C726a843913EB573a'),
LTAI_PUBLISHER_ADDRESS: z.string().startsWith('0x').optional().default('0xCBFc3EeC41CBBfCAcc50337d712890C47a14ba99'),
});

const env = envSchema.parse(process.env);

export default env;
21 changes: 21 additions & 0 deletions src/pages/AccountSettings.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<template>
<h2>Yo</h2>
</template>

<script lang="ts" setup>
import { onMounted } from 'vue';
import { useAccount } from '@wagmi/vue';
import { useRouter } from 'vue-router';
import { useQuasar } from 'quasar';
const account = useAccount();
const router = useRouter();
const $q = useQuasar();
onMounted(async () => {
if (!account.isConnected.value) {
$q.notify({ message: 'Account not connected', color: 'negative' });
await router.push({ path: '/' });
}
});
</script>
2 changes: 1 addition & 1 deletion src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default route(function (/* { store, ssrContext } */) {
});

Router.beforeEach(async (_to, _from, next) => {
// @TODO ensure pinia+persist storage ready
// TODO ensure pinia+persist storage ready
// something like await storageReady
next();
});
Expand Down
1 change: 1 addition & 0 deletions src/router/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const routes = [
path: 'subscriptions',
component: () => import('pages/Subscriptions.vue'),
},
{ path: 'account', component: () => import('pages/AccountSettings.vue') },
],
},

Expand Down
5 changes: 3 additions & 2 deletions src/stores/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import { base } from '@wagmi/vue/chains';
import { useTokensStore } from 'stores/tokens';
import { useKnowledgeStore } from 'stores/knowledge';
import { useSubscriptionStore } from 'stores/subscription';
import env from 'src/config/env';

const LTAI_BASE_ADDRESS = process.env.LTAI_BASE_ADDRESS || 'F8B1b47AA748F5C7b5D0e80C726a843913EB573a';
const LTAI_BASE_ADDRESS = env.LTAI_BASE_ADDRESS as `0x${string}`;

type AccountStoreState = {
alephStorage: AlephPersistentStorage | null;
Expand Down Expand Up @@ -66,7 +67,7 @@ export const useAccountStore = defineStore('account', {

const balance = await getBalance(config, {
address: account.address,
token: `0x${LTAI_BASE_ADDRESS}`,
token: LTAI_BASE_ADDRESS,
chainId: base.id,
});

Expand Down
3 changes: 2 additions & 1 deletion src/stores/tokens.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { defineStore } from 'pinia';
import { AlephHttpClient } from '@aleph-sdk/client';
import env from 'src/config/env';

type TokensStoreState = {
tokens: Record<string, number>;
pending_tokens: Record<string, number>;
estimated_3yr_tokens: Record<string, number>;
};

const AGGREGATE_PUBLISHER_ADDRESS = process.env.LTAI_PUBLISHER_ADDRESS || '0xCBFc3EeC41CBBfCAcc50337d712890C47a14ba99';
const AGGREGATE_PUBLISHER_ADDRESS = env.LTAI_PUBLISHER_ADDRESS;
const AGGREGATE_KEYS = ['tokens', 'pending_tokens', 'estimated_3yr_tokens'];

export const useTokensStore = defineStore('tokens', {
Expand Down

0 comments on commit d96a834

Please sign in to comment.