Compare commits

..

4 Commits

6 changed files with 39 additions and 67 deletions

View File

@ -55,24 +55,7 @@ func (h *MenuHandlers) CheckBalance(ctx context.Context, sym string, input []byt
}
}
// get current credit
currentCredit, err := store.ReadEntry(ctx, sessionId, storedb.DATA_CURRENT_CREDIT)
if err != nil {
if !db.IsNotFound(err) {
logg.ErrorCtxf(ctx, "failed to read currentCredit entry with", "key", storedb.DATA_CURRENT_CREDIT, "error", err)
return res, err
}
}
// get current debt
currentDebt, err := store.ReadEntry(ctx, sessionId, storedb.DATA_CURRENT_DEBT)
if err != nil {
if !db.IsNotFound(err) {
logg.ErrorCtxf(ctx, "failed to read currentDebt entry with", "key", storedb.DATA_CURRENT_DEBT, "error", err)
return res, err
}
}
content, err = loadUserContent(ctx, string(activeSym), string(activeBal), string(accAlias), string(currentCredit), string(currentDebt))
content, err = loadUserContent(ctx, string(activeSym), string(activeBal), string(accAlias))
if err != nil {
return res, err
}
@ -82,7 +65,7 @@ func (h *MenuHandlers) CheckBalance(ctx context.Context, sym string, input []byt
}
// loadUserContent loads the main user content in the main menu: the alias, balance and active symbol associated with active voucher
func loadUserContent(ctx context.Context, activeSym, balance, alias, currectCredit, currentDebt string) (string, error) {
func loadUserContent(ctx context.Context, activeSym, balance, alias string) (string, error) {
var content string
code := codeFromCtx(ctx)
@ -95,25 +78,13 @@ func loadUserContent(ctx context.Context, activeSym, balance, alias, currectCred
formattedAmount = "0.00"
}
formattedCredit, err := store.TruncateDecimalString(currectCredit, 0)
if err != nil {
formattedCredit = "0"
}
formattedDebt, err := store.TruncateDecimalString(currentDebt, 0)
if err != nil {
formattedDebt = "0"
}
// format the final outputs
balStr := fmt.Sprintf("%s %s", formattedAmount, activeSym)
creditStr := fmt.Sprintf("C: %s ksh", formattedCredit)
debtStr := fmt.Sprintf("D: %s ksh", formattedDebt)
if alias != "" {
content = l.Get("%s\nBal: %s\n%s\n%s", alias, balStr, creditStr, debtStr)
content = l.Get("%s\nBalance: %s\n", alias, balStr)
} else {
content = l.Get("Bal: %s\n%s\n%s", balStr, creditStr, debtStr)
content = l.Get("Balance: %s\n", balStr)
}
return content, nil
}
@ -149,7 +120,9 @@ func (h *MenuHandlers) CalculateCreditAndDebt(ctx context.Context, sym string, i
flag_api_call_error, _ := h.flagManager.GetFlag("flag_api_call_error")
// set the default flag set/reset and content
res.FlagReset = append(res.FlagReset, flag_api_call_error)
res.Content = l.Get("Credit: %s KSH\nDebt: %s KSH\n", "0", "0")
// Fetch session data
_, _, activeSym, _, publicKey, _, err := h.getSessionData(ctx, sessionId)
@ -247,8 +220,6 @@ func (h *MenuHandlers) CalculateCreditAndDebt(ctx context.Context, sym string, i
storedb.DATA_POOL_TO_BALANCES: data.Balances,
storedb.DATA_POOL_TO_DECIMALS: data.Decimals,
storedb.DATA_POOL_TO_ADDRESSES: data.Addresses,
storedb.DATA_CURRENT_CREDIT: kshFormattedCredit,
storedb.DATA_CURRENT_DEBT: kshFormattedDebt,
}
// Write data entries
@ -259,5 +230,7 @@ func (h *MenuHandlers) CalculateCreditAndDebt(ctx context.Context, sym string, i
}
}
res.Content = l.Get("Credit: %s KSH\nDebt: %s KSH\n", kshFormattedCredit, kshFormattedDebt)
return res, nil
}

View File

@ -28,6 +28,7 @@ func (h *MenuHandlers) CalculateMaxPayDebt(ctx context.Context, sym string, inpu
inputStr := string(input)
if inputStr == "0" || inputStr == "9" {
res.FlagReset = append(res.FlagReset, flag_low_swap_amount, flag_api_call_error)
return res, nil
}
@ -36,11 +37,13 @@ func (h *MenuHandlers) CalculateMaxPayDebt(ctx context.Context, sym string, inpu
// Resolve active pool
_, activePoolName, err := h.resolveActivePoolDetails(ctx, sessionId)
if err != nil {
res.FlagReset = append(res.FlagReset, flag_low_swap_amount, flag_api_call_error)
return res, err
}
metadata, err := store.GetSwapToVoucherData(ctx, userStore, sessionId, "1")
if err != nil {
res.FlagReset = append(res.FlagReset, flag_low_swap_amount, flag_api_call_error)
return res, fmt.Errorf("failed to retrieve swap to voucher data: %v", err)
}
if metadata == nil {
@ -111,6 +114,8 @@ func (h *MenuHandlers) CalculateMaxPayDebt(ctx context.Context, sym string, inpu
swapData.ActiveSwapToSym,
)
res.FlagReset = append(res.FlagReset, flag_low_swap_amount, flag_api_call_error)
return res, nil
}

View File

@ -1,35 +1,26 @@
LOAD clear_temporary_value 2
RELOAD clear_temporary_value
LOAD manage_vouchers 0
LOAD manage_vouchers 160
RELOAD manage_vouchers
CATCH api_failure flag_api_call_error 1
LOAD calc_credit_debt 60
RELOAD calc_credit_debt
CATCH api_failure flag_api_call_error 1
LOAD check_balance 148
RELOAD check_balance
MAP check_balance
MOUT send 1
MOUT pay_debt 2
MOUT swap 3
MOUT vouchers 4
MOUT select_pool 5
MOUT mpesa 6
MOUT account 7
MOUT help 8
MOUT swap 2
MOUT vouchers 3
MOUT select_pool 4
MOUT mpesa 5
MOUT account 6
MOUT help 7
MOUT quit 9
MNEXT next 11
MPREV prev 22
HALT
INCMP credit_send 1
INCMP pay_debt 2
INCMP swap_to_list 3
INCMP my_vouchers 4
INCMP select_pool 5
INCMP mpesa 6
INCMP my_account 7
INCMP help 8
INCMP swap_to_list 2
INCMP my_vouchers 3
INCMP select_pool 4
INCMP mpesa 5
INCMP my_account 6
INCMP help 7
INCMP quit 9
INCMP > 11
INCMP < 22
INCMP . *

View File

@ -1 +1 @@
{{.check_balance}}
{{.calc_credit_debt}}

View File

@ -1,9 +1,16 @@
MAP check_balance
MOUT get_mpesa 1
MOUT send_mpesa 2
LOAD calc_credit_debt 150
RELOAD calc_credit_debt
CATCH api_failure flag_api_call_error 1
MAP calc_credit_debt
MOUT pay_debt 1
MOUT get_mpesa 2
MOUT send_mpesa 3
MOUT back 0
MOUT quit 9
HALT
INCMP get_mpesa 1
INCMP send_mpesa 2
INCMP ^ 0
INCMP pay_debt 1
INCMP get_mpesa 2
INCMP send_mpesa 3
INCMP quit 9
INCMP . *

View File

@ -93,10 +93,6 @@ const (
DATA_SEND_TRANSACTION_TYPE
// Holds the recipient formatted phone number
DATA_RECIPIENT_PHONE_NUMBER
// holds the current credit of the user
DATA_CURRENT_CREDIT
// holds the current debt of the user
DATA_CURRENT_DEBT
)
const (