Skip to content

Commit

Permalink
Merge pull request #4 from klntsky/sqlite2pglite
Browse files Browse the repository at this point in the history
SQLite -> PGLite, tests, generators
  • Loading branch information
Vishtar authored Jun 27, 2024
2 parents 830cec5 + ddb27d5 commit 23719d1
Show file tree
Hide file tree
Showing 104 changed files with 2,661 additions and 1,590 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ TELEGRAM_BOT_WEBHOOK_PATH=
TELEGRAM_BOT_WEB_APP=
EXPRESS_PORT=
TONAPI_TOKEN=
NOTIFICATION_RATE_UP=2
NOTIFICATION_RATE_DOWN=0.5
28 changes: 28 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Run tests

on:
pull_request:
types: [opened, synchronize]

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [22.x]

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: npm install tsx

- name: Run tests
run: npx tsx --test --test-reporter spec '**/tests/**/*.ts'
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
/logs/
/.vscode/
/public/
main.db
/data/
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"htmlWhitespaceSensitivity": "ignore",
"printWidth": 100,
"arrowParens": "avoid",
"jsxBracketSameLine": false,
"bracketSameLine": false,
"singleAttributePerLine": true
}
}
Expand Down
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,33 @@
# ton_2x
# Ton 2x Bot

Twice as simple. Trading tools for everyone!

## Description

Ton 2x Bot simplifies trading and helps users save money during the mass adoption era of cryptocurrency.
It proactively notifies users of their gains via Telegram, making it easy to manage owned tokens and seize good exit opportunities.

## Features

- **Simplistic Mini App**: Designed for inexperienced users new to DeFi and those with limited capital who trade for fun.
- **Telegram Notifications**: Automatic setup for price alerts, ensuring users stay informed without needing complicated instruments.
- **Profit and Loss Tracker**: Tracks the price since the last purchase and notifies users when their tokens achieve a 2x gain or 0.5x loss, helping them make a profit and avoid losses.

## How It Works

1. Link your wallet to Ton 2x Bot.
2. Receive proactive notifications in Telegram about your token gains.
3. Make informed trading decisions with minimal effort.

## Links

- [Bot](https://t.me/ton_2x_bot)
- [Announcements](https://t.me/ton_2x_en)
- [Announcements in Russian](https://t.me/ton_2x_ru)
- [DoraHack: Ton 2x Bot](https://dorahacks.io/buidl/13230)

## Tests

All tests are located in the [tests](./tests) directory. Currently, there is one unit test for the main business function:

- [tests/getNotifications.test.ts](./tests/getNotifications.test.ts)
14 changes: 7 additions & 7 deletions drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { defineConfig } from 'drizzle-kit';

export default defineConfig({
schema: './src/db/schema/index.ts',
out: './src/db/migrations',
dialect: 'sqlite',
dbCredentials: {
url: './main.db',
},
});
schema: './src/db/schema/index.ts',
out: './src/db/migrations',
dialect: 'postgresql',
dbCredentials: {
url: 'file://data/postgresql',
},
});
4 changes: 4 additions & 0 deletions frontend/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@ module.exports = {
'react/react-in-jsx-scope': 'off',
'prettier/prettier': ['warn'],
"@typescript-eslint/no-unused-vars": ['warn'],
semi: [
'warn',
'never'
],
},
}
2 changes: 1 addition & 1 deletion frontend/.prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"semi": true,
"semi": false,
"singleQuote": true,
"jsxSingleQuote": false,
"arrowParens": "avoid"
Expand Down
83 changes: 39 additions & 44 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,75 +1,70 @@
import { useEffect } from 'react';
import { Chart } from './Components/Chart';
import { useTonConnectModal, useTonConnectUI } from '@tonconnect/ui-react';
import { useEffect } from 'react'
import { useTonConnectModal, useTonConnectUI } from '@tonconnect/ui-react'
import {
bindMiniAppCSSVars,
bindThemeParamsCSSVars,
useMiniApp,
useThemeParams,
} from '@tma.js/sdk-react';
import { retrieveLaunchParams } from '@tma.js/sdk';
import { usePostData } from './Hooks';
import { useParams } from 'react-router-dom';
} from '@tma.js/sdk-react'
import { retrieveLaunchParams } from '@tma.js/sdk'

function App() {
const query = useParams();
const modal = useTonConnectModal();
const [tonConnectUI] = useTonConnectUI();
const themeParams = useThemeParams();
const miniApp = useMiniApp();
const { mutate } = usePostData();
miniApp.ready();
import { Chart } from './components/Chart'
import { usePostData } from './hooks'

export const App = () => {
const launchParams = retrieveLaunchParams()
if (!launchParams.initData?.user?.id) {
throw new Error(`There is no user id in launchParams`)
}
const modal = useTonConnectModal()
const [tonConnectUI] = useTonConnectUI()
const themeParams = useThemeParams()
const miniApp = useMiniApp()
const { mutate } = usePostData()
miniApp.ready()

useEffect(() => {
return bindMiniAppCSSVars(miniApp, themeParams);
}, [miniApp, themeParams]);
return bindMiniAppCSSVars(miniApp, themeParams)
}, [miniApp, themeParams])

useEffect(() => {
return bindThemeParamsCSSVars(themeParams);
}, [themeParams]);
return bindThemeParamsCSSVars(themeParams)
}, [themeParams])

// useEffect(() => {
// if (modal.state.status === 'closed') {
// if (!query.address) {
// modal.open();
// }
// } else {
// if (query.address) {
// modal.close();
// }
// if (modal.state.status === 'closed' && !tonConnectUI.account?.address) {
// modal.open();
// }
// }, [modal, modal.state.status, query.address]);
// }, [modal.state.status]);

useEffect(() => {
if (!query.address) {
modal.open();
}
modal.open()

tonConnectUI.onStatusChange(wallet => {
const myURL = new URL(window.location.href);
const launchParams = retrieveLaunchParams();
const launchParams = retrieveLaunchParams()
console.log(123, {
id: launchParams.initData?.user?.id,
address: wallet?.account.address,
});
if (query.address || !wallet?.account.address) return;
myURL.searchParams.set('address', wallet.account.address);
window.location.href = myURL.toString();
})
if (!wallet?.account.address) return
mutate({
url: '/postUserWallet',
data: {
id: launchParams.initData?.user?.id,
address: wallet?.account.address,
},
});
});
}, []);
})
})
}, [])

return (
<div className="App">
<Chart />
{tonConnectUI.account?.address ? (
<Chart
address={tonConnectUI.account.address}
userId={launchParams.initData.user.id}
/>
) : null}
</div>
);
)
}

export default App;
4 changes: 0 additions & 4 deletions frontend/src/Components/Loader/Loader.tsx

This file was deleted.

1 change: 0 additions & 1 deletion frontend/src/Hooks/index.ts

This file was deleted.

25 changes: 0 additions & 25 deletions frontend/src/Hooks/useFetchRates.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
import { AreaChart, Badge, BadgeDelta, Card, Flex } from '@tremor/react';
import { badgeType, chartColor, formatDataToChart } from '../utils';
import { useFetchRates } from '../Hooks/useFetchRates';
import Loader from './Loader/Loader';
import { useTranslation } from 'react-i18next';
import { AreaChart, Badge, BadgeDelta, Card, Flex } from '@tremor/react'
import { badgeType, chartColor, formatDataToChart } from '../utils'
import { useFetchRates } from '../hooks/useFetchRates'
import { Loader } from './Loader'
import { useTranslation } from 'react-i18next'

// const valueFormatter = function (number: number) {
// return '$' + new Intl.NumberFormat('us').format(number).toString();
// };

export function Chart() {
const { t } = useTranslation();
const { data, isLoading } = useFetchRates();
export const Chart = (props: { address: string; userId: number }) => {
const { t } = useTranslation()
const { data, isLoading } = useFetchRates(props)

if (isLoading) {
return (
<Flex justifyContent="center" alignItems="center" className="h-screen">
<Loader />
</Flex>
);
)
}
if (!data?.length) {
return (
<Flex justifyContent="center" alignItems="center" className="h-screen">
<h2 className="text-2xl text-slate-600">{t('label.noJettons')}</h2>
</Flex>
);
)
}

if (data) {
Expand All @@ -45,7 +41,7 @@ export function Chart() {
<div className="w-[2rem]">
<img
src={obj.image}
alt="..."
alt={obj.symbol}
className="shadow rounded-full max-w-full h-auto align-middle border-none"
/>
</div>
Expand Down Expand Up @@ -91,6 +87,6 @@ export function Chart() {
))
: null}
</div>
);
)
}
}
5 changes: 5 additions & 0 deletions frontend/src/components/Loader/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import s from './styles.module.css'

export const Loader = () => {
return <div className={s.loader}></div>
}
Loading

0 comments on commit 23719d1

Please sign in to comment.