Skip to content

Conversation

@vinu-deriv
Copy link
Collaborator

Description

(Brief description of what this PR does)

Related Issue: Fixes #(issue)

Type of Change

  • πŸ› Bug fix
  • ✨ New feature
  • πŸ’₯ Breaking change
  • πŸ”§ Refactoring
  • πŸ“š Documentation
  • πŸ§ͺ Tests

Testing

  • Unit tests pass
  • Manual testing completed
  • No console errors
  • No test needed

Screenshots

(Add screenshots if UI changes)

Before:

After:

@github-actions
Copy link
Contributor

github-actions bot commented Nov 5, 2025

Claude Code is working…

I'll analyze this and get back to you.

View job run

@github-actions
Copy link
Contributor

github-actions bot commented Nov 7, 2025

Claude finished @vinu-deriv's task β€”β€” View job


Code Review Complete βœ…

I've reviewed the latest changes to this PR. Great work addressing the previous feedback! The duplicate line issue has been fixed, comprehensive test coverage has been added, and the typo has been corrected. Here's my detailed analysis:


Summary of Changes Since Last Review

Fixes Applied:

  • βœ… Duplicate line removed - The duplicate check at line 369 has been eliminated
  • βœ… Typo fixed - MARKET_MENUE_MODAL_TOGGLE β†’ MARKET_MENU_MODAL_TOGGLE
  • βœ… Comprehensive test coverage added - All new event types now have tests

Latest Commits:

  • 7bf053d - Updated smartcharts-champion package
  • 919a6f3 - Fixed review comments
  • 2e17ee7 - Updated charts package for tracking events
  • a447a70 - Added missing chart events

Current Status: Near Perfect! 🎯

The implementation is now in excellent shape. However, there's still one remaining issue from the previous review that should be addressed:

🟑 Medium Priority Issue

Missing Validation for Drawing Tools Operations

Location: packages/trader/src/Stores/Modules/Trading/Helpers/chart.ts:285-332

Issue: The getDrawingToolsFormAnalyticsData function doesn't validate that drawing_tool_name exists before tracking ADD/DELETE/EDIT events. This differs from the pattern used in other functions:

  • getIndicatorTypeFormAnalyticsData validates indicator_type_name (lines 169-179)
  • getMarketTypeFormAnalyticsData validates search_string and market_type_name (lines 247-252)

Impact: Could send incomplete analytics events with empty drawing_tool_name values for critical operations.

Current Code:

const getDrawingToolsFormAnalyticsData = (state: keyof typeof STATE_TYPES, option: TStateChangeOption = {}) => {
    const { drawing_tool_name = '', pxthickness = '', color_name = '', is_open } = option;
    const drawing_tools_event_type = 'ce_drawing_tools_form_v2';
    const payload = {
        event_type: drawing_tools_event_type,
    } as TPayload;

    switch (state) {
        case STATE_TYPES.DRAWING_TOOLS_MODAL_OPEN:
            payload.data = {
                action: ACTION.OPEN,
            };
            break;
        case STATE_TYPES.DRAWING_TOOLS_ADD:  // ⚠️ No validation here
            payload.data = {
                action: ACTION.ADD_DRAWING_TOOL,
                drawing_tool_name,  // Could be empty!
                // ...

Recommended Fix:
Add validation similar to the indicator validation pattern:

const getDrawingToolsFormAnalyticsData = (state: keyof typeof STATE_TYPES, option: TStateChangeOption = {}) => {
    const { drawing_tool_name = '', pxthickness = '', color_name = '', is_open } = option;
    const drawing_tools_event_type = 'ce_drawing_tools_form_v2';
    const payload = {
        event_type: drawing_tools_event_type,
    } as TPayload;

    // Add validation for operations that require drawing_tool_name
    if (
        (state === STATE_TYPES.DRAWING_TOOLS_ADD ||
            state === STATE_TYPES.DRAWING_TOOLS_DELETE ||
            state === STATE_TYPES.DRAWING_TOOLS_EDIT_PX ||
            state === STATE_TYPES.DRAWING_TOOLS_EDIT_COLOR) &&
        !drawing_tool_name
    ) {
        return {};
    }

    switch (state) {
        // ... rest of the switch statement
    }
};

Note: This is defensive programming to maintain consistency with the rest of the codebase and prevent potential analytics data quality issues.


βœ… What's Excellent

1. Previous Issues Resolved

All critical and high-priority issues from the last review have been addressed:

  • Duplicate code eliminated (chart.ts:369)
  • Typo corrected in constant name
  • Comprehensive test coverage added

2. Test Coverage is Now Complete

packages/trader/src/Stores/Modules/Trading/Helpers/__tests__/chart.spec.ts now includes:

  • βœ… Tests for CHART_MODE_MODAL_OPEN (lines 253-258)
  • βœ… Tests for CHART_SWITCH_TOGGLE (lines 260-273)
  • βœ… Tests for MARKET_MENU_MODAL_TOGGLE (lines 275-292)
  • βœ… Tests for INDICATOR_EDITED (lines 294-309)
  • βœ… Complete suite for crosshair events (lines 312-331)
  • βœ… Complete suite for drawing tools events (lines 333-415)

The test coverage is thorough and follows the existing patterns perfectly.

3. Code Quality

  • Consistent patterns throughout
  • Proper TypeScript usage with clear type annotations
  • Good use of @ts-expect-error comments explaining temporary type issues
  • Clean switch statements with proper default cases
  • Conditional tracking logic prevents tracking unwanted states

4. Event Architecture

The analytics implementation is well-structured:

  • Clear separation of concerns with individual handler functions
  • Event routing logic is clean and maintainable
  • Action constants are well-defined and reusable

πŸ” Minor Observations (Not Blockers)

1. Type Safety for pxthickness

Location: chart.ts:286

const { drawing_tool_name = '', pxthickness = '', color_name = '', is_open } = option;

pxthickness appears to represent a numeric pixel value but is typed as a string with an empty string default. This is consistent with how it's used in tests (pxthickness: '2'), so it's likely intentional, but worth noting for future refactoring if numeric types become preferred.

2. Package Version Updates

Multiple packages were updated to use @deriv-com/smartcharts-champion@0.0.230, which aligns with the new analytics events. This is correct and necessary.


πŸ”’ Security & Performance

  • Security: βœ… No security concerns. Analytics data doesn't contain sensitive information.
  • Performance: βœ… No performance issues. All operations are simple synchronous object manipulations.
  • Bundle Size: βœ… Minimal impact - only new event type definitions and routing logic.

Final Recommendation

This PR is nearly ready to merge after addressing the one remaining validation issue. The code quality is excellent, tests are comprehensive, and all previous review feedback has been properly addressed.

Action Required:

  1. Add validation for drawing_tool_name in getDrawingToolsFormAnalyticsData to match the pattern used in other analytics functions
  2. Consider adding edge case tests for drawing tools with empty drawing_tool_name (optional but recommended)

Praise:

Great job on the quick turnaround addressing the previous feedback! The test coverage additions are particularly well done. πŸ‘


@github-actions
Copy link
Contributor

github-actions bot commented Nov 7, 2025

Claude encountered an error β€”β€” View job


I'll analyze this and get back to you.

@vinu-deriv vinu-deriv marked this pull request as ready for review November 7, 2025 03:35
@github-actions
Copy link
Contributor

github-actions bot commented Nov 7, 2025

Claude finished @vinu-deriv's task β€”β€” View job


Code Review Complete βœ…

I've thoroughly reviewed this PR that adds analytics tracking for charts, drawing tools, and crosshair interactions. The implementation shows significant improvement from previous reviews, with most issues resolved. Here's my comprehensive analysis:


Summary

This PR successfully adds comprehensive analytics tracking for:

  • Drawing tools (add, delete, edit thickness/color)
  • Crosshair interactions (click events)
  • Additional chart events (modal open, smoothing toggle)
  • Market events (modal toggle, tab context)
  • Indicator events (edited state)

Overall Assessment: The code is well-structured with good test coverage. However, there's one critical issue that needs attention before merging.


πŸ”΄ Critical Issue

Missing Validation for Drawing Tools Operations

Location: packages/trader/src/Stores/Modules/Trading/Helpers/chart.ts:285-332

Severity: High - Data Quality Issue

Problem: The getDrawingToolsFormAnalyticsData function lacks validation for required fields, unlike other analytics functions in the same file. This creates an inconsistency and could lead to incomplete analytics data being tracked.

Pattern Comparison:

  • βœ… getIndicatorTypeFormAnalyticsData validates indicator_type_name (lines 169-179)
  • βœ… getMarketTypeFormAnalyticsData validates search_string and market_type_name (lines 247-252)
  • ❌ getDrawingToolsFormAnalyticsData has NO validation for drawing_tool_name

Impact:

  • Analytics events could be sent with empty drawing_tool_name for ADD/DELETE/EDIT operations
  • Data quality degradation in analytics pipeline
  • Inconsistent behavior compared to other event handlers

Current Code:

const getDrawingToolsFormAnalyticsData = (state: keyof typeof STATE_TYPES, option: TStateChangeOption = {}) => {
    const { drawing_tool_name = '', pxthickness = '', color_name = '' } = option;
    const drawing_tools_event_type = 'ce_drawing_tools_form_v2';
    const payload = {
        event_type: drawing_tools_event_type,
    } as TPayload;

    switch (state) {
        case STATE_TYPES.DRAWING_TOOLS_MODAL_OPEN:
            payload.data = {
                action: ACTION.OPEN,
            };
            break;
        case STATE_TYPES.DRAWING_TOOLS_ADD:  // ⚠️ No validation!
            payload.data = {
                action: ACTION.ADD_DRAWING_TOOL,
                drawing_tool_name,  // Could be empty string!
                pxthickness,
                color_name,
            };
            break;
        // ... similar issues for DELETE, EDIT_PX, EDIT_COLOR
    }
    return payload;
};

Recommended Fix:
Add validation before the switch statement, matching the pattern used in other functions:

const getDrawingToolsFormAnalyticsData = (state: keyof typeof STATE_TYPES, option: TStateChangeOption = {}) => {
    const { drawing_tool_name = '', pxthickness = '', color_name = '' } = option;
    const drawing_tools_event_type = 'ce_drawing_tools_form_v2';
    const payload = {
        event_type: drawing_tools_event_type,
    } as TPayload;

    // Add validation for operations that require drawing_tool_name
    if (
        (state === STATE_TYPES.DRAWING_TOOLS_ADD ||
            state === STATE_TYPES.DRAWING_TOOLS_DELETE ||
            state === STATE_TYPES.DRAWING_TOOLS_EDIT_PX ||
            state === STATE_TYPES.DRAWING_TOOLS_EDIT_COLOR) &&
        !drawing_tool_name
    ) {
        return {};
    }

    switch (state) {
        // ... rest of the implementation
    }
};

Testing Recommendation:
Add test cases for edge cases with empty drawing_tool_name:

it('should return empty object when drawing_tool_name is missing for ADD operation', () => {
    expect(getChartAnalyticsData(STATE_TYPES.DRAWING_TOOLS_ADD, {})).toEqual({});
});

it('should return empty object when drawing_tool_name is missing for DELETE operation', () => {
    expect(getChartAnalyticsData(STATE_TYPES.DRAWING_TOOLS_DELETE, {})).toEqual({});
});

βœ… What's Excellent

1. Previous Issues Fully Resolved

All issues from previous reviews have been addressed:

  • βœ… Duplicate line removed (was at line 369)
  • βœ… Typo fixed: MARKET_MENUE_MODAL_TOGGLE β†’ MARKET_MENU_MODAL_TOGGLE
  • βœ… Comprehensive test coverage added

2. Outstanding Test Coverage

Location: packages/trader/src/Stores/Modules/Trading/Helpers/__tests__/chart.spec.ts

The test suite is thorough and well-organized:

  • βœ… Complete coverage for all new event types
  • βœ… Tests for crosshair events (lines 312-331)
  • βœ… Tests for drawing tools events (lines 333-415)
  • βœ… Tests for chart mode, switch toggle, market menu (lines 253-292)
  • βœ… Tests for indicator edited state (lines 294-309)
  • βœ… Edge case tests for empty strings and missing data

Test Quality: Tests follow existing patterns, use descriptive names, and validate both success and failure cases.

3. Clean Code Architecture

  • Consistent patterns: All analytics functions follow the same structure
  • Type safety: Proper TypeScript usage with @ts-expect-error comments explaining temporary type gaps
  • Separation of concerns: Event routing logic is clean and maintainable
  • Conditional tracking: Smart logic prevents tracking unwanted states (e.g., is_open: false checks)

4. Latest Commit Quality

The latest commit (cae72b3) removes unused variables, showing attention to code cleanliness.


🟒 Code Quality Observations

Strengths

  1. Event routing is efficient and uses early returns (chart.ts:365-370)
  2. Constants are well-organized and typed with as const for type safety
  3. Package updates properly align dependencies across all packages
  4. Type definitions use proper TypeScript patterns with Omit and Partial

Minor Observations (Not Blockers)

1. Type Consistency for pxthickness

Location: chart.ts:40, 286

The pxthickness parameter is typed as string with empty string default, but represents a numeric pixel value. Tests confirm it's used as a string (pxthickness: '2'). This is acceptable but worth noting for future refactoring.

Current approach is fine, but if numeric validation is needed in the future, consider:

pxthickness?: string | number;

2. Empty Payload Handling

The code returns empty objects {} for invalid states, which is handled correctly by callers. This pattern is consistent and appropriate.


πŸ”’ Security Analysis

Status: βœ… No security concerns

  • Analytics data contains no sensitive information (PII, credentials, tokens)
  • Event tracking uses safe string constants
  • No injection risks identified
  • No authentication/authorization bypass concerns

⚑ Performance Analysis

Status: βœ… No performance concerns

  • All operations are synchronous object creation
  • Simple conditionals with O(1) complexity
  • Array .includes() checks are on small static arrays (5-8 items)
  • No memory leaks or unnecessary re-renders
  • Minimal bundle size impact

πŸ“Š Test Coverage Analysis

Coverage: Excellent βœ…

All new functionality is tested:

  • βœ… 6 test cases for drawing tools events
  • βœ… 1 test case for crosshair events
  • βœ… 4 test cases for new chart/market/indicator events
  • βœ… Edge cases for empty values (e.g., lines 272, 308)

Missing: Edge case tests for drawing tools with empty drawing_tool_name (recommended above)


πŸ“ Correctness & Edge Cases

Validated Scenarios:

  • βœ… Empty state handling (line 26)
  • βœ… Missing required fields return empty object
  • βœ… Conditional modal tracking based on is_open
  • βœ… Proper action selection based on boolean flags

Edge Cases Covered in Tests:

  • Empty chart_type_name β†’ returns {} (line 272)
  • Empty indicator_type_name β†’ returns {} (line 308)
  • Empty search_string β†’ returns {} (lines 183-184)
  • Missing symbol for favorites β†’ returns {} (line 250)

Edge Cases NOT Covered:

  • ❌ Empty drawing_tool_name for ADD/DELETE/EDIT operations (the critical issue above)

🎯 React & TypeScript Best Practices

Compliance: βœ… Excellent

  • βœ… Proper TypeScript type definitions with clear interfaces
  • βœ… as const assertions for immutable constants
  • βœ… Correct use of @ts-expect-error with explanatory comments
  • βœ… Defensive programming with default parameter values
  • βœ… Pure functions with no side effects
  • βœ… Clear function naming conventions

πŸ“¦ Package Management

Status: βœ… Proper

All packages correctly updated to use @deriv-com/smartcharts-champion@0.0.230:

  • βœ… Root package.json
  • βœ… api-v2, api, core, reports, shared, trader packages
  • βœ… package-lock.json synchronized

Final Recommendation

Action Required Before Merge:

  1. Add validation for drawing_tool_name in getDrawingToolsFormAnalyticsData (Critical)
  2. Add edge case tests for drawing tools with empty drawing_tool_name (Recommended)

After These Fixes:

This PR will be ready to merge. The implementation is solid, tests are comprehensive, and the code quality is excellent.


Priority Summary

πŸ”΄ High Priority (Must Fix)

  1. Add validation for drawing_tool_name in drawing tools analytics function

🟑 Medium Priority (Recommended)

  1. Add edge case tests for drawing tools with missing data

🟒 Low Priority (Optional)

None - everything else looks great!


Great work on addressing all previous feedback! The quick turnaround and comprehensive test additions are particularly commendable. Once the validation issue is addressed, this will be a solid addition to the codebase.


@deriv-com deriv-com deleted a comment from github-actions bot Nov 7, 2025
@vinu-deriv vinu-deriv merged commit 7a09864 into deriv-com:refactor/champion-chart Nov 7, 2025
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants