Skip to content
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

Sync main w/ prod #845

Merged
merged 67 commits into from
Sep 9, 2024
Merged

Sync main w/ prod #845

merged 67 commits into from
Sep 9, 2024

Conversation

marc-aurele-besner
Copy link
Collaborator

@marc-aurele-besner marc-aurele-besner commented Sep 6, 2024

User description

Sync main w/ prod


PR Type

Enhancement, Tests, Bug fix, Documentation


Description

  • Added new GraphQL types and queries for accounts and transfers, enhancing data fetching capabilities.
  • Implemented AccountTransfersList component to display account transfers with sorting and pagination.
  • Enhanced ActionsModal with improved validation and transaction logging.
  • Simplified AccountExtrinsicList component layout and logic.
  • Introduced transaction logging in useTxHelper for better error tracking.
  • Updated staking-related queries and components to handle pending actions and statuses more effectively.
  • Refactored caching and event processing logic in staking indexers for better performance and clarity.
  • Removed cookie-based network selection and optimized network URI logic in ChainProvider.
  • Improved tooltip rendering and visibility logic in the common components.
  • Added enums for staking statuses and actions to centralize state management.

Changes walkthrough 📝

Relevant files
Enhancement
15 files
accounts.ts
Add GraphQL types and queries for accounts and transfers 

explorer/gql/types/accounts.ts

  • Added GraphQL types for accounts and transfers.
  • Defined comparison expressions for various data types.
  • Introduced queries and subscriptions for account and transfer data.
  • +560/-0 
    AccountTransfersList.tsx
    Implement AccountTransfersList component with data fetching

    explorer/src/components/Consensus/Account/AccountTransfersList.tsx

  • Implemented AccountTransfersList component to display account
    transfers.
  • Utilized GraphQL queries to fetch transfer data.
  • Added sorting and pagination functionalities.
  • +287/-0 
    ActionsModal.tsx
    Enhance ActionsModal with validation and logging                 

    explorer/src/components/Staking/ActionsModal.tsx

  • Updated validation schema for staking actions.
  • Added transaction logging functionality.
  • Improved slider value handling in forms.
  • +12/-5   
    AccountExtrinsicList.tsx
    Simplify AccountExtrinsicList component layout and logic 

    explorer/src/components/Consensus/Account/AccountExtrinsicList.tsx

  • Removed unused filters and improved component layout.
  • Simplified the rendering logic for extrinsic lists.
  • +19/-31 
    useTxHelper.ts
    Add transaction logging to useTxHelper hook                           

    explorer/src/hooks/useTxHelper.ts

  • Added transaction logging on success and error.
  • Integrated path-based logging for transactions.
  • +12/-6   
    staking.ts
    Update NominationsListQuery with pending actions                 

    explorer/gql/types/staking.ts

    • Updated NominationsListQuery to include pending actions.
    +1/-1     
    NominationsTable.tsx
    Refine NominationsTable action logic based on status         

    explorer/src/components/Staking/NominationsTable.tsx

  • Refined action exclusion logic based on operator status.
  • Improved handling of pending actions for nominations.
  • +7/-12   
    cache.ts
    Rename RewardEvent and implement batch saving in cache     

    indexers/staking-squid/src/utils/cache.ts

  • Renamed RewardEvent to Reward.
  • Implemented batch saving for cache entries.
  • +12/-6   
    unlock.ts
    Update unlock event processing with total withdrawals logic

    indexers/staking-squid/src/events/unlock.ts

  • Updated total withdrawals logic for various entities.
  • Set pending action to NO_ACTION_REQUIRED for nominators.
  • +16/-35 
    ChainProvider.tsx
    Simplify network URI logic in ChainProvider                           

    explorer/src/providers/ChainProvider.tsx

  • Removed cookie-based network selection.
  • Simplified network URI determination logic.
  • +2/-5     
    Tooltip.tsx
    Optimize Tooltip component with useMemo                                   

    explorer/src/components/common/Tooltip.tsx

  • Optimized tooltip rendering using useMemo.
  • Improved tooltip visibility toggling logic.
  • +20/-12 
    OperatorsList.tsx
    Adjust OperatorsList actions based on status and pending actions

    explorer/src/components/Staking/OperatorsList.tsx

  • Adjusted action exclusion based on operator status and pending
    actions.
  • +4/-8     
    epoch.ts
    Update epoch transition logic for domains and operators   

    indexers/staking-squid/src/events/epoch.ts

  • Updated domain and operator calculations for epoch transitions.
  • Adjusted pending action logic for nominators.
  • +12/-3   
    Account.tsx
    Add AccountTransfersList to account page with tabs             

    explorer/src/components/Consensus/Account/Account.tsx

  • Added AccountTransfersList to account page with tabbed navigation.
  • +12/-2   
    staking.ts
    Add enums for staking statuses and actions                             

    explorer/src/constants/staking.ts

    • Introduced enums for operator and nominator statuses and actions.
    +44/-0   
    Additional files (token-limit)
    37 files
    public_account_extrinsic_total_count.yaml
    ...                                                                                                           

    indexers/db/metadata/databases/leaderboard/tables/public_account_extrinsic_total_count.yaml

    ...

    +16/-0   
    public_account_transfer_receiver_total_count.yaml
    ...                                                                                                           

    indexers/db/metadata/databases/leaderboard/tables/public_account_transfer_receiver_total_count.yaml

    ...

    +16/-0   
    public_account_transfer_receiver_total_value.yaml
    ...                                                                                                           

    indexers/db/metadata/databases/leaderboard/tables/public_account_transfer_receiver_total_value.yaml

    ...

    +16/-0   
    public_account_transfer_sender_total_count.yaml
    ...                                                                                                           

    indexers/db/metadata/databases/leaderboard/tables/public_account_transfer_sender_total_count.yaml

    ...

    +16/-0   
    public_account_transfer_sender_total_value.yaml
    ...                                                                                                           

    indexers/db/metadata/databases/leaderboard/tables/public_account_transfer_sender_total_value.yaml

    ...

    +16/-0   
    public_operator_total_rewards_collected.yaml
    ...                                                                                                           

    indexers/db/metadata/databases/leaderboard/tables/public_operator_total_rewards_collected.yaml

    ...

    +16/-0   
    public_operator_total_tax_collected.yaml
    ...                                                                                                           

    indexers/db/metadata/databases/leaderboard/tables/public_operator_total_tax_collected.yaml

    ...

    +16/-0   
    public_farmer_block_total_count.yaml
    ...                                                                                                           

    indexers/db/metadata/databases/leaderboard/tables/public_farmer_block_total_count.yaml

    ...

    +16/-0   
    public_farmer_block_total_value.yaml
    ...                                                                                                           

    indexers/db/metadata/databases/leaderboard/tables/public_farmer_block_total_value.yaml

    ...

    +16/-0   
    public_farmer_vote_total_count.yaml
    ...                                                                                                           

    indexers/db/metadata/databases/leaderboard/tables/public_farmer_vote_total_count.yaml

    ...

    +16/-0   
    public_farmer_vote_total_value.yaml
    ...                                                                                                           

    indexers/db/metadata/databases/leaderboard/tables/public_farmer_vote_total_value.yaml

    ...

    +16/-0   
    public_account_remark_count.yaml
    ...                                                                                                           

    indexers/db/metadata/databases/leaderboard/tables/public_account_remark_count.yaml

    ...

    +16/-0   
    public_operator_bundle_total_count.yaml
    ...                                                                                                           

    indexers/db/metadata/databases/leaderboard/tables/public_operator_bundle_total_count.yaml

    ...

    +16/-0   
    public_reward_event.yaml
    ...                                                                                                           

    indexers/db/metadata/databases/staking/tables/public_reward_event.yaml

    ...

    +16/-0   
    settings.json
    ...                                                                                                           

    .vscode/settings.json

    ...

    +2/-0     
    .env
    ...                                                                                                           

    .env

    ...

    +5/-2     
    .env
    ...                                                                                                           

    indexers/staking-squid/.env

    ...

    +1/-1     
    squid.yaml
    ...                                                                                                           

    indexers/staking-squid/squid.yaml

    ...

    +1/-1     
    config.yaml
    ...                                                                                                           

    indexers/db/config.yaml

    ...

    +7/-0     
    init-db.sql
    ...                                                                                                           

    indexers/db/docker-entrypoint-initdb.d/init-db.sql

    ...

    +4/-0     
    actions.yaml
    ...                                                                                                           

    indexers/db/metadata/actions.yaml

    ...

    +6/-0     
    squid_processor_status.yaml
    ...                                                                                                           

    indexers/db/metadata/databases/leaderboard/tables/squid_processor_status.yaml

    ...

    +3/-0     
    squid_processor_status.yaml
    ...                                                                                                           

    indexers/db/metadata/databases/staking/tables/squid_processor_status.yaml

    ...

    +3/-0     
    public_migrations.yaml
    ...                                                                                                           

    indexers/db/metadata/databases/staking/tables/public_migrations.yaml

    ...

    +3/-0     
    graphql_schema_introspection.yaml
    ...                                                                                                           

    indexers/db/metadata/graphql_schema_introspection.yaml

    ...

    +1/-0     
    version.yaml
    ...                                                                                                           

    indexers/db/metadata/version.yaml

    ...

    +1/-0     
    cron_triggers.yaml
    ...                                                                                                           

    indexers/db/metadata/cron_triggers.yaml

    ...

    +1/-0     
    remote_schemas.yaml
    ...                                                                                                           

    indexers/db/metadata/remote_schemas.yaml

    ...

    +1/-0     
    allow_list.yaml
    ...                                                                                                           

    indexers/db/metadata/allow_list.yaml

    ...

    +1/-0     
    inherited_roles.yaml
    ...                                                                                                           

    indexers/db/metadata/inherited_roles.yaml

    ...

    +1/-0     
    metrics_config.yaml
    ...                                                                                                           

    indexers/db/metadata/metrics_config.yaml

    ...

    +1/-0     
    opentelemetry.yaml
    ...                                                                                                           

    indexers/db/metadata/opentelemetry.yaml

    ...

    +1/-0     
    rest_endpoints.yaml
    ...                                                                                                           

    indexers/db/metadata/rest_endpoints.yaml

    ...

    +1/-0     
    api_limits.yaml
    ...                                                                                                           

    indexers/db/metadata/api_limits.yaml

    ...

    +1/-0     
    backend_configs.yaml
    ...                                                                                                           

    indexers/db/metadata/backend_configs.yaml

    ...

    +1/-0     
    query_collections.yaml
    ...                                                                                                           

    indexers/db/metadata/query_collections.yaml

    ...

    +1/-0     
    network.yaml
    ...                                                                                                           

    indexers/db/metadata/network.yaml

    ...

    +1/-0     

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    Copy link

    netlify bot commented Sep 6, 2024

    Deploy Preview for dev-astral ready!

    Name Link
    🔨 Latest commit b088a4c
    🔍 Latest deploy log https://app.netlify.com/sites/dev-astral/deploys/66db93c5dc13990008401989
    😎 Deploy Preview https://deploy-preview-845--dev-astral.netlify.app
    📱 Preview on mobile
    Toggle QR Code...

    QR Code

    Use your smartphone camera to open QR code link.

    To edit notification comments on pull requests, go to your Netlify site configuration.

    Copy link

    netlify bot commented Sep 6, 2024

    Deploy Preview for astral-prod ready!

    Name Link
    🔨 Latest commit b088a4c
    🔍 Latest deploy log https://app.netlify.com/sites/astral-prod/deploys/66db93c50afc7200081a2f89
    😎 Deploy Preview https://deploy-preview-845--astral-prod.netlify.app
    📱 Preview on mobile
    Toggle QR Code...

    QR Code

    Use your smartphone camera to open QR code link.

    To edit notification comments on pull requests, go to your Netlify site configuration.

    Copy link

    Report too large to display inline

    View full report↗︎

    @github-actions github-actions bot added documentation Improvements or additions to documentation enhancement New feature or request Bug fix tests Review effort [1-5]: 5 labels Sep 6, 2024
    Copy link

    github-actions bot commented Sep 6, 2024

    PR Reviewer Guide 🔍

    ⏱️ Estimated effort to review: 5 🔵🔵🔵🔵🔵
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Key issues to review

    Large File
    The file 'explorer/gql/types/accounts.ts' is exceptionally large (560 lines of code). This could impact maintainability and readability. Consider splitting into smaller, more focused modules.

    Code Duplication
    There appears to be significant duplication in the rendering logic within the 'AccountTransfersList.tsx' component. Consider abstracting common patterns into reusable components or hooks to improve code maintainability.

    Complex Component
    The 'ActionsModal' component is complex and handles multiple states and side effects. Refactoring into smaller subcomponents or using a state management library could help manage complexity.

    Error Handling
    The 'useTxHelper' hook does not adequately handle potential errors from transactions. It should be robust against failures and provide clear feedback to the user.

    Data Consistency
    The event processing functions in 'unlock.ts' do not consistently update related entities in the cache, which might lead to data inconsistency issues.

    Copy link

    github-actions bot commented Sep 6, 2024

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Correctly calculate the offset to handle negative or zero page indices

    Ensure that the offset calculation correctly handles cases where
    pagination.pageIndex is zero or negative.

    explorer/src/components/Consensus/Account/AccountTransfersList.tsx [83]

    -offset: pagination.pageIndex > 0 ? pagination.pageIndex * pagination.pageSize : undefined,
    +offset: Math.max(0, pagination.pageIndex) * pagination.pageSize,
     
    Suggestion importance[1-10]: 10

    Why: Correctly calculating the offset is essential for preventing errors in pagination, especially when handling edge cases like zero or negative page indices.

    10
    Ensure case insensitivity in string comparison for runtime determination

    Consider checking for case insensitivity when using
    stringifiedRuntime.includes("autoId") to ensure consistent behavior regardless of
    the case in the runtime string.

    indexers/staking-squid/src/events/epoch.ts [93-95]

    -_domain.runtime = stringifiedRuntime.includes("autoId")
    +_domain.runtime = stringifiedRuntime.toLowerCase().includes("autoid")
       ? DomainRuntime.AutoId
       : DomainRuntime.EVM;
     
    Suggestion importance[1-10]: 8

    Why: This suggestion addresses a potential issue with case sensitivity that could lead to inconsistent behavior. Ensuring case insensitivity in string comparison is a good practice for robustness.

    8
    Best practice
    Improve type safety by specifying more accurate types for numeric and timestamptz

    Consider using a more specific type instead of any for the numeric and timestamptz
    scalar types to ensure type safety and avoid potential runtime errors.

    explorer/codegen.ts [15-16]

     export type Scalars = {
       ID: { input: string; output: string; }
       String: { input: string; output: string; }
       Boolean: { input: boolean; output: boolean; }
       Int: { input: number; output: number; }
       Float: { input: number; output: number; }
    -  numeric: { input: any; output: any; }
    -  timestamptz: { input: any; output: any; }
    +  numeric: { input: number; output: number; }
    +  timestamptz: { input: Date; output: Date; }
     };
     
    Suggestion importance[1-10]: 9

    Why: This suggestion improves type safety by specifying more accurate types for numeric and timestamptz, which can prevent potential runtime errors and enhance code reliability.

    9
    Use optional chaining to safely access properties on potentially undefined objects

    Use optional chaining to safely access properties on potentially undefined objects
    to prevent runtime errors.

    explorer/src/components/Consensus/Account/AccountTransfersList.tsx [63-69]

     const orderBy = useMemo(
       () =>
    -    sorting && sorting.length > 0
    +    sorting?.length > 0
           ? sorting[0].id.endsWith('aggregate')
             ? { [sorting[0].id]: sorting[0].desc ? { count: OrderBy.Desc } : { count: OrderBy.Asc } }
             : { [sorting[0].id]: sorting[0].desc ? OrderBy.Desc : OrderBy.Asc }
           : { id: OrderBy.Asc },
       [sorting],
     )
     
    Suggestion importance[1-10]: 8

    Why: Using optional chaining is a best practice that enhances code safety by preventing errors when accessing properties on possibly undefined objects.

    8
    Possible bug
    Add a null check for sorting[0].id to prevent potential runtime errors

    Consider handling the case where sorting[0].id is undefined or null to prevent
    runtime errors.

    explorer/src/components/Consensus/Account/AccountTransfersList.tsx [63-69]

    -sorting && sorting.length > 0
    +sorting && sorting.length > 0 && sorting[0].id
       ? sorting[0].id.endsWith('aggregate')
         ? { [sorting[0].id]: sorting[0].desc ? { count: OrderBy.Desc } : { count: OrderBy.Asc } }
         : { [sorting[0].id]: sorting[0].desc ? OrderBy.Desc : OrderBy.Asc }
       : { id: OrderBy.Asc },
     
    Suggestion importance[1-10]: 9

    Why: Adding a null check for sorting[0].id is crucial to prevent potential runtime errors, especially when accessing properties on potentially undefined objects.

    9
    Add explicit check to prevent division by zero in share price calculation

    To avoid potential division by zero errors, add an explicit check before performing
    the division when calculating domain.currentSharePrice.

    indexers/staking-squid/src/events/epoch.ts [196-200]

    -domain.currentSharePrice =
    -  domain.currentTotalShares > BigInt(0)
    -    ? (domain.currentTotalStake * SHARES_CALCULATION_MULTIPLIER) /
    -      domain.currentTotalShares
    -    : BigInt(0);
    +if (domain.currentTotalShares === BigInt(0)) {
    +  domain.currentSharePrice = BigInt(0);
    +} else {
    +  domain.currentSharePrice = (domain.currentTotalStake * SHARES_CALCULATION_MULTIPLIER) /
    +    domain.currentTotalShares;
    +}
     
    Suggestion importance[1-10]: 9

    Why: The suggestion correctly identifies a potential division by zero error and provides a solution to prevent it, which is crucial for preventing runtime errors.

    9
    Enhancement
    Enhance error logging by including the error object

    To improve error handling, log the error message to provide more context about the
    failure when sending logs.

    explorer/src/app/api/log/[...params]/route.ts [37-38]

     } catch (error) {
    -  console.error('Error sending log:')
    +  console.error('Error sending log:', error)
       return NextResponse.json({ error: 'Failed to send log' }, { status: 500 })
     }
     
    Suggestion importance[1-10]: 8

    Why: Including the error object in the log enhances error handling by providing more context, which is crucial for debugging and maintaining the application.

    8
    Maintainability
    Add responsive classes to maintain layout consistency across devices

    Ensure consistent responsive design by adding missing responsive classes to the new
    div element for better layout management on different screen sizes.

    explorer/src/components/Consensus/Account/Account.tsx [83]

    -<div className='mb-8 flex flex-col gap-8 lg:flex-row lg:justify-between'>
    +<div className='mb-8 flex flex-col gap-8 lg:flex-row lg:justify-between lg:gap-4 xl:gap-8'>
     
    Suggestion importance[1-10]: 7

    Why: Adding responsive classes improves layout consistency across devices, enhancing the user experience and maintaining a professional appearance.

    7
    Simplify the conditional logic in the orderBy calculation for better readability

    Replace the ternary operator with a simpler conditional check for better
    readability.

    explorer/src/components/Consensus/Account/AccountTransfersList.tsx [63-69]

     const orderBy = useMemo(
       () =>
    -    sorting && sorting.length > 0
    -      ? sorting[0].id.endsWith('aggregate')
    -        ? { [sorting[0].id]: sorting[0].desc ? { count: OrderBy.Desc } : { count: OrderBy.Asc } }
    -        : { [sorting[0].id]: sorting[0].desc ? OrderBy.Desc : OrderBy.Asc }
    +    sorting?.length > 0
    +      ? {
    +          [sorting[0].id]: sorting[0].id.endsWith('aggregate')
    +            ? { count: sorting[0].desc ? OrderBy.Desc : OrderBy.Asc }
    +            : sorting[0].desc ? OrderBy.Desc : OrderBy.Asc,
    +        }
           : { id: OrderBy.Asc },
       [sorting],
     )
     
    Suggestion importance[1-10]: 7

    Why: Simplifying the conditional logic improves code readability and maintainability, making it easier for developers to understand and modify the code in the future.

    7
    Consolidate repeated withdrawal updates and cache settings into a single function

    Refactor repeated code for setting total withdrawals and updating cache into a
    function to reduce duplication and improve maintainability.

    indexers/staking-squid/src/events/unlock.ts [126-137]

    -domain.totalWithdrawals += amountBigInt;
    -cache.domains.set(domain.id, domain);
    -account.totalWithdrawals += amountBigInt;
    -cache.accounts.set(account.id, account);
    -operator.totalWithdrawals += amountBigInt;
    -cache.operators.set(operator.id, operator);
    -nominator.totalWithdrawals += amountBigInt;
    -cache.nominators.set(nominator.id, nominator);
    +updateTotalWithdrawalsAndCache(domain, amountBigInt, cache.domains);
    +updateTotalWithdrawalsAndCache(account, amountBigInt, cache.accounts);
    +updateTotalWithdrawalsAndCache(operator, amountBigInt, cache.operators);
    +updateTotalWithdrawalsAndCache(nominator, amountBigInt, cache.nominators);
     
    Suggestion importance[1-10]: 7

    Why: This suggestion reduces code duplication and enhances maintainability by consolidating repeated logic into a function, which is a good practice for cleaner code.

    7
    Encapsulate the creation and storage of reward events into a single function

    Refactor the creation of operatorRewardedEvent to ensure that the event creation and
    its properties are encapsulated within a function to enhance modularity and
    readability.

    indexers/staking-squid/src/events/operator.ts [198-203]

    -const operatorRewardedEvent = createRewardEvent(block, extrinsic, event, {
    -  operatorId: operator.id,
    -  domainId: operator.domainId,
    -  amount,
    -});
    -cache.operatorRewards.set(operatorRewardedEvent.id, operatorRewardedEvent);
    +const operatorRewardedEvent = createAndStoreRewardEvent(block, extrinsic, event, operator, cache);
     
    Suggestion importance[1-10]: 6

    Why: Encapsulating the creation and storage of reward events into a single function improves code modularity and readability, which is beneficial for maintainability.

    6
    Cleanup
    Remove unnecessary ESLint directive to clean up the code

    Remove the commented-out eslint-disable camelcase directive as it is no longer
    necessary after the refactor.

    explorer/src/components/Consensus/Account/AccountExtrinsicList.tsx [61]

    -/* eslint-disable camelcase */
    +// Removed unnecessary ESLint disable directive
     
    Suggestion importance[1-10]: 6

    Why: Removing unnecessary ESLint directives cleans up the code, making it more readable and maintainable without affecting functionality.

    6

    @marc-aurele-besner marc-aurele-besner merged commit a671279 into production Sep 9, 2024
    24 of 27 checks passed
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    Bug fix documentation Improvements or additions to documentation enhancement New feature or request Review effort [1-5]: 5 tests
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants