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

feat(synapse-interface): SDK bridgequote chainID validation #2803

Merged
merged 8 commits into from
Jun 27, 2024

Conversation

abtestingalpha
Copy link
Collaborator

@abtestingalpha abtestingalpha commented Jun 27, 2024

Summary by CodeRabbit

  • New Features

    • Added new properties originChainId and destChainId to bridge quotes for more detailed route information.
    • Introduced function to compare chain IDs affecting button states in BridgeTransactionButton.
  • Bug Fixes

    • Enhanced logging for bridge quotes to aid in debugging and analysis.
  • Chores

    • Updated dependencies and imports for improved code consistency.
  • Refactor

    • Restructured functions for fetching and processing bridge quotes, including removal of unused imports and interfaces.

7c5975c: synapse-interface preview link
f23f66a: synapse-interface preview link
cc071d5: synapse-interface preview link
4b8644d: synapse-interface preview link
94bd2da: synapse-interface preview link
54993fa: synapse-interface preview link

Copy link
Contributor

coderabbitai bot commented Jun 27, 2024

Warning

Rate limit exceeded

@abtestingalpha has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 36 minutes and 36 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 9ed70cb and 6f571ab.

Walkthrough

The recent updates primarily enhance the Synapse module's functionality by integrating originChainId and destChainId properties into various components. These changes ensure more detailed bridge route details, streamlined state management, and improved UX based on precise chain ID data validation. Additionally, some unused imports and functions were removed to optimize performance and maintainability.

Changes

File Change Summary
.../synapseModuleSet.ts Added originChainId and destChainId parameters to the object returned by getBridgeRouteDetails method.
.../types.ts Included originChainId and destChainId fields in the BridgeQuote type.
.../sdk.test.ts Added tests for originChainId and destChainId properties to the SynapseSDK test suite.
.../BridgeTransactionButton.tsx Introduced chainSelectionsMatchBridgeQuote function to compare chain IDs and determine the button's state.
.../bridge.ts Added originChainId and destChainId properties to EMPTY_BRIDGE_QUOTE and EMPTY_BRIDGE_QUOTE_ZERO constants.
.../package.json Changed dependency for @synapsecns/sdk-router from ^0.6.0 to "file:../sdk-router".
.../index.tsx Added logging for allBridgeQuotes and included originChainId and destChainId in quote object destructuring.
.../reducer.ts Changed import statements for BridgeQuote and Token to type-only imports.
.../index.tsx Integrated originChainId and destChainId into the BridgeQuote type.
.../hooks.ts Removed imports and async thunk functions related to fetching bridge quotes, refocusing on state management hooks.
.../fetchBridgeQuotes.tsx Restructured fetchBridgeQuote function, removed unused imports, refined logic for fetching bridge quotes, and added locateBestExchangeRateToken function.

Poem

In the code, new paths align,
IDs of chains, now they define.
Route details crisp, bridges strong,
State refined, errors gone.
Synapse flows with data clear,
To every dev, bring cheer! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

  • Added originChainId and destChainId to BridgeQuote in synapseModuleSet.ts
  • Updated BridgeQuote type with chain IDs in types.ts
  • Enhanced test cases for chain ID validation in sdk.test.ts
  • Introduced chain ID validation in BridgeTransactionButton.tsx
  • Included chain IDs in EMPTY_BRIDGE_QUOTE objects in bridge.ts
  • Updated package.json to use local SDK changes
  • Added debugging logs and chain IDs in index.tsx
  • Imported BridgeQuote and Token types in reducer.ts
  • Enhanced BridgeQuote type with chain IDs in types/index.tsx

9 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

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: 0

Outside diff range and nitpick comments (5)
packages/synapse-interface/components/StateManagedBridge/BridgeTransactionButton.tsx (1)

Line range hint 66-66: Consider Using Optional Chaining

The static analysis tool suggests using optional chaining for safer property access. This is generally a good practice to prevent runtime errors due to null or undefined values, especially in a dynamic language like JavaScript.

- bridgeQuote.originChainId
+ bridgeQuote?.originChainId
packages/synapse-interface/utils/types/index.tsx (2)

Line range hint 319-319: Simplify Conditional Expression

The use of a ternary operator here is unnecessary. Simplifying this by directly assigning the boolean value can improve code readability.

- const isMetaVar = Boolean(swapDepositAddresses || forceMeta)
+ const isMetaVar = !!(swapDepositAddresses || forceMeta)

Line range hint 341-347: Remove Redundant Else Clause

The else clause is unnecessary as the previous branches include return statements. Removing it can simplify the control flow and improve readability.

- else {
-   return obj
- }
+ return obj
packages/synapse-interface/pages/state-managed-bridge/index.tsx (2)

Line range hint 230-230: Simplify boolean expression.

Consider simplifying the boolean expression to enhance code readability and reduce complexity.

- const isUnsupported = AcceptedChainId[fromChainId] ? false : true
+ const isUnsupported = !AcceptedChainId[fromChainId]

Line range hint 578-578: Add missing key property in iterable elements.

React elements in a list require a key property to maintain their identity across re-renders, which improves performance and prevents UI issues.

- <>{instance.MaintenanceCountdownProgressBar}</>
+ <div key={instance.id}>{instance.MaintenanceCountdownProgressBar}</div>
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between bbe8dc3 and 3edf444.

Files selected for processing (9)
  • packages/sdk-router/src/module/synapseModuleSet.ts (1 hunks)
  • packages/sdk-router/src/module/types.ts (1 hunks)
  • packages/sdk-router/src/sdk.test.ts (13 hunks)
  • packages/synapse-interface/components/StateManagedBridge/BridgeTransactionButton.tsx (2 hunks)
  • packages/synapse-interface/constants/bridge.ts (2 hunks)
  • packages/synapse-interface/package.json (1 hunks)
  • packages/synapse-interface/pages/state-managed-bridge/index.tsx (3 hunks)
  • packages/synapse-interface/slices/bridge/reducer.ts (1 hunks)
  • packages/synapse-interface/utils/types/index.tsx (1 hunks)
Files skipped from review due to trivial changes (2)
  • packages/sdk-router/src/sdk.test.ts
  • packages/synapse-interface/package.json
Additional context used
Biome
packages/synapse-interface/components/StateManagedBridge/BridgeTransactionButton.tsx

[error] 66-66: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

packages/synapse-interface/utils/types/index.tsx

[error] 319-319: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


[error] 341-347: This else clause can be omitted because previous branches break early.

Unsafe fix: Omit the else clause.

(lint/style/noUselessElse)

packages/synapse-interface/pages/state-managed-bridge/index.tsx

[error] 230-230: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


[error] 578-578: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

Additional comments not posted (8)
packages/synapse-interface/constants/bridge.ts (1)

20-21: Proper Initialization of Chain IDs in Constants

The addition of originChainId and destChainId set to null in both EMPTY_BRIDGE_QUOTE and EMPTY_BRIDGE_QUOTE_ZERO constants is a correct implementation to support the new functionality of tracking chain IDs. This change ensures that these objects are ready to be used with the new data structure requirements.

Also applies to: 38-39

packages/sdk-router/src/module/types.ts (1)

67-68: Updated BridgeQuote Type with Chain IDs

The addition of originChainId and destChainId fields to the BridgeQuote type is correctly implemented. This update is essential for tracking the chain IDs in bridge transactions, aligning with the PR's objectives.

packages/synapse-interface/components/StateManagedBridge/BridgeTransactionButton.tsx (1)

79-84: Addition of chainSelectionsMatchBridgeQuote Function

The new function chainSelectionsMatchBridgeQuote correctly checks the match between user-selected chain IDs and those in the bridge quote. This is a necessary addition for ensuring the UI's consistency with the backend state.

packages/sdk-router/src/module/synapseModuleSet.ts (1)

218-219: Updated finalizeBridgeRoute Method with Chain IDs

The inclusion of originChainId and destChainId in the finalizeBridgeRoute method is correctly implemented. This enhancement aligns with the PR's objectives to track chain IDs more thoroughly across the application.

packages/synapse-interface/utils/types/index.tsx (1)

86-87: Updated BridgeQuote Type in Utility Types

The addition of originChainId and destChainId to the BridgeQuote type in the utility types is correctly implemented, ensuring consistency across different parts of the application.

packages/synapse-interface/slices/bridge/reducer.ts (1)

5-5: Use of TypeScript type imports is appropriate.

The modification to use type imports for BridgeQuote and Token is a good practice in TypeScript to avoid runtime import overhead.

packages/synapse-interface/pages/state-managed-bridge/index.tsx (2)

167-167: Logging addition is beneficial for debugging.

Adding a console log for allBridgeQuotes helps in tracking the fetch and filter operations on bridge quotes, which is useful for debugging and ensuring data integrity.


283-284: Enhancement by adding chain IDs to bridge quotes.

The inclusion of originChainId and destChainId in the bridge quote enriches the transaction data, providing critical information for cross-chain operations and improving traceability.

Copy link

codecov bot commented Jun 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 25.71943%. Comparing base (18ac4e6) to head (6f571ab).
Report is 2 commits behind head on master.

Additional details and impacted files
@@                 Coverage Diff                 @@
##              master       #2803         +/-   ##
===================================================
+ Coverage   25.60341%   25.71943%   +0.11601%     
===================================================
  Files            758         700         -58     
  Lines          54399       51673       -2726     
  Branches          80          80                 
===================================================
- Hits           13928       13290        -638     
+ Misses         39037       37019       -2018     
+ Partials        1434        1364         -70     
Flag Coverage Δ
cctp-relayer ?
packages 90.47619% <ø> (ø)
promexporter ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

cloudflare-workers-and-pages bot commented Jun 27, 2024

Deploying sanguine with  Cloudflare Pages  Cloudflare Pages

Latest commit: 89ed125
Status: ✅  Deploy successful!
Preview URL: https://15c21c5e.sanguine.pages.dev
Branch Preview URL: https://fe-bridgequote-chain-ids.sanguine.pages.dev

View logs

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

  • Removed async thunks fetchAndStoreBridgeQuote and fetchAndStoreBridgeQuotes from hooks.ts
  • Removed extra reducers handling fetchAndStoreBridgeQuotes in reducer.ts
  • Refactored fetchBridgeQuotes.tsx, removing fetchBridgeQuote, fetchBridgeQuotes, and BridgeQuoteRequest
  • Deleted useAlternateBridgeQuotes.ts custom hook
  • Added destinationToken and destinationChainId to BridgeQuoteResponse in types/index.tsx

5 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

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: 0

Outside diff range and nitpick comments (2)
packages/synapse-interface/utils/types/index.tsx (2)

Line range hint 324-324: Simplify Boolean Expression

The use of a ternary operator here is unnecessary and can be simplified.

- this.isEthSwap = swapEthAddresses ? true : false
+ this.isEthSwap = Boolean(swapEthAddresses)

Line range hint 346-352: Remove Redundant Else Clause

The else clause following an early return is redundant and can be omitted for cleaner code.

if (condition) {
  return value;
}
- else {
-   other code
- }
+ other code
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3edf444 and 2b25ca3.

Files selected for processing (4)
  • packages/synapse-interface/slices/bridge/hooks.ts (2 hunks)
  • packages/synapse-interface/slices/bridge/reducer.ts (3 hunks)
  • packages/synapse-interface/utils/actions/fetchBridgeQuotes.tsx (1 hunks)
  • packages/synapse-interface/utils/types/index.tsx (1 hunks)
Files skipped from review due to trivial changes (1)
  • packages/synapse-interface/slices/bridge/hooks.ts
Files skipped from review as they are similar to previous changes (1)
  • packages/synapse-interface/slices/bridge/reducer.ts
Additional context used
Biome
packages/synapse-interface/utils/types/index.tsx

[error] 324-324: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


[error] 346-352: This else clause can be omitted because previous branches break early.

Unsafe fix: Omit the else clause.

(lint/style/noUselessElse)

Additional comments not posted (1)
packages/synapse-interface/utils/types/index.tsx (1)

86-88: Update to BridgeQuote type: Addition of Chain IDs

The addition of originChainId and destChainId to the BridgeQuote type is consistent with the PR's objective to enhance bridge routing and quote management by including chain IDs.

Copy link

cloudflare-workers-and-pages bot commented Jun 27, 2024

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6f571ab
Status: ✅  Deploy successful!
Preview URL: https://44f58db6.sanguine-fe.pages.dev
Branch Preview URL: https://fe-bridgequote-chain-ids.sanguine-fe.pages.dev

View logs

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

  • Enhanced BridgeQuote details with originChainId and destChainId
  • Improved chain ID comparison for button state and label accuracy
  • Updated @synapsecns/sdk-router dependency to version 0.7.0
  • Added Scroll chain support in widget package
  • Refactored fetchBridgeQuote functionality and state management hooks

18 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

@github-actions github-actions bot removed the M-deps label Jun 27, 2024
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

  • Enhanced BridgeQuote details to include originChainId and destChainId
  • Improved chain ID comparison for button states and labels
  • Updated package dependency for @synapsecns/sdk-router
  • Restructured fetchBridgeQuote functionality, removing unused imports
  • Adjusted type declarations in import statements for better clarity

2 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

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: 0

Outside diff range and nitpick comments (2)
packages/synapse-interface/pages/state-managed-bridge/index.tsx (2)

Line range hint 228-228: Simplify boolean assignment for isUnsupported.

The current implementation uses a ternary operator unnecessarily. You can simplify this by directly assigning the result of the condition.

- const isUnsupported = AcceptedChainId[fromChainId] ? false : true
+ const isUnsupported = !AcceptedChainId[fromChainId]

Line range hint 576-576: Add a key property to the mapped MaintenanceCountdownProgressBar components.

React requires a unique key prop on elements in a list for efficient updates. This is missing in the current implementation.

- <>{instance.MaintenanceCountdownProgressBar}</>
+ <div key={instance.id}>{instance.MaintenanceCountdownProgressBar}</div>
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2b25ca3 and 9ed70cb.

Files selected for processing (1)
  • packages/synapse-interface/pages/state-managed-bridge/index.tsx (2 hunks)
Additional context used
Biome
packages/synapse-interface/pages/state-managed-bridge/index.tsx

[error] 228-228: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


[error] 576-576: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

Additional comments not posted (1)
packages/synapse-interface/pages/state-managed-bridge/index.tsx (1)

204-205: Ensure proper integration of originChainId and destChainId in bridge quote updates.

The addition of originChainId and destChainId to the bridge quote structure is crucial for the new validation feature. It's important to ensure these fields are correctly used and integrated throughout the component's logic.

Also applies to: 281-282

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

  • Added originChainId and destChainId to bridge quotes for detailed route info
  • Enhanced chain ID validation affecting button states in BridgeTransactionButton
  • Improved logging for bridge quotes
  • Updated dependencies and imports
  • Refactored functions for fetching and processing bridge quotes, removed unused imports/interfaces

2 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

  • Added originChainId and destChainId to bridge quotes for detailed route info
  • Button states now influenced by chain ID comparisons
  • Enhanced logging for bridge quotes
  • Refactored functions for fetching and processing bridge quotes
  • Updated dependencies and imports for consistency

1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

@abtestingalpha abtestingalpha force-pushed the fe/bridgequote-chain-ids branch from 89ed125 to 6f571ab Compare June 27, 2024 21:44
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

  • Added originChainId and destChainId properties to bridge quotes for detailed route info
  • Introduced chain ID comparison function affecting button states in BridgeTransactionButton
  • Enhanced logging for bridge quotes
  • Updated dependencies and imports
  • Restructured functions for fetching and processing bridge quotes, removed unused imports/interfaces

1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant