-
Notifications
You must be signed in to change notification settings - Fork 59
fix: bot offline #642
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
fix: bot offline #642
Conversation
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.OpenSSF Scorecard
Scanned Manifest Files |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
|
Claude finished @mayuran-deriv's task in 2m 52s —— View job Code Review Update ✅SummaryThis PR has been updated since the last review and the critical notification timing issue has been fixed! The notification now displays only after all validation checks pass, right before the bot starts running. Three commits in this PR:
What Changed Since Last Review✅ FIXED: Notification timing issue (previously critical)
Current State Analysis🟡 Medium Priority Issues1. URL parsing on every render - performance concern (src/components/bot-stopped.tsx:24-26) const urlParams = new URLSearchParams(window.location.search);
const account_param = urlParams.get('account');
const is_virtual = client?.is_virtual || account_param === 'demo' || false;Issue: Component is wrapped in Impact: Minor performance overhead from repeated URL parsing. Recommendation: Memoize URL parsing to avoid unnecessary work: const is_virtual = useMemo(() => {
const urlParams = new URLSearchParams(window.location.search);
const account_param = urlParams.get('account');
return client?.is_virtual || account_param === 'demo';
}, [client?.is_virtual]); // Only re-parse when client.is_virtual changesNote: 2. Missing fallback for real accounts without currency (src/components/bot-stopped.tsx:55-58) } else if (currency) {
// For real accounts, set the account parameter to the currency
url.searchParams.set('account', currency);
}Issue: If Impact: Real accounts without currency might not route correctly to reports page. Recommendation: Add defensive handling: } else if (currency) {
url.searchParams.set('account', currency);
} else {
// Real account should have currency - log warning for debugging
console.warn('[BotStopped] Real account missing currency, reports may not load correctly');
}🟢 Low Priority / Code Quality3. Redundant boolean coercion (src/components/bot-stopped.tsx:26) const is_virtual = client?.is_virtual || account_param === 'demo' || false;Issue: The Fix: const is_virtual = client?.is_virtual || account_param === 'demo';4. Unnecessary curly braces for static string (src/components/bot-stopped.tsx:43) className={'dc-dialog bot-stopped-dialog'}Fix: className="dc-dialog bot-stopped-dialog"🔒 Security Review✅ No security issues detected
🧪 Test Coverage
Recommended test scenarios:
📈 Performance ReviewGood practices:
Could improve:
✨ What's Good
📋 Final RecommendationsBefore merging (Optional improvements):
Future improvements:
🎯 Overall AssessmentExcellent work addressing the critical review feedback! The notification timing fix is exactly what was needed. The PR improves offline handling with:
The remaining issues are minor (performance optimization, defensive code, style). The core functionality is solid and the critical bug has been fixed. Status: ✅ Ready to merge (with optional improvements to consider) The critical issue from the previous review has been resolved. Remaining suggestions are performance optimizations and code quality improvements that can be addressed in follow-up PRs if desired. |
|
Claude finished @mayuran-deriv's task in 2m 34s —— View job Code Review Complete ✅SummaryThis PR improves the bot offline handling with three key changes:
Overall, this is a solid improvement that enhances user experience during offline/connection issues. The code is well-structured and the previous critical issue (notification timing) has been addressed. 🔴 High Priority IssuesNone identified - No blocking or critical issues found. 🟡 Medium Priority Issues1. URL parsing on every render - Performance concernLocation: const urlParams = new URLSearchParams(window.location.search);
const account_param = urlParams.get('account');
const is_virtual = client?.is_virtual || account_param === 'demo' || false;Issue: The component is wrapped in Impact: Minor performance overhead from repeated Recommendation: Use import { useMemo } from 'react';
const is_virtual = useMemo(() => {
const urlParams = new URLSearchParams(window.location.search);
const account_param = urlParams.get('account');
return client?.is_virtual || account_param === 'demo';
}, [client?.is_virtual]);2. Missing error handling for accounts without currencyLocation: } else if (currency) {
// For real accounts, set the account parameter to the currency
url.searchParams.set('account', currency);
}Issue: If Impact: Real accounts without currency will navigate to reports without an account parameter, potentially showing incorrect or no data. Recommendation: Add defensive logging to track this edge case: } else if (currency) {
url.searchParams.set('account', currency);
} else {
// Real account without currency - this shouldn't happen but log for debugging
console.warn('[BotStopped] Real account missing currency, reports may not load correctly');
}3. Potential stale closure with URL parameter checkLocation: Issue: The account parameter in the URL is read once when the component renders, but if the user switches accounts (which updates the URL), the component may not re-render because Impact: The Context: Looking at the code pattern, it seems account switches likely cause full page reloads or proper re-renders, but this isn't guaranteed from this code alone. Recommendation: Consider whether Alternative approach: Rely solely on 🟢 Low Priority / Code Quality4. Redundant boolean coercionLocation: const is_virtual = client?.is_virtual || account_param === 'demo' || false;Issue: The Fix: const is_virtual = client?.is_virtual || account_param === 'demo';5. Unnecessary curly braces for static stringLocation: className={'dc-dialog bot-stopped-dialog'}Fix: className="dc-dialog bot-stopped-dialog"6. Redundant variable assignmentLocation: const getCurrency = client?.getCurrency;
const currency = getCurrency?.();Issue: The intermediate Better approach: const currency = client?.getCurrency();7. Inconsistent message capitalizationLocation: Observation: The new message "Your connection to the server was lost, all trades have been settled." uses lowercase "all" after a comma. While grammatically acceptable, consider: <Localize i18n_default_text='Your connection to the server was lost. All trades have been settled. Check the Reports page for final results.' />This makes each sentence independent and clearer. (This is subjective, so low priority.) 🔒 Security Review✅ No security issues detected
🧪 Test Coverage
Recommended test scenarios: BotStopped Component Testsdescribe('BotStopped', () => {
it('shows offline message when internet disconnected and bot running', () => {});
it('shows connection interrupted message for internal websocket issues', () => {});
it('constructs demo account URL with account=demo parameter', () => {});
it('constructs real account URL with account=currency parameter', () => {});
it('handles real account without currency gracefully', () => {});
it('reloads page on close button click', () => {});
it('navigates to reports page on View Report button', () => {});
it('does not show dialog when both online and websocket initialized', () => {});
it('handles keyboard navigation (Enter key on close)', () => {});
});RunPanelStore Testsdescribe('RunPanelStore.onRunButtonClick', () => {
it('shows keep_screen_alive notification only after validation passes', () => {});
it('does not show notification when user not logged in', () => {});
it('does not show notification when self-exclusion blocks bot', () => {});
it('does not show notification when strategy validation fails', () => {});
it('shows notification immediately before bot starts running', () => {});
});URL Construction Edge Cases
📈 Performance Review✅ Good practices:
🟡 Could improve:
✨ What's Good About This PR
📋 Recommendations SummaryBefore merging (optional improvements):
Future improvements:
🎯 Overall AssessmentStatus: ✅ Ready to merge with minor improvements recommended This PR successfully addresses the bot offline handling with improved UX and correct notification timing. The critical notification timing issue from the previous review has been properly fixed. The remaining issues are minor optimization opportunities and code quality improvements. What works well:
What could be improved:
The medium priority items are worth addressing but not blockers. The PR can merge as-is, with these improvements tackled in a follow-up if desired. |
|
Preview Link: https://mayuran-bot-offline.bot-65f.pages.dev
|
No description provided.