Compare commits

...

13 Commits

Author SHA1 Message Date
alfred-mk
398610924b removed the debug output
Some checks failed
release / docker (push) Has been cancelled
2025-11-26 13:02:26 +03:00
alfred-mk
3fdb0e3426 update the symbol to send_max_amount with debug output 2025-11-26 12:56:04 +03:00
c18d40286e Merge pull request 'credit-send-hotfix' (#109) from credit-send-hotfix into master
Reviewed-on: #109
2025-11-18 08:52:21 +01:00
Alfred Kamanda
c2cf8e91e5 removed the print debug statements
Some checks failed
release / docker (push) Has been cancelled
2025-11-14 10:55:54 +03:00
Alfred Kamanda
20cfb47940 updated the size outputs 2025-11-14 10:49:11 +03:00
Alfred Kamanda
03d6cbd429 added a debug for the returned content 2025-11-14 10:46:22 +03:00
Alfred Kamanda
ee41f73347 added a debug log 2025-11-14 10:41:34 +03:00
Alfred Kamanda
bafe3cc04e added the swap menu swahili version 2025-11-13 17:13:34 +03:00
Alfred Kamanda
308dc93a91 return nil to CATCH the flag_api_call_error 2025-11-13 17:09:30 +03:00
Alfred Kamanda
8d29c364c3 updated the swahili message for output length error 2025-11-13 17:07:57 +03:00
Alfred Kamanda
d52d6c478f added a CATCH for the api_call_error flag
Some checks failed
release / docker (push) Has been cancelled
2025-11-13 01:46:36 +03:00
Alfred Kamanda
208eac5a3c use the correct 'flag_api_call_error' 2025-11-13 01:44:50 +03:00
fc2ca0f546 Merge pull request 'send with swap' (#102) from send-with-swap into master
Some checks failed
release / docker (push) Has been cancelled
Reviewed-on: #102
2025-11-12 08:54:05 +01:00
12 changed files with 49 additions and 43 deletions

View File

@@ -22,12 +22,12 @@ func (h *MenuHandlers) GetPools(ctx context.Context, sym string, input []byte) (
}
userStore := h.userdataStore
flag_api_error, _ := h.flagManager.GetFlag("flag_api_error")
flag_api_call_error, _ := h.flagManager.GetFlag("flag_api_call_error")
// call the api to get a list of top 5 pools sorted by swaps
topPools, err := h.accountService.FetchTopPools(ctx)
if err != nil {
res.FlagSet = append(res.FlagSet, flag_api_error)
res.FlagSet = append(res.FlagSet, flag_api_call_error)
logg.ErrorCtxf(ctx, "failed on FetchTransactions", "error", err)
return res, err
}
@@ -129,12 +129,12 @@ func (h *MenuHandlers) ViewPool(ctx context.Context, sym string, input []byte) (
}
if poolData == nil {
flag_api_error, _ := h.flagManager.GetFlag("flag_api_call_error")
flag_api_call_error, _ := h.flagManager.GetFlag("flag_api_call_error")
// no match found. Call the API using the inputStr as the symbol
poolResp, err := h.accountService.RetrievePoolDetails(ctx, inputStr)
if err != nil {
res.FlagSet = append(res.FlagSet, flag_api_error)
res.FlagSet = append(res.FlagSet, flag_api_call_error)
return res, nil
}

View File

@@ -41,7 +41,7 @@ func (h *MenuHandlers) LoadSwapToList(ctx context.Context, sym string, input []b
l.AddDomain("default")
flag_incorrect_voucher, _ := h.flagManager.GetFlag("flag_incorrect_voucher")
flag_api_error, _ := h.flagManager.GetFlag("flag_api_error")
flag_api_call_error, _ := h.flagManager.GetFlag("flag_api_call_error")
inputStr := string(input)
if inputStr == "0" {
@@ -88,7 +88,7 @@ func (h *MenuHandlers) LoadSwapToList(ctx context.Context, sym string, input []b
// call the api using the ActivePoolAddress and ActiveVoucherAddress to check if it is part of the pool
r, err := h.accountService.CheckTokenInPool(ctx, string(activePoolAddress), string(activeAddress))
if err != nil {
res.FlagSet = append(res.FlagSet, flag_api_error)
res.FlagSet = append(res.FlagSet, flag_api_call_error)
logg.ErrorCtxf(ctx, "failed on CheckTokenInPool", "error", err)
return res, err
}
@@ -110,7 +110,7 @@ func (h *MenuHandlers) LoadSwapToList(ctx context.Context, sym string, input []b
// call the api using the activePoolAddress to get a list of SwapToSymbolsData
swapToList, err := h.accountService.GetPoolSwappableVouchers(ctx, string(activePoolAddress))
if err != nil {
res.FlagSet = append(res.FlagSet, flag_api_error)
res.FlagSet = append(res.FlagSet, flag_api_call_error)
logg.ErrorCtxf(ctx, "failed on FetchTransactions", "error", err)
return res, err
}
@@ -165,7 +165,7 @@ func (h *MenuHandlers) SwapMaxLimit(ctx context.Context, sym string, input []byt
}
flag_incorrect_voucher, _ := h.flagManager.GetFlag("flag_incorrect_voucher")
flag_api_error, _ := h.flagManager.GetFlag("flag_api_error")
flag_api_call_error, _ := h.flagManager.GetFlag("flag_api_call_error")
flag_low_swap_amount, _ := h.flagManager.GetFlag("flag_low_swap_amount")
res.FlagReset = append(res.FlagReset, flag_incorrect_voucher, flag_low_swap_amount)
@@ -202,9 +202,9 @@ func (h *MenuHandlers) SwapMaxLimit(ctx context.Context, sym string, input []byt
logg.InfoCtxf(ctx, "Call GetSwapFromTokenMaxLimit with:", "ActivePoolAddress", swapData.ActivePoolAddress, "ActiveSwapFromAddress", swapData.ActiveSwapFromAddress, "ActiveSwapToAddress", swapData.ActiveSwapToAddress, "publicKey", swapData.PublicKey)
r, err := h.accountService.GetSwapFromTokenMaxLimit(ctx, swapData.ActivePoolAddress, swapData.ActiveSwapFromAddress, swapData.ActiveSwapToAddress, swapData.PublicKey)
if err != nil {
res.FlagSet = append(res.FlagSet, flag_api_error)
res.FlagSet = append(res.FlagSet, flag_api_call_error)
logg.ErrorCtxf(ctx, "failed on GetSwapFromTokenMaxLimit", "error", err)
return res, err
return res, nil
}
// Scale down the amount
@@ -310,8 +310,8 @@ func (h *MenuHandlers) SwapPreview(ctx context.Context, sym string, input []byte
// call the API to get the quote
r, err := h.accountService.GetPoolSwapQuote(ctx, finalAmountStr, swapData.PublicKey, swapData.ActiveSwapFromAddress, swapData.ActivePoolAddress, swapData.ActiveSwapToAddress)
if err != nil {
flag_api_error, _ := h.flagManager.GetFlag("flag_api_call_error")
res.FlagSet = append(res.FlagSet, flag_api_error)
flag_api_call_error, _ := h.flagManager.GetFlag("flag_api_call_error")
res.FlagSet = append(res.FlagSet, flag_api_call_error)
res.Content = l.Get("Your request failed. Please try again later.")
logg.ErrorCtxf(ctx, "failed on poolSwap", "error", err)
return res, nil
@@ -364,8 +364,8 @@ func (h *MenuHandlers) InitiateSwap(ctx context.Context, sym string, input []byt
// Call the poolSwap API
r, err := h.accountService.PoolSwap(ctx, swapAmountStr, swapData.PublicKey, swapData.ActiveSwapFromAddress, swapData.ActivePoolAddress, swapData.ActiveSwapToAddress)
if err != nil {
flag_api_error, _ := h.flagManager.GetFlag("flag_api_call_error")
res.FlagSet = append(res.FlagSet, flag_api_error)
flag_api_call_error, _ := h.flagManager.GetFlag("flag_api_call_error")
res.FlagSet = append(res.FlagSet, flag_api_call_error)
res.Content = l.Get("Your request failed. Please try again later.")
logg.ErrorCtxf(ctx, "failed on poolSwap", "error", err)
return res, nil

View File

@@ -133,7 +133,7 @@ func (h *MenuHandlers) handleAddress(ctx context.Context, sessionId, recipient s
func (h *MenuHandlers) handleAlias(ctx context.Context, sessionId, recipient string, res *resource.Result) (resource.Result, error) {
store := h.userdataStore
flag_invalid_recipient, _ := h.flagManager.GetFlag("flag_invalid_recipient")
flag_api_error, _ := h.flagManager.GetFlag("flag_api_call_error")
flag_api_call_error, _ := h.flagManager.GetFlag("flag_api_call_error")
var aliasAddressResult string
@@ -151,11 +151,11 @@ func (h *MenuHandlers) handleAlias(ctx context.Context, sessionId, recipient str
alias, err := h.accountService.CheckAliasAddress(ctx, fqdn)
if err == nil {
res.FlagReset = append(res.FlagReset, flag_api_error)
res.FlagReset = append(res.FlagReset, flag_api_call_error)
aliasAddressResult = alias.Address
break
} else {
res.FlagSet = append(res.FlagSet, flag_api_error)
res.FlagSet = append(res.FlagSet, flag_api_call_error)
logg.ErrorCtxf(ctx, "Alias resolution failed", "alias", fqdn, "error", err)
return *res, nil
}
@@ -318,7 +318,7 @@ func (h *MenuHandlers) MaxAmount(ctx context.Context, sym string, input []byte)
return res, fmt.Errorf("missing session")
}
flag_api_error, _ := h.flagManager.GetFlag("flag_api_error")
flag_api_call_error, _ := h.flagManager.GetFlag("flag_api_call_error")
flag_swap_transaction, _ := h.flagManager.GetFlag("flag_swap_transaction")
userStore := h.userdataStore
@@ -335,11 +335,12 @@ 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, or if the sym is max_amount, return balance
if string(transactionType) == "normal" || sym == "max_amount" {
// 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
}
@@ -366,8 +367,9 @@ func (h *MenuHandlers) MaxAmount(ctx context.Context, sym string, input []byte)
canSwap, err := h.accountService.CheckTokenInPool(ctx, string(activePoolAddress), string(activeAddress))
if err != nil || !canSwap.CanSwapFrom {
if err != nil {
res.FlagSet = append(res.FlagSet, flag_api_error)
res.FlagSet = append(res.FlagSet, flag_api_call_error)
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))
@@ -377,8 +379,9 @@ func (h *MenuHandlers) MaxAmount(ctx context.Context, sym string, input []byte)
// retrieve the max credit send amounts
maxSAT, maxRAT, err := h.calculateSendCreditLimits(ctx, activePoolAddress, activeAddress, recipientActiveAddress, publicKey, activeDecimal, recipientActiveDecimal)
if err != nil {
res.FlagSet = append(res.FlagSet, flag_api_error)
return res, err
res.FlagSet = append(res.FlagSet, flag_api_call_error)
logg.ErrorCtxf(ctx, "failed on calculateSendCreditLimits", "error", err)
return res, nil
}
// Fallback if below minimum
@@ -668,8 +671,8 @@ func (h *MenuHandlers) InitiateTransaction(ctx context.Context, sym string, inpu
res.Content = l.Get("An unexpected error occurred. Please try again later.")
}
flag_api_error, _ := h.flagManager.GetFlag("flag_api_call_error")
res.FlagSet = append(res.FlagSet, flag_api_error)
flag_api_call_error, _ := h.flagManager.GetFlag("flag_api_call_error")
res.FlagSet = append(res.FlagSet, flag_api_call_error)
logg.ErrorCtxf(ctx, "failed on TokenTransfer", "error", err)
return res, nil
}
@@ -752,8 +755,8 @@ func (h *MenuHandlers) TransactionSwapPreview(ctx context.Context, sym string, i
// call the credit send API to get the reverse quote
r, err := h.accountService.GetCreditSendReverseQuote(ctx, swapData.ActivePoolAddress, swapData.ActiveSwapFromAddress, swapData.ActiveSwapToAddress, finalAmountStr)
if err != nil {
flag_api_error, _ := h.flagManager.GetFlag("flag_api_call_error")
res.FlagSet = append(res.FlagSet, flag_api_error)
flag_api_call_error, _ := h.flagManager.GetFlag("flag_api_call_error")
res.FlagSet = append(res.FlagSet, flag_api_call_error)
res.Content = l.Get("Your request failed. Please try again later.")
logg.ErrorCtxf(ctx, "failed GetCreditSendReverseQuote poolSwap", "error", err)
return res, nil
@@ -831,8 +834,8 @@ func (h *MenuHandlers) TransactionInitiateSwap(ctx context.Context, sym string,
// Call the poolSwap API
poolSwap, err := h.accountService.PoolSwap(ctx, swapAmountStr, swapData.PublicKey, swapData.ActiveSwapFromAddress, swapData.ActivePoolAddress, swapData.ActiveSwapToAddress)
if err != nil {
flag_api_error, _ := h.flagManager.GetFlag("flag_api_call_error")
res.FlagSet = append(res.FlagSet, flag_api_error)
flag_api_call_error, _ := h.flagManager.GetFlag("flag_api_call_error")
res.FlagSet = append(res.FlagSet, flag_api_call_error)
res.Content = l.Get("Your request failed. Please try again later.")
logg.ErrorCtxf(ctx, "failed on poolSwap", "error", err)
return res, nil
@@ -863,8 +866,8 @@ func (h *MenuHandlers) TransactionInitiateSwap(ctx context.Context, sym string,
// Call TokenTransfer with the expected swap amount
tokenTransfer, err := h.accountService.TokenTransfer(ctx, string(amount), swapData.PublicKey, string(recipientPublicKey), swapData.ActiveSwapToAddress)
if err != nil {
flag_api_error, _ := h.flagManager.GetFlag("flag_api_call_error")
res.FlagSet = append(res.FlagSet, flag_api_error)
flag_api_call_error, _ := h.flagManager.GetFlag("flag_api_call_error")
res.FlagSet = append(res.FlagSet, flag_api_call_error)
res.Content = l.Get("Your request failed. Please try again later.")
logg.ErrorCtxf(ctx, "failed on TokenTransfer", "error", err)
return res, nil

View File

@@ -277,7 +277,7 @@ func TestMaxAmount(t *testing.T) {
}
}
res, err := h.MaxAmount(ctx, "max_amount", []byte(""))
res, err := h.MaxAmount(ctx, "send_max_amount", []byte(""))
if tt.expectedError {
assert.Error(t, err)

View File

@@ -20,7 +20,7 @@ func (h *MenuHandlers) CheckTransactions(ctx context.Context, sym string, input
}
flag_no_transfers, _ := h.flagManager.GetFlag("flag_no_transfers")
flag_api_error, _ := h.flagManager.GetFlag("flag_api_error")
flag_api_call_error, _ := h.flagManager.GetFlag("flag_api_call_error")
userStore := h.userdataStore
logdb := h.logDb
@@ -33,11 +33,11 @@ func (h *MenuHandlers) CheckTransactions(ctx context.Context, sym string, input
// Fetch transactions from the API using the public key
transactionsResp, err := h.accountService.FetchTransactions(ctx, string(publicKey))
if err != nil {
res.FlagSet = append(res.FlagSet, flag_api_error)
res.FlagSet = append(res.FlagSet, flag_api_call_error)
logg.ErrorCtxf(ctx, "failed on FetchTransactions", "error", err)
return res, err
}
res.FlagReset = append(res.FlagReset, flag_api_error)
res.FlagReset = append(res.FlagReset, flag_api_call_error)
// Return if there are no transactions
if len(transactionsResp) == 0 {

View File

@@ -85,7 +85,7 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountService)
ls.DbRs.AddLocalFunc("validate_recipient", appHandlers.ValidateRecipient)
ls.DbRs.AddLocalFunc("transaction_reset", appHandlers.TransactionReset)
ls.DbRs.AddLocalFunc("invite_valid_recipient", appHandlers.InviteValidRecipient)
ls.DbRs.AddLocalFunc("max_amount", appHandlers.MaxAmount)
ls.DbRs.AddLocalFunc("send_max_amount", appHandlers.MaxAmount)
ls.DbRs.AddLocalFunc("credit_max_amount", appHandlers.MaxAmount)
ls.DbRs.AddLocalFunc("validate_amount", appHandlers.ValidateAmount)
ls.DbRs.AddLocalFunc("reset_transaction_amount", appHandlers.ResetTransactionAmount)

View File

@@ -1 +1 @@
{{.max_amount}}
{{.send_max_amount}}

View File

@@ -1,7 +1,8 @@
LOAD reset_transaction_amount 10
LOAD max_amount 160
RELOAD max_amount
MAP max_amount
RELOAD reset_transaction_amount
LOAD send_max_amount 0
RELOAD send_max_amount
MAP send_max_amount
MOUT back 0
HALT
LOAD validate_amount 64
@@ -9,7 +10,7 @@ RELOAD validate_amount
CATCH api_failure flag_api_call_error 1
CATCH invalid_amount flag_invalid_amount 1
INCMP _ 0
LOAD get_recipient 0
LOAD get_recipient 100
LOAD get_sender 64
LOAD get_amount 32
INCMP transaction_pin *

View File

@@ -1 +1 @@
{{.max_amount}}
{{.send_max_amount}}

View File

@@ -1,6 +1,7 @@
LOAD reset_transaction_amount 10
LOAD credit_max_amount 160
RELOAD credit_max_amount
CATCH api_failure flag_api_call_error 1
MAP credit_max_amount
MOUT back 0
HALT

View File

@@ -0,0 +1 @@
Badilisha

View File

@@ -1,2 +1,2 @@
Chagua nambari au ishara ya sarafu kubadilisha KWENDA:
Chagua nambari au ishara ya sarafu unayotaka kupokea.
{{.swap_to_list}}