Skip to content

feat(signer): add some tari signer improvements#31

Merged
karczuRF merged 3 commits into
developmentfrom
feat/tari-signer
May 13, 2025
Merged

feat(signer): add some tari signer improvements#31
karczuRF merged 3 commits into
developmentfrom
feat/tari-signer

Conversation

@karczuRF

@karczuRF karczuRF commented May 13, 2025

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features
    • Tari account balance is now displayed dynamically based on your actual wallet balance, replacing previously hardcoded values in the interface.
  • Chores
    • Improved internal state management to fetch and store the latest Tari wallet balance.
    • Updated API connection to use a fixed staging environment URL for bridge operations.

@coderabbitai

coderabbitai Bot commented May 13, 2025

Copy link
Copy Markdown

Walkthrough

The changes update balance handling for the Tari network by introducing a new WalletBalance type, updating the getTariBalance method to return this type, and integrating dynamic balance retrieval throughout the frontend. The Tari account store now fetches and stores the current available balance, which is reflected in the UI components instead of a hardcoded value.

Changes

File(s) Change Summary
clients/tari-l1-signer.ts Changed getTariBalance return type from Promise<string> to Promise<WalletBalance> and imported WalletBalance.
components/bridge-modal.tsx
components/main/main.component.tsx
Replaced hardcoded Tari balance display with dynamic available_balance from the Tari account store using useTariAccount.
store/account.ts Extended state to include available_balance, initialized it, and updated setTariAccount to fetch/store dynamic balance.
types/tapplet/account.ts Added WalletBalance and PendingBridgeTx interfaces.
hooks/use-bridge-to-ethereum.ts Hardcoded the API base URL for the bridge to a staging endpoint, replacing dynamic config usage.

Sequence Diagram(s)

sequenceDiagram
    participant UI as UI Component
    participant Store as Tari Account Store
    participant Signer as TariL1Signer
    participant Backend as Tari Backend

    UI->>Store: useTariAccount()
    Store->>Signer: getTariBalance()
    Signer->>Backend: sendRequest('getTariBalance')
    Backend-->>Signer: WalletBalance
    Signer-->>Store: WalletBalance
    Store-->>UI: available_balance
    UI->>UI: Display available_balance
Loading

Possibly related PRs

  • feat(signer): add Tari L1 signer #23: The main PR changes the return type of the getTariBalance method in the existing TariL1Signer class, which was originally introduced in the retrieved PR that added the entire TariL1Signer implementation including this method.

Suggested reviewers

  • mariusjagminas

Poem

A hop, a skip, a balance anew,
From static to dynamic, the numbers grew!
Tari’s coins now dance and show,
Real-time sums in every flow.
With types defined and stores in sync,
The bridge feels smoother, don’t you think?
🐇✨

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.

@karczuRF karczuRF merged commit 4d38e2c into development May 13, 2025
1 of 2 checks passed

@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)
clients/tari-l1-signer.ts (1)

8-8: Update JSDoc to reflect new return type.

The return type has been changed from Promise<string> to Promise<WalletBalance>, which is a good enhancement. However, the JSDoc comment still indicates it returns "XTM amount" which is now inaccurate.

Update the JSDoc to match the new return type:

 /**
  * @description get Tari Account balance
- * @returns XTM amount
+ * @returns WalletBalance object containing available_balance, timelocked_balance, pending_incoming_balance, and pending_outgoing_balance
  */

Also applies to: 94-94

store/account.ts (1)

47-49: Well-implemented balance fetching and storage!

The integration of balance fetching and storage works well. The balance is fetched after confirming the account and connection status, and properly stored in the state.

Consider adding a more specific error message when balance fetching fails, as the current catch block only mentions "Could not set the Tari account" which doesn't specifically indicate balance retrieval issues:

    } catch (error) {
-     console.error('Could not set the Tari account: ', error)
+     console.error('Could not set the Tari account or fetch balance: ', error)
    }

Also applies to: 54-54

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a89813b and bedb03f.

📒 Files selected for processing (6)
  • clients/tari-l1-signer.ts (2 hunks)
  • components/bridge-modal.tsx (3 hunks)
  • components/main/main.component.tsx (3 hunks)
  • hooks/use-bridge-to-ethereum.ts (2 hunks)
  • store/account.ts (3 hunks)
  • types/tapplet/account.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
components/bridge-modal.tsx (1)
store/account.ts (1)
  • useTariAccount (32-79)
components/main/main.component.tsx (1)
store/account.ts (1)
  • useTariAccount (32-79)
clients/tari-l1-signer.ts (1)
types/tapplet/account.ts (1)
  • WalletBalance (6-11)
🔇 Additional comments (6)
types/tapplet/account.ts (2)

6-11: Well-defined interface for wallet balance.

The WalletBalance interface is well-structured with clear property names that follow a consistent naming convention (snake_case). The interface provides a comprehensive view of different balance components, which will be valuable for accurate balance reporting throughout the application.


13-15: Clean interface for pending bridge transactions.

The PendingBridgeTx interface is simple and focused, containing just what's needed to track pending bridge transactions.

components/bridge-modal.tsx (1)

12-12: Great improvement using dynamic balance.

Replacing the hardcoded balance with the actual user balance from the Tari account store is a significant improvement for user experience. This ensures users always see their current available balance.

Also applies to: 22-22, 124-124

clients/tari-l1-signer.ts (1)

94-100:

Details

❓ Verification inconclusive

Verify backend compatibility with WalletBalance interface.

This method now returns a complex WalletBalance object instead of a string, which is a potentially breaking change. The TODO comment suggests this might still need implementation on the Tari Universe side.

Please verify that the backend implementation of getTariBalance actually returns an object that matches the WalletBalance interface structure. If the method currently returns a string, additional work may be needed on the backend to support this change.


🏁 Script executed:

#!/bin/bash
# Check if there are other places using getTariBalance that might expect a string
rg "getTariBalance\(\)" -A 3 -B 3

Length of output: 916


Verify backend returns a WalletBalance object

It looks like there are no callers expecting a string—e.g. in store/account.ts you log and consume the result as an object—so please confirm that your backend’s getTariBalance RPC now returns an object matching the WalletBalance interface (rather than a raw string amount). If it still returns a string, you’ll need to update the backend API to supply the full balance structure.

Files to check:

  • clients/tari-l1-signer.ts (lines 94–100): method signature and return type
  • store/account.ts: usage of signer.getTariBalance() with object fields
components/main/main.component.tsx (1)

14-14: Great improvement with dynamic Tari balance!

The integration of the useTariAccount hook to display the actual Tari balance is well-implemented. This replaces the hardcoded Tari balance value with the dynamically fetched available_balance, providing users with accurate information.

Note that balances for other networks are still hardcoded, as referenced in the TODO comment on line 69. Might be worth planning for future enhancements to fetch those balances dynamically as well.

Also applies to: 32-32, 72-72

store/account.ts (1)

7-7: Good addition of balance state management!

The state interface and initial state are properly updated to include the available_balance property, with a sensible default value of 0.

Also applies to: 27-27

@@ -1,4 +1,4 @@
import { config } from '@/config'
// import { config } from '@/config'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Avoid hardcoding API URLs in the code.

Replacing configuration-based API URL with a hardcoded staging URL creates several issues:

  1. Reduces flexibility across environments (dev, staging, prod)
  2. Makes it harder to switch environments without code changes
  3. May cause issues if the staging environment changes or is unavailable

Consider replacing with:

-// import { config } from '@/config'
+import { config } from '@/config'

-// OpenAPI.BASE = config.BACKEND_API_URL
-OpenAPI.BASE = 'https://api.staging-bridge.tari.com'
+OpenAPI.BASE = config.BACKEND_API_URL

Also applies to: 14-15


🏁 Script executed:

#!/bin/bash
# Check if config.ts file exists and verify BACKEND_API_URL structure
fd "config\.(ts|js)" --exec grep -l "BACKEND_API_URL" {} \;

Length of output: 62


🏁 Script executed:

#!/bin/bash
# List all config.ts/js files in the repo
echo "Config files found:"
fd "config\\.(ts|js)" || echo "No config.ts/js files at root level"

# Search for BACKEND_API_URL usage across the codebase
echo "Occurrences of BACKEND_API_URL:"
rg -n "BACKEND_API_URL" || echo "No occurrences of BACKEND_API_URL found"

Length of output: 397


🏁 Script executed:

#!/bin/bash
# Display the first 30 lines of config/index.ts to verify export structure
echo "=== config/index.ts ==="
sed -n '1,30p' config/index.ts || echo "Unable to read config/index.ts"

Length of output: 374


🏁 Script executed:

#!/bin/bash
# Display the first 30 lines of hooks/use-bridge-to-ethereum.ts to verify imports and URL assignment
echo "=== hooks/use-bridge-to-ethereum.ts (lines 1-30) ==="
sed -n '1,30p' hooks/use-bridge-to-ethereum.ts || echo "File not found"

Length of output: 1076


Avoid hardcoding API URLs

Hardcoding the staging endpoint reduces flexibility and forces code changes for environment switches. Since config/index.ts already exports BACKEND_API_URL, you can drive the base URL from environment variables:

• File: hooks/use-bridge-to-ethereum.ts
– Uncomment the import for config
– Replace the hardcoded staging URL with config.BACKEND_API_URL

Suggested diff:

--- a/hooks/use-bridge-to-ethereum.ts
+++ b/hooks/use-bridge-to-ethereum.ts
@@ 1,3c1,3
-// import { config } from '@/config'
+import { config } from '@/config'

@@ 14,16c14
-// OpenAPI.BASE = config.BACKEND_API_URL
-OpenAPI.BASE = 'https://api.staging-bridge.tari.com'
+OpenAPI.BASE = config.BACKEND_API_URL

This ensures the bridge service URL adapts to dev, staging or prod based on process.env.NEXT_PUBLIC_BACKEND_API_URL.

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