Wallet fails to change/update when value would lower it below 0

When a player incurs a penalty (for example when forfeiting a match), the wallet fails to update completely.

Is there a way to make it lower the amount to 0 at least, or even better below 0?

The wallet API is not designed to store negative values. You can submit changesets that would lower values to exactly 0 but never negative.

For example if the wallet currently contains {"coins":10} then the changesets {"coins":-10} or {"coins":-5} are both valid because the resulting value would be >= 0, but the changeset {"coins":-20} is not valid.

Sure I understand if that is intentional, but is it possible to have it automatically lower to exactly 0 if the changeset would lower it below 0?

That would save a lot of error handling and would also save having to fetch the user account at runtime, then fetch the wallet, just to make sure it’s high enough to lower :sweat_smile:

There is no separate operation to fetch the account and fetch the wallet. The account contains the wallet.

No, it’s currently not possible to submit a wallet operation to deduct all of a given currency field. It’s not a common operation so hasn’t been requested so far. Usually purchases/deductions have a fixed value associated, and the player either can or cannot afford them.

I’d suggest your use case is unusual so you should do exactly what you say: read the wallet, and deduct the exact amount that just happens to be everything they have of some currency.

I’m aware of that too, which is what make it so tedious.

Thanks anyway, it’s a minor optimization so it should be fine without it!

From your post above it sounded like you were expecting two different operations: one to fetch the account, one to fetch the wallet.

Just to be clear for others that find this post: fetching the user’s account and wallet is all one operation, they’re provided together.