Skip to content

Commit

Permalink
feat: Connect KharCoin to Ton network And Save Wallet to backend data…
Browse files Browse the repository at this point in the history
…base
  • Loading branch information
Javid Momeni committed Jun 30, 2024
1 parent e47f967 commit 318a7a4
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 219 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@mantine/core": "7.10.1",
"@mantine/hooks": "7.10.1",
"@tabler/icons-react": "^3.5.0",
"@tonconnect/ui-react": "^2.0.5",
"@twa-dev/sdk": "^7.0.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
Expand Down
4 changes: 4 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import { theme } from './theme';
import React from 'react';
import FooterMenu from './components/FooterMenu/FooterMenu';
import HeaderMenu from './components/HeaderMenu/HeaderMenu';
import { TonConnectUIProvider } from '@tonconnect/ui-react';



export default function App() {
// const user = WebApp.initDataUnsafe.user;
// const usertgid = user?.id;
return (
<React.StrictMode>
<TonConnectUIProvider manifestUrl="https://kc.rahomaskan.com/tonconnect-manifest.json">
<DirectionProvider initialDirection="rtl">
<MantineProvider
theme={theme}
Expand All @@ -38,6 +41,7 @@ export default function App() {
<Router />
</MantineProvider>
</DirectionProvider>
</TonConnectUIProvider>
</React.StrictMode>
);
}
2 changes: 2 additions & 0 deletions src/components/HeaderMenu/HeaderMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Avatar, Container, Flex, UnstyledButton, rem } from '@mantine/core';
import { IconAt, IconUserShare, IconWallet } from '@tabler/icons-react';
import { TonConnectButton } from '@tonconnect/ui-react';

function HeaderMenu({ username, photoUrl }: { username: string; photoUrl: string }) {
return (
Expand Down Expand Up @@ -34,6 +35,7 @@ function HeaderMenu({ username, photoUrl }: { username: string; photoUrl: string
style={{ textAlign: 'center', color: 'white' }}
>
<IconWallet style={{ width: rem(24), height: rem(24) }} />
<TonConnectButton />
</UnstyledButton>
</Flex>
</Container>
Expand Down
53 changes: 45 additions & 8 deletions src/pages/Boosts.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,37 @@ import HeaderMenu from '../components/HeaderMenu/HeaderMenu';
import { Welcome } from '../components/Welcome/Welcome';
import { AppShell, Container, SimpleGrid, Title, Text, Box, Button } from '@mantine/core';
import WebApp from '@twa-dev/sdk';
import { useTonAddress } from '@tonconnect/ui-react';
import { useEffect } from 'react';

export function BoostsPage() {
const user = WebApp.initDataUnsafe.user;
const usertgid = user?.id;
const userFriendlyAddress = useTonAddress();

useEffect(() => {
if (userFriendlyAddress) {
fetch('https://kharcoin.com/api/savewallet', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
usertgid,
userFriendlyAddress,
}),
})
.then(response => response.json())
.then(data => {
console.log('Success:', data);
// Handle success, e.g., show a message to the user
})
.catch((error) => {
console.error('Error:', error);
// Handle errors, e.g., show an error message to the user
});
}
}, [usertgid]);
return (
<Container size={'xs'}>
<AppShell
Expand All @@ -19,13 +47,22 @@ export function BoostsPage() {
<AppShell.Main>
<Container>
<Title order={1}>تقویت</Title>
{userFriendlyAddress && (
<>
{userFriendlyAddress}
<div>
<span>کیف پول شما برای بازی <br /> {userFriendlyAddress} <br /> است</span>
</div>
</>
)}

<Box pt={'lg'} mt={'lg'} ta={'center'}>
<Button variant="filled" color="yellow" size="xl" radius="md" ta={'center'}>
خر کوین
</Button>
</Box>
<Button variant="filled" color="yellow" size="xl" radius="md" ta={'center'}>
خر کوین
</Button>
</Box>
<SimpleGrid cols={2} spacing="xl" verticalSpacing="xl" pt={'lg'} mt={'lg'}>
<Box p={'lg'} bg={'gray'}>
<Box p={'lg'} bg={'gray'}>
<Text
ta={'center'}
size="xl"
Expand All @@ -35,8 +72,8 @@ export function BoostsPage() {
>
شــیــر خـــــر
</Text>
</Box>
<Box p={'lg'} bg={'gray'}>
</Box>
<Box p={'lg'} bg={'gray'}>
<Text
ta={'center'}
size="xl"
Expand Down Expand Up @@ -78,4 +115,4 @@ export function BoostsPage() {
</AppShell>
</Container>
);
}
}
Loading

0 comments on commit 318a7a4

Please sign in to comment.