(balance) may set min and max values for transaction #33

Open
opened 2023-05-16 05:43:14 +00:00 by crimsen · 3 comments
Owner

It is possible to create a transaction with very very small value e.g. 1e-8 or very big values e.g. 1e+8.

It is better to set max and min Values to create transaction.
Maybe 100 for max and 0.01 for min?

It is possible to create a transaction with very very small value e.g. 1e-8 or very big values e.g. 1e+8. It is better to set max and min Values to create transaction. Maybe 100 for max and 0.01 for min?
crimsen added the
🐞 bug
💡 enhancement
🎒 backend
📺 frontend
labels 2023-05-16 05:43:14 +00:00
crimsen self-assigned this 2023-05-16 05:43:15 +00:00
Author
Owner

The bug is more deeper than expected. There is following behavior in backend.
If you set a transaction for 0.005€ your amount will be 0.01€
If you set a transaction for 0.004€ your amount will be 0.00€, but when you do it some more times your get an amount of 0.01€ and the databes says there was no amount.

class Transaction(db.Model, ModelSerializeMixin):
    __allow_unmapped__ = True
    __tablename__ = "balance_transaction"

    # Public and exported member
    id: int = db.Column("id", Serial, primary_key=True)
    time: datetime = db.Column(UtcDateTime, nullable=False, default=UtcDateTime.current_utc)
    amount: float = db.Column(db.Numeric(precision=5, scale=2, asdecimal=False), nullable=False)
    reversal_id: Optional[int] = db.Column(Serial, db.ForeignKey("balance_transaction.id"))

The code of the transaction shows, there is a scale of 2, but the database save more than it shows.

To fix it, we have to check the amount can't lower than 0.01. Maybe sqlalchemy has a attribute for the database to fix it! (for backend)

In frontend we have to validate that the amount can't be lower than 0.01 in the input field.

The bug is more deeper than expected. There is following behavior in backend. If you set a transaction for 0.005€ your amount will be 0.01€ If you set a transaction for 0.004€ your amount will be 0.00€, but when you do it some more times your get an amount of 0.01€ and the databes says there was no amount. ```python class Transaction(db.Model, ModelSerializeMixin): __allow_unmapped__ = True __tablename__ = "balance_transaction" # Public and exported member id: int = db.Column("id", Serial, primary_key=True) time: datetime = db.Column(UtcDateTime, nullable=False, default=UtcDateTime.current_utc) amount: float = db.Column(db.Numeric(precision=5, scale=2, asdecimal=False), nullable=False) reversal_id: Optional[int] = db.Column(Serial, db.ForeignKey("balance_transaction.id")) ``` The code of the transaction shows, there is a scale of 2, but the database save more than it shows. To fix it, we have to check the amount can't lower than 0.01. Maybe sqlalchemy has a attribute for the database to fix it! (for backend) In frontend we have to validate that the amount can't be lower than 0.01 in the input field.
Author
Owner

Update:

With the scale of 2 in the database, it will simple round to the scale. So in the database is 0.004 a 0.00 and 0.005 a 0.01. This can be correct, maybe it is better always round up oder round down.

In the frontend when you do transaction, it calculate with the exact value, because it get only a ok or not ok from backend to save traffic.
It looks like your balance is higher or lower than expect. If you refresh the site the correct balance value from backend (with the database round priority) will be shown.

Because the minimum value to do a transaction should be 0.01 we have to say the database it should always floor the value to the scale size.
In frontend we have to validate the value like the comment before.

Update: With the scale of 2 in the database, it will simple round to the scale. So in the database is 0.004 a 0.00 and 0.005 a 0.01. This can be correct, maybe it is better always round up oder round down. In the frontend when you do transaction, it calculate with the exact value, because it get only a ok or not ok from backend to save traffic. It looks like your balance is higher or lower than expect. If you refresh the site the correct balance value from backend (with the database round priority) will be shown. Because the minimum value to do a transaction should be 0.01 we have to say the database it should always floor the value to the scale size. In frontend we have to validate the value like the comment before.
Author
Owner

Can only do amounts of min 0.01 is fixed in commit 56b09abeaa441d38aacbf1bcdaeba0099ce6ef4a and cab172dc65

But no max value of amount is set yet.

Can only do amounts of min 0.01 is fixed in commit [56b09abeaa441d38aacbf1bcdaeba0099ce6ef4a](https://flaschengeist.dev/Flaschengeist/flaschengeist-balance/commit/56b09abeaa441d38aacbf1bcdaeba0099ce6ef4a) and cab172dc65a71070f06af6866bc6ec8ca2887b62 But no max value of amount is set yet.
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: Flaschengeist/flaschengeist#33
No description provided.