Hu-Fi / Mr.Market

Mr. Market is the exchange oracle of HuFi, and a CeFi crypto bot on Mixin Messenger
https://mr-market-one.vercel.app
GNU Affero General Public License v3.0
1 stars 6 forks source link

Fine tuning details #149

Closed zed-wong closed 2 months ago

zed-wong commented 2 months ago

User description

Fixing some minor issues in UI and code


Type

enhancement, bug_fix


Description


Changes walkthrough

Relevant files
Enhancement
i18n.ts
Enhance i18n Setup and Refactor Language Key Function       

interface/src/i18n/i18n.ts
  • Added a function normalizeLocale to handle locale normalization based
    on navigator settings.
  • Updated initialLocale to use normalizeLocale function for setting up
    i18n configuration.
  • Refactored getNameByKey to use langs array for finding language names,
    improving maintainability.
  • +14/-23 
    connectWallet.svelte
    Refactor Wallet Connection Component with Simplified SVG and Updated
    Text

    interface/src/lib/components/wallet/connect/connectWallet.svelte
  • Simplified the SVG component and adjusted its viewbox and class
    attributes.
  • Updated text class to font-bold and modified the i18n key for wallet
    connection instructions.
  • Updated ConnectWalletBtn component usage with new class attributes for
    consistent styling.
  • +6/-7     
    zh.json
    Comprehensive Update of Chinese Translations for Enhanced Clarity and
    Consistency

    interface/src/i18n/zh.json
  • Standardized terminology across various keys (e.g., changed "互换" to
    "兑换").
  • Updated translation keys to reflect more accurate and formal language.
  • Added new keys for updated functionalities and corrected existing
    translations for clarity.
  • +129/-111
    grow.svelte
    Update Grow Component's SVG and Connection Instructions Styling

    interface/src/lib/components/grow/grow.svelte
  • Adjusted SVG dimensions and viewbox in the non-connected state.
  • Enhanced text styling for connection instructions using font-bold.
  • Streamlined the use of ConnectWalletBtn with updated class attributes.

  • +3/-4     
    Dependencies
    package.json
    Update `daisyui` Dependency to Version 4.10                           

    interface/package.json - Updated `daisyui` package from version 4.4.23 to 4.10.
    +1/-1     
    Bug_fix
    price.svelte
    Fix Color Display of Change Percentage in Candle Price Component

    interface/src/lib/components/market/candle/price.svelte
  • Fixed the color of the change percentage text to reflect the actual
    price movement (up or down).
  • +2/-2     

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

    vercel[bot] commented 2 months ago

    The latest updates on your projects. Learn more about Vercel for Git ↗︎

    Name Status Preview Comments Updated (UTC)
    mr-market ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 14, 2024 3:37pm
    railway-app[bot] commented 2 months ago

    This PR is being deployed to Railway 🚅

    railway-app[bot] commented 2 months ago

    This PR is being deployed to Railway 🚅

    Mr.Market: ◻️ REMOVED

    github-actions[bot] commented 2 months ago

    PR Description updated to latest commit (https://github.com/Hu-Fi/Mr.Market/commit/b55ad9abada0f58e8490633a3be5476583bdaccd)

    github-actions[bot] commented 2 months ago

    PR Review

    (Review updated until commit https://github.com/Hu-Fi/Mr.Market/commit/b55ad9abada0f58e8490633a3be5476583bdaccd)

    ⏱️ Estimated effort to review [1-5] 3, because the PR includes multiple enhancements and bug fixes across various files, involving both backend logic and UI components. The changes are moderate in number and complexity, requiring careful review to ensure functionality and style consistency.
    🧪 Relevant tests No
    🔍 Possible issues Possible Bug: The new `normalizeLocale` function in `i18n.ts` does not handle locales other than 'en-' prefixes, which might not be sufficient for a robust internationalization setup.
    Code Redundancy: Similar SVG elements are used in multiple Svelte components (`connectWallet.svelte` and `grow.svelte`), suggesting a potential for creating a reusable component.
    🔒 Security concerns No
    Code feedback:
    relevant fileinterface/src/i18n/i18n.ts
    suggestion       Consider handling more locale variations or documenting the limitation of the `normalizeLocale` function to only handle 'en-' prefixed locales. This enhancement ensures broader internationalization support. [important]
    relevant lineif (!locale || locale.startsWith('en-')) {

    relevant fileinterface/src/lib/components/wallet/connect/connectWallet.svelte
    suggestion       Extract the repeated SVG element into a separate reusable Svelte component to reduce redundancy and improve maintainability. This change can be applied to all instances where the SVG is used. [important]
    relevant line

    relevant fileinterface/src/lib/components/market/candle/price.svelte
    suggestion       Modify the class binding to dynamically assign the correct color class based on the price change direction. This change ensures that price decreases are visually distinct from increases. [important]
    relevant line 0 ? UpColorText : DownColorText)}>

    relevant fileinterface/src/lib/components/common/connectWalletBtn.svelte
    suggestion       Add explicit hover and focus states to the `ConnectWalletBtn` to enhance UI consistency and user experience. This change ensures visual feedback on button interaction. [medium]
    relevant lineclass={clsx("btn rounded-full no-animation text-base-100 !h-10 min-h-10 bg-slate-800 hover:bg-slate-800 focus:bg-slate-800", clazz)}


    ✨ Review tool usage guide:
    **Overview:** The `review` tool scans the PR code changes, and generates a PR review which includes several types of feedbacks, such as possible PR issues, security threats and relevant test in the PR. More feedbacks can be [added](https://pr-agent-docs.codium.ai/tools/review/#general-configurations) by configuring the tool. The tool can be triggered [automatically](https://pr-agent-docs.codium.ai/usage-guide/automations_and_usage/#github-app-automatic-tools-when-a-new-pr-is-opened) every time a new PR is opened, or can be invoked manually by commenting on any PR. - When commenting, to edit [configurations](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml#L23) related to the review tool (`pr_reviewer` section), use the following template: ``` /review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=... ``` - With a [configuration file](https://pr-agent-docs.codium.ai/usage-guide/configuration_options/), use the following template: ``` [pr_reviewer] some_config1=... some_config2=... ``` See the review [usage page](https://pr-agent-docs.codium.ai/tools/review/) for a comprehensive guide on using this tool.
    github-actions[bot] commented 2 months ago

    PR Code Suggestions

    CategorySuggestions                                                                                                                                                       
    Possible issue
    Add a check for empty or undefined langs array to prevent runtime errors. ___ **Consider handling the case where the langs array might be empty or undefined in the
    getNameByKey function to prevent runtime errors.** [interface/src/i18n/i18n.ts [40-43]](https://github.com/Hu-Fi/Mr.Market/pull/149/files#diff-3908f4d1008a33bb029973c3fe402b2f9eeb5d1797397e96811e8a03c0202848R40-R43) ```diff export const getNameByKey = (k: string) => { + if (!langs || langs.length === 0) return "English"; const lang = langs.find(lang => lang.key === k); return lang ? lang.name : "English"; }; ```
    Enhancement
    Use a ternary operator to simplify the normalizeLocale function. ___ **Refactor the normalizeLocale function to use a ternary operator for cleaner and more
    concise code.** [interface/src/i18n/i18n.ts [13-18]](https://github.com/Hu-Fi/Mr.Market/pull/149/files#diff-3908f4d1008a33bb029973c3fe402b2f9eeb5d1797397e96811e8a03c0202848R13-R18) ```diff const normalizeLocale = () => { const locale = getLocaleFromNavigator(); - if (!locale || locale.startsWith('en-')) { - return 'en-US'; - } - return locale; + return (!locale || locale.startsWith('en-')) ? 'en-US' : locale; }; ```
    Improve button accessibility by adding distinct hover and focus styles. ___ **Add explicit hover and focus styles to the button to improve accessibility and user
    experience.** [interface/src/lib/components/common/connectWalletBtn.svelte [34]](https://github.com/Hu-Fi/Mr.Market/pull/149/files#diff-e4c4aabcf6a4083502cddfbd41e4ba22bff0ecf35ece70283f5c287ad7ed8b78R34-R34) ```diff
    Restore authentication functionality using ConnectWalletBtn with consistent styling. ___ **Replace the removed authentication logic with a new, simplified version using
    ConnectWalletBtn for consistency and to handle authentication.** [interface/src/lib/components/home/oauth/connectMixin.svelte [25]](https://github.com/Hu-Fi/Mr.Market/pull/149/files#diff-9900fdef6564837a60597b2cc56579c0a4fd4657bbe885bf665f6f0ea6ab9348R25-R25) ```diff - + ```
    Add a default class to the element for consistent styling. ___ **Consider adding a default class to the element to ensure consistent styling when neither
    UpColorText nor DownColorText is applied. This can help maintain a uniform appearance in
    scenarios where $CandlePair.change might not properly trigger either condition due to
    unexpected values.** [interface/src/lib/components/market/candle/price.svelte [40]](https://github.com/Hu-Fi/Mr.Market/pull/149/files#diff-606006e359e8dcbbee749f7a9c7130701955eb3cd05406e59db719eee7ce41d3R40-R40) ```diff - 0 ? UpColorText : DownColorText)}> + 0 ? UpColorText : DownColorText)}> ```
    Improve accessibility by adding a title attribute to the SVG element. ___ **Consider adding a title attribute to the element to provide a text alternative which
    improves accessibility and is helpful for screen reader users.** [interface/src/lib/components/wallet/connect/connectWallet.svelte [7]](https://github.com/Hu-Fi/Mr.Market/pull/149/files#diff-383c71cdaca0de7703f2407db8964c31b83a5d6d9c0a0d74f4b8480b14cf3fc7R7-R7) ```diff -... +... ```
    Best practice
    Ensure a valid locale key is used in getNameByKey by checking $locale before fallback. ___ **Ensure that the getNameByKey function is called with a valid locale key by checking if
    $locale is defined.** [interface/src/lib/components/home/user/settings.svelte [10]](https://github.com/Hu-Fi/Mr.Market/pull/149/files#diff-b2e3034ae6c78f2040b654657cf8d847484fa38da5d19b609f5f2b4aaf392958R10-R10) ```diff -{key: 'lang', name: $_('language'), value: getNameByKey($locale || 'en-US'), fn: ()=>{goto('/home/user/i18n')}} +{key: 'lang', name: $_('language'), value: getNameByKey($locale ? $locale : 'en-US'), fn: ()=>{goto('/home/user/i18n')}} ```
    Add a class to the button for consistent styling. ___ **The button element is missing a class attribute which can lead to inconsistent styling.
    Consider adding a default class or a conditional class based on the state or properties of
    the component.** [interface/src/lib/components/market/candle/title.svelte [41]](https://github.com/Hu-Fi/Mr.Market/pull/149/files#diff-45a800628caa32fc13c0741ea3a9bed3ce24eba7e67d97b2f2e3a1de47dca0e6R41-R41) ```diff -
    Standardize the use of spacing utilities to maintain consistent styling. ___ **Use utility classes for margin and padding directly from your CSS framework instead of
    custom styles to maintain consistency across your project.** [interface/src/lib/components/wallet/connect/connectWallet.svelte [6]](https://github.com/Hu-Fi/Mr.Market/pull/149/files#diff-383c71cdaca0de7703f2407db8964c31b83a5d6d9c0a0d74f4b8480b14cf3fc7R6-R6) ```diff -
    +
    ```
    Maintainability
    Remove unused variable to clean up the code. ___ **The variable newsUpdated is set to false without any apparent use or reassignment in the
    provided code snippet. If this variable is not used later in the code, consider removing
    it to clean up the script block.** [interface/src/lib/components/topBar/homeBar.svelte [11]](https://github.com/Hu-Fi/Mr.Market/pull/149/files#diff-7836eb6f3244c0b291af48c7c2da5967f00ce1da9b2e799bb46b5c5695fab2e0R11-R11) ```diff -let newsUpdated = false; +// Removed unused variable +// let newsUpdated = false; ```
    Use a reactive statement for class logic to enhance readability. ___ **To enhance code readability and maintainability, consider using a computed or reactive
    statement for the class logic instead of inline ternary operations within the template.** [interface/src/lib/components/market/candle/price.svelte [40]](https://github.com/Hu-Fi/Mr.Market/pull/149/files#diff-606006e359e8dcbbee749f7a9c7130701955eb3cd05406e59db719eee7ce41d3R40-R40) ```diff - 0 ? UpColorText : DownColorText)}> + + ```
    Handle localization dynamically to support changes in language preferences. ___ **Avoid using hardcoded localization keys directly in the markup. Instead, use a reactive
    statement to handle potential changes in localization context or keys.** [interface/src/lib/components/wallet/connect/connectWallet.svelte [9]](https://github.com/Hu-Fi/Mr.Market/pull/149/files#diff-383c71cdaca0de7703f2407db8964c31b83a5d6d9c0a0d74f4b8480b14cf3fc7R9-R9) ```diff -{$_('connect_wallet_order_intro')} +{#if $locale === 'en'}Connect your wallet to order{#elseif $locale === 'es'}Conecta tu cartera para ordenar{#else}{$_('connect_wallet_order_intro')}{/if} ```
    Accessibility
    Add an aria-label to the button for better accessibility. ___ **Ensure accessibility by adding an aria-label to the button for better screen reader
    support, describing the action or purpose of the button.** [interface/src/lib/components/market/candle/title.svelte [41]](https://github.com/Hu-Fi/Mr.Market/pull/149/files#diff-45a800628caa32fc13c0741ea3a9bed3ce24eba7e67d97b2f2e3a1de47dca0e6R41-R41) ```diff -
    Enhance accessibility by adding aria-label to buttons. ___ **Ensure that interactive elements like buttons have accessible names. The ConnectWalletBtn
    component should have an aria-label attribute if it does not include text that is
    accessible to screen readers.** [interface/src/lib/components/wallet/connect/connectWallet.svelte [11]](https://github.com/Hu-Fi/Mr.Market/pull/149/files#diff-383c71cdaca0de7703f2407db8964c31b83a5d6d9c0a0d74f4b8480b14cf3fc7R11-R11) ```diff - + ```
    Performance
    Use external SVG files instead of inline SVG for better performance and maintainability. ___ **Replace inline SVG with an external SVG file to reduce the size of your HTML document and
    improve caching strategies.** [interface/src/lib/components/wallet/connect/connectWallet.svelte [7]](https://github.com/Hu-Fi/Mr.Market/pull/149/files#diff-383c71cdaca0de7703f2407db8964c31b83a5d6d9c0a0d74f4b8480b14cf3fc7R7-R7) ```diff -... +Wallet Connection Icon ```

    ✨ Improve tool usage guide:
    **Overview:** The `improve` tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered [automatically](https://pr-agent-docs.codium.ai/usage-guide/automations_and_usage/#github-app-automatic-tools-when-a-new-pr-is-opened) every time a new PR is opened, or can be invoked manually by commenting on a PR. - When commenting, to edit [configurations](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml#L78) related to the improve tool (`pr_code_suggestions` section), use the following template: ``` /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=... ``` - With a [configuration file](https://pr-agent-docs.codium.ai/usage-guide/configuration_options/), use the following template: ``` [pr_code_suggestions] some_config1=... some_config2=... ``` See the improve [usage page](https://pr-agent-docs.codium.ai/tools/improve/) for a comprehensive guide on using this tool.
    github-actions[bot] commented 2 months ago

    PR Description updated to latest commit (https://github.com/Hu-Fi/Mr.Market/commit/b55ad9abada0f58e8490633a3be5476583bdaccd)

    github-actions[bot] commented 2 months ago

    Persistent review updated to latest commit https://github.com/Hu-Fi/Mr.Market/commit/b55ad9abada0f58e8490633a3be5476583bdaccd

    github-actions[bot] commented 2 months ago

    PR Code Suggestions

    CategorySuggestions                                                                                                                                                       
    Enhancement
    Add validation for supported locales in the normalizeLocale function. ___ **Consider handling the case where getLocaleFromNavigator() returns a locale that is not
    supported by your application. Currently, the function normalizeLocale only handles
    locales starting with 'en-', but other locales are directly returned without any checks.
    You can add a list of supported locales and check against it.** [interface/src/i18n/i18n.ts [13-18]](https://github.com/Hu-Fi/Mr.Market/pull/149/files#diff-3908f4d1008a33bb029973c3fe402b2f9eeb5d1797397e96811e8a03c0202848R13-R18) ```diff +const supportedLocales = ['en-US', 'de-DE', 'es-ES']; // Add all supported locales const normalizeLocale = () => { const locale = getLocaleFromNavigator(); - if (!locale || locale.startsWith('en-')) { + if (!locale || !supportedLocales.includes(locale)) { return 'en-US'; } return locale; }; ```
    Add distinct visual feedback for hover and focus states on the button. ___ **Consider adding a specific class for hover and focus states to maintain consistency and
    enhance user experience, as the current implementation uses the same class for different
    states which might not be visually effective.** [interface/src/lib/components/common/connectWalletBtn.svelte [34]](https://github.com/Hu-Fi/Mr.Market/pull/149/files#diff-e4c4aabcf6a4083502cddfbd41e4ba22bff0ecf35ece70283f5c287ad7ed8b78R34-R34) ```diff
    Add a default class to the element for consistent styling. ___ **Consider adding a default class for the element to ensure consistent styling when neither
    UpColorText nor DownColorText is applied. This can help maintain a uniform appearance in
    edge cases where $CandlePair.change might not be greater than 0 or less than 0 due to
    unexpected data or errors.** [interface/src/lib/components/market/candle/price.svelte [40]](https://github.com/Hu-Fi/Mr.Market/pull/149/files#diff-606006e359e8dcbbee749f7a9c7130701955eb3cd05406e59db719eee7ce41d3R40-R40) ```diff - 0 ? UpColorText : DownColorText)}> + 0 ? UpColorText : $CandlePair.change < 0 ? DownColorText : 'default-class')}> ```
    Use semantic HTML for text to improve accessibility and SEO. ___ **To enhance the semantic structure and accessibility, wrap the text inside the element
    with a more descriptive HTML element such as

    or , depending on the importance and role of
    the text in the interface.** [interface/src/lib/components/wallet/connect/connectWallet.svelte [8-10]](https://github.com/Hu-Fi/Mr.Market/pull/149/files#diff-383c71cdaca0de7703f2407db8964c31b83a5d6d9c0a0d74f4b8480b14cf3fc7R8-R10) ```diff - + {$_('connect_wallet_order_intro')} - + ```

    Best practice
    Improve robustness of getNameByKey by using optional chaining and nullish coalescing. ___ **Refactor the getNameByKey function to handle undefined lang more robustly by checking if
    lang is undefined before accessing its properties. This prevents potential runtime errors.** [interface/src/i18n/i18n.ts [40-42]](https://github.com/Hu-Fi/Mr.Market/pull/149/files#diff-3908f4d1008a33bb029973c3fe402b2f9eeb5d1797397e96811e8a03c0202848R40-R42) ```diff export const getNameByKey = (k: string) => { const lang = langs.find(lang => lang.key === k); - return lang ? lang.name : "English"; + return lang?.name ?? "English"; }; ```
    Initialize state variables based on conditions or configurations. ___ **Consider initializing newsUpdated with a value derived from a condition or a configuration
    to avoid potential issues with uninitialized state or unexpected behavior when the
    component loads.** [interface/src/lib/components/topBar/homeBar.svelte [11]](https://github.com/Hu-Fi/Mr.Market/pull/149/files#diff-7836eb6f3244c0b291af48c7c2da5967f00ce1da9b2e799bb46b5c5695fab2e0R11-R11) ```diff -let newsUpdated = false; +let newsUpdated = getInitialNewsUpdatedState(); // Assuming getInitialNewsUpdatedState() is a method that determines the initial state ```
    Use CSS classes for hover effects instead of inline styles. ___ **It's recommended to use CSS classes for hover effects instead of inline styles for
    maintainability and separation of concerns. Define a CSS class for the hover state in your
    stylesheet and apply it to the ConnectWalletBtn component.** [interface/src/lib/components/wallet/connect/connectWallet.svelte [11]](https://github.com/Hu-Fi/Mr.Market/pull/149/files#diff-383c71cdaca0de7703f2407db8964c31b83a5d6d9c0a0d74f4b8480b14cf3fc7R11-R11) ```diff - + ```
    Define default dimensions for SVGs to prevent layout shifts. ___ **To ensure consistent styling and avoid potential layout shifts, specify a default height
    and width for the element in a CSS class. This practice helps maintain layout stability
    during loading or if the SVG fails to load.** [interface/src/lib/components/wallet/connect/connectWallet.svelte [7]](https://github.com/Hu-Fi/Mr.Market/pull/149/files#diff-383c71cdaca0de7703f2407db8964c31b83a5d6d9c0a0d74f4b8480b14cf3fc7R7-R7) ```diff -... +... ```
    Accessibility
    Enhance accessibility by adding an aria-label to the SVG element. ___ **To improve the accessibility and usability of the SVG graphic, consider adding an
    aria-label attribute that describes the graphic. This helps screen readers and other
    assistive technologies.** [interface/src/lib/components/grow/grow.svelte [18]](https://github.com/Hu-Fi/Mr.Market/pull/149/files#diff-a561971bfab499718ea919451aa03c40f79232dfd382618b0f7c885e95e7415bR18-R18) ```diff - + ```
    Improve button accessibility by adding descriptive attributes. ___ **Ensure that the button element has a descriptive class name or an aria-label attribute to
    improve accessibility. This helps users with screen readers understand the function of the
    button.** [interface/src/lib/components/market/candle/title.svelte [41]](https://github.com/Hu-Fi/Mr.Market/pull/149/files#diff-45a800628caa32fc13c0741ea3a9bed3ce24eba7e67d97b2f2e3a1de47dca0e6R41-R41) ```diff -
    Add an alt attribute to the element to enhance accessibility. ___ **Consider adding an alt attribute to the element to improve accessibility. This attribute
    should describe the image or icon being displayed, which is useful for screen readers and
    when the image cannot be displayed.** [interface/src/lib/components/wallet/connect/connectWallet.svelte [7]](https://github.com/Hu-Fi/Mr.Market/pull/149/files#diff-383c71cdaca0de7703f2407db8964c31b83a5d6d9c0a0d74f4b8480b14cf3fc7R7-R7) ```diff -... +... ```
    Maintainability
    Ensure ConnectWalletBtn handles all states and events for better maintainability. ___ **Since the ConnectWalletBtn component is used, ensure that it handles all necessary states
    and events, such as loading states and click events, which were previously handled in the
    script. This centralizes the logic and improves maintainability.** [interface/src/lib/components/home/oauth/connectMixin.svelte [25]](https://github.com/Hu-Fi/Mr.Market/pull/149/files#diff-9900fdef6564837a60597b2cc56579c0a4fd4657bbe885bf665f6f0ea6ab9348R25-R25) ```diff - + ```
    Refactor the inline SVG into a separate component for better maintainability. ___ **For better readability and maintainability, consider breaking down the large inline SVG
    into a separate component or an SVG file. This approach can make the code cleaner and
    easier to manage, especially if the SVG needs to be reused or modified.** [interface/src/lib/components/wallet/connect/connectWallet.svelte [7]](https://github.com/Hu-Fi/Mr.Market/pull/149/files#diff-383c71cdaca0de7703f2407db8964c31b83a5d6d9c0a0d74f4b8480b14cf3fc7R7-R7) ```diff -... + ```

    ✨ Improve tool usage guide:
    **Overview:** The `improve` tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered [automatically](https://pr-agent-docs.codium.ai/usage-guide/automations_and_usage/#github-app-automatic-tools-when-a-new-pr-is-opened) every time a new PR is opened, or can be invoked manually by commenting on a PR. - When commenting, to edit [configurations](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml#L78) related to the improve tool (`pr_code_suggestions` section), use the following template: ``` /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=... ``` - With a [configuration file](https://pr-agent-docs.codium.ai/usage-guide/configuration_options/), use the following template: ``` [pr_code_suggestions] some_config1=... some_config2=... ``` See the improve [usage page](https://pr-agent-docs.codium.ai/tools/improve/) for a comprehensive guide on using this tool.