Compare commits

..

No commits in common. "0f7be3147e501f66ff7c014b296b1b98f0c298b9" and "70ae3c7818bbbc3005cfeac269612fc8af352508" have entirely different histories.

6 changed files with 67 additions and 39 deletions

View File

@ -55,7 +55,24 @@ func (h *MenuHandlers) CheckBalance(ctx context.Context, sym string, input []byt
}
}
content, err = loadUserContent(ctx, string(activeSym), string(activeBal), string(accAlias))
// 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))
if err != nil {
return res, err
}
@ -65,7 +82,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 string) (string, error) {
func loadUserContent(ctx context.Context, activeSym, balance, alias, currectCredit, currentDebt string) (string, error) {
var content string
code := codeFromCtx(ctx)
@ -78,13 +95,25 @@ func loadUserContent(ctx context.Context, activeSym, balance, alias string) (str
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\nBalance: %s\n", alias, balStr)
content = l.Get("%s\nBal: %s\n%s\n%s", alias, balStr, creditStr, debtStr)
} else {
content = l.Get("Balance: %s\n", balStr)
content = l.Get("Bal: %s\n%s\n%s", balStr, creditStr, debtStr)
}
return content, nil
}
@ -120,9 +149,7 @@ 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)
@ -220,6 +247,8 @@ 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
@ -230,7 +259,5 @@ 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,7 +28,6 @@ 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
}
@ -37,13 +36,11 @@ 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 {
@ -114,8 +111,6 @@ 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,26 +1,35 @@
LOAD clear_temporary_value 2
RELOAD clear_temporary_value
LOAD manage_vouchers 160
LOAD manage_vouchers 0
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 swap 2
MOUT vouchers 3
MOUT select_pool 4
MOUT mpesa 5
MOUT account 6
MOUT help 7
MOUT pay_debt 2
MOUT swap 3
MOUT vouchers 4
MOUT select_pool 5
MOUT mpesa 6
MOUT account 7
MOUT help 8
MOUT quit 9
MNEXT next 11
MPREV prev 22
HALT
INCMP credit_send 1
INCMP swap_to_list 2
INCMP my_vouchers 3
INCMP select_pool 4
INCMP mpesa 5
INCMP my_account 6
INCMP help 7
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 quit 9
INCMP > 11
INCMP < 22
INCMP . *

View File

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

View File

@ -1,16 +1,9 @@
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
MAP check_balance
MOUT get_mpesa 1
MOUT send_mpesa 2
MOUT quit 9
HALT
INCMP ^ 0
INCMP pay_debt 1
INCMP get_mpesa 2
INCMP send_mpesa 3
INCMP get_mpesa 1
INCMP send_mpesa 2
INCMP quit 9
INCMP . *

View File

@ -93,6 +93,10 @@ 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 (