Feat/direct fee read only#410
Merged
Merged
Conversation
…e live on-chain rate
…k, refresh, and error recovery
…urrent-fee-basis-points
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.
Smart contract (
tipstream.clar
)
Added get-fee-summary(amount uint) — a single read-only call that returns the complete fee picture as a tuple: fee-basis-points, basis-points-divisor, min-fee-ustx, fee-percent, fee-for-amount, amount, and net-amount. No inference needed anywhere.
Frontend config (
contracts.js
)
Added FN_GET_FEE_FOR_AMOUNT and FN_GET_FEE_SUMMARY constants.
Frontend lib (
admin-contract.js
)
Added fetchFeeForAmount(amountMicroSTX) and fetchFeeSummary(amountMicroSTX) — both call the contract directly via the read-only API and return typed results.
Frontend hook (
useContractFee.js
)
New useContractFee hook that fetches the live current-fee-basis-points from the contract on mount and at a configurable poll interval. Falls back to the SDK's compile-time constant when the contract is unreachable, so the fee preview never breaks. Returns feeBasisPoints, feePercent, loading, error, isLive, and refresh.
SendTip.jsx
Replaced the hardcoded FEE_PERCENT import with useContractFee. All fee calculations — balance check, post-condition ceiling, fee preview, and confirm dialog — now use the live on-chain rate passed as feeBasisPoints to the SDK helpers.
AdminDashboard.jsx
Added a "Current Fee Rate" status card to the status bar, reading from feeState.currentFeeBasisPoints so the admin always sees the live rate without a separate lookup.
useAdmin.js
Initialised currentFeeBasisPoints: 0 in the feeState default so the admin dashboard renders cleanly before data loads.
Closes #344