Compare commits
26 Commits
v1.4.2-rc.
...
credit-sen
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c2cf8e91e5
|
||
|
|
20cfb47940
|
||
|
|
03d6cbd429
|
||
|
|
ee41f73347
|
||
|
|
bafe3cc04e
|
||
|
|
308dc93a91
|
||
|
|
8d29c364c3
|
||
|
|
d52d6c478f
|
||
|
|
208eac5a3c
|
||
| fc2ca0f546 | |||
|
|
724bc1bcf3 | ||
| 6e8c0fbcb3 | |||
|
|
9f8cf95e0f
|
||
|
|
97be6e943c
|
||
|
|
ba93bd9152
|
||
|
|
5fac27d00e
|
||
|
|
348185ef96
|
||
|
|
f51f577e2a
|
||
|
|
582f349be3
|
||
|
|
8ce17a8d1e
|
||
|
|
4092437d21
|
||
|
|
37f4b60679
|
||
|
|
878b5d0aa5
|
||
|
|
d2b934feda
|
||
|
|
4c80606b56
|
||
|
|
38ab1ecdd1
|
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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, return balance
|
||||
if string(transactionType) == "normal" {
|
||||
// If normal transaction, or if the sym is max_amount, return balance
|
||||
if string(transactionType) == "normal" || sym == "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
|
||||
@@ -789,7 +792,7 @@ func (h *MenuHandlers) TransactionSwapPreview(ctx context.Context, sym string, i
|
||||
return res, err
|
||||
}
|
||||
|
||||
res.Content = fmt.Sprintf(
|
||||
res.Content = l.Get(
|
||||
"%s will receive %s %s",
|
||||
string(recipientPhoneNumber), qouteAmount, swapData.ActiveSwapToSym,
|
||||
)
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -86,6 +86,7 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountService)
|
||||
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("credit_max_amount", appHandlers.MaxAmount)
|
||||
ls.DbRs.AddLocalFunc("validate_amount", appHandlers.ValidateAmount)
|
||||
ls.DbRs.AddLocalFunc("reset_transaction_amount", appHandlers.ResetTransactionAmount)
|
||||
ls.DbRs.AddLocalFunc("get_recipient", appHandlers.GetRecipient)
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
LOAD reset_transaction_amount 10
|
||||
LOAD max_amount 160
|
||||
RELOAD reset_transaction_amount
|
||||
LOAD max_amount 0
|
||||
RELOAD max_amount
|
||||
MAP max_amount
|
||||
MOUT back 0
|
||||
HALT
|
||||
LOAD clear_trans_type_flag 6
|
||||
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
|
||||
LOAD get_recipient 100
|
||||
LOAD get_sender 64
|
||||
LOAD get_amount 32
|
||||
INCMP transaction_pin *
|
||||
|
||||
1
services/registration/credit_amount
Normal file
1
services/registration/credit_amount
Normal file
@@ -0,0 +1 @@
|
||||
{{.credit_max_amount}}
|
||||
19
services/registration/credit_amount.vis
Normal file
19
services/registration/credit_amount.vis
Normal file
@@ -0,0 +1,19 @@
|
||||
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
|
||||
LOAD clear_trans_type_flag 6
|
||||
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
|
||||
LOAD get_sender 64
|
||||
LOAD get_amount 32
|
||||
INCMP transaction_pin *
|
||||
1
services/registration/credit_amount_swa
Normal file
1
services/registration/credit_amount_swa
Normal file
@@ -0,0 +1 @@
|
||||
{{.credit_max_amount}}
|
||||
1
services/registration/credit_send
Normal file
1
services/registration/credit_send
Normal file
@@ -0,0 +1 @@
|
||||
Enter recipient's phone number/address/alias:
|
||||
12
services/registration/credit_send.vis
Normal file
12
services/registration/credit_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 credit_amount *
|
||||
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
|
||||
1
services/registration/credit_send_swa
Normal file
1
services/registration/credit_send_swa
Normal file
@@ -0,0 +1 @@
|
||||
Weka nambari ya simu/anwani/lakabu:
|
||||
@@ -50,5 +50,7 @@ msgid "Maximum amount: %s %s\nEnter amount:"
|
||||
msgstr "Kiwango cha juu: %s %s\nWeka kiwango:"
|
||||
|
||||
msgid "Credit Available: %s %s\n(You can swap up to %s %s -> %s %s).\nEnter %s amount:"
|
||||
msgstr "Kiwango kinachopatikana: %s %s\n(Unaweza kubadilisha hadi %s %s -> %s %s)\nWeka %s kiwango:"
|
||||
msgstr "Kiwango kinachopatikana: %s %s\n(Unaweza kubadilisha hadi %s %s -> %s %s)\nWeka kiwango cha %s:"
|
||||
|
||||
msgid "%s will receive %s %s"
|
||||
msgstr "%s atapokea %s %s"
|
||||
@@ -7,18 +7,20 @@ LOAD check_balance 128
|
||||
RELOAD check_balance
|
||||
MAP check_balance
|
||||
MOUT send 1
|
||||
MOUT swap 2
|
||||
MOUT vouchers 3
|
||||
MOUT select_pool 4
|
||||
MOUT account 5
|
||||
MOUT help 6
|
||||
MOUT credit_send 2
|
||||
MOUT swap 3
|
||||
MOUT vouchers 4
|
||||
MOUT select_pool 5
|
||||
MOUT account 6
|
||||
MOUT help 7
|
||||
MOUT quit 9
|
||||
HALT
|
||||
INCMP send 1
|
||||
INCMP swap_to_list 2
|
||||
INCMP my_vouchers 3
|
||||
INCMP select_pool 4
|
||||
INCMP my_account 5
|
||||
INCMP help 6
|
||||
INCMP credit_send 2
|
||||
INCMP swap_to_list 3
|
||||
INCMP my_vouchers 4
|
||||
INCMP select_pool 5
|
||||
INCMP my_account 6
|
||||
INCMP help 7
|
||||
INCMP quit 9
|
||||
INCMP . *
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
CATCH no_voucher flag_no_active_voucher 1
|
||||
LOAD get_pools 0
|
||||
RELOAD get_pools
|
||||
MAP get_pools
|
||||
LOAD get_default_pool 20
|
||||
RELOAD get_default_pool
|
||||
|
||||
@@ -1 +1 @@
|
||||
Weka nambari ya simu:
|
||||
Weka nambari ya simu/Anwani/Lakabu:
|
||||
1
services/registration/swap_menu_swa
Normal file
1
services/registration/swap_menu_swa
Normal file
@@ -0,0 +1 @@
|
||||
Badilisha
|
||||
@@ -1,2 +1,2 @@
|
||||
Chagua nambari au ishara ya sarafu kubadilisha KWENDA:
|
||||
Chagua nambari au ishara ya sarafu unayotaka kupokea.
|
||||
{{.swap_to_list}}
|
||||
3
services/registration/transaction_swap_swa
Normal file
3
services/registration/transaction_swap_swa
Normal file
@@ -0,0 +1,3 @@
|
||||
{{.transaction_swap_preview}}
|
||||
|
||||
Tafadhali weka PIN yako kudhibitisha:
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"math/big"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
||||
)
|
||||
@@ -21,25 +22,34 @@ type TransactionData struct {
|
||||
ActiveAddress string
|
||||
}
|
||||
|
||||
// TruncateDecimalString safely truncates the input amount to the specified decimal places
|
||||
// TruncateDecimalString safely truncates (not rounds) a number string to the specified decimal places
|
||||
func TruncateDecimalString(input string, decimalPlaces int) (string, error) {
|
||||
num, ok := new(big.Float).SetString(input)
|
||||
if !ok {
|
||||
if _, err := strconv.ParseFloat(input, 64); err != nil {
|
||||
return "", fmt.Errorf("invalid input")
|
||||
}
|
||||
|
||||
// Multiply by 10^decimalPlaces
|
||||
scale := new(big.Float).SetInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(int64(decimalPlaces)), nil))
|
||||
scaled := new(big.Float).Mul(num, scale)
|
||||
// Split input into integer and fractional parts
|
||||
parts := strings.SplitN(input, ".", 2)
|
||||
intPart := parts[0]
|
||||
var fracPart string
|
||||
|
||||
// Truncate by converting to int (chops off decimals)
|
||||
intPart, _ := scaled.Int(nil)
|
||||
if len(parts) == 2 {
|
||||
fracPart = parts[1]
|
||||
}
|
||||
|
||||
// Divide back to get truncated float
|
||||
truncated := new(big.Float).Quo(new(big.Float).SetInt(intPart), scale)
|
||||
// Truncate or pad fractional part
|
||||
if len(fracPart) > decimalPlaces {
|
||||
fracPart = fracPart[:decimalPlaces]
|
||||
} else {
|
||||
fracPart = fracPart + strings.Repeat("0", decimalPlaces-len(fracPart))
|
||||
}
|
||||
|
||||
// Format with fixed decimals
|
||||
return truncated.Text('f', decimalPlaces), nil
|
||||
// Handle zero decimal places
|
||||
if decimalPlaces == 0 {
|
||||
return intPart, nil
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s.%s", intPart, fracPart), nil
|
||||
}
|
||||
|
||||
func ParseAndScaleAmount(storedAmount, activeDecimal string) (string, error) {
|
||||
|
||||
@@ -22,6 +22,13 @@ func TestTruncateDecimalString(t *testing.T) {
|
||||
want: "4.00",
|
||||
expectError: false,
|
||||
},
|
||||
{
|
||||
name: "precision test",
|
||||
input: "2.1",
|
||||
decimalPlaces: 2,
|
||||
want: "2.10",
|
||||
expectError: false,
|
||||
},
|
||||
{
|
||||
name: "single decimal",
|
||||
input: "4.1",
|
||||
|
||||
Reference in New Issue
Block a user