Commit 47579ea9 authored by Sybren A. Stüvel's avatar Sybren A. Stüvel

Afromen: Limit how much money is transferred

parent b2c3b7ee
......@@ -36,6 +36,8 @@ const (
currency = "EUR"
)
var maxTransfer = bunqapi.NewAmount(currency, 40*100)
var applicationVersion = "set-during-build"
var cliArgs struct {
......@@ -167,7 +169,26 @@ func afromen(client *bunqapi.Client, threshold bunqapi.Amount) {
return
}
logger = logger.WithField("toTransfer", toTransfer.String())
// Limit to 'maxTransfer'
if isGreater, err := toTransfer.GreaterThan(maxTransfer); err != nil {
logrus.WithFields(logrus.Fields{
"toTransfer": toTransfer.String(),
"maxTransfer": maxTransfer.String(),
logrus.ErrorKey: err,
}).Panic("unable to compare toTransfer with maxTransfer")
} else if isGreater {
logrus.WithFields(logrus.Fields{
"difference": toTransfer.String(),
"toTransfer": maxTransfer.String(),
}).Info("limiting how much is transferred")
toTransfer = maxTransfer
}
logger = logger.WithFields(logrus.Fields{
"toTransfer": toTransfer.String(),
"fromBalance": fromAccount.Balance.String(),
"toBalance": toAccount.Balance.String(),
})
logger.Info("going to transfer money")
toAlias := toAccount.IBANAlias()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment