Compare commits
7 Commits
5ed7cbd40a
...
504fcb67d3
| Author | SHA1 | Date | |
|---|---|---|---|
| 504fcb67d3 | |||
| 0e38ef1d04 | |||
| 115cf2fbc9 | |||
| f4c8c45ed1 | |||
| 1a61ea6de3 | |||
| 50c2aff79e | |||
| ea71c08143 |
@ -34,6 +34,7 @@ INCLUDE_STABLES_PARAM=false
|
||||
DEFAULT_MPESA_ADDRESS=0x48a953cA5cf5298bc6f6Af3C608351f537AAcb9e
|
||||
MIN_MPESA_SEND_AMOUNT=100
|
||||
MAX_MPESA_SEND_AMOUNT=250000
|
||||
MIN_MPESA_WITHDRAW_AMOUNT=20
|
||||
DEFAULT_MPESA_ASSET=cUSD
|
||||
MPESA_BEARER_TOKEN=eyJeSIsInRcCI6IkpXVCJ.yJwdWJsaWNLZXkiOiIwrrrrrr
|
||||
MPESA_ONRAMP_BASE=https://pretium.v1.grassecon.net
|
||||
|
||||
@ -102,6 +102,16 @@ func MinMpesaSendAmount() float64 {
|
||||
return f
|
||||
}
|
||||
|
||||
func MinMpesaWithdrawAmount() float64 {
|
||||
v := env.GetEnv("MIN_MPESA_WITHDRAW_AMOUNT", "20")
|
||||
f, err := strconv.ParseFloat(v, 64)
|
||||
if err != nil {
|
||||
return 20 // fallback
|
||||
}
|
||||
return f
|
||||
}
|
||||
|
||||
|
||||
func MaxMpesaSendAmount() float64 {
|
||||
v := env.GetEnv("MAX_MPESA_SEND_AMOUNT", "250000")
|
||||
f, err := strconv.ParseFloat(v, 64)
|
||||
|
||||
@ -28,20 +28,36 @@ func (h *MenuHandlers) GetMpesaMaxLimit(ctx context.Context, sym string, input [
|
||||
flag_api_call_error, _ := h.flagManager.GetFlag("flag_api_call_error")
|
||||
flag_low_swap_amount, _ := h.flagManager.GetFlag("flag_low_swap_amount")
|
||||
flag_incorrect_pool, _ := h.flagManager.GetFlag("flag_incorrect_pool")
|
||||
flag_incorrect_voucher, _ := h.flagManager.GetFlag("flag_incorrect_voucher")
|
||||
|
||||
code := codeFromCtx(ctx)
|
||||
l := gotext.NewLocale(translationDir, code)
|
||||
l.AddDomain("default")
|
||||
|
||||
inputStr := string(input)
|
||||
if inputStr == "0" || inputStr == "9" {
|
||||
if inputStr == "0" || inputStr == "99" || inputStr == "88" || inputStr == "98" {
|
||||
res.FlagReset = append(res.FlagReset, flag_low_swap_amount, flag_api_call_error, flag_incorrect_voucher)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
userStore := h.userdataStore
|
||||
metadata, err := store.GetOrderedVoucherData(ctx, userStore, sessionId, inputStr)
|
||||
if err != nil {
|
||||
return res, fmt.Errorf("failed to retrieve swap to voucher data: %v", err)
|
||||
}
|
||||
if metadata == nil {
|
||||
res.FlagSet = append(res.FlagSet, flag_incorrect_voucher)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// Store the active transaction voucher data
|
||||
if err := store.StoreTemporaryVoucher(ctx, h.userdataStore, sessionId, metadata); err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed on StoreTemporaryVoucher", "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
// Fetch session data
|
||||
_, activeBal, _, activeAddress, publicKey, activeDecimal, err := h.getSessionData(ctx, sessionId)
|
||||
_, _, _, _, publicKey, _, err := h.getSessionData(ctx, sessionId)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@ -83,8 +99,12 @@ func (h *MenuHandlers) GetMpesaMaxLimit(ctx context.Context, sym string, input [
|
||||
return res, err
|
||||
}
|
||||
|
||||
// Fetch min withdrawal amount from config/env
|
||||
minksh := fmt.Sprintf("%f", config.MinMpesaWithdrawAmount())
|
||||
minKshFormatted, _ := store.TruncateDecimalString(minksh, 0)
|
||||
|
||||
// If RAT is the same as SAT, return early with KSH format
|
||||
if string(activeAddress) == string(recipientActiveAddress) {
|
||||
if string(metadata.TokenAddress) == string(recipientActiveAddress) {
|
||||
txType = "normal"
|
||||
// Save the transaction type
|
||||
if err := userStore.WriteEntry(ctx, sessionId, storedb.DATA_SEND_TRANSACTION_TYPE, []byte(txType)); err != nil {
|
||||
@ -92,14 +112,15 @@ func (h *MenuHandlers) GetMpesaMaxLimit(ctx context.Context, sym string, input [
|
||||
return res, err
|
||||
}
|
||||
|
||||
activeFloat, _ := strconv.ParseFloat(string(activeBal), 64)
|
||||
activeFloat, _ := strconv.ParseFloat(string(metadata.Balance), 64)
|
||||
ksh := fmt.Sprintf("%f", activeFloat*rates.Buy)
|
||||
|
||||
kshFormatted, _ := store.TruncateDecimalString(ksh, 0)
|
||||
maxKshFormatted, _ := store.TruncateDecimalString(ksh, 0)
|
||||
|
||||
res.Content = l.Get(
|
||||
"Enter the amount of Mpesa to get: (Max %s Ksh)\n",
|
||||
kshFormatted,
|
||||
"Enter the amount of Mpesa to withdraw: (Min: Ksh %s, Max %s Ksh)\n",
|
||||
minKshFormatted,
|
||||
maxKshFormatted,
|
||||
)
|
||||
|
||||
return res, nil
|
||||
@ -112,7 +133,7 @@ func (h *MenuHandlers) GetMpesaMaxLimit(ctx context.Context, sym string, input [
|
||||
}
|
||||
|
||||
// Check if sender token is swappable
|
||||
canSwap, err := h.accountService.CheckTokenInPool(ctx, string(activePoolAddress), string(activeAddress))
|
||||
canSwap, err := h.accountService.CheckTokenInPool(ctx, string(activePoolAddress), string(metadata.TokenAddress))
|
||||
if err != nil {
|
||||
res.FlagSet = append(res.FlagSet, flag_api_call_error)
|
||||
logg.ErrorCtxf(ctx, "failed on CheckTokenInPool", "error", err)
|
||||
@ -125,7 +146,7 @@ func (h *MenuHandlers) GetMpesaMaxLimit(ctx context.Context, sym string, input [
|
||||
}
|
||||
|
||||
// retrieve the max credit send amounts
|
||||
_, maxRAT, err := h.calculateSendCreditLimits(ctx, activePoolAddress, activeAddress, recipientActiveAddress, publicKey, activeDecimal, recipientActiveDecimal)
|
||||
_, maxRAT, err := h.calculateSendCreditLimits(ctx, activePoolAddress, []byte(metadata.TokenAddress), recipientActiveAddress, publicKey, []byte(metadata.TokenDecimals), recipientActiveDecimal)
|
||||
if err != nil {
|
||||
res.FlagSet = append(res.FlagSet, flag_api_call_error)
|
||||
logg.ErrorCtxf(ctx, "failed on calculateSendCreditLimits", "error", err)
|
||||
@ -155,25 +176,26 @@ func (h *MenuHandlers) GetMpesaMaxLimit(ctx context.Context, sym string, input [
|
||||
}
|
||||
|
||||
// save swap related data for the swap preview
|
||||
metadata := &dataserviceapi.TokenHoldings{
|
||||
swapMetadata := &dataserviceapi.TokenHoldings{
|
||||
TokenAddress: string(recipientActiveAddress),
|
||||
TokenSymbol: string(recipientActiveSym),
|
||||
TokenDecimals: string(recipientActiveDecimal),
|
||||
}
|
||||
|
||||
// Store the active swap_to data
|
||||
if err := store.UpdateSwapToVoucherData(ctx, userStore, sessionId, metadata); err != nil {
|
||||
if err := store.UpdateSwapToVoucherData(ctx, userStore, sessionId, swapMetadata); err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed on UpdateSwapToVoucherData", "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
maxKsh := maxFloat * rates.Buy
|
||||
kshStr := fmt.Sprintf("%f", maxKsh)
|
||||
kshFormatted, _ := store.TruncateDecimalString(kshStr, 0)
|
||||
maxKshFormatted, _ := store.TruncateDecimalString(kshStr, 0)
|
||||
|
||||
res.Content = l.Get(
|
||||
"Enter the amount of Mpesa to get: (Max %s Ksh)\n",
|
||||
kshFormatted,
|
||||
"Enter the amount of Mpesa to withdraw: (Min: Ksh %s, Max %s Ksh)\n",
|
||||
minKshFormatted,
|
||||
maxKshFormatted,
|
||||
)
|
||||
|
||||
return res, nil
|
||||
@ -189,7 +211,7 @@ func (h *MenuHandlers) GetMpesaPreview(ctx context.Context, sym string, input []
|
||||
|
||||
// INPUT IN RAT Ksh
|
||||
inputStr := string(input)
|
||||
if inputStr == "9" {
|
||||
if inputStr == "0" || inputStr == "9" {
|
||||
return res, nil
|
||||
}
|
||||
|
||||
@ -219,16 +241,18 @@ func (h *MenuHandlers) GetMpesaPreview(ctx context.Context, sym string, input []
|
||||
return res, nil
|
||||
}
|
||||
|
||||
min := config.MinMpesaWithdrawAmount()
|
||||
|
||||
if kshAmount < min {
|
||||
// if the input is below the minimum
|
||||
res.FlagSet = append(res.FlagSet, flag_invalid_amount)
|
||||
res.Content = inputStr
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// divide by the buy rate
|
||||
inputAmount := kshAmount / rates.Buy
|
||||
|
||||
// store the user's raw input amount in the temporary value
|
||||
err = userStore.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(inputStr))
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed to write temporary inputStr entry with", "key", storedb.DATA_TEMPORARY_VALUE, "value", inputStr, "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
swapData, err := store.ReadSwapPreviewData(ctx, userStore, sessionId)
|
||||
if err != nil {
|
||||
return res, err
|
||||
@ -239,19 +263,21 @@ func (h *MenuHandlers) GetMpesaPreview(ctx context.Context, sym string, input []
|
||||
return res, err
|
||||
}
|
||||
|
||||
if string(transactionType) == "normal" {
|
||||
activeBal, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_BAL)
|
||||
// get the selected voucher
|
||||
mpesaWithdrawalVoucher, err := store.GetTemporaryVoucherData(ctx, h.userdataStore, sessionId)
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed to read activeBal entry with", "key", storedb.DATA_ACTIVE_BAL, "error", err)
|
||||
return res, err
|
||||
}
|
||||
balanceValue, err := strconv.ParseFloat(string(activeBal), 64)
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "Failed to convert the activeBal to a float", "error", err)
|
||||
logg.ErrorCtxf(ctx, "failed on GetTemporaryVoucherData", "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
if inputAmount > balanceValue {
|
||||
maxValue, err := strconv.ParseFloat(mpesaWithdrawalVoucher.Balance, 64)
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "Failed to convert the swapMaxAmount to a float", "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
if string(transactionType) == "normal" {
|
||||
if inputAmount > maxValue {
|
||||
res.FlagSet = append(res.FlagSet, flag_invalid_amount)
|
||||
res.Content = inputStr
|
||||
return res, nil
|
||||
@ -270,7 +296,7 @@ func (h *MenuHandlers) GetMpesaPreview(ctx context.Context, sym string, input []
|
||||
|
||||
res.Content = l.Get(
|
||||
"You are sending %s %s in order to receive ~ %s ksh",
|
||||
qouteInputAmount, swapData.ActiveSwapFromSym, inputStr,
|
||||
qouteInputAmount, mpesaWithdrawalVoucher.TokenSymbol, inputStr,
|
||||
)
|
||||
|
||||
return res, nil
|
||||
@ -365,6 +391,12 @@ func (h *MenuHandlers) InitiateGetMpesa(ctx context.Context, sym string, input [
|
||||
return res, err
|
||||
}
|
||||
|
||||
mpesaWithdrawalVoucher, err := store.GetTemporaryVoucherData(ctx, h.userdataStore, sessionId)
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed on GetTemporaryVoucherData", "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
if string(transactionType) == "normal" {
|
||||
// Call TokenTransfer for the normal transaction
|
||||
data, err := store.ReadTransactionData(ctx, h.userdataStore, sessionId)
|
||||
@ -372,12 +404,12 @@ func (h *MenuHandlers) InitiateGetMpesa(ctx context.Context, sym string, input [
|
||||
return res, err
|
||||
}
|
||||
|
||||
finalAmountStr, err := store.ParseAndScaleAmount(data.Amount, data.ActiveDecimal)
|
||||
finalAmountStr, err := store.ParseAndScaleAmount(data.Amount, mpesaWithdrawalVoucher.TokenDecimals)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
tokenTransfer, err := h.accountService.TokenTransfer(ctx, finalAmountStr, data.PublicKey, mpesaAddress, data.ActiveAddress)
|
||||
tokenTransfer, err := h.accountService.TokenTransfer(ctx, finalAmountStr, data.PublicKey, mpesaAddress, mpesaWithdrawalVoucher.TokenAddress)
|
||||
if err != nil {
|
||||
res.FlagSet = append(res.FlagSet, flag_api_call_error)
|
||||
res.Content = l.Get("Your request failed. Please try again later.")
|
||||
@ -416,11 +448,6 @@ func (h *MenuHandlers) InitiateGetMpesa(ctx context.Context, sym string, input [
|
||||
// TODO: remove this temporary time delay and replace with a swap and send endpoint
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
finalKshStr, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
amount, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_AMOUNT)
|
||||
if err != nil {
|
||||
return res, err
|
||||
@ -437,7 +464,7 @@ func (h *MenuHandlers) InitiateGetMpesa(ctx context.Context, sym string, input [
|
||||
|
||||
logg.InfoCtxf(ctx, "final TokenTransfer after swap", "trackingId", tokenTransfer.TrackingId)
|
||||
|
||||
res.Content = l.Get("Your request has been sent. You will receive ~ %s ksh", finalKshStr)
|
||||
res.Content = l.Get("Your request has been sent. Please await confirmation")
|
||||
res.FlagReset = append(res.FlagReset, flag_account_authorized)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
@ -12,8 +12,8 @@ import (
|
||||
"gopkg.in/leonelquinteros/gotext.v1"
|
||||
)
|
||||
|
||||
// GetPoolDepositVouchers returns a list of stable coins
|
||||
func (h *MenuHandlers) GetPoolDepositVouchers(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||
// GetOrderedVouchers returns a list of ordered vouchers with stables at the top
|
||||
func (h *MenuHandlers) GetOrderedVouchers(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||
var res resource.Result
|
||||
sessionId, ok := ctx.Value("SessionId").(string)
|
||||
if !ok {
|
||||
@ -26,10 +26,10 @@ func (h *MenuHandlers) GetPoolDepositVouchers(ctx context.Context, sym string, i
|
||||
|
||||
userStore := h.userdataStore
|
||||
|
||||
// Read stable vouchers from the store
|
||||
voucherData, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_STABLE_VOUCHER_SYMBOLS)
|
||||
// Read ordered vouchers from the store
|
||||
voucherData, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_ORDERED_VOUCHER_SYMBOLS)
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed to read stable voucherData entires with", "key", storedb.DATA_STABLE_VOUCHER_SYMBOLS, "error", err)
|
||||
logg.ErrorCtxf(ctx, "failed to read stable voucherData entires with", "key", storedb.DATA_ORDERED_VOUCHER_SYMBOLS, "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
@ -37,9 +37,9 @@ func (h *MenuHandlers) GetPoolDepositVouchers(ctx context.Context, sym string, i
|
||||
return res, nil
|
||||
}
|
||||
|
||||
voucherBalances, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_STABLE_VOUCHER_BALANCES)
|
||||
voucherBalances, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_ORDERED_VOUCHER_BALANCES)
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed to read stable voucherData entires with", "key", storedb.DATA_STABLE_VOUCHER_BALANCES, "error", err)
|
||||
logg.ErrorCtxf(ctx, "failed to read stable voucherData entires with", "key", storedb.DATA_ORDERED_VOUCHER_BALANCES, "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ func (h *MenuHandlers) PoolDepositMaxAmount(ctx context.Context, sym string, inp
|
||||
}
|
||||
|
||||
userStore := h.userdataStore
|
||||
metadata, err := store.GetStableVoucherData(ctx, userStore, sessionId, inputStr)
|
||||
metadata, err := store.GetOrderedVoucherData(ctx, userStore, sessionId, inputStr)
|
||||
if err != nil {
|
||||
return res, fmt.Errorf("failed to retrieve swap to voucher data: %v", err)
|
||||
}
|
||||
|
||||
@ -3,10 +3,12 @@ package application
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"git.defalsify.org/vise.git/db"
|
||||
"git.defalsify.org/vise.git/resource"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/config"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
|
||||
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
||||
dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api"
|
||||
@ -172,35 +174,55 @@ func (h *MenuHandlers) ManageVouchers(ctx context.Context, sym string, input []b
|
||||
}
|
||||
}
|
||||
|
||||
// Filter stable vouchers
|
||||
filteredStableVouchers := make([]dataserviceapi.TokenHoldings, 0)
|
||||
// Get stable voucher priority order (lower index = higher priority)
|
||||
stablePriority := make(map[string]int)
|
||||
stableAddresses := config.StableVoucherAddresses()
|
||||
|
||||
for i, addr := range stableAddresses {
|
||||
stablePriority[strings.ToLower(addr)] = i
|
||||
}
|
||||
|
||||
// Split vouchers into stable and non-stable
|
||||
stableVouchers := make([]dataserviceapi.TokenHoldings, 0)
|
||||
nonStableVouchers := make([]dataserviceapi.TokenHoldings, 0)
|
||||
|
||||
for _, v := range vouchersResp {
|
||||
|
||||
if isStableVoucher(v.TokenAddress) {
|
||||
filteredStableVouchers = append(filteredStableVouchers, v)
|
||||
stableVouchers = append(stableVouchers, v)
|
||||
} else {
|
||||
nonStableVouchers = append(nonStableVouchers, v)
|
||||
}
|
||||
}
|
||||
|
||||
// No stable vouchers
|
||||
if len(filteredStableVouchers) == 0 {
|
||||
// No stable vouchers at all
|
||||
if len(stableVouchers) == 0 {
|
||||
res.FlagSet = append(res.FlagSet, flag_no_stable_vouchers)
|
||||
return res, nil
|
||||
} else {
|
||||
res.FlagReset = append(res.FlagReset, flag_no_stable_vouchers)
|
||||
}
|
||||
|
||||
res.FlagReset = append(res.FlagReset, flag_no_stable_vouchers)
|
||||
// Sort stable vouchers by configured priority
|
||||
sort.SliceStable(stableVouchers, func(i, j int) bool {
|
||||
ai := stablePriority[strings.ToLower(stableVouchers[i].TokenAddress)]
|
||||
aj := stablePriority[strings.ToLower(stableVouchers[j].TokenAddress)]
|
||||
return ai < aj
|
||||
})
|
||||
|
||||
// Process stable vouchers for later use
|
||||
stableVoucherData := store.ProcessVouchers(filteredStableVouchers)
|
||||
// Final ordered list: stable first, then others
|
||||
orderedVouchers := append(stableVouchers, nonStableVouchers...)
|
||||
|
||||
stableVoucherDataMap := map[storedb.DataTyp]string{
|
||||
storedb.DATA_STABLE_VOUCHER_SYMBOLS: stableVoucherData.Symbols,
|
||||
storedb.DATA_STABLE_VOUCHER_BALANCES: stableVoucherData.Balances,
|
||||
storedb.DATA_STABLE_VOUCHER_DECIMALS: stableVoucherData.Decimals,
|
||||
storedb.DATA_STABLE_VOUCHER_ADDRESSES: stableVoucherData.Addresses,
|
||||
// Process ALL vouchers (stable first)
|
||||
orderedVoucherData := store.ProcessVouchers(orderedVouchers)
|
||||
|
||||
orderedVoucherDataMap := map[storedb.DataTyp]string{
|
||||
storedb.DATA_ORDERED_VOUCHER_SYMBOLS: orderedVoucherData.Symbols,
|
||||
storedb.DATA_ORDERED_VOUCHER_BALANCES: orderedVoucherData.Balances,
|
||||
storedb.DATA_ORDERED_VOUCHER_DECIMALS: orderedVoucherData.Decimals,
|
||||
storedb.DATA_ORDERED_VOUCHER_ADDRESSES: orderedVoucherData.Addresses,
|
||||
}
|
||||
|
||||
// Write data entries
|
||||
for key, value := range stableVoucherDataMap {
|
||||
for key, value := range orderedVoucherDataMap {
|
||||
if err := userStore.WriteEntry(ctx, sessionId, key, []byte(value)); err != nil {
|
||||
logg.ErrorCtxf(ctx, "Failed to write data entry for sessionId: %s", sessionId, "key", key, "error", err)
|
||||
continue
|
||||
|
||||
@ -150,7 +150,7 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountService)
|
||||
ls.DbRs.AddLocalFunc("calculate_max_pay_debt", appHandlers.CalculateMaxPayDebt)
|
||||
ls.DbRs.AddLocalFunc("confirm_debt_removal", appHandlers.ConfirmDebtRemoval)
|
||||
ls.DbRs.AddLocalFunc("initiate_pay_debt", appHandlers.InitiatePayDebt)
|
||||
ls.DbRs.AddLocalFunc("get_pool_deposit_vouchers", appHandlers.GetPoolDepositVouchers)
|
||||
ls.DbRs.AddLocalFunc("get_ordered_vouchers", appHandlers.GetOrderedVouchers)
|
||||
ls.DbRs.AddLocalFunc("pool_deposit_max_amount", appHandlers.PoolDepositMaxAmount)
|
||||
ls.DbRs.AddLocalFunc("confirm_pool_deposit", appHandlers.ConfirmPoolDeposit)
|
||||
ls.DbRs.AddLocalFunc("initiate_pool_deposit", appHandlers.InitiatePoolDeposit)
|
||||
|
||||
@ -1 +1 @@
|
||||
{{.get_mpesa_max_limit}}
|
||||
{{.get_ordered_vouchers}}
|
||||
@ -1,10 +1,15 @@
|
||||
CATCH no_voucher flag_no_active_voucher 1
|
||||
LOAD get_ordered_vouchers 0
|
||||
MAP get_ordered_vouchers
|
||||
MOUT back 0
|
||||
MOUT quit 99
|
||||
MNEXT next 88
|
||||
MPREV prev 98
|
||||
HALT
|
||||
INCMP > 88
|
||||
INCMP < 98
|
||||
INCMP _ 0
|
||||
INCMP quit 99
|
||||
LOAD get_mpesa_max_limit 0
|
||||
RELOAD get_mpesa_max_limit
|
||||
MAP get_mpesa_max_limit
|
||||
MOUT back 0
|
||||
MOUT quit 9
|
||||
HALT
|
||||
INCMP _ 0
|
||||
INCMP quit 9
|
||||
INCMP get_mpesa_confirmation *
|
||||
INCMP mpesa_max_limit *
|
||||
|
||||
@ -1,7 +1,4 @@
|
||||
LOAD get_mpesa_preview 0
|
||||
MAP get_mpesa_preview
|
||||
CATCH api_failure flag_api_call_error 1
|
||||
CATCH invalid_credit_send_amount flag_invalid_amount 1
|
||||
MOUT back 0
|
||||
MOUT quit 9
|
||||
HALT
|
||||
|
||||
@ -1 +1 @@
|
||||
Get M-Pesa
|
||||
Withdraw
|
||||
1
services/registration/invalid_get_mpesa_amount
Normal file
1
services/registration/invalid_get_mpesa_amount
Normal file
@ -0,0 +1 @@
|
||||
Amount {{.get_mpesa_preview}} is invalid, please try again:
|
||||
7
services/registration/invalid_get_mpesa_amount.vis
Normal file
7
services/registration/invalid_get_mpesa_amount.vis
Normal file
@ -0,0 +1,7 @@
|
||||
MAP get_mpesa_preview
|
||||
RELOAD reset_transaction_amount
|
||||
MOUT retry 1
|
||||
MOUT quit 9
|
||||
HALT
|
||||
INCMP _ 1
|
||||
INCMP quit 9
|
||||
1
services/registration/invalid_get_mpesa_amount_swa
Normal file
1
services/registration/invalid_get_mpesa_amount_swa
Normal file
@ -0,0 +1 @@
|
||||
Kiwango {{.get_mpesa_preview}} sio sahihi, tafadhali weka tena:
|
||||
1
services/registration/mpesa_max_limit
Normal file
1
services/registration/mpesa_max_limit
Normal file
@ -0,0 +1 @@
|
||||
{{.get_mpesa_max_limit}}
|
||||
13
services/registration/mpesa_max_limit.vis
Normal file
13
services/registration/mpesa_max_limit.vis
Normal file
@ -0,0 +1,13 @@
|
||||
LOAD reset_transaction_amount 10
|
||||
RELOAD reset_transaction_amount
|
||||
MAP get_mpesa_max_limit
|
||||
MOUT back 0
|
||||
MOUT quit 9
|
||||
HALT
|
||||
INCMP _ 0
|
||||
INCMP quit 9
|
||||
LOAD get_mpesa_preview 90
|
||||
RELOAD get_mpesa_preview
|
||||
CATCH api_failure flag_api_call_error 1
|
||||
CATCH invalid_get_mpesa_amount flag_invalid_amount 1
|
||||
INCMP get_mpesa_confirmation *
|
||||
@ -1 +1 @@
|
||||
{{.get_pool_deposit_vouchers}}
|
||||
{{.get_ordered_vouchers}}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
CATCH no_voucher flag_no_active_voucher 1
|
||||
CATCH no_stable_voucher flag_no_stable_vouchers 1
|
||||
LOAD get_pool_deposit_vouchers 0
|
||||
MAP get_pool_deposit_vouchers
|
||||
LOAD get_ordered_vouchers 0
|
||||
MAP get_ordered_vouchers
|
||||
MOUT back 0
|
||||
MOUT quit 99
|
||||
MNEXT next 88
|
||||
|
||||
@ -1 +1 @@
|
||||
Send M-Pesa
|
||||
Top-up
|
||||
@ -104,14 +104,14 @@ const (
|
||||
DATA_VOUCHER_DECIMALS
|
||||
// List of voucher EVM addresses for vouchers valid in the user context.
|
||||
DATA_VOUCHER_ADDRESSES
|
||||
// List of stable voucher symbols in the user context.
|
||||
DATA_STABLE_VOUCHER_SYMBOLS
|
||||
// List of stable voucher decimal counts for vouchers valid in the user context.
|
||||
DATA_STABLE_VOUCHER_BALANCES
|
||||
// List of stable voucher decimal counts for vouchers valid in the user context.
|
||||
DATA_STABLE_VOUCHER_DECIMALS
|
||||
// List of stable voucher EVM addresses for vouchers valid in the user context.
|
||||
DATA_STABLE_VOUCHER_ADDRESSES
|
||||
// List of ordered voucher symbols in the user context.
|
||||
DATA_ORDERED_VOUCHER_SYMBOLS
|
||||
// List of ordered voucher balances in the user context.
|
||||
DATA_ORDERED_VOUCHER_BALANCES
|
||||
// List of ordered voucher decimals in the user context.
|
||||
DATA_ORDERED_VOUCHER_DECIMALS
|
||||
// List of ordered voucher EVM addresses in the user context.
|
||||
DATA_ORDERED_VOUCHER_ADDRESSES
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@ -120,13 +120,13 @@ func GetVoucherData(ctx context.Context, store DataStore, sessionId string, inpu
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetStableVoucherData retrieves and matches stable voucher data
|
||||
func GetStableVoucherData(ctx context.Context, store DataStore, sessionId string, input string) (*dataserviceapi.TokenHoldings, error) {
|
||||
// GetOrderedVoucherData retrieves and matches ordered voucher data
|
||||
func GetOrderedVoucherData(ctx context.Context, store DataStore, sessionId string, input string) (*dataserviceapi.TokenHoldings, error) {
|
||||
keys := []storedb.DataTyp{
|
||||
storedb.DATA_STABLE_VOUCHER_SYMBOLS,
|
||||
storedb.DATA_STABLE_VOUCHER_BALANCES,
|
||||
storedb.DATA_STABLE_VOUCHER_DECIMALS,
|
||||
storedb.DATA_STABLE_VOUCHER_ADDRESSES,
|
||||
storedb.DATA_ORDERED_VOUCHER_SYMBOLS,
|
||||
storedb.DATA_ORDERED_VOUCHER_BALANCES,
|
||||
storedb.DATA_ORDERED_VOUCHER_DECIMALS,
|
||||
storedb.DATA_ORDERED_VOUCHER_ADDRESSES,
|
||||
}
|
||||
data := make(map[storedb.DataTyp]string)
|
||||
|
||||
@ -139,10 +139,10 @@ func GetStableVoucherData(ctx context.Context, store DataStore, sessionId string
|
||||
}
|
||||
|
||||
symbol, balance, decimal, address := MatchVoucher(input,
|
||||
data[storedb.DATA_STABLE_VOUCHER_SYMBOLS],
|
||||
data[storedb.DATA_STABLE_VOUCHER_BALANCES],
|
||||
data[storedb.DATA_STABLE_VOUCHER_DECIMALS],
|
||||
data[storedb.DATA_STABLE_VOUCHER_ADDRESSES],
|
||||
data[storedb.DATA_ORDERED_VOUCHER_SYMBOLS],
|
||||
data[storedb.DATA_ORDERED_VOUCHER_BALANCES],
|
||||
data[storedb.DATA_ORDERED_VOUCHER_DECIMALS],
|
||||
data[storedb.DATA_ORDERED_VOUCHER_ADDRESSES],
|
||||
)
|
||||
|
||||
if symbol == "" {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user