forked from urdt/ussd
Include the active symbol in the send menu
This commit is contained in:
parent
e15bac98a5
commit
728815f0c6
@ -70,6 +70,7 @@ func (ls *LocalHandlerService) GetHandler(accountService server.AccountServiceIn
|
||||
ls.DbRs.AddLocalFunc("check_balance", ussdHandlers.CheckBalance)
|
||||
ls.DbRs.AddLocalFunc("validate_recipient", ussdHandlers.ValidateRecipient)
|
||||
ls.DbRs.AddLocalFunc("transaction_reset", ussdHandlers.TransactionReset)
|
||||
ls.DbRs.AddLocalFunc("max_amount", ussdHandlers.MaxAmount)
|
||||
ls.DbRs.AddLocalFunc("validate_amount", ussdHandlers.ValidateAmount)
|
||||
ls.DbRs.AddLocalFunc("reset_transaction_amount", ussdHandlers.ResetTransactionAmount)
|
||||
ls.DbRs.AddLocalFunc("get_recipient", ussdHandlers.GetRecipient)
|
||||
|
@ -785,6 +785,28 @@ func (h *Handlers) ResetTransactionAmount(ctx context.Context, sym string, input
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// MaxAmount gets the current balance from the API and sets it as
|
||||
// the result content.
|
||||
func (h *Handlers) MaxAmount(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||
var res resource.Result
|
||||
var err error
|
||||
|
||||
sessionId, ok := ctx.Value("SessionId").(string)
|
||||
if !ok {
|
||||
return res, fmt.Errorf("missing session")
|
||||
}
|
||||
store := h.userdataStore
|
||||
|
||||
activeBal, err := store.ReadEntry(ctx, sessionId, utils.DATA_ACTIVE_BAL)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
res.Content = string(activeBal)
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// ValidateAmount ensures that the given input is a valid amount and that
|
||||
// it is not more than the current balance.
|
||||
func (h *Handlers) ValidateAmount(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||
@ -824,12 +846,14 @@ func (h *Handlers) ValidateAmount(ctx context.Context, sym string, input []byte)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
err = store.WriteEntry(ctx, sessionId, utils.DATA_AMOUNT, []byte(amountStr))
|
||||
// Format the amount with 2 decimal places before saving
|
||||
formattedAmount := fmt.Sprintf("%.2f", inputAmount)
|
||||
err = store.WriteEntry(ctx, sessionId, utils.DATA_AMOUNT, []byte(formattedAmount))
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
res.Content = fmt.Sprintf("%.3f", inputAmount)
|
||||
res.Content = fmt.Sprintf("%s", formattedAmount)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
@ -872,9 +896,16 @@ func (h *Handlers) GetAmount(ctx context.Context, sym string, input []byte) (res
|
||||
return res, fmt.Errorf("missing session")
|
||||
}
|
||||
store := h.userdataStore
|
||||
|
||||
// retrieve the active symbol
|
||||
activeSym, err := store.ReadEntry(ctx, sessionId, utils.DATA_ACTIVE_SYM)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
amount, _ := store.ReadEntry(ctx, sessionId, utils.DATA_AMOUNT)
|
||||
|
||||
res.Content = string(amount)
|
||||
res.Content = fmt.Sprintf("%s %s", string(amount), string(activeSym))
|
||||
|
||||
return res, nil
|
||||
}
|
||||
@ -900,7 +931,9 @@ func (h *Handlers) InitiateTransaction(ctx context.Context, sym string, input []
|
||||
|
||||
recipient, _ := store.ReadEntry(ctx, sessionId, utils.DATA_RECIPIENT)
|
||||
|
||||
res.Content = l.Get("Your request has been sent. %s will receive %s from %s.", string(recipient), string(amount), string(sessionId))
|
||||
activeSym, _ := store.ReadEntry(ctx, sessionId, utils.DATA_ACTIVE_SYM)
|
||||
|
||||
res.Content = l.Get("Your request has been sent. %s will receive %s %s from %s.", string(recipient), string(amount), string(activeSym), string(sessionId))
|
||||
|
||||
account_authorized_flag, err := h.flagManager.GetFlag("flag_account_authorized")
|
||||
if err != nil {
|
||||
|
@ -1,2 +1,2 @@
|
||||
Maximum amount: {{.check_balance}}
|
||||
Maximum amount: {{.max_amount}}
|
||||
Enter amount:
|
@ -1,6 +1,7 @@
|
||||
LOAD reset_transaction_amount 0
|
||||
LOAD check_balance 48
|
||||
MAP check_balance
|
||||
LOAD max_amount 10
|
||||
RELOAD max_amount
|
||||
MAP max_amount
|
||||
MOUT back 0
|
||||
HALT
|
||||
LOAD validate_amount 64
|
||||
@ -10,5 +11,5 @@ CATCH invalid_amount flag_invalid_amount 1
|
||||
INCMP _ 0
|
||||
LOAD get_recipient 12
|
||||
LOAD get_sender 64
|
||||
LOAD get_amount 12
|
||||
LOAD get_amount 32
|
||||
INCMP transaction_pin *
|
||||
|
@ -1,2 +1,2 @@
|
||||
Kiwango cha juu: {{.check_balance}}
|
||||
Kiwango cha juu: {{.max_amount}}
|
||||
Weka kiwango:
|
@ -1,8 +1,8 @@
|
||||
msgid "Your account balance is %s"
|
||||
msgstr "Salio lako ni %s"
|
||||
|
||||
msgid "Your request has been sent. %s will receive %s from %s."
|
||||
msgstr "Ombi lako limetumwa. %s atapokea %s kutoka kwa %s."
|
||||
msgid "Your request has been sent. %s will receive %s %s from %s."
|
||||
msgstr "Ombi lako limetumwa. %s atapokea %s %s kutoka kwa %s."
|
||||
|
||||
msgid "Thank you for using Sarafu. Goodbye!"
|
||||
msgstr "Asante kwa kutumia huduma ya Sarafu. Kwaheri!"
|
||||
|
Loading…
Reference in New Issue
Block a user