Compare commits
15 Commits
debt-menu
...
v1.4.7-rc.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
78e028b2b6
|
||
| b5015e8831 | |||
|
|
7fdc734c7f | ||
| bf75d2cea4 | |||
|
|
5b995c9d9c
|
||
|
|
1a7d160ae6
|
||
|
|
2b4aefdbc9
|
||
|
|
549f2d023b
|
||
| 7bf71cbfff | |||
|
|
295ca6e53e
|
||
|
|
de32deab80
|
||
|
|
1a9dd64dd6
|
||
|
|
0d92872d90
|
||
|
|
77f0585b56
|
||
| 38f0058d0a |
@@ -39,7 +39,7 @@ DEFAULT_MPESA_ASSET=cUSD
|
||||
MPESA_BEARER_TOKEN=eyJeSIsInRcCI6IkpXVCJ.yJwdWJsaWNLZXkiOiIwrrrrrr
|
||||
MPESA_ONRAMP_BASE=https://pretium.v1.grassecon.net
|
||||
|
||||
# Known stable voucher addresses (USDm, USD₮)
|
||||
STABLE_VOUCHER_ADDRESSES=0x765DE816845861e75A25fCA122bb6898B8B1282a,0x48065fbBE25f71C9282ddf5e1cD6D6A887483D5e
|
||||
# Known stable voucher addresses (USDm, USD₮, USDC)
|
||||
STABLE_VOUCHER_ADDRESSES=0x765DE816845861e75A25fCA122bb6898B8B1282a,0x48065fbBE25f71C9282ddf5e1cD6D6A887483D5e,0xcebA9300f2b948710d2653dD7B07f33A8B32118C
|
||||
DEFAULT_STABLE_VOUCHER_ADDRESS=0x765DE816845861e75A25fCA122bb6898B8B1282a
|
||||
DEFAULT_STABLE_VOUCHER_DECIMALS=18
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -100,11 +100,13 @@ 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, return early with KSH format
|
||||
if string(metadata.TokenAddress) == string(recipientActiveAddress) {
|
||||
// If SAT is the same as RAT (default USDm),
|
||||
// or if the voucher is a stable coin
|
||||
// return early with KSH format
|
||||
if string(metadata.TokenAddress) == string(recipientActiveAddress) || isStableVoucher(metadata.TokenAddress) {
|
||||
txType = "normal"
|
||||
// Save the transaction type
|
||||
if err := userStore.WriteEntry(ctx, sessionId, storedb.DATA_SEND_TRANSACTION_TYPE, []byte(txType)); err != nil {
|
||||
@@ -113,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",
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -242,7 +242,9 @@ func (h *MenuHandlers) determineAndSaveTransactionType(
|
||||
// fetch data for use (to_voucher data)
|
||||
recipientActiveSym, recipientActiveAddress, recipientActiveDecimal, err := h.getRecipientData(ctx, string(recipientPhoneNumber))
|
||||
if err != nil {
|
||||
return err
|
||||
// missing key (case for new users)
|
||||
logg.ErrorCtxf(ctx, "failed on getRecipientData", "error", err)
|
||||
return nil
|
||||
}
|
||||
swapMetadata := &dataserviceapi.TokenHoldings{
|
||||
TokenAddress: string(recipientActiveAddress),
|
||||
@@ -297,6 +299,11 @@ func (h *MenuHandlers) TransactionReset(ctx context.Context, sym string, input [
|
||||
return res, nil
|
||||
}
|
||||
|
||||
err = store.WriteEntry(ctx, sessionId, storedb.DATA_TRANSACTION_CUSTOM_VOUCHER_STATE, []byte(""))
|
||||
if err != nil {
|
||||
return res, nil
|
||||
}
|
||||
|
||||
res.FlagReset = append(res.FlagReset, flag_invalid_recipient, flag_invalid_recipient_with_invite)
|
||||
|
||||
return res, nil
|
||||
@@ -373,11 +380,27 @@ func (h *MenuHandlers) MaxAmount(ctx context.Context, sym string, input []byte)
|
||||
// Format the active balance amount to 2 decimal places
|
||||
formattedBalance, _ := store.TruncateDecimalString(string(activeBal), 2)
|
||||
|
||||
// Case for M-Pesa
|
||||
// if the recipient is Mpesa (address), check if the sender's voucher is a stable coin
|
||||
recipientAddress, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_RECIPIENT)
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "Failed to read recipient's address", "error", err)
|
||||
return res, err
|
||||
}
|
||||
if string(recipientAddress) == config.DefaultMpesaAddress() && isStableVoucher(string(activeAddress)) {
|
||||
res.FlagReset = append(res.FlagReset, flag_swap_transaction)
|
||||
res.Content = l.Get("Maximum amount: %s %s\nEnter amount:", formattedBalance, string(activeSym))
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// confirm the transaction type
|
||||
swapToVoucher, err := store.ReadSwapToVoucher(ctx, h.userdataStore, sessionId)
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed on ReadSwapFromVoucher", "error", err)
|
||||
return res, err
|
||||
// switch to normal transaction as the recipient isn't registered (pool or alias only on sarafu)
|
||||
res.FlagReset = append(res.FlagReset, flag_swap_transaction)
|
||||
res.Content = l.Get("Maximum amount: %s %s\nEnter amount:", formattedBalance, string(activeSym))
|
||||
return res, nil
|
||||
}
|
||||
|
||||
if string(swapToVoucher.TokenAddress) == string(activeAddress) {
|
||||
|
||||
@@ -1 +1 @@
|
||||
My Account
|
||||
Account
|
||||
@@ -1 +1 @@
|
||||
Akaunti yangu
|
||||
Akaunti
|
||||
@@ -1 +1 @@
|
||||
Select pool
|
||||
Pool
|
||||
@@ -1 +1 @@
|
||||
Chagua Bwawa
|
||||
Bwawa
|
||||
@@ -1 +1 @@
|
||||
My Vouchers
|
||||
Vouchers
|
||||
@@ -1 +1 @@
|
||||
Sarafu yangu
|
||||
Sarafu
|
||||
Reference in New Issue
Block a user