-
Notifications
You must be signed in to change notification settings - Fork 0
Add Shopping tab, fiat rate fallback, and performance optimizations #391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nghiacc
wants to merge
13
commits into
master
Choose a base branch
from
feature/shopping-fiat-fallback-optimization
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
61c541e
feat: Shopping tab, fiat rate fallback, and performance optimization
nghiacc 968793a
fix: Code formatting and additional refinements
nghiacc bd02191
fix: Reorder imports in useOfferPrice hook
nghiacc 989474e
refactor: Extract rate transformation logic into reusable utility fun…
nghiacc ae060b2
docs: Add comprehensive documentation for rate transformation refacto…
nghiacc 1757960
chore: Apply Prettier formatting and finalize documentation
nghiacc b959b17
fix: Address AI review comments
nghiacc c289abc
fix: Handle legacy Goods & Services offers without price
nghiacc 7d884ec
fix: Address three new AI review comments
nghiacc 37b902e
refactor: Remove client-side Telegram alert code
nghiacc 21da5d2
fix: Add null check for coinPayment in getCoinRate
nghiacc 3b1a112
feat: Add unified fiat rate error banner across all pages
nghiacc 0011299
refactor: Clean up PlaceAnOrderModal component styling
nghiacc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
apps/telegram-ecash-escrow/src/app/api/alerts/telegram/route.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| import { NextRequest, NextResponse } from 'next/server'; | ||
|
|
||
| /** | ||
| * Send critical alerts to Telegram channel or group | ||
| * POST /api/alerts/telegram | ||
| * | ||
| * Works with both: | ||
| * - Telegram Channels (one-way broadcast) | ||
| * - Telegram Groups (team discussion) | ||
| * | ||
| * Body: { | ||
| * message: string, | ||
| * severity: 'critical' | 'error' | 'warning' | 'info', | ||
| * service: string, | ||
| * details?: any | ||
| * } | ||
| */ | ||
| export async function POST(request: NextRequest) { | ||
| try { | ||
| const body = await request.json(); | ||
| const { message, severity = 'error', service, details } = body; | ||
|
|
||
| // Get Telegram configuration from environment | ||
| const botToken = process.env.BOT_TOKEN; | ||
| const alertChannelId = process.env.TELEGRAM_ALERT_CHANNEL_ID; | ||
|
|
||
| if (!botToken) { | ||
| console.error('BOT_TOKEN not configured in environment variables'); | ||
| return NextResponse.json({ error: 'Telegram bot token not configured' }, { status: 500 }); | ||
| } | ||
|
|
||
| if (!alertChannelId) { | ||
| console.warn('TELEGRAM_ALERT_CHANNEL_ID not configured - alert not sent'); | ||
| return NextResponse.json({ warning: 'Alert channel/group not configured', messageSent: false }, { status: 200 }); | ||
| } | ||
|
|
||
| // Format the message with severity emoji | ||
| const severityEmojis = { | ||
| critical: '🚨', | ||
| error: '❌', | ||
| warning: '⚠️', | ||
| info: 'ℹ️' | ||
| }; | ||
|
|
||
| const emoji = severityEmojis[severity as keyof typeof severityEmojis] || '❌'; | ||
|
|
||
| // Build the alert message | ||
| let alertMessage = `${emoji} *${severity.toUpperCase()}*: ${service}\n\n`; | ||
| alertMessage += `${message}\n\n`; | ||
|
|
||
| if (details) { | ||
| alertMessage += `*Details:*\n\`\`\`\n${JSON.stringify(details, null, 2)}\n\`\`\`\n\n`; | ||
| } | ||
|
|
||
| alertMessage += `*Time:* ${new Date().toISOString()}\n`; | ||
| alertMessage += `*Environment:* ${process.env.NODE_ENV || 'unknown'}`; | ||
|
|
||
| // Send to Telegram using Bot API | ||
| const telegramApiUrl = `https://api.telegram.org/bot${botToken}/sendMessage`; | ||
|
|
||
| const telegramResponse = await fetch(telegramApiUrl, { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': 'application/json' | ||
| }, | ||
| body: JSON.stringify({ | ||
| chat_id: alertChannelId, | ||
| text: alertMessage, | ||
| parse_mode: 'Markdown', | ||
| disable_web_page_preview: true | ||
| }) | ||
| }); | ||
|
|
||
| const telegramData = await telegramResponse.json(); | ||
|
|
||
| if (!telegramResponse.ok) { | ||
| console.error('Failed to send Telegram alert:', telegramData); | ||
| return NextResponse.json( | ||
| { | ||
| error: 'Failed to send Telegram alert', | ||
| details: telegramData | ||
| }, | ||
| { status: 500 } | ||
| ); | ||
| } | ||
|
|
||
| console.log('Telegram alert sent successfully:', { | ||
| service, | ||
| severity, | ||
| messageId: telegramData.result?.message_id | ||
| }); | ||
|
|
||
| return NextResponse.json({ | ||
| success: true, | ||
| messageSent: true, | ||
| messageId: telegramData.result?.message_id | ||
| }); | ||
| } catch (error) { | ||
| console.error('Error sending Telegram alert:', error); | ||
| return NextResponse.json( | ||
| { | ||
| error: 'Internal server error', | ||
| message: error instanceof Error ? error.message : 'Unknown error' | ||
| }, | ||
| { status: 500 } | ||
| ); | ||
| } | ||
| } | ||
98 changes: 98 additions & 0 deletions
98
apps/telegram-ecash-escrow/src/app/api/telegram/get-chat-ids/route.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import { NextRequest, NextResponse } from 'next/server'; | ||
|
|
||
| /** | ||
| * Helper endpoint to get Telegram chat IDs for setup | ||
| * GET /api/telegram/get-chat-ids | ||
| * | ||
| * This is a temporary endpoint to help you find your group/channel ID | ||
| * Remove this file after you've configured TELEGRAM_ALERT_CHANNEL_ID | ||
| */ | ||
| export async function GET(request: NextRequest) { | ||
| const botToken = process.env.BOT_TOKEN; | ||
|
|
||
| if (!botToken) { | ||
| return NextResponse.json( | ||
| { | ||
| error: 'BOT_TOKEN not configured', | ||
| message: 'Please set BOT_TOKEN in your .env file' | ||
| }, | ||
| { status: 500 } | ||
| ); | ||
| } | ||
nghiacc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| try { | ||
| // Get recent updates from Telegram | ||
| const response = await fetch(`https://api.telegram.org/bot${botToken}/getUpdates`, { cache: 'no-store' }); | ||
|
|
||
| if (!response.ok) { | ||
| throw new Error(`Telegram API returned ${response.status}`); | ||
| } | ||
|
|
||
| const data = await response.json(); | ||
|
|
||
| if (!data.ok) { | ||
| return NextResponse.json( | ||
| { | ||
| error: 'Telegram API error', | ||
| details: data | ||
| }, | ||
| { status: 500 } | ||
| ); | ||
| } | ||
|
|
||
| // Extract chat information from updates | ||
| const chats = new Map(); | ||
|
|
||
| data.result.forEach((update: any) => { | ||
| const chat = update.message?.chat || update.my_chat_member?.chat; | ||
| if (chat) { | ||
| chats.set(chat.id, { | ||
| id: chat.id, | ||
| title: chat.title || chat.first_name || 'Unknown', | ||
| type: chat.type, | ||
| username: chat.username | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| const chatList = Array.from(chats.values()); | ||
|
|
||
| // Separate by type | ||
| const groups = chatList.filter(c => c.type === 'group' || c.type === 'supergroup'); | ||
| const channels = chatList.filter(c => c.type === 'channel'); | ||
| const privateChats = chatList.filter(c => c.type === 'private'); | ||
|
|
||
| return NextResponse.json({ | ||
| success: true, | ||
| message: 'Chat IDs found! Copy the ID you need and add it to TELEGRAM_ALERT_CHANNEL_ID in your .env file', | ||
| groups: groups.length > 0 ? groups : undefined, | ||
| channels: channels.length > 0 ? channels : undefined, | ||
| privateChats: privateChats.length > 0 ? privateChats : undefined, | ||
| allChats: chatList, | ||
| instructions: { | ||
| step1: 'Find your group/channel in the list above', | ||
| step2: 'Copy the "id" value (should be negative, e.g., -123456789)', | ||
| step3: 'Add to .env: TELEGRAM_ALERT_CHANNEL_ID="-123456789"', | ||
| step4: 'Restart your app', | ||
| step5: 'DELETE THIS FILE (src/app/api/telegram/get-chat-ids/route.ts) for security' | ||
| }, | ||
| troubleshooting: { | ||
| noChatsSeen: "If you don't see your group/channel:", | ||
| solution1: '1. Make sure your bot is added to the group/channel', | ||
| solution2: '2. Make sure bot is an admin in the group/channel', | ||
| solution3: '3. Send a message in the group (e.g., "test")', | ||
| solution4: '4. Refresh this page' | ||
| } | ||
| }); | ||
| } catch (error) { | ||
| console.error('Error fetching Telegram updates:', error); | ||
| return NextResponse.json( | ||
| { | ||
| error: 'Failed to fetch updates', | ||
| message: error instanceof Error ? error.message : 'Unknown error', | ||
| details: 'Make sure BOT_TOKEN is correct in .env' | ||
| }, | ||
| { status: 500 } | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.