Skip to content

Comments

feat(dashboard): integrate real STRK and STRKP balances#557

Merged
kimcascante merged 4 commits intoFutureMindsTeam:mainfrom
Sendi0011:feat/ISSUE-DASH-004-integrate-balances-card
Nov 6, 2025
Merged

feat(dashboard): integrate real STRK and STRKP balances#557
kimcascante merged 4 commits intoFutureMindsTeam:mainfrom
Sendi0011:feat/ISSUE-DASH-004-integrate-balances-card

Conversation

@Sendi0011
Copy link
Contributor

📌 Description

Replaced mock balance data in the BalancesCard component with real STRK and STRKP token balances fetched dynamically from the connected user's wallet using Scaffold-Stark hooks.

Previously, the dashboard displayed hardcoded mock values (123.45 STRKP, 0.78 STRK). Now it reads actual token balances from smart contracts and updates them in real-time when the user connects/disconnects their wallet.

🎯 Motivation and Context

Users need to see their actual token holdings on the dashboard. This is essential for:

  • Accurate account balance tracking
  • Making informed decisions about ticket purchases
  • Verifying wallet connections are working properly
  • Providing real-time feedback on token balances

The implementation resolves the disconnect between the UI and actual blockchain data, making the dashboard a reliable source of truth for user balances.

Closes #554

🛠️ How to Test the Change (if applicable)

  1. Navigate to http://localhost:3000/dapp/dashboard
  2. Connect your wallet using the connect button (ensure you have test STRK or STRKP tokens on devnet)
  3. Observe the BalancesCard component in the right sidebar - you should see loading spinners briefly, then real balance values appear
  4. Verify the displayed balances match your actual wallet holdings (formatted to 2 decimals)
  5. Disconnect your wallet - balances should reset to 0.00
  6. Reconnect your wallet - balances should reload correctly
  7. Check the browser console (F12) - there should be no errors or warnings

🖼️ Screenshots (if applicable)

Before: Mock data showing "123.45 STRKP, 0.78 STRK"
After: Real balances showing actual wallet holdings with loading states
Screenshot 2025-10-15 at 22 09 50

🔍 Type of Change

  • 🐞 Bugfix - Fixes an existing issue or bug in the code.
  • New Feature - Adds a new feature or functionality.
  • 🚀 Hotfix - A quick fix for a critical issue in production.
  • 🔄 Refactoring - Improves the code structure without changing its behavior.
  • 📖 Documentation - Updates or creates new documentation.
  • Other (please specify) - Any other change that does not fit into the categories above.

✅ Checklist Before Merging

  • 🧪 I have tested the code and it works as expected.
  • 🎨 My changes follow the project's coding style.
  • 📖 I have updated the documentation if necessary.
  • ⚠️ No new warnings or errors were introduced.
  • 🔍 I have reviewed and approved my own code before submitting.

📌 Additional Notes

Files Modified

  • packages/nextjs/utils/formatBalance.ts (NEW) - Utility function to convert token balances from wei (18 decimals) to readable decimal format
  • packages/nextjs/app/dapp/dashboard/page.tsx (MODIFIED) - Integrated real balance fetching using Scaffold-Stark hooks

Implementation Details

Balance Reading Strategy:

  1. Use useAccount hook from @starknet-react/core to get connected wallet address
  2. Use useScaffoldReadContract to call balanceOf(userAddress) on StarkPlayERC20 contract
  3. Use useScaffoldReadContract to fetch STRK balance from StarkPlayVault contract
  4. Format values using formatBalance() helper function (converts from wei to decimal)
  5. Pass formatted values as props to BalancesCard component

Key Functions:

  • formatBalance(balance, decimals, displayDecimals) - Converts wei to readable decimals
  • Automatically handles loading states with skeleton loaders
  • Gracefully handles disconnected wallets (shows 0.00)
  • Error handling with fallback to 0 balance

Contract Functions Used:

  • StarkPlayERC20.balanceOf(account) - Returns STRKP balance in wei
  • StarkPlayVault.get_total_strk_stored() - Returns STRK balance info

Testing Notes

  • Tested with connected wallet: balances load correctly
  • Tested with disconnected wallet: shows 0.00 with appropriate loading states
  • Verified balance formatting: values display with exactly 2 decimals
  • Confirmed no console errors or TypeScript warnings
  • Wallet connection/disconnection triggers re-fetch automatically

Known Limitations

  • STRK balance currently uses vault total stored value (may need adjustment if different approach is preferred)
  • Balances update on a 5-second interval via Scaffold-Stark's watch mechanism
  • For real-time updates on balance changes, consider implementing event listeners in future iteration

Related Issues

@davidmelendez
Copy link
Collaborator

Hello @Sendi0011 ,

Thank you for your work. Since we’re participating in the StarkNet Hackathon, we need to pause the submission of commits and merging of PRs because this week was the submission deadline, and we’ve been informed that the project must not have any changes after the cutoff date for review. Therefore, your PR will be reviewed until further notice.

Over the weekend, I’ll download your PR and test it so we can see if I need to provide any feedback. For now, I’d appreciate it if you could check the workflow errors, as it’s currently failing.

- Add formatBalance utility to convert wei to decimal format
- Read STRKP token balance from StarkPlayERC20 contract
- Read STRK token balance from StarkPlayVault contract
- Implement loading states while fetching balances
- Use connected user address via useAccount hook
- Format values to 2 decimals for UI display
- Handle wallet disconnection gracefully

Closes FutureMindsTeam#554
@Sendi0011 Sendi0011 force-pushed the feat/ISSUE-DASH-004-integrate-balances-card branch from 434c6bc to 2abb91e Compare October 16, 2025 21:18
@Sendi0011
Copy link
Contributor Author

Hello @Sendi0011 ,

Thank you for your work. Since we’re participating in the StarkNet Hackathon, we need to pause the submission of commits and merging of PRs because this week was the submission deadline, and we’ve been informed that the project must not have any changes after the cutoff date for review. Therefore, your PR will be reviewed until further notice.

Over the weekend, I’ll download your PR and test it so we can see if I need to provide any feedback. For now, I’d appreciate it if you could check the workflow errors, as it’s currently failing.

GM Thanks for the update, @davidmelendez , I’ve fixed the workflow errors. Appreciate the heads-up and will wait for your review.

@davidmelendez
Copy link
Collaborator

Hello @Sendi0011, Can you please check the error CI?

@Sendi0011
Copy link
Contributor Author

Sendi0011 commented Nov 2, 2025

Hello @Sendi0011, Can you please check the error CI?

GM @davidmelendez i just made changes to that

@davidmelendez davidmelendez self-assigned this Nov 2, 2025
@kimcascante kimcascante merged commit f74b3b3 into FutureMindsTeam:main Nov 6, 2025
1 check 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.

ISSUE-DASH-004: Integrate BalancesCard with Real STRK and STRKP Balances

4 participants