Correct total calculator to use 8 decimals

This commit is contained in:
Rene Vergara 2022-07-22 13:41:19 -05:00
parent 20061285a2
commit 80c6fe6b71
Signed by: pitmutt
GPG Key ID: 65122AD495A7F5B2
3 changed files with 11 additions and 3 deletions

View File

@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Fixed calculation of order total to ensure 8 decimal places
- Fixed test for looking for an order with incorrect ID
- Fixed payment scan to focus only on new transactions

View File

@ -188,7 +188,7 @@ updateOrderTotals o =
(qprice o)
(newTotal o)
(if qprice o /= 0
then newTotal o / qprice o
then roundZec (newTotal o / qprice o)
else 0)
(qlines o)
(qpaid o)
@ -215,3 +215,7 @@ markOrderPaid i =
modify
(select ["_id" =: (read i :: B.ObjectId)] "orders")
["$set" =: ["paid" =: True]]
-- | Helper function to round to 8 decimal places
roundZec :: Double -> Double
roundZec n = fromInteger (round $ n * (10 ^ 8)) / (10.0 ^^ 8)

View File

@ -294,6 +294,10 @@ decodeHexText h = E.decodeUtf8With lenientDecode $ BS.pack $ hexRead h
encodeHexText :: T.Text -> String
encodeHexText t = T.unpack . toText . fromBytes $ E.encodeUtf8 t
-- | Helper function to round to 8 decimal places
roundZec :: Double -> Double
roundZec n = fromInteger (round $ n * (10 ^ 8)) / (10.0 ^^ 8)
-- Types for the ZGo database documents
-- | Type to model a country for the database's country list
data Country =
@ -788,8 +792,7 @@ scanPayments config pipe = do
getOrderId re t = do
let reg = matchAllText re (T.unpack $ zmemo t)
if not (null reg)
then do
fst $ head reg ! 1
then fst $ head reg ! 1
else ""
-- | RPC methods