Fix treasury balance visibility#279
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes Made:
Created useTreasuryBalance hook (
useTreasuryBalance.ts
)
Fetches treasury balance from the Stacks API
Provides balance in both micro-STX and STX
Auto-refreshes every 60 seconds
Includes error handling and loading states
Updated CreateProposalForm component (
CreateProposalForm.tsx
)
Added treasury balance display near the proposal form
Integrated real-time validation against treasury balance
Added pre-submit warning when request exceeds available funds
Visual indicators for treasury health status
Updated SPA CreateProposalPage (
CreateProposal.tsx
)
Added treasury balance display
Integrated treasury balance validation
Added warning messages for insufficient funds
Enhanced validation logic (
validation.ts
)
Created validateAmountAgainstTreasury function
Validates proposal amounts against current treasury balance
Provides clear error messages with available balance
Refactored TreasuryBalance component (
TreasuryBalance.tsx
)
Now uses the shared useTreasuryBalance hook
Reduced code duplication
Added comprehensive tests (
validation.test.ts
)
Tests for treasury balance validation
Edge cases for null balance and decimal amounts
All tests passing
Commits (7 total):
add treasury balance hook for fetching contract balance
integrate treasury balance display in proposal form
refactor treasury balance component to use shared hook
add treasury balance validation helper function
add treasury balance display to spa proposal form
export treasury balance hook from hooks index
add tests for treasury balance validation
Acceptance Criteria Met:
✅ Treasury health is visible during proposal drafting
✅ Amount validation mirrors on-chain rules
✅ Users understand why a proposal may be unfundable before they submit it
✅ Balance is synchronized with the same source used by execution flow
✅ Pre-submit warning when request exceeds available funds
Closes #250