Compare commits
2 Commits
credit-sen
...
self-pin-r
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fe5772fb3b
|
||
|
|
82d0e588c9
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -8,4 +8,3 @@ id_*
|
||||
*.gdbm
|
||||
*.log
|
||||
user-data
|
||||
**/*/vise-asm
|
||||
|
||||
@@ -21,6 +21,7 @@ func (h *MenuHandlers) Authorize(ctx context.Context, sym string, input []byte)
|
||||
flag_incorrect_pin, _ := h.flagManager.GetFlag("flag_incorrect_pin")
|
||||
flag_account_authorized, _ := h.flagManager.GetFlag("flag_account_authorized")
|
||||
flag_allow_update, _ := h.flagManager.GetFlag("flag_allow_update")
|
||||
flag_account_pin_reset, _ := h.flagManager.GetFlag("flag_account_pin_reset")
|
||||
|
||||
pinInput := string(input)
|
||||
|
||||
@@ -33,7 +34,9 @@ func (h *MenuHandlers) Authorize(ctx context.Context, sym string, input []byte)
|
||||
AccountPin, err := store.ReadEntry(ctx, sessionId, storedb.DATA_ACCOUNT_PIN)
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed to read AccountPin entry with", "key", storedb.DATA_ACCOUNT_PIN, "error", err)
|
||||
return res, err
|
||||
logg.InfoCtxf(ctx, "Setting the flag_account_pin_reset flag for the user to set their own PIN")
|
||||
res.FlagSet = append(res.FlagSet, flag_account_pin_reset)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// verify that the user provided the correct PIN
|
||||
|
||||
@@ -3,7 +3,6 @@ package application
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"git.defalsify.org/vise.git/db"
|
||||
"git.defalsify.org/vise.git/resource"
|
||||
@@ -105,7 +104,6 @@ func (h *MenuHandlers) GetDefaultPool(ctx context.Context, sym string, input []b
|
||||
|
||||
// ViewPool retrieves the pool details from the user store
|
||||
// and displays it to the user for them to select it.
|
||||
// if the data does not exist, it calls the API to get the pool details
|
||||
func (h *MenuHandlers) ViewPool(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||
var res resource.Result
|
||||
sessionId, ok := ctx.Value("SessionId").(string)
|
||||
@@ -133,11 +131,8 @@ func (h *MenuHandlers) ViewPool(ctx context.Context, sym string, input []byte) (
|
||||
if poolData == nil {
|
||||
flag_api_call_error, _ := h.flagManager.GetFlag("flag_api_call_error")
|
||||
|
||||
// convert to uppercase before the call
|
||||
poolSymbol := strings.ToUpper(inputStr)
|
||||
|
||||
// no match found. Call the API using the inputStr as the symbol
|
||||
poolResp, err := h.accountService.RetrievePoolDetails(ctx, poolSymbol)
|
||||
poolResp, err := h.accountService.RetrievePoolDetails(ctx, inputStr)
|
||||
if err != nil {
|
||||
res.FlagSet = append(res.FlagSet, flag_api_call_error)
|
||||
return res, nil
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -259,7 +258,6 @@ func (h *MenuHandlers) TransactionReset(ctx context.Context, sym string, input [
|
||||
|
||||
flag_invalid_recipient, _ := h.flagManager.GetFlag("flag_invalid_recipient")
|
||||
flag_invalid_recipient_with_invite, _ := h.flagManager.GetFlag("flag_invalid_recipient_with_invite")
|
||||
|
||||
store := h.userdataStore
|
||||
err = store.WriteEntry(ctx, sessionId, storedb.DATA_AMOUNT, []byte(""))
|
||||
if err != nil {
|
||||
@@ -338,13 +336,28 @@ 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)
|
||||
|
||||
// If normal transaction return balance
|
||||
if string(transactionType) == "normal" {
|
||||
// If normal transaction, or if the sym is send_max_amount, return balance
|
||||
if string(transactionType) == "normal" || sym == "send_max_amount" {
|
||||
res.FlagReset = append(res.FlagReset, flag_swap_transaction)
|
||||
|
||||
res.Content = l.Get("Maximum amount: %s %s\nEnter amount:", formattedBalance, string(activeSym))
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
res.FlagSet = append(res.FlagSet, flag_swap_transaction)
|
||||
|
||||
// Get the recipient's phone number to read other data items
|
||||
recipientPhoneNumber, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_RECIPIENT_PHONE_NUMBER)
|
||||
if err != nil {
|
||||
// invalid state
|
||||
return res, err
|
||||
}
|
||||
recipientActiveSym, recipientActiveAddress, recipientActiveDecimal, err := h.getRecipientData(ctx, string(recipientPhoneNumber))
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
// Resolve active pool address
|
||||
activePoolAddress, err := h.resolveActivePoolAddress(ctx, sessionId)
|
||||
if err != nil {
|
||||
@@ -359,31 +372,16 @@ func (h *MenuHandlers) MaxAmount(ctx context.Context, sym string, input []byte)
|
||||
logg.ErrorCtxf(ctx, "failed on CheckTokenInPool", "error", err)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
res.FlagReset = append(res.FlagReset, flag_swap_transaction)
|
||||
res.Content = l.Get("Maximum amount: %s %s\nEnter amount:", formattedBalance, string(activeSym))
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// Get the recipient's phone number to read other data items
|
||||
recipientPhoneNumber, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_RECIPIENT_PHONE_NUMBER)
|
||||
if err != nil {
|
||||
// invalid state
|
||||
return res, err
|
||||
}
|
||||
recipientActiveSym, recipientActiveAddress, recipientActiveDecimal, err := h.getRecipientData(ctx, string(recipientPhoneNumber))
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
// retrieve the max credit send amounts
|
||||
maxSAT, maxRAT, err := h.calculateSendCreditLimits(ctx, activePoolAddress, activeAddress, recipientActiveAddress, publicKey, activeDecimal, recipientActiveDecimal)
|
||||
if err != nil {
|
||||
// if an error (such as Swap rates not found for the speficied pool and tokens), fall back to a normal transaction
|
||||
res.FlagSet = append(res.FlagSet, flag_api_call_error)
|
||||
logg.ErrorCtxf(ctx, "failed on calculateSendCreditLimits", "error", err)
|
||||
res.FlagReset = append(res.FlagReset, flag_swap_transaction)
|
||||
res.Content = l.Get("Maximum amount: %s %s\nEnter amount:", formattedBalance, string(activeSym))
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
@@ -415,9 +413,6 @@ func (h *MenuHandlers) MaxAmount(ctx context.Context, sym string, input []byte)
|
||||
return res, err
|
||||
}
|
||||
|
||||
// only set the flag once all checks pass
|
||||
res.FlagSet = append(res.FlagSet, flag_swap_transaction)
|
||||
|
||||
res.Content = l.Get(
|
||||
"Credit Available: %s %s\n(You can swap up to %s %s -> %s %s).\nEnter %s amount:",
|
||||
maxRAT,
|
||||
@@ -758,19 +753,8 @@ func (h *MenuHandlers) TransactionSwapPreview(ctx context.Context, sym string, i
|
||||
return res, err
|
||||
}
|
||||
|
||||
// multiply by 1.015 (i.e. * 1015 / 1000)
|
||||
amountInt, ok := new(big.Int).SetString(finalAmountStr, 10)
|
||||
if !ok {
|
||||
return res, fmt.Errorf("invalid amount: %s", finalAmountStr)
|
||||
}
|
||||
|
||||
amountInt.Mul(amountInt, big.NewInt(1015))
|
||||
amountInt.Div(amountInt, big.NewInt(1000))
|
||||
|
||||
scaledFinalAmountStr := amountInt.String()
|
||||
|
||||
// call the credit send API to get the reverse quote
|
||||
r, err := h.accountService.GetCreditSendReverseQuote(ctx, swapData.ActivePoolAddress, swapData.ActiveSwapFromAddress, swapData.ActiveSwapToAddress, scaledFinalAmountStr)
|
||||
r, err := h.accountService.GetCreditSendReverseQuote(ctx, swapData.ActivePoolAddress, swapData.ActiveSwapFromAddress, swapData.ActiveSwapToAddress, finalAmountStr)
|
||||
if err != nil {
|
||||
flag_api_call_error, _ := h.flagManager.GetFlag("flag_api_call_error")
|
||||
res.FlagSet = append(res.FlagSet, flag_api_call_error)
|
||||
@@ -782,23 +766,23 @@ func (h *MenuHandlers) TransactionSwapPreview(ctx context.Context, sym string, i
|
||||
sendInputAmount := r.InputAmount // amount of SAT that should be swapped
|
||||
sendOutputAmount := r.OutputAmount // amount of RAT that will be received
|
||||
|
||||
// store the finalAmountStr as the final amount (that will be sent after the swap)
|
||||
err = userStore.WriteEntry(ctx, sessionId, storedb.DATA_AMOUNT, []byte(finalAmountStr))
|
||||
// store the sendOutputAmount as the final amount (that will be sent)
|
||||
err = userStore.WriteEntry(ctx, sessionId, storedb.DATA_AMOUNT, []byte(sendOutputAmount))
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed to write output amount value entry with", "key", storedb.DATA_AMOUNT, "value", sendOutputAmount, "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
// Scale down the quoted output amount
|
||||
// quoteAmountStr := store.ScaleDownBalance(sendOutputAmount, swapData.ActiveSwapToDecimal)
|
||||
quoteAmountStr := store.ScaleDownBalance(sendOutputAmount, swapData.ActiveSwapToDecimal)
|
||||
|
||||
// Format the qouteAmount amount to 2 decimal places
|
||||
// qouteAmount, _ := store.TruncateDecimalString(quoteAmountStr, 2)
|
||||
qouteAmount, _ := store.TruncateDecimalString(quoteAmountStr, 2)
|
||||
|
||||
// store the qouteAmount in the temporary value
|
||||
err = userStore.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(inputStr))
|
||||
err = userStore.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(qouteAmount))
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed to write temporary inputStr entry with", "key", storedb.DATA_TEMPORARY_VALUE, "value", inputStr, "error", err)
|
||||
logg.ErrorCtxf(ctx, "failed to write temporary qouteAmount entry with", "key", storedb.DATA_TEMPORARY_VALUE, "value", qouteAmount, "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
@@ -811,7 +795,7 @@ func (h *MenuHandlers) TransactionSwapPreview(ctx context.Context, sym string, i
|
||||
|
||||
res.Content = l.Get(
|
||||
"%s will receive %s %s",
|
||||
string(recipientPhoneNumber), inputStr, swapData.ActiveSwapToSym,
|
||||
string(recipientPhoneNumber), qouteAmount, swapData.ActiveSwapToSym,
|
||||
)
|
||||
|
||||
return res, nil
|
||||
|
||||
@@ -7,6 +7,7 @@ MOUT back 0
|
||||
MOUT quit 9
|
||||
HALT
|
||||
RELOAD authorize_account
|
||||
CATCH self_reset_pin flag_account_pin_reset 1
|
||||
CATCH incorrect_pin flag_incorrect_pin 1
|
||||
INCMP _ 0
|
||||
INCMP quit 9
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
LOAD reset_transaction_amount 10
|
||||
RELOAD reset_transaction_amount
|
||||
LOAD credit_max_amount 160
|
||||
RELOAD credit_max_amount
|
||||
CATCH api_failure flag_api_call_error 1
|
||||
@@ -11,6 +10,7 @@ RELOAD clear_trans_type_flag
|
||||
CATCH transaction_swap flag_swap_transaction 1
|
||||
LOAD validate_amount 64
|
||||
RELOAD validate_amount
|
||||
CATCH api_failure flag_api_call_error 1
|
||||
CATCH invalid_amount flag_invalid_amount 1
|
||||
INCMP _ 0
|
||||
LOAD get_recipient 0
|
||||
|
||||
1
services/registration/credit_send_menu
Normal file
1
services/registration/credit_send_menu
Normal file
@@ -0,0 +1 @@
|
||||
Credit-Send
|
||||
1
services/registration/credit_send_menu_swa
Normal file
1
services/registration/credit_send_menu_swa
Normal file
@@ -0,0 +1 @@
|
||||
Tuma-Mkopo
|
||||
@@ -7,6 +7,7 @@ MOUT quit 9
|
||||
HALT
|
||||
LOAD authorize_account 6
|
||||
RELOAD authorize_account
|
||||
CATCH self_reset_pin flag_account_pin_reset 1
|
||||
CATCH incorrect_pin flag_incorrect_pin 1
|
||||
INCMP _ 0
|
||||
INCMP quit 9
|
||||
|
||||
@@ -7,20 +7,22 @@ LOAD check_balance 128
|
||||
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 credit_send 2
|
||||
MOUT swap 3
|
||||
MOUT vouchers 4
|
||||
MOUT select_pool 5
|
||||
MOUT mpesa 6
|
||||
MOUT account 7
|
||||
MOUT help 8
|
||||
MOUT quit 9
|
||||
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 send 1
|
||||
INCMP credit_send 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 . *
|
||||
|
||||
1
services/registration/send
Normal file
1
services/registration/send
Normal file
@@ -0,0 +1 @@
|
||||
Enter recipient's phone number/address/alias:
|
||||
12
services/registration/send.vis
Normal file
12
services/registration/send.vis
Normal file
@@ -0,0 +1,12 @@
|
||||
LOAD transaction_reset 0
|
||||
RELOAD transaction_reset
|
||||
CATCH no_voucher flag_no_active_voucher 1
|
||||
MOUT back 0
|
||||
HALT
|
||||
LOAD validate_recipient 50
|
||||
RELOAD validate_recipient
|
||||
CATCH api_failure flag_api_call_error 1
|
||||
CATCH invalid_recipient flag_invalid_recipient 1
|
||||
CATCH invite_recipient flag_invalid_recipient_with_invite 1
|
||||
INCMP _ 0
|
||||
INCMP amount *
|
||||
@@ -6,6 +6,7 @@ MOUT quit 9
|
||||
HALT
|
||||
LOAD authorize_account 6
|
||||
RELOAD authorize_account
|
||||
CATCH self_reset_pin flag_account_pin_reset 1
|
||||
CATCH incorrect_pin flag_incorrect_pin 1
|
||||
INCMP _ 0
|
||||
INCMP quit 9
|
||||
|
||||
1
services/registration/send_swa
Normal file
1
services/registration/send_swa
Normal file
@@ -0,0 +1 @@
|
||||
Weka nambari ya simu/Anwani/Lakabu:
|
||||
@@ -6,6 +6,7 @@ MOUT quit 9
|
||||
LOAD authorize_account 6
|
||||
HALT
|
||||
RELOAD authorize_account
|
||||
CATCH self_reset_pin flag_account_pin_reset 1
|
||||
CATCH incorrect_pin flag_incorrect_pin 1
|
||||
INCMP _ 0
|
||||
INCMP quit 9
|
||||
|
||||
@@ -9,6 +9,7 @@ MOUT quit 9
|
||||
LOAD authorize_account 6
|
||||
HALT
|
||||
RELOAD authorize_account
|
||||
CATCH self_reset_pin flag_account_pin_reset 1
|
||||
CATCH incorrect_pin flag_incorrect_pin 1
|
||||
INCMP _ 0
|
||||
INCMP quit 9
|
||||
|
||||
@@ -7,6 +7,7 @@ MOUT quit 9
|
||||
LOAD authorize_account 6
|
||||
HALT
|
||||
RELOAD authorize_account
|
||||
CATCH self_reset_pin flag_account_pin_reset 1
|
||||
CATCH incorrect_pin flag_incorrect_pin 1
|
||||
INCMP _ 0
|
||||
INCMP quit 9
|
||||
|
||||
@@ -4,6 +4,7 @@ MOUT quit 9
|
||||
LOAD authorize_account 6
|
||||
HALT
|
||||
RELOAD authorize_account
|
||||
CATCH self_reset_pin flag_account_pin_reset 1
|
||||
CATCH incorrect_pin flag_incorrect_pin 1
|
||||
INCMP _ 0
|
||||
INCMP quit 9
|
||||
|
||||
@@ -4,6 +4,7 @@ MOUT quit 9
|
||||
LOAD authorize_account 6
|
||||
HALT
|
||||
RELOAD authorize_account
|
||||
CATCH self_reset_pin flag_account_pin_reset 1
|
||||
CATCH incorrect_pin flag_incorrect_pin 1
|
||||
INCMP _ 0
|
||||
INCMP quit 9
|
||||
|
||||
Reference in New Issue
Block a user