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): bridge quote uuid #2900

Merged
merged 30 commits into from
Aug 29, 2024
Merged

Conversation

bigboydiamonds
Copy link
Collaborator

@bigboydiamonds bigboydiamonds commented Jul 20, 2024

Require #2896 to be merged in first

null
c4a392e: synapse-interface preview link
7eb45d3: synapse-interface preview link
dd77bd4: synapse-interface preview link
6212b70: synapse-interface preview link
ec9ad93: synapse-interface preview link

Summary by CodeRabbit

  • New Features

    • Introduced a pendingLabel for the button in the transaction process to enhance user feedback during loading.
    • Added an id property to the EMPTY_BRIDGE_QUOTE for better tracking of bridge quotes.
    • New utility function to convert UUIDs to Unix timestamps, improving timestamp handling.
  • Improvements

    • Enhanced error logging by switching from console.log to console.error for better visibility.
    • Improved time management and bridge transaction handling with updated time calculation methods.
    • Implemented a timeout mechanism for bridge quotes to ensure timely updates.
    • Updated the BridgeQuote type to include an id for enhanced data handling.

c69c4ff: synapse-interface preview link
3f782e6: synapse-interface preview link
db4d6c0: synapse-interface preview link
bcdc933: synapse-interface preview link
28fd8da: synapse-interface preview link

Copy link

cloudflare-workers-and-pages bot commented Jul 20, 2024

Deploying sanguine with  Cloudflare Pages  Cloudflare Pages

Latest commit: ef838ad
Status: ✅  Deploy successful!
Preview URL: https://f2647e0e.sanguine.pages.dev
Branch Preview URL: https://fe-bridge-quote-uuid.sanguine.pages.dev

View logs

Copy link
Contributor

coderabbitai bot commented Jul 20, 2024

Walkthrough

The changes involve enhancements to various components, primarily focusing on time management and bridge transaction handling. Key updates include the introduction of new utility functions for time calculations, modifications to existing components to utilize these functions, and the addition of identifiers to bridge quotes. These adjustments aim to improve the interface and data handling within the application, ensuring effective tracking and user feedback during transactions.

Changes

Files Change Summary
packages/synapse-interface/components/StateManagedBridge/BridgeTransactionButton.tsx Added pendingLabel to buttonProperties for loading state indication.
packages/synapse-interface/components/_Transaction/components/AnimatedProgressBar.tsx Replaced getTimeMinutesBeforeNow with getUnixTimeMinutesBeforeNow for time calculations.
packages/synapse-interface/constants/bridge.ts Introduced id property to EMPTY_BRIDGE_QUOTE constant for better identification.
packages/synapse-interface/package.json Added uuidv7 dependency to support UUID generation.
packages/synapse-interface/pages/state-managed-bridge/index.tsx Updated time management logic with new utility functions; added quoteTimeout constant; improved error logging.
packages/synapse-interface/slices/bridgeQuote/thunks.ts Modified fetchBridgeQuote function to include id in input parameters.
packages/synapse-interface/utils/convertUuidToUnix.ts Introduced a utility function to convert UUIDs to Unix timestamps.
packages/synapse-interface/utils/hooks/useApplicationListener.ts Replaced time retrieval function for historical checks with getUnixTimeMinutesBeforeNow.
packages/synapse-interface/utils/hooks/useIntervalTimer.ts Updated time calculation method by replacing getTimeMinutesFromNow with getUnixTimeMinutesFromNow.
packages/synapse-interface/utils/hooks/useStaleQuoteUpdater.ts Incorporated convertUuidToUnix for deriving timestamps from UUIDs.
packages/synapse-interface/utils/hooks/useTransactionListener.ts Changed historical time calculation to use getUnixTimeMinutesBeforeNow.
packages/synapse-interface/utils/time.ts Renamed time functions to reflect Unix timestamp format.
packages/synapse-interface/utils/txErrorHandler.tsx Removed console log for error object to reduce verbosity.
packages/synapse-interface/utils/types/index.tsx Added id property to the BridgeQuote type for improved tracking.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant BridgeTransactionButton
    participant StateManagedBridge
    participant fetchBridgeQuote

    User->>BridgeTransactionButton: Clicks button
    BridgeTransactionButton->>StateManagedBridge: Trigger transaction
    StateManagedBridge->>fetchBridgeQuote: Fetch bridge quote with id
    fetchBridgeQuote-->>StateManagedBridge: Return quote
    StateManagedBridge-->>BridgeTransactionButton: Update button state
    BridgeTransactionButton-->>User: Show updated state
Loading

🐇 In a world where bridges gleam,
With transactions flowing like a dream,
UUIDs now dance and play,
Unix time leads the way,
Enhancements hop, and errors beam! 🌟


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

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.

@bigboydiamonds bigboydiamonds marked this pull request as draft July 20, 2024 01:40
@bigboydiamonds bigboydiamonds changed the base branch from master to sdk/bridge-quote-uuid July 20, 2024 01:41
Copy link

cloudflare-workers-and-pages bot commented Jul 22, 2024

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: ef838ad
Status: ✅  Deploy successful!
Preview URL: https://70d4116d.sanguine-fe.pages.dev
Branch Preview URL: https://fe-bridge-quote-uuid.sanguine-fe.pages.dev

View logs

@github-actions github-actions bot added size/m and removed size/s labels Aug 26, 2024
@bigboydiamonds bigboydiamonds changed the title [wip] feat(synapse-interface): bridge quote uuid feat(synapse-interface): bridge quote uuid Aug 26, 2024
@bigboydiamonds bigboydiamonds marked this pull request as ready for review August 26, 2024 22:39
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: 1

Outside diff range, codebase verification and nitpick comments (1)
packages/synapse-interface/utils/hooks/useStaleQuoteUpdater.ts (1)

18-18: Comment clarity improvement.

The comment clarifying the default value of staleTimeout is helpful. Ensure that this comment is consistent across the codebase.

Ensure that similar comments are added wherever staleTimeout is used.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c366782 and 1756d6d.

Files selected for processing (14)
  • packages/synapse-interface/components/StateManagedBridge/BridgeTransactionButton.tsx (1 hunks)
  • packages/synapse-interface/components/_Transaction/components/AnimatedProgressBar.tsx (2 hunks)
  • packages/synapse-interface/constants/bridge.ts (1 hunks)
  • packages/synapse-interface/package.json (1 hunks)
  • packages/synapse-interface/pages/state-managed-bridge/index.tsx (12 hunks)
  • packages/synapse-interface/slices/bridgeQuote/thunks.ts (2 hunks)
  • packages/synapse-interface/utils/convertUuidToUnix.ts (1 hunks)
  • packages/synapse-interface/utils/hooks/useApplicationListener.ts (3 hunks)
  • packages/synapse-interface/utils/hooks/useIntervalTimer.ts (2 hunks)
  • packages/synapse-interface/utils/hooks/useStaleQuoteUpdater.ts (2 hunks)
  • packages/synapse-interface/utils/hooks/useTransactionListener.ts (1 hunks)
  • packages/synapse-interface/utils/time.ts (1 hunks)
  • packages/synapse-interface/utils/txErrorHandler.tsx (1 hunks)
  • packages/synapse-interface/utils/types/index.tsx (1 hunks)
Files skipped from review due to trivial changes (2)
  • packages/synapse-interface/utils/time.ts
  • packages/synapse-interface/utils/txErrorHandler.tsx
Additional comments not posted (21)
packages/synapse-interface/utils/convertUuidToUnix.ts (1)

1-1: Verify the import.

Ensure that UUID is correctly imported from uuidv7. If not, update the import statement accordingly.

packages/synapse-interface/utils/hooks/useIntervalTimer.ts (2)

3-3: Verify the import and implementation of getUnixTimeMinutesFromNow.

Ensure that getUnixTimeMinutesFromNow is correctly implemented and imported from @/utils/time.


17-17: Ensure the new function behaves as expected.

Verify that getUnixTimeMinutesFromNow behaves as expected and does not introduce any bugs in the timer functionality.

Also applies to: 24-24

packages/synapse-interface/constants/bridge.ts (1)

7-7: Verify the usage of the id property.

Ensure that the id property is used consistently throughout the codebase and does not introduce any bugs.

packages/synapse-interface/utils/hooks/useStaleQuoteUpdater.ts (3)

22-22: LGTM!

The logic to derive quoteTime from quote.id using convertUuidToUnix is correctly implemented.

The code changes are approved.


24-24: LGTM!

The isValidQuote logic is correctly updated to use the new quoteTime.

The code changes are approved.


7-7: Ensure correctness of the new utility function.

The convertUuidToUnix function is newly introduced. Ensure that this function correctly converts the UUID to a Unix timestamp.

Run the following script to verify the implementation of convertUuidToUnix:

Verification successful

The convertUuidToUnix function is correctly implemented.

The function accurately extracts a timestamp from a UUID by parsing its bytes and converting them to a Unix timestamp. This logic is consistent with typical practices for handling UUIDs.

  • Location: packages/synapse-interface/utils/convertUuidToUnix.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of `convertUuidToUnix`.

# Test: Search for the function implementation. Expect: Correct conversion logic.
rg --type python -A 5 $'def convertUuidToUnix'

Length of output: 78


Script:

#!/bin/bash
# Description: Verify the implementation of `convertUuidToUnix`.

# Test: Search for the function implementation across the codebase.
rg 'function convertUuidToUnix' -A 5

Length of output: 38


Script:

#!/bin/bash
# Description: Search for any occurrence of `convertUuidToUnix` in the codebase.

# Search for `convertUuidToUnix` to find its usage or definition.
rg 'convertUuidToUnix'

# Search for the import statement to trace its origin.
rg 'import .*convertUuidToUnix'

Length of output: 927


Script:

#!/bin/bash
# Description: Extract the implementation of `convertUuidToUnix` to verify its logic.

# Search for the implementation in `convertUuidToUnix.ts`.
rg 'export const convertUuidToUnix' -A 10

Length of output: 947

packages/synapse-interface/utils/hooks/useApplicationListener.ts (3)

30-30: LGTM!

The logic to derive sevenDaysAgo using getUnixTimeMinutesBeforeNow is correctly implemented.

The code changes are approved.


45-47: LGTM!

The logic to update lastConnectedTime using getUnixTimeMinutesBeforeNow is correctly implemented.

The code changes are approved.


13-13: Ensure correctness of the new utility function.

The getUnixTimeMinutesBeforeNow function is newly introduced. Ensure that this function correctly calculates the Unix time.

Run the following script to verify the implementation of getUnixTimeMinutesBeforeNow:

Verification successful

The getUnixTimeMinutesBeforeNow function is correctly implemented.

The function accurately calculates the Unix time by subtracting the specified minutes from the current time in seconds. This implementation is consistent with the expected behavior. No issues were found with this change.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of `getUnixTimeMinutesBeforeNow`.

# Test: Search for the function implementation. Expect: Correct calculation logic.
rg --type python -A 5 $'def getUnixTimeMinutesBeforeNow'

Length of output: 88


Script:

#!/bin/bash
# Description: Verify the implementation of `getUnixTimeMinutesBeforeNow`.

# Test: Search for the function implementation in JavaScript or TypeScript. Expect: Correct calculation logic.
ast-grep --lang javascript --pattern 'function getUnixTimeMinutesBeforeNow($$$) { $$$ }'

Length of output: 90


Script:

#!/bin/bash
# Description: Search for any occurrence of `getUnixTimeMinutesBeforeNow` in JavaScript and TypeScript files.

rg 'getUnixTimeMinutesBeforeNow' --type js --type ts -A 5

Length of output: 4978

packages/synapse-interface/utils/hooks/useTransactionListener.ts (2)

20-20: LGTM!

The logic to derive queryHistoricalTime using getUnixTimeMinutesBeforeNow is correctly implemented.

The code changes are approved.


18-18: Ensure correctness of the new utility function.

The getUnixTimeMinutesBeforeNow function is newly introduced. Ensure that this function correctly calculates the Unix time.

Run the following script to verify the implementation of getUnixTimeMinutesBeforeNow:

packages/synapse-interface/package.json (1)

74-74: LGTM!

The addition of the uuidv7 dependency is appropriate and enhances the project's capabilities.

The code changes are approved.

packages/synapse-interface/components/_Transaction/components/AnimatedProgressBar.tsx (1)

2-2: LGTM! But verify the implementation of getUnixTimeMinutesBeforeNow.

The replacement of getTimeMinutesBeforeNow with getUnixTimeMinutesBeforeNow is appropriate. Ensure that the new function is correctly implemented and imported.

The code changes are approved.

Run the following script to verify the implementation of getUnixTimeMinutesBeforeNow:

Also applies to: 22-22

Verification successful

Function getUnixTimeMinutesBeforeNow is correctly implemented and used.

The function getUnixTimeMinutesBeforeNow is defined in packages/synapse-interface/utils/time.ts and is correctly imported and used across the codebase, including the file under review. The implementation appears to be consistent with its intended purpose.

  • Location of definition: packages/synapse-interface/utils/time.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of `getUnixTimeMinutesBeforeNow`.

# Test: Search for the function implementation. Expect: The function should be defined and correctly implemented.
rg --type ts $'getUnixTimeMinutesBeforeNow'

Length of output: 1260

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

100-100: LGTM!

The addition of the pendingLabel property improves the user interface by providing clearer communication of the button's state during asynchronous operations.

The code changes are approved.

packages/synapse-interface/slices/bridgeQuote/thunks.ts (1)

Line range hint 109-121: LGTM!

The function is correctly implemented and the addition of id enhances the tracking of bridge quotes.

The code changes are approved.

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

73-73: LGTM!

The addition of id enhances the tracking of bridge quotes and the type is correctly defined.

The code changes are approved.

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

57-63: LGTM!

The imports are correctly added and improve the functionality of the component.

The code changes are approved.


81-81: LGTM!

The constant quoteTimeout is correctly defined and likely represents a timeout duration for bridge quote operations.

The code changes are approved.


141-141: LGTM!

The change improves the accuracy of timestamp calculations.

The code changes are approved.


231-241: LGTM!

The changes enhance the robustness and error handling of the function.

The code changes are approved.

Also applies to: 399-399

)

if (timeDifference > quoteTimeout && !isLoading) {
await getAndSetBridgeQuote()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't think we should do this here after executeBridge has been called, which implies user has agreed to quote at t_0. If the quote changes at t_1, then they won't know the quote's changed since it won't be obvious to them.

Example: User sees RFQ quote from chainA to chainB for 100 USDC -> 99 USDC (t_0). They click bridge but don't sign just yet. RFQ ChainB inventory adjusts. Some seconds pass. getAndSetBridgeQuote() is called. Now the new quote is 100 USDC -> 80 USDC on CCTP/SynapseBridge (t_1), but there's no clear indicator to the user that anything's changed (since they're expecting is to sign the txn in their wallet). Issue is mainly the user agreed to quote at t_0 but not t_1 even though they're signing for it.

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1756d6d and 04716d4.

Files selected for processing (1)
  • packages/synapse-interface/pages/state-managed-bridge/index.tsx (12 hunks)
Additional comments not posted (8)
packages/synapse-interface/pages/state-managed-bridge/index.tsx (8)

57-63: LGTM!

The import statements for the new utility functions are correctly added.


72-72: LGTM!

Declaring dispatch at the beginning of the component improves readability and ensures it is available throughout the component's lifecycle.


81-81: LGTM!

The quoteTimeout constant is correctly introduced and likely represents a timeout duration for bridge quote operations.


141-141: LGTM!

The currentTimestamp is now correctly calculated using getUnixTimeMinutesFromNow, reflecting a shift in how timestamps are calculated for bridge transactions.


205-206: LGTM!

Passing quoteTimeout as an argument to useStaleQuoteUpdater ensures that the timeout duration is correctly applied.


231-231: LGTM!

The currentTimestamp is now correctly calculated using getUnixTimeMinutesFromNow, reflecting a shift in how timestamps are calculated for bridge transactions.


243-244: LGTM!

Including address and bridgeQuote.id in the segmentAnalyticsEvent call ensures that the analytics event captures the necessary information for tracking the bridge transaction.


390-390: LGTM!

Using console.error instead of console.log enhances error visibility and debugging.

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 04716d4 and ef838ad.

Files selected for processing (2)
  • packages/synapse-interface/package.json (1 hunks)
  • packages/synapse-interface/pages/state-managed-bridge/index.tsx (12 hunks)
Files skipped from review due to trivial changes (1)
  • packages/synapse-interface/package.json
Files skipped from review as they are similar to previous changes (1)
  • packages/synapse-interface/pages/state-managed-bridge/index.tsx

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

Successfully merging this pull request may close these issues.

2 participants