Skip to content

Tracking pending transactions#30

Merged
Niferu merged 1 commit into
developmentfrom
feat/functionality
May 13, 2025
Merged

Tracking pending transactions#30
Niferu merged 1 commit into
developmentfrom
feat/functionality

Conversation

@Niferu

@Niferu Niferu commented May 13, 2025

Copy link
Copy Markdown
Contributor

Implemented processed transaction tracking to store to prevent multiple transactions at once from single user

Summary by CodeRabbit

  • New Features

    • Added real-time tracking of ongoing transactions, with UI updates to reflect processing status.
    • The "Continue" button is now automatically disabled during active transaction processing to prevent duplicate actions.
  • Improvements

    • Enhanced management of pending transactions, providing more accurate feedback during bridging operations.

@coderabbitai

coderabbitai Bot commented May 13, 2025

Copy link
Copy Markdown

Walkthrough

The changes introduce explicit tracking and management of pending bridge transactions and processing state within the account store and propagate this state to UI components. New methods and properties are added to manage transaction processing, and UI elements are updated to reflect ongoing transaction status, disabling actions as appropriate during processing.

Changes

File(s) Change Summary
app/page.tsx Utilizes new transaction processing state and management methods from the account hook; updates callback logic for bridging to Ethereum; passes new isProcessingTransaction prop to MainComponent.
components/main/main.component.tsx Adds isProcessingTransaction prop; updates UI logic to disable actions when a transaction is processing.
components/main/main.types.ts Adds isProcessingTransaction: boolean to MainComponentProps type.
store/account.ts Adds isProcessingTransaction flag and pending transaction management methods to store state and actions.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant MainComponent
    participant HomePage
    participant useTariAccount (store)

    User->>MainComponent: Click "Bridge to Ethereum"
    MainComponent->>HomePage: handleBridgeToEthereum()
    HomePage->>useTariAccount: addPendingTransaction(txId)
    HomePage->>useTariAccount: bridgeToEthereum()
    alt Success
        HomePage->>MainComponent: Advance modal step
        HomePage->>useTariAccount: removePendingTransaction(txId)
    else Error
        HomePage->>useTariAccount: removePendingTransaction(txId)
        HomePage->>Console: Log error
    end
    useTariAccount-->>MainComponent: Update isProcessingTransaction
    MainComponent->>User: Disable/enable UI based on isProcessingTransaction
Loading

Possibly related PRs

  • feat(signer): add Tari L1 signer #23: Introduced signer infrastructure and initial transaction state management, which this PR extends by integrating pending transaction and processing state logic.

Poem

A rabbit hops with nimble feet,
Now tracking every bridge complete!
Pending lists and flags in tow,
The UI learns when not to go.
With every hop, a safer dance—
Transactions wait, then leap, perchance!
🐇✨

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
store/account.ts (2)

56-61: Guard against duplicate transaction IDs.

The addPendingTransaction function adds transaction IDs to the array without checking for duplicates. While unlikely with the current timestamp-based ID generation, adding a check would make the code more robust.

  addPendingTransaction: (txId: string) => {
    set((state) => ({
-     pendingBridgeTx: [...state.pendingBridgeTx, txId],
+     pendingBridgeTx: state.pendingBridgeTx.includes(txId) 
+       ? state.pendingBridgeTx 
+       : [...state.pendingBridgeTx, txId],
      isProcessingTransaction: true,
    }))
  },

71-73: Potential inconsistency with direct state setting.

The setProcessingTransaction method allows directly setting the processing state, which could potentially get out of sync with the actual pending transactions. Consider adding a warning comment to document this potential issue or adding validation that prevents setting isProcessingTransaction to false when there are still pending transactions.

  setProcessingTransaction: (isProcessing: boolean) => {
-   set({ isProcessingTransaction: isProcessing })
+   set((state) => {
+     // Prevent setting isProcessingTransaction to false if there are pending transactions
+     if (!isProcessing && state.pendingBridgeTx.length > 0) {
+       console.warn('Attempting to set isProcessingTransaction to false while pending transactions exist')
+       return { isProcessingTransaction: true }
+     }
+     return { isProcessingTransaction: isProcessing }
+   })
  },
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8e09262 and d520892.

📒 Files selected for processing (4)
  • app/page.tsx (3 hunks)
  • components/main/main.component.tsx (1 hunks)
  • components/main/main.types.ts (1 hunks)
  • store/account.ts (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
app/page.tsx (1)
store/account.ts (1)
  • useTariAccount (30-74)
🔇 Additional comments (9)
components/main/main.types.ts (1)

12-12: LGTM: Adding isProcessingTransaction property is appropriate.

Adding the isProcessingTransaction boolean property to MainComponentProps allows the component to reflect the transaction processing state in the UI, which is essential for providing feedback to users during bridging operations.

store/account.ts (4)

7-8: LGTM: State properties for tracking pending transactions.

The changes to the State interface appropriately add support for tracking pending transactions with the pendingBridgeTx array and the processing status with the isProcessingTransaction flag.


13-15: LGTM: New action methods for transaction management.

These methods provide a complete API for managing pending transactions and their processing state, which aligns well with the PR objectives.


27-27: LGTM: Initial state initialization.

Setting the initial processing state to false is appropriate, as no transactions would be in progress when the application first loads.


62-70: LGTM: Effective removal of pending transactions.

The removePendingTransaction implementation correctly removes the specified transaction ID and updates the processing state based on whether any transactions remain. This ensures the UI state accurately reflects the actual processing state.

components/main/main.component.tsx (2)

25-25: LGTM: Adding isProcessingTransaction to component props.

Properly destructuring the new prop that was added to the component's type definition.


32-32: LGTM: Updating the disabled state logic.

The updated isDisabled logic correctly incorporates the transaction processing state, which prevents users from initiating new transactions while one is already in progress. This is a good UX improvement.

app/page.tsx (2)

33-38: LGTM: Destructuring transaction-related properties.

Properly accessing the transaction management functionality from the account store.


135-135: LGTM: Combining processing state indicators.

Using a logical OR between isProcessingTransaction and isBridging ensures that the UI remains disabled during any kind of transaction processing, whether it's tracked in the account store or by the bridge hook.

Comment thread app/page.tsx
Comment on lines +102 to +114
const txId = `bridge-${Date.now()}`

addPendingTransaction(txId)

bridgeToEthereum({ amount, ethAddress: address })
.then(() => {
setModalStep(2)
})
.catch((error) => {
console.error('Bridge operation failed:', error)

removePendingTransaction(txId)
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling feedback for the user.

While the code correctly adds and removes pending transactions, it doesn't provide any user feedback when a bridge operation fails. The transaction is removed from pending, but the UI doesn't reflect the error.

  bridgeToEthereum({ amount, ethAddress: address })
    .then(() => {
      setModalStep(2)
    })
    .catch((error) => {
      console.error('Bridge operation failed:', error)
+     // Provide user feedback about the error
+     // For example, showing an error message or resetting the modal state
+     setModalStep(1) // Go back to previous step or create a new error step
+     // Consider using a toast notification or modal to display the error
      removePendingTransaction(txId)
    })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const txId = `bridge-${Date.now()}`
addPendingTransaction(txId)
bridgeToEthereum({ amount, ethAddress: address })
.then(() => {
setModalStep(2)
})
.catch((error) => {
console.error('Bridge operation failed:', error)
removePendingTransaction(txId)
})
const txId = `bridge-${Date.now()}`
addPendingTransaction(txId)
bridgeToEthereum({ amount, ethAddress: address })
.then(() => {
setModalStep(2)
})
.catch((error) => {
console.error('Bridge operation failed:', error)
// Provide user feedback about the error
// For example, showing an error message or resetting the modal state
setModalStep(1) // Go back to previous step or create a new error step
// Consider using a toast notification or modal to display the error
removePendingTransaction(txId)
})

@Niferu Niferu merged commit a89813b into development May 13, 2025
2 checks passed
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.

1 participant