Skip to content

Commit

Permalink
fixes, minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Vishtar committed Jul 5, 2024
1 parent 0c0e543 commit efae2d9
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion frontend/src/types/TJettonData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ export type TJettonData = {
symbol: string
image?: string
pnlPercentage: number
chart: [timestamp: number, price: number][]
chart: [timestamp: number, price: number | string][]
lastBuyTime: number
}
7 changes: 4 additions & 3 deletions frontend/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ export const chartColor = (arr: TChartData[]) => {
}
}

export const formatDataToChart = (input: { chart: [number, number][] }) =>
export const formatDataToChart = (input: {
chart: [number, number | string][]
}) =>
input.chart.map(arr => {
const price = arr[1] > 0.01 ? Number(arr[1].toFixed(2)) : arr[1].toFixed(20)
return {
date: timeConverter(arr[0]),
Price: price,
Price: arr[1],
}
})

Expand Down
11 changes: 5 additions & 6 deletions src/services/bot/i18n/en.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getEmojiForWallet } from '../../../utils'
import { jettonNamesWithSpecialCharacters } from '../constants'
import type { TI18nLocalization } from './types'

export const en: TI18nLocalization = {
Expand All @@ -16,20 +17,18 @@ If you have any questions, feel free to ask in the [chat](https://t.me/+mwwKEfMA
Send an address you want to watch or connect your own 👇
`,
youNoLongerHaveJetton: (ticker: string) =>
`You no longer hold $${ticker}, notifications for this jetton have been stopped.`,
`👋 You no longer hold $${jettonNamesWithSpecialCharacters[ticker] || ticker.toUpperCase()}, notifications for this jetton have been stopped.`,
detectedNewJetton: (ticker: string) =>
`🆕 New jetton found: $${ticker}. I will notify you when the price moves up or down by 2x`,
`💎 New jetton found: $${jettonNamesWithSpecialCharacters[ticker] || ticker.toUpperCase()}. I will notify you when the price moves up or down by 2x.`,
notification: {
x2: (ticker: string, wallet: string, price: number | string) => `
📈 $${ticker} made 2x! Wallet:
📈 $${jettonNamesWithSpecialCharacters[ticker] || ticker.toUpperCase()} made 2x! Wallet:
${getEmojiForWallet(wallet)} \`${wallet}\`
💵 Current price: $${price}
`,
x05: (ticker: string, wallet: string, price: number | string) => `
📉 $${ticker} has dropped in price by half from the moment you purchased it. Wallet:
📉 $${jettonNamesWithSpecialCharacters[ticker] || ticker.toUpperCase()} has dropped in price by half. Wallet:
${getEmojiForWallet(wallet)} \`${wallet}\`
💵 Current price: $${price}
`,
},
Expand Down
10 changes: 4 additions & 6 deletions src/services/bot/i18n/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,17 @@ export const ru = {
Отправьте ваш адрес или привяжите кошелёк 👇
`,
youNoLongerHaveJetton: (ticker: string) =>
`Вы больше не холдите $${jettonNamesWithSpecialCharacters[ticker] || ticker}, уведомления для этого жетона остановлены`,
`👋 Вы больше не холдите $${jettonNamesWithSpecialCharacters[ticker] || ticker.toUpperCase()}, уведомления для этого жетона остановлены.`,
detectedNewJetton: (ticker: string) =>
`🆕 Обнаружен новый жетон $${jettonNamesWithSpecialCharacters[ticker] || ticker}. Вы получите уведомление, когда его цена сделает 2x или упадёт вдвое`,
`💎 Обнаружен новый жетон $${jettonNamesWithSpecialCharacters[ticker] || ticker.toUpperCase()}. Вы получите уведомление, когда его цена сделает 2x или упадёт вдвое.`,
notification: {
x2: (ticker: string, wallet: string, price: number | string) => `
📈 Жетон $${jettonNamesWithSpecialCharacters[ticker] || ticker} сделал x2! Адрес:
📈 Жетон $${jettonNamesWithSpecialCharacters[ticker] || ticker.toUpperCase()} сделал x2! Адрес:
${getEmojiForWallet(wallet)} \`${wallet}\`
💵 Актуальная цена: $${price}`,
x05: (ticker: string, wallet: string, price: number | string) => `
📉 Жетон $${jettonNamesWithSpecialCharacters[ticker] || ticker} подешевел вдвое. Адрес:
📉 Жетон $${jettonNamesWithSpecialCharacters[ticker] || ticker.toUpperCase()} подешевел вдвое. Адрес:
${getEmojiForWallet(wallet)} \`${wallet}\`
💵 Актуальная цена: $${price}`,
},
newWalletConnected: (address: string, tickers: string) => `
Expand Down
1 change: 1 addition & 0 deletions src/services/bot/types/TNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type TBaseNotification = {
export type TJettonRateNotification = TBaseNotification & {
price: number
timestamp: number
decimals: number
action: ENotificationType.UP | ENotificationType.DOWN
}
export type TNewJettonNotification = Omit<TBaseNotification, 'jettonId'> & {
Expand Down
2 changes: 2 additions & 0 deletions src/services/bot/utils/getNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export async function* getNotifications(
if (!newestTransactionInDb) {
continue
}
const decimals = addressJettonsFromChainObj[jetton.token].decimals
delete addressJettonsFromChainObj[jetton.token]
const timestamp = Math.floor(Date.now() / 1000)
const price = await getPrice(jetton.token)
Expand All @@ -71,6 +72,7 @@ export async function* getNotifications(
jettonId: jetton.id,
symbol: jetton.ticker,
price: price,
decimals,
action: rateDirection,
timestamp,
}
Expand Down
4 changes: 2 additions & 2 deletions src/services/bot/utils/handleNotification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ export const handleNotification = async (bot: Telegraf<TTelegrafContext>) => {
? i18n(userSettings?.languageCode).message.notification.x2(
notification.symbol,
walletUserFriendly,
normalizePrice(notification.price),
normalizePrice(notification.price, notification.decimals),
)
: i18n(userSettings?.languageCode).message.notification.x05(
notification.symbol,
walletUserFriendly,
normalizePrice(notification.price),
normalizePrice(notification.price, notification.decimals),
)
await bot.telegram.sendMessage(notification.userId, text, { parse_mode: 'Markdown' })
console.log('rates', notification.price.toString())
Expand Down
2 changes: 1 addition & 1 deletion src/utils/getDbConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const getDbConnection = async () => {
})
}
const connection = drizzle(db, {
logger: true,
// logger: true,
})

// @ts-expect-error object restructuring didn't work that easy for types
Expand Down
4 changes: 2 additions & 2 deletions src/utils/normalizePrice.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const normalizePrice = (price: number) =>
price > 0.01 ? Number(price.toFixed(2)) : price.toFixed(20)
export const normalizePrice = (price: number, decimals?: number) =>
price > 0.01 ? Number(price.toFixed(2)) : price.toFixed(decimals || 20)
5 changes: 3 additions & 2 deletions src/utils/parseTxData/api.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { getAddressPnL, getChart, getJettonsByAddress } from '.'
import { normalizePrice } from '..'

export const api = async (address: string) => {
const jettons = await getJettonsByAddress(address)
const res: Record<
string,
(typeof jettons)[number] & {
pnlPercentage?: number
chart: [timestamp: number, price: number][]
chart: [timestamp: number, price: number | string][]
lastBuyTime: number
}
> = {}
Expand All @@ -20,7 +21,7 @@ export const api = async (address: string) => {
res[jettonInfo.symbol] = {
...jettonInfo,
pnlPercentage,
chart: (slicedChart.length >= 2 ? slicedChart : chart).reverse(),
chart: (slicedChart.length >= 2 ? slicedChart : chart).reverse().map(entity => [entity[0], normalizePrice(entity[1], jettonInfo.decimals)]),
lastBuyTime,
}
}
Expand Down

0 comments on commit efae2d9

Please sign in to comment.