-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: subtract pending txs from available balance #3525
Conversation
@alter-eggo can we link a particular issue to this PR? 🙏 |
🔥 |
export function stxAvailableBalanceValidator(availableBalance: Money) { | ||
export function stxAvailableBalanceValidator( | ||
availableBalance: Money, | ||
pendingTxsBalance: BigNumber |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also pass this in as Money
, rather than just the BigNumber
?
Thinking behind this suggestion is to keep the core data models whole. This enables certain properties. One example: a safer way to perform this operation might be to create a separate helper fn subtractMoney(x: Money, y: Money)
that throws an error if (x.symbol !== y.symbol)
b34e16b
to
a894886
Compare
I prefer not to see this live without the option to "delete/cancel" transactions. This would make it immensely hard to unstuck a stuck wallet even if that becomes rare I believe it will happen (Stuck in this case would be because a pending STX transfer out is higher than the current balance). I would like to see this fix go live together with, to be safe: #3406 |
src/app/common/money/format-money.ts
Outdated
export function subtractMoney(xAmount: Money, yAmount: Money) { | ||
if (xAmount.symbol !== yAmount.symbol) throw new Error('Cannot subtract different currencies'); | ||
return xAmount.amount.minus(yAmount.amount); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think should should also return money, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@314159265359879 the cancel option is going to take a considerable more work. I'm thinking we do want to tackle that soon but that waiting to release this enhancement seems like a net loss since we're probably helping more users with this enhancement sans cancel option than creating problems due to the rare case you flag here? |
a894886
to
b14897f
Compare
I agree I expressed that stronger than I meant. I hope the cancel option can be added soon after. Testing this build I noticed that transactions with defined postconditions "transfer exactly xx STX" out are not yet subtracted from the available amount. Can that be added or would that be a separate PR? I like how STX transfers out as well as the pending STX fees are deducted. I was wondering if we should explain possible difference between available balance (shown on error) and the balance shown in the lower richt corner. Situation currently leading to stuck wallet:
|
Mind creating a separate issue and assigning to @alter-eggo so we can tackle separately?
Can you create a separate issue for this possible enhancement as well? With a screenshot of this state as it's currently shown for review |
@fbwoolf to merge and release |
See title