Skip to content

feat: adds unwrap daily limit check#96

Merged
martinserts merged 3 commits into
developmentfrom
verify-unwrap-limit
Dec 12, 2025
Merged

feat: adds unwrap daily limit check#96
martinserts merged 3 commits into
developmentfrom
verify-unwrap-limit

Conversation

@martinserts

Copy link
Copy Markdown
Contributor

Description

Fetches remaining daily limit for unwrapping.
Will reject amounts, which exceed daily limit with an error message.

Screenshot 2025-12-12 at 12 23 31

Motivation and Context

Users could Unwrap any amount as long as they had enough wXTM in their wallet.
Our Bridge has daily limits. So if anyone tried to bridge amounts, which exceed daily limit, bridge just got stuck.
This change limits the amounts users can bridge.

How Has This Been Tested?

Decreased daily limit to 100 in admin UI.

Screenshot 2025-12-12 at 12 22 53

Tried to unwrap an amount, which exceeds it.

Screenshot 2025-12-12 at 12 23 31

Breaking Changes

  • None
  • Requires data directory on base node to be deleted
  • Requires hard fork
  • Other - Please specify

@martinserts martinserts self-assigned this Dec 12, 2025
@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @martinserts, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a critical enhancement to the unwrapping functionality of the bridge, ensuring that users cannot initiate transactions that would exceed the predefined daily unwrapping limits. By integrating a client-side validation mechanism, the application now proactively fetches the remaining daily limit and validates user input against it. This prevents failed transactions and improves the overall user experience by providing clear, immediate feedback when an attempted unwrap amount is too high, thereby streamlining the unwrapping process and maintaining bridge stability.

Highlights

  • Daily Limit Enforcement: Implemented a client-side check to prevent unwrapping amounts that exceed the daily limit, providing immediate feedback to the user.
  • Real-time Limit Display: The application now fetches and displays the remaining daily unwrapping limit to users, updating every 30 seconds.
  • Improved User Feedback: Users receive an immediate error message if their attempted unwrap amount surpasses the daily limit, preventing failed transactions.
  • Backend API Update: The @tari-project/wxtm-bridge-backend-api package has been updated to version 0.1.63 to support the new limit fetching functionality.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces a daily unwrapping limit feature by updating the @tari-project/wxtm-bridge-backend-api dependency and integrating its TokensUnwrappedService. The app/page.tsx component now fetches the remaining daily limit, converts it from micro-XTM to XTM, and passes it to the BridgeForm and BridgeInput components. The BridgeInput component includes a new validation rule to prevent users from exceeding this limit, and the useBridgeToTari hook also performs a pre-check against the daily limit before initiating a transaction. Review comments suggest improving error handling in useBridgeToTari by throwing a specific error instead of returning false when the daily limit is exceeded, and refactoring duplicated micro-XTM to XTM conversion logic and magic numbers into shared utility functions and constants for better maintainability and readability.

Comment on lines +109 to +112
if (amountNum > limitXtm) {
console.error(`[ TAPPLET-BRIDGE ] Daily limit exceeded. Limit: ${limitXtm}, Amount: ${amountNum}`)
return false
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Instead of returning false when the daily limit is exceeded, it would be better to throw an error with a specific message. This would allow the UI to display a more informative error to the user, rather than a generic failure message. This would also make it consistent with the error handling in handleBridgeToEthereum.

Then, you'll need to update the catch block at the end of the bridgeToTari function to re-throw the error, and update handleBridgeToTari in app/page.tsx to handle rejected promises, similar to how handleBridgeToEthereum does.

      if (amountNum > limitXtm) {
        throw new Error(`[ TAPPLET-BRIDGE ] Daily limit exceeded. Limit: ${limitXtm}, Amount: ${amountNum}`);
      }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added the change to throw error - 6183f89

But I will not rethrow, since callers of bridgeToTari() do not expect exceptions.

Comment thread app/page.tsx
Comment on lines +158 to +166
const fetchDailyLimit = async () => {
try {
const limitMicro = await TokensUnwrappedService.getRemainingDailyLimit()
const limitXtm = Number(BigInt(limitMicro) / BigInt(1_000_000))
setRemainingDailyLimit(limitXtm)
} catch (error) {
console.error('[ TAPPLET-BRIDGE ] Failed to fetch daily limit:', error)
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This logic for converting microXTM to XTM, and the magic number 1_000_000, are duplicated in hooks/use-bridge-to-tari.ts. To improve maintainability, this should be refactored.

Consider the following:

  1. Define a constant for 1_000_000 in a shared location like config/index.ts. For example: export const MICRO_XTM_PER_XTM = 1_000_000;
  2. Create a utility function for the conversion in a shared file (e.g., utils/parse-wxtm-token-amount.ts):
    import { MICRO_XTM_PER_XTM } from '@/config';
    
    export const microXtmToXtm = (microXtm: string | bigint): number => {
      return Number(BigInt(microXtm) / BigInt(MICRO_XTM_PER_XTM));
    };
  3. Use this new utility function here and in hooks/use-bridge-to-tari.ts.

Additionally, the interval 30000 on line 170 could also be extracted into a named constant (e.g., REFETCH_LIMIT_INTERVAL) to improve readability.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added microXtmToXtm() - 678ffb0

Comment thread hooks/use-bridge-to-tari.ts Outdated
Comment on lines +104 to +105
const limitMicro = await TokensUnwrappedService.getRemainingDailyLimit()
const limitXtm = Number(BigInt(limitMicro) / BigInt(1_000_000))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This logic for fetching and converting the daily limit is duplicated from app/page.tsx. As suggested in the comment on that file, this should be refactored into a shared utility function to avoid code duplication and magic numbers.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added microXtmToXtm() - 678ffb0

@shanimal08 shanimal08 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

untested, but LGTM!

@martinserts martinserts merged commit e41aaa3 into development Dec 12, 2025
4 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.

2 participants