Compare commits
4 Commits
70ae3c7818
...
0f7be3147e
| Author | SHA1 | Date | |
|---|---|---|---|
| 0f7be3147e | |||
| 6a4909b8a1 | |||
| 7783ba8835 | |||
| e4c10d23d3 |
@ -55,24 +55,7 @@ func (h *MenuHandlers) CheckBalance(ctx context.Context, sym string, input []byt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// get current credit
|
content, err = loadUserContent(ctx, string(activeSym), string(activeBal), string(accAlias))
|
||||||
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 {
|
if err != nil {
|
||||||
return res, err
|
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
|
// 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
|
var content string
|
||||||
|
|
||||||
code := codeFromCtx(ctx)
|
code := codeFromCtx(ctx)
|
||||||
@ -95,25 +78,13 @@ func loadUserContent(ctx context.Context, activeSym, balance, alias, currectCred
|
|||||||
formattedAmount = "0.00"
|
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
|
// format the final outputs
|
||||||
balStr := fmt.Sprintf("%s %s", formattedAmount, activeSym)
|
balStr := fmt.Sprintf("%s %s", formattedAmount, activeSym)
|
||||||
creditStr := fmt.Sprintf("C: %s ksh", formattedCredit)
|
|
||||||
debtStr := fmt.Sprintf("D: %s ksh", formattedDebt)
|
|
||||||
|
|
||||||
if alias != "" {
|
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 {
|
} else {
|
||||||
content = l.Get("Bal: %s\n%s\n%s", balStr, creditStr, debtStr)
|
content = l.Get("Balance: %s\n", balStr)
|
||||||
}
|
}
|
||||||
return content, nil
|
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")
|
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.FlagReset = append(res.FlagReset, flag_api_call_error)
|
||||||
|
res.Content = l.Get("Credit: %s KSH\nDebt: %s KSH\n", "0", "0")
|
||||||
|
|
||||||
// Fetch session data
|
// Fetch session data
|
||||||
_, _, activeSym, _, publicKey, _, err := h.getSessionData(ctx, sessionId)
|
_, _, 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_BALANCES: data.Balances,
|
||||||
storedb.DATA_POOL_TO_DECIMALS: data.Decimals,
|
storedb.DATA_POOL_TO_DECIMALS: data.Decimals,
|
||||||
storedb.DATA_POOL_TO_ADDRESSES: data.Addresses,
|
storedb.DATA_POOL_TO_ADDRESSES: data.Addresses,
|
||||||
storedb.DATA_CURRENT_CREDIT: kshFormattedCredit,
|
|
||||||
storedb.DATA_CURRENT_DEBT: kshFormattedDebt,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write data entries
|
// 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
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,6 +28,7 @@ func (h *MenuHandlers) CalculateMaxPayDebt(ctx context.Context, sym string, inpu
|
|||||||
|
|
||||||
inputStr := string(input)
|
inputStr := string(input)
|
||||||
if inputStr == "0" || inputStr == "9" {
|
if inputStr == "0" || inputStr == "9" {
|
||||||
|
res.FlagReset = append(res.FlagReset, flag_low_swap_amount, flag_api_call_error)
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,11 +37,13 @@ func (h *MenuHandlers) CalculateMaxPayDebt(ctx context.Context, sym string, inpu
|
|||||||
// Resolve active pool
|
// Resolve active pool
|
||||||
_, activePoolName, err := h.resolveActivePoolDetails(ctx, sessionId)
|
_, activePoolName, err := h.resolveActivePoolDetails(ctx, sessionId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
res.FlagReset = append(res.FlagReset, flag_low_swap_amount, flag_api_call_error)
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
metadata, err := store.GetSwapToVoucherData(ctx, userStore, sessionId, "1")
|
metadata, err := store.GetSwapToVoucherData(ctx, userStore, sessionId, "1")
|
||||||
if err != nil {
|
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)
|
return res, fmt.Errorf("failed to retrieve swap to voucher data: %v", err)
|
||||||
}
|
}
|
||||||
if metadata == nil {
|
if metadata == nil {
|
||||||
@ -111,6 +114,8 @@ func (h *MenuHandlers) CalculateMaxPayDebt(ctx context.Context, sym string, inpu
|
|||||||
swapData.ActiveSwapToSym,
|
swapData.ActiveSwapToSym,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
res.FlagReset = append(res.FlagReset, flag_low_swap_amount, flag_api_call_error)
|
||||||
|
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,35 +1,26 @@
|
|||||||
LOAD clear_temporary_value 2
|
LOAD clear_temporary_value 2
|
||||||
RELOAD clear_temporary_value
|
RELOAD clear_temporary_value
|
||||||
LOAD manage_vouchers 0
|
LOAD manage_vouchers 160
|
||||||
RELOAD manage_vouchers
|
RELOAD manage_vouchers
|
||||||
CATCH api_failure flag_api_call_error 1
|
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
|
LOAD check_balance 148
|
||||||
RELOAD check_balance
|
RELOAD check_balance
|
||||||
MAP check_balance
|
MAP check_balance
|
||||||
MOUT send 1
|
MOUT send 1
|
||||||
MOUT pay_debt 2
|
MOUT swap 2
|
||||||
MOUT swap 3
|
MOUT vouchers 3
|
||||||
MOUT vouchers 4
|
MOUT select_pool 4
|
||||||
MOUT select_pool 5
|
MOUT mpesa 5
|
||||||
MOUT mpesa 6
|
MOUT account 6
|
||||||
MOUT account 7
|
MOUT help 7
|
||||||
MOUT help 8
|
|
||||||
MOUT quit 9
|
MOUT quit 9
|
||||||
MNEXT next 11
|
|
||||||
MPREV prev 22
|
|
||||||
HALT
|
HALT
|
||||||
INCMP credit_send 1
|
INCMP credit_send 1
|
||||||
INCMP pay_debt 2
|
INCMP swap_to_list 2
|
||||||
INCMP swap_to_list 3
|
INCMP my_vouchers 3
|
||||||
INCMP my_vouchers 4
|
INCMP select_pool 4
|
||||||
INCMP select_pool 5
|
INCMP mpesa 5
|
||||||
INCMP mpesa 6
|
INCMP my_account 6
|
||||||
INCMP my_account 7
|
INCMP help 7
|
||||||
INCMP help 8
|
|
||||||
INCMP quit 9
|
INCMP quit 9
|
||||||
INCMP > 11
|
|
||||||
INCMP < 22
|
|
||||||
INCMP . *
|
INCMP . *
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
{{.check_balance}}
|
{{.calc_credit_debt}}
|
||||||
@ -1,9 +1,16 @@
|
|||||||
MAP check_balance
|
LOAD calc_credit_debt 150
|
||||||
MOUT get_mpesa 1
|
RELOAD calc_credit_debt
|
||||||
MOUT send_mpesa 2
|
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
|
MOUT quit 9
|
||||||
HALT
|
HALT
|
||||||
INCMP get_mpesa 1
|
INCMP ^ 0
|
||||||
INCMP send_mpesa 2
|
INCMP pay_debt 1
|
||||||
|
INCMP get_mpesa 2
|
||||||
|
INCMP send_mpesa 3
|
||||||
INCMP quit 9
|
INCMP quit 9
|
||||||
INCMP . *
|
INCMP . *
|
||||||
|
|||||||
@ -93,10 +93,6 @@ const (
|
|||||||
DATA_SEND_TRANSACTION_TYPE
|
DATA_SEND_TRANSACTION_TYPE
|
||||||
// Holds the recipient formatted phone number
|
// Holds the recipient formatted phone number
|
||||||
DATA_RECIPIENT_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 (
|
const (
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user