Skip to content

Commit

Permalink
Feat: restructure dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
jaavid committed Jul 18, 2024
1 parent fd50462 commit 0a84f61
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 107 deletions.
7 changes: 7 additions & 0 deletions src/config/apiConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const API_BASE_URL = 'https://api.kharcoin.info/api/';
const ASSETS_URL = 'https://bot.kharcoin.info/';

export const API_CONFIG = {
API_BASE_URL,
ASSETS_URL,
};
15 changes: 15 additions & 0 deletions src/config/interfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export interface ITaskType {
TypeID: number;
TaskType: string;
TaskCount: number;
TaskColor: string;
}

export interface ITask {
id: number;
name: string;
expired: number;
type: number;
link: string;
reward: number;
}
5 changes: 3 additions & 2 deletions src/pages/Boosts.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AppShell, Container, SimpleGrid, Title, Text, Box, Button } from '@mant
import WebApp from '@twa-dev/sdk';
import { useTonAddress } from '@tonconnect/ui-react';
import { useEffect } from 'react';
import { API_CONFIG } from '../config/apiConfig';

export function BoostsPage() {
const user = WebApp.initDataUnsafe.user;
Expand All @@ -22,7 +23,7 @@ export function BoostsPage() {
method: 'POST',
body: formdata,
};
fetch('https://api.kharcoin.info/api/savewallet', requestOptions)
fetch(`${API_CONFIG.API_BASE_URL}savewallet`, requestOptions)
.then((response) => {
if (!response.ok) {
throw new Error('Network response was not ok');
Expand All @@ -39,7 +40,7 @@ export function BoostsPage() {
<AppShell.Header>
<HeaderMenu
username={user?.username ?? 'KC'}
photoUrl={user?.photo_url ?? 'https://bot.kharcoin.info/assets/images/kharcoin.jpg'}
photoUrl={user?.photo_url ?? `${API_CONFIG.ASSETS_URL}assets/images/kharcoin.jpg`}
/>
</AppShell.Header>
<AppShell.Main>
Expand Down
113 changes: 8 additions & 105 deletions src/pages/Earn.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,36 @@ import HeaderMenu from '../components/HeaderMenu/HeaderMenu';
import { AppShell, Blockquote, Container, List, ThemeIcon, Title, rem } from '@mantine/core';
import WebApp from '@twa-dev/sdk';
import { useEffect, useState } from 'react';
import { API_CONFIG } from '../config/apiConfig';

interface TaskType {
TypeID: number; // Assuming TypeID is a number, adjust the type accordingly
TaskType: string;
TaskCount: number;
TaskColor: string;
}

interface Task {
id: number;
name: string;
expired: number;
type: number;
link: string;
reward: number;
}
import {ITaskType, ITask} from '../config/interfaces';

export function EarnPage() {
const user = WebApp.initDataUnsafe.user;
const usertgid = user?.id;

const [taskstypes, setTaskstypes] = useState<TaskType[]>([]);
const [taskstypes, setTaskstypes] = useState<ITaskType[]>([]);

useEffect(() => {
// Fetch tasks from the API
fetch('https://api.kharcoin.info/api/tasks/types')
fetch(`${API_CONFIG.API_BASE_URL}tasks/types`)
.then(response => response.json())
.then(data => setTaskstypes(data))
.catch(error => console.error('Error fetching tasks:', error));
}, []);


const [taskDetails, setTaskDetails] = useState<{ [key: number]: Task[] }>({});
const [taskDetails, setTaskDetails] = useState<{ [key: number]: ITask[] }>({});

useEffect(() => {
const fetchDataForEachTaskType = async () => {
const promises = taskstypes.map(async (taskType) => { // Use taskType instead of task
const response = await fetch(`https://api.kharcoin.info/api/tasks/bytype/${taskType.TypeID}`);
const response = await fetch(`${API_CONFIG.API_BASE_URL}tasks/bytype/${taskType.TypeID}`);
const data = await response.json();
return { taskID: taskType.TypeID, details: data };
});
const results = await Promise.all(promises);
const formattedResults = results.reduce<{ [key: number]: Task[] }>((acc, curr) => {
const formattedResults = results.reduce<{ [key: number]: ITask[] }>((acc, curr) => {
acc[curr.taskID] = curr.details;
return acc;
}, {});
Expand All @@ -68,7 +55,7 @@ useEffect(() => {
<AppShell.Header>
<HeaderMenu
username={user?.username ?? 'KC'}
photoUrl={user?.photo_url ?? 'https://kc.rahomaskan.com/assets/images/kharcoin.jpg'}
photoUrl={user?.photo_url ?? `${API_CONFIG.ASSETS_URL}assets/images/kharcoin.jpg`}
/>
</AppShell.Header>
<AppShell.Main>
Expand Down Expand Up @@ -112,90 +99,6 @@ useEffect(() => {
</List>
</Blockquote>
))}


{/* <Blockquote
color="yellow"
cite="درآمد ویژه : کانال خرکوین"
icon={<IconInfoCircle />}
mt="xl"
>
<List
spacing="xs"
size="sm"
center
icon={
<ThemeIcon color="teal" size={24} radius="xl">
<IconBrandTelegram style={{ width: rem(16), height: rem(16) }} />
</ThemeIcon>
}
>
<List.Item>50 خرتومن : کانال خر کوین</List.Item>
</List>
</Blockquote>
<Blockquote
color="green"
cite="درآمد جدید : کانالهای تلگرام"
icon={<IconInfoCircle />}
mt="xl"
>
<List
spacing="xs"
size="sm"
center
icon={
<ThemeIcon color="teal" size={24} radius="xl">
<IconBrandTelegram style={{ width: rem(16), height: rem(16) }} />
</ThemeIcon>
}
>
<List.Item>10 خرتومن : گروه خر کوین</List.Item>
<List.Item>50 خرتومن : کانال نوبیتکس</List.Item>
<List.Item>30 خرتومن : کانال جاوید</List.Item>
</List>
</Blockquote>
<Blockquote
color="green"
cite="درآمد جدید : کانالهای یوتیوب"
icon={<IconInfoCircle />}
mt="xl"
>
<List
spacing="xs"
size="sm"
center
icon={
<ThemeIcon color="red" size={24} radius="xl">
<IconBrandYoutube style={{ width: rem(16), height: rem(16) }} />
</ThemeIcon>
}
>
<List.Item>10 خرتومن : کانال خران</List.Item>
<List.Item>10 خرتومن : کانال خران</List.Item>
<List.Item>10 خرتومن : کانال خران</List.Item>
<List.Item>10 خرتومن : کانال خران</List.Item>
</List>
</Blockquote>
<Blockquote color="red" cite="درآمدهای قبلی" icon={<IconInfoCircle />} mt="xl">
<List
spacing="xs"
size="sm"
center
icon={
<ThemeIcon color="red" size={24} radius="xl">
<IconBrandYoutube style={{ width: rem(16), height: rem(16) }} />
</ThemeIcon>
}
>
<List.Item>خربازی</List.Item>
<List.Item>خربازی</List.Item>
<List.Item>خربازی</List.Item>
<List.Item>خربازی</List.Item>
</List>
</Blockquote> */}
</Container>
</AppShell.Main>
<AppShell.Footer>
Expand Down

0 comments on commit 0a84f61

Please sign in to comment.