Compare commits

..

5 Commits

Author SHA1 Message Date
alfred-mk
2b4aefdbc9 include the active pool symbol in the balance response
Some checks failed
release / docker (push) Has been cancelled
2026-03-02 12:39:52 +03:00
alfred-mk
549f2d023b rename the menu nodes to shorten the content 2026-03-02 12:28:34 +03:00
7bf71cbfff Merge pull request 'allow-stables-direct-to-mpesa' (#118) from allow-stables-direct-to-mpesa into master
Reviewed-on: #118
2026-02-26 18:17:42 +01:00
Alfred Kamanda
295ca6e53e use the token transfer API for pool deposit
Some checks failed
release / docker (push) Has been cancelled
2026-02-26 14:24:04 +03:00
alfred-mk
de32deab80 set the flag_low_swap_amount for amounts below the min withdrawal
Some checks failed
release / docker (push) Has been cancelled
2026-02-25 15:51:48 +03:00
9 changed files with 31 additions and 19 deletions

View File

@@ -13,8 +13,7 @@ import (
"gopkg.in/leonelquinteros/gotext.v1"
)
// CheckBalance retrieves the balance of the active voucher and sets
// the balance as the result content.
// CheckBalance retrieves the balance of the active voucher, alias and pool symbol
func (h *MenuHandlers) CheckBalance(ctx context.Context, sym string, input []byte) (resource.Result, error) {
var (
res resource.Result
@@ -38,7 +37,6 @@ func (h *MenuHandlers) CheckBalance(ctx context.Context, sym string, input []byt
return res, err
}
}
activeBal, err := store.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_BAL)
if err != nil {
if !db.IsNotFound(err) {
@@ -47,6 +45,7 @@ func (h *MenuHandlers) CheckBalance(ctx context.Context, sym string, input []byt
}
}
// get the account alias
accAlias, err := store.ReadEntry(ctx, sessionId, storedb.DATA_ACCOUNT_ALIAS)
if err != nil {
if !db.IsNotFound(err) {
@@ -55,7 +54,13 @@ func (h *MenuHandlers) CheckBalance(ctx context.Context, sym string, input []byt
}
}
content, err = loadUserContent(ctx, string(activeSym), string(activeBal), string(accAlias))
// Resolve active pool
_, activePoolSymbol, err := h.resolveActivePoolDetails(ctx, sessionId)
if err != nil {
return res, err
}
content, err = loadUserContent(ctx, string(activeSym), string(activeBal), string(accAlias), string(activePoolSymbol))
if err != nil {
return res, err
}
@@ -65,7 +70,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, activePoolSymbol string) (string, error) {
var content string
code := codeFromCtx(ctx)
@@ -82,9 +87,9 @@ func loadUserContent(ctx context.Context, activeSym, balance, alias string) (str
balStr := fmt.Sprintf("%s %s", formattedAmount, activeSym)
if alias != "" {
content = l.Get("%s\nBalance: %s\n", alias, balStr)
content = l.Get("%s\n%s\nPool: %s\n", alias, balStr, activePoolSymbol)
} else {
content = l.Get("Balance: %s\n", balStr)
content = l.Get("%s\nPool: %s\n", balStr, activePoolSymbol)
}
return content, nil
}

View File

@@ -100,8 +100,8 @@ func (h *MenuHandlers) GetMpesaMaxLimit(ctx context.Context, sym string, input [
}
// Fetch min withdrawal amount from config/env
minksh := fmt.Sprintf("%f", config.MinMpesaWithdrawAmount())
minKshFormatted, _ := store.TruncateDecimalString(minksh, 0)
minWithdraw := config.MinMpesaWithdrawAmount() // float64 (20)
minKshFormatted, _ := store.TruncateDecimalString(fmt.Sprintf("%f", minWithdraw), 0)
// If SAT is the same as RAT (default USDm),
// or if the voucher is a stable coin
@@ -115,9 +115,16 @@ func (h *MenuHandlers) GetMpesaMaxLimit(ctx context.Context, sym string, input [
}
activeFloat, _ := strconv.ParseFloat(string(metadata.Balance), 64)
ksh := fmt.Sprintf("%f", activeFloat*rates.Buy)
kshValue := activeFloat * rates.Buy
maxKshFormatted, _ := store.TruncateDecimalString(ksh, 0)
maxKshFormatted, _ := store.TruncateDecimalString(fmt.Sprintf("%f", kshValue), 0)
// Ensure that the max is greater than the min
if kshValue < minWithdraw {
res.FlagSet = append(res.FlagSet, flag_low_swap_amount)
res.Content = l.Get("%s Ksh", maxKshFormatted)
return res, nil
}
res.Content = l.Get(
"Enter the amount of Mpesa to withdraw: (Min: Ksh %s, Max %s Ksh)\n",

View File

@@ -206,8 +206,8 @@ func (h *MenuHandlers) InitiatePoolDeposit(ctx context.Context, sym string, inpu
return res, err
}
// Call pool deposit API
r, err := h.accountService.PoolDeposit(ctx, finalAmountStr, string(publicKey), string(activePoolAddress), poolDepositVoucher.TokenAddress)
// Call token transfer API and send the token to the pool address
r, err := h.accountService.TokenTransfer(ctx, finalAmountStr, string(publicKey), string(activePoolAddress), poolDepositVoucher.TokenAddress)
if err != nil {
flag_api_call_error, _ := h.flagManager.GetFlag("flag_api_call_error")
res.FlagSet = append(res.FlagSet, flag_api_call_error)

View File

@@ -1 +1 @@
My Account
Account

View File

@@ -1 +1 @@
Akaunti yangu
Akaunti

View File

@@ -1 +1 @@
Select pool
Pool

View File

@@ -1 +1 @@
Chagua Bwawa
Bwawa

View File

@@ -1 +1 @@
My Vouchers
Vouchers

View File

@@ -1 +1 @@
Sarafu yangu
Sarafu