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

fix: resolved the issue where headerShown: false was not working after the interface rendering & added the AnchorSizableText component & fixed the issue of the Loading indicator showing twice on the market detail page. (OK-32345) #6395

Merged
merged 9 commits into from
Dec 23, 2024

Conversation

huhuanming
Copy link
Contributor

@huhuanming huhuanming commented Dec 22, 2024

Summary by CodeRabbit

  • 新特性

    • ToastGallery 组件中添加了一个新按钮,触发包含超链接的吐司通知。
    • TradingView 组件中添加了 onLoadEnd 属性,用于加载完成后的回调。
    • 在多个路由配置中添加了 headerShown 属性,根据平台环境动态控制头部显示。
  • 修复

    • 恢复了 TabStackNavigator 组件中的 headerShown 属性,确保其一致性。
  • 文档

    • 更新了 TokenPriceChart 组件以增强加载状态管理。
  • 重构

    • 简化了 Toast 组件的渲染逻辑,移除了 URL 处理的正则表达式。

Copy link

codesandbox bot commented Dec 22, 2024

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link
Contributor

coderabbitai bot commented Dec 22, 2024

概述

代码变更综述

这次代码变更涉及多个组件和路由配置,主要包括以下几个关键方面:

  1. 引入了新的 AnchorSizableText 组件,用于处理文本中的超链接
  2. 修改了 Toast 组件的文本渲染逻辑
  3. 调整了多个路由的头部显示配置
  4. 优化了 TradingView 和 TokenPriceChart 组件的加载状态管理

变更详情

文件变更

文件路径 变更摘要
packages/components/src/actions/Toast/index.tsx 使用 AnchorSizableText 替换原有的文本渲染逻辑
packages/components/src/content/AnchorSizableText/index.tsx 新增组件,处理文本中的超链接
packages/kit/src/routes/Tab/* 多个路由配置添加 headerShown 属性
packages/kit/src/components/TradingView/index.tsx 移除加载状态,添加 onLoadEnd 回调
packages/kit/src/views/Market/components/TokenPriceChart.tsx 改进加载状态管理

主要变更点

  1. AnchorSizableText 组件

    • 新增组件,支持在文本中自动识别和渲染超链接
    • 提供灵活的正则匹配和链接处理能力
  2. 路由配置

    • 在多个路由中根据平台环境动态控制头部显示
    • 使用 platformEnv.isNative 判断是否显示头部
  3. 加载状态管理

    • TradingView 和 TokenPriceChart 组件优化加载反馈
    • 引入 onLoadEnd 回调,提供更精细的加载状态控制

技术亮点

  • 组件渲染逻辑更加简洁和灵活
  • 平台适配性增强
  • 用户体验改进,特别是加载状态的处理

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary or Summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@huhuanming huhuanming enabled auto-merge (squash) December 22, 2024 17:31
@huhuanming huhuanming changed the title fix: resolved the issue where headerShown: false was not working after the interface rendering & Added the AnchorSizableText component & Fixed the issue of the Loading indicator showing twice on the market detail page. (OK-32345) fix: resolved the issue where headerShown: false was not working after the interface rendering & added the AnchorSizableText component & fixed the issue of the Loading indicator showing twice on the market detail page. (OK-32345) Dec 22, 2024
@huhuanming huhuanming disabled auto-merge December 22, 2024 17:36
@huhuanming huhuanming enabled auto-merge (squash) December 22, 2024 17:36
...props
}: IAnchorSizableTextProps) {
const line = children as string;
const isAnchor = anchorRegExp.test(line);

Check failure

Code scanning / CodeQL

Polynomial regular expression used on uncontrolled data High

This
regular expression
that depends on
library input
may run slow on strings starting with '<url ' and with many repetitions of ' '.
This
regular expression
that depends on
library input
may run slow on strings starting with '' and with many repetitions of 'a'.
const line = children as string;
const isAnchor = anchorRegExp.test(line);
if (isAnchor) {
const parts = line.split(anchorRegExp);

Check failure

Code scanning / CodeQL

Polynomial regular expression used on uncontrolled data High

This
regular expression
that depends on
library input
may run slow on strings starting with '<url ' and with many repetitions of ' '.
This
regular expression
that depends on
library input
may run slow on strings starting with '' and with many repetitions of 'a'.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 8

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 95f5391 and d5025a1.

📒 Files selected for processing (14)
  • packages/components/src/actions/Toast/index.tsx (2 hunks)
  • packages/components/src/content/AnchorSizableText/index.tsx (1 hunks)
  • packages/components/src/content/index.ts (1 hunks)
  • packages/components/src/layouts/Navigation/Navigator/TabStackNavigator.tsx (1 hunks)
  • packages/kit/src/components/TradingView/index.tsx (1 hunks)
  • packages/kit/src/routes/Tab/Discovery/router.ts (1 hunks)
  • packages/kit/src/routes/Tab/Earn/router.ts (2 hunks)
  • packages/kit/src/routes/Tab/Marktet/router.ts (2 hunks)
  • packages/kit/src/routes/Tab/Swap/router.ts (2 hunks)
  • packages/kit/src/routes/Tab/router.ts (0 hunks)
  • packages/kit/src/views/Developer/pages/Gallery/Components/stories/Toast.tsx (1 hunks)
  • packages/kit/src/views/Developer/pages/Gallery/Components/stories/TradingView.tsx (1 hunks)
  • packages/kit/src/views/Home/router/index.ts (2 hunks)
  • packages/kit/src/views/Market/components/TokenPriceChart.tsx (7 hunks)
💤 Files with no reviewable changes (1)
  • packages/kit/src/routes/Tab/router.ts
🧰 Additional context used
🪛 eslint
packages/kit/src/views/Developer/pages/Gallery/Components/stories/Toast.tsx

[error] 44-44: Insert ⏎···················

(prettier/prettier)

🪛 GitHub Check: CodeQL
packages/components/src/content/AnchorSizableText/index.tsx

[failure] 19-19: Polynomial regular expression used on uncontrolled data
This regular expression that depends on library input may run slow on strings starting with '<url ' and with many repetitions of ' '.
This regular expression that depends on library input may run slow on strings starting with '' and with many repetitions of 'a'.


[failure] 21-21: Polynomial regular expression used on uncontrolled data
This regular expression that depends on library input may run slow on strings starting with '<url ' and with many repetitions of ' '.
This regular expression that depends on library input may run slow on strings starting with '' and with many repetitions of 'a'.

🔇 Additional comments (11)
packages/kit/src/views/Developer/pages/Gallery/Components/stories/TradingView.tsx (1)

30-30: 代码实现正确!

在示例组件中添加 onLoadEnd 回调函数的实现简单明了,符合演示目的。

packages/kit/src/views/Market/components/TokenPriceChart.tsx (2)

52-57: 实现正确且时机恰当!

onLoadEnd 回调函数的调用时机正确,在数据加载完成后执行。

Also applies to: 103-103


178-181: 代码结构清晰!

正确地将 onLoadEnd 属性传递给底层 TradingView 组件。

Also applies to: 196-196

packages/kit/src/routes/Tab/Earn/router.ts (1)

2-2: 代码实现正确,建议验证其他路由配置

代码变更符合需求,通过 platformEnv.isNative 来控制标题栏显示是个好方案。

Also applies to: 16-16

✅ Verification successful

路由配置已统一使用 headerShown 属性

检查结果显示所有 Tab 路由和主页路由都统一使用了 headerShown: !platformEnv.isNative 配置,实现保持一致。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查其他路由文件中是否统一使用了相同的 headerShown 配置
rg "headerShown:\s*!platformEnv.isNative" --type ts

Length of output: 477

packages/kit/src/routes/Tab/Marktet/router.ts (1)

2-2: 代码实现正确,建议验证详情页行为

主页面的 headerShown 实现与其他路由一致。建议确认 MarketDetail 路由是否也需要类似的 headerShown 控制。

Also applies to: 22-22

packages/kit/src/routes/Tab/Discovery/router.ts (1)

18-18: 代码变更看起来不错!

根据平台环境动态控制 header 显示的实现方式简洁明了,与其他路由文件保持一致。

packages/kit/src/views/Home/router/index.ts (1)

2-2: 实现方式正确且统一!

新增的 platformEnv 导入以及基于平台环境的 headerShown 控制逻辑,与项目其他路由配置保持一致。

Also applies to: 31-31

packages/components/src/layouts/Navigation/Navigator/TabStackNavigator.tsx (1)

43-43: 关键修复已完成,建议验证完整流程!

headerShown 属性已正确恢复到 Stack.Screen 的选项中。这个改动解决了 headerShown: false 不生效的问题。建议在不同平台环境下验证 header 的显示/隐藏状态。

✅ Verification successful

headerShown 属性配置正确,无需其他修改

代码检查显示:

  • TabStackNavigator 中的 headerShown 属性配置合理,与全局配置保持一致
  • GlobalScreenOptions 中的 headerShown 默认值设置完善,覆盖了各种场景
  • 不同平台(iOS/Android/Browser)的 headerShown 配置已经适配
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查其他路由文件中是否还有类似的 headerShown 配置需要修复

# 搜索所有包含 headerShown 的路由配置文件
rg -l "headerShown" --type ts

# 检查 Stack.Screen 组件的使用情况
ast-grep --pattern 'Stack.Screen' 

Length of output: 2031


Script:

#!/bin/bash
# 检查 headerShown 的具体使用方式
rg "headerShown" -B 2 -A 2 packages/components/src/layouts/Navigation/Navigator/TabStackNavigator.tsx

# 检查其他文件中 headerShown 的使用模式
rg "headerShown" -B 2 -A 2 packages/components/src/layouts/Navigation/GlobalScreenOptions.ts packages/components/src/layouts/Navigation/GlobalScreenOptions.native.ts

# 检查 Stack.Screen 的选项配置
ast-grep --pattern 'Stack.Screen $$$options={$_}$$$'

Length of output: 8345

packages/components/src/content/index.ts (1)

1-1: 导出声明看起来不错!

新增的 AnchorSizableText 组件导出遵循了现有的导出模式,保持了代码的一致性。

packages/components/src/content/AnchorSizableText/index.tsx (2)

5-9: 接口定义清晰简洁

Props 接口设计合理,通过继承 ISizableTextProps 扩展了必要的属性。


12-14: ⚠️ Potential issue

注意:正则表达式可能存在性能风险

当前的正则表达式实现可能在处理特定输入时导致性能问题:

  1. 对于包含大量重复模式的文本可能会导致性能下降
  2. 建议添加输入长度限制以防止潜在的 DOS 攻击

建议添加以下安全措施:

 export function AnchorSizableText({
   anchorRegExp = /<url(?:\s+[^>]*?)?>(.*?)<\/url>/g,
   hrefRegExp = /href="(.*?)"/,
   children,
   anchorProps,
   ...props
 }: IAnchorSizableTextProps) {
   const line = children as string;
+  if (line.length > 1000) {
+    console.warn('Text length exceeds safe limit');
+    return <SizableText {...props}>{line}</SizableText>;
+  }

Likely invalid or redundant comment.

@huhuanming huhuanming merged commit 44126d6 into x Dec 23, 2024
7 of 8 checks passed
@huhuanming huhuanming deleted the ui-issues branch December 23, 2024 03:58
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.

3 participants