Skip to content
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

Merged
merged 1 commit into from
Apr 18, 2023
Merged

Conversation

alter-eggo
Copy link
Contributor

@alter-eggo alter-eggo commented Apr 7, 2023

Try out this version of the Hiro Wallet - download extension builds.

See title

@vercel vercel bot temporarily deployed to Preview April 7, 2023 16:36 Inactive
@markmhendrickson
Copy link
Collaborator

@alter-eggo can we link a particular issue to this PR? 🙏

@Hero-Gamer
Copy link

🔥

export function stxAvailableBalanceValidator(availableBalance: Money) {
export function stxAvailableBalanceValidator(
availableBalance: Money,
pendingTxsBalance: BigNumber
Copy link
Collaborator

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)

@alter-eggo alter-eggo marked this pull request as ready for review April 12, 2023 18:31
@vercel vercel bot temporarily deployed to Preview April 12, 2023 18:32 Inactive
@314159265359879
Copy link
Contributor

314159265359879 commented Apr 13, 2023

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

Comment on lines 31 to 34
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);
}
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@markmhendrickson
Copy link
Collaborator

markmhendrickson commented Apr 13, 2023

@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?

@vercel vercel bot temporarily deployed to Preview April 13, 2023 15:29 Inactive
@314159265359879
Copy link
Contributor

@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?

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.
I.e "Available balance takes into account pending transfers of STX and pending fees"
(...and other transactions with postconditions that suggest outgoing STX).

Situation currently leading to stuck wallet:

  1. Swap 200 STX to ALEX (on DEX)
  2. Send max amount of STX to exchange (with wallet)
    = stuck wallet after 1. is processed.

@markmhendrickson
Copy link
Collaborator

markmhendrickson commented Apr 14, 2023

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?

Mind creating a separate issue and assigning to @alter-eggo so we can tackle separately?

I was wondering if we should explain possible difference between available balance (shown on error) and the balance shown in the lower richt corner.
I.e "Available balance takes into account pending transfers of STX and pending fees"
(...and other transactions with postconditions that suggest outgoing STX).

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

@markmhendrickson
Copy link
Collaborator

@fbwoolf to merge and release

@fbwoolf fbwoolf added this pull request to the merge queue Apr 18, 2023
Merged via the queue into dev with commit 21493a6 Apr 18, 2023
@fbwoolf fbwoolf deleted the feat/send-max branch April 18, 2023 14:39
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.

Transaction amount + fee still exceeding address' total balance causing pending issues
6 participants