Compare commits
No commits in common. "master" and "v1.4.2-rc.5" have entirely different histories.
master
...
v1.4.2-rc.
@ -335,8 +335,8 @@ func (h *MenuHandlers) MaxAmount(ctx context.Context, sym string, input []byte)
|
|||||||
// Format the active balance amount to 2 decimal places
|
// Format the active balance amount to 2 decimal places
|
||||||
formattedBalance, _ := store.TruncateDecimalString(string(activeBal), 2)
|
formattedBalance, _ := store.TruncateDecimalString(string(activeBal), 2)
|
||||||
|
|
||||||
// If normal transaction, or if the sym is max_amount, return balance
|
// If normal transaction, return balance
|
||||||
if string(transactionType) == "normal" || sym == "max_amount" {
|
if string(transactionType) == "normal" {
|
||||||
res.FlagReset = append(res.FlagReset, flag_swap_transaction)
|
res.FlagReset = append(res.FlagReset, flag_swap_transaction)
|
||||||
|
|
||||||
res.Content = l.Get("Maximum amount: %s %s\nEnter amount:", formattedBalance, string(activeSym))
|
res.Content = l.Get("Maximum amount: %s %s\nEnter amount:", formattedBalance, string(activeSym))
|
||||||
@ -789,7 +789,7 @@ func (h *MenuHandlers) TransactionSwapPreview(ctx context.Context, sym string, i
|
|||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
res.Content = l.Get(
|
res.Content = fmt.Sprintf(
|
||||||
"%s will receive %s %s",
|
"%s will receive %s %s",
|
||||||
string(recipientPhoneNumber), qouteAmount, swapData.ActiveSwapToSym,
|
string(recipientPhoneNumber), qouteAmount, swapData.ActiveSwapToSym,
|
||||||
)
|
)
|
||||||
|
|||||||
@ -86,7 +86,6 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountService)
|
|||||||
ls.DbRs.AddLocalFunc("transaction_reset", appHandlers.TransactionReset)
|
ls.DbRs.AddLocalFunc("transaction_reset", appHandlers.TransactionReset)
|
||||||
ls.DbRs.AddLocalFunc("invite_valid_recipient", appHandlers.InviteValidRecipient)
|
ls.DbRs.AddLocalFunc("invite_valid_recipient", appHandlers.InviteValidRecipient)
|
||||||
ls.DbRs.AddLocalFunc("max_amount", appHandlers.MaxAmount)
|
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("validate_amount", appHandlers.ValidateAmount)
|
||||||
ls.DbRs.AddLocalFunc("reset_transaction_amount", appHandlers.ResetTransactionAmount)
|
ls.DbRs.AddLocalFunc("reset_transaction_amount", appHandlers.ResetTransactionAmount)
|
||||||
ls.DbRs.AddLocalFunc("get_recipient", appHandlers.GetRecipient)
|
ls.DbRs.AddLocalFunc("get_recipient", appHandlers.GetRecipient)
|
||||||
|
|||||||
@ -4,6 +4,9 @@ RELOAD max_amount
|
|||||||
MAP max_amount
|
MAP max_amount
|
||||||
MOUT back 0
|
MOUT back 0
|
||||||
HALT
|
HALT
|
||||||
|
LOAD clear_trans_type_flag 6
|
||||||
|
RELOAD clear_trans_type_flag
|
||||||
|
CATCH transaction_swap flag_swap_transaction 1
|
||||||
LOAD validate_amount 64
|
LOAD validate_amount 64
|
||||||
RELOAD validate_amount
|
RELOAD validate_amount
|
||||||
CATCH api_failure flag_api_call_error 1
|
CATCH api_failure flag_api_call_error 1
|
||||||
|
|||||||
@ -1 +0,0 @@
|
|||||||
{{.credit_max_amount}}
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
LOAD reset_transaction_amount 10
|
|
||||||
LOAD credit_max_amount 160
|
|
||||||
RELOAD credit_max_amount
|
|
||||||
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 +0,0 @@
|
|||||||
{{.credit_max_amount}}
|
|
||||||
@ -1 +0,0 @@
|
|||||||
Enter recipient's phone number/address/alias:
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
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 +0,0 @@
|
|||||||
Credit-Send
|
|
||||||
@ -1 +0,0 @@
|
|||||||
Tuma-Mkopo
|
|
||||||
@ -1 +0,0 @@
|
|||||||
Weka nambari ya simu/anwani/lakabu:
|
|
||||||
@ -50,7 +50,5 @@ msgid "Maximum amount: %s %s\nEnter amount:"
|
|||||||
msgstr "Kiwango cha juu: %s %s\nWeka kiwango:"
|
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:"
|
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 kiwango cha %s:"
|
msgstr "Kiwango kinachopatikana: %s %s\n(Unaweza kubadilisha hadi %s %s -> %s %s)\nWeka %s kiwango:"
|
||||||
|
|
||||||
msgid "%s will receive %s %s"
|
|
||||||
msgstr "%s atapokea %s %s"
|
|
||||||
@ -7,20 +7,18 @@ LOAD check_balance 128
|
|||||||
RELOAD check_balance
|
RELOAD check_balance
|
||||||
MAP check_balance
|
MAP check_balance
|
||||||
MOUT send 1
|
MOUT send 1
|
||||||
MOUT credit_send 2
|
MOUT swap 2
|
||||||
MOUT swap 3
|
MOUT vouchers 3
|
||||||
MOUT vouchers 4
|
MOUT select_pool 4
|
||||||
MOUT select_pool 5
|
MOUT account 5
|
||||||
MOUT account 6
|
MOUT help 6
|
||||||
MOUT help 7
|
|
||||||
MOUT quit 9
|
MOUT quit 9
|
||||||
HALT
|
HALT
|
||||||
INCMP send 1
|
INCMP send 1
|
||||||
INCMP credit_send 2
|
INCMP swap_to_list 2
|
||||||
INCMP swap_to_list 3
|
INCMP my_vouchers 3
|
||||||
INCMP my_vouchers 4
|
INCMP select_pool 4
|
||||||
INCMP select_pool 5
|
INCMP my_account 5
|
||||||
INCMP my_account 6
|
INCMP help 6
|
||||||
INCMP help 7
|
|
||||||
INCMP quit 9
|
INCMP quit 9
|
||||||
INCMP . *
|
INCMP . *
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
CATCH no_voucher flag_no_active_voucher 1
|
CATCH no_voucher flag_no_active_voucher 1
|
||||||
LOAD get_pools 0
|
LOAD get_pools 0
|
||||||
RELOAD get_pools
|
|
||||||
MAP get_pools
|
MAP get_pools
|
||||||
LOAD get_default_pool 20
|
LOAD get_default_pool 20
|
||||||
RELOAD get_default_pool
|
RELOAD get_default_pool
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
Weka nambari ya simu/Anwani/Lakabu:
|
Weka nambari ya simu:
|
||||||
@ -1,3 +0,0 @@
|
|||||||
{{.transaction_swap_preview}}
|
|
||||||
|
|
||||||
Tafadhali weka PIN yako kudhibitisha:
|
|
||||||
@ -7,7 +7,6 @@ import (
|
|||||||
"math/big"
|
"math/big"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
|
|
||||||
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
||||||
)
|
)
|
||||||
@ -22,34 +21,25 @@ type TransactionData struct {
|
|||||||
ActiveAddress string
|
ActiveAddress string
|
||||||
}
|
}
|
||||||
|
|
||||||
// TruncateDecimalString safely truncates (not rounds) a number string to the specified decimal places
|
// TruncateDecimalString safely truncates the input amount to the specified decimal places
|
||||||
func TruncateDecimalString(input string, decimalPlaces int) (string, error) {
|
func TruncateDecimalString(input string, decimalPlaces int) (string, error) {
|
||||||
if _, err := strconv.ParseFloat(input, 64); err != nil {
|
num, ok := new(big.Float).SetString(input)
|
||||||
|
if !ok {
|
||||||
return "", fmt.Errorf("invalid input")
|
return "", fmt.Errorf("invalid input")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Split input into integer and fractional parts
|
// Multiply by 10^decimalPlaces
|
||||||
parts := strings.SplitN(input, ".", 2)
|
scale := new(big.Float).SetInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(int64(decimalPlaces)), nil))
|
||||||
intPart := parts[0]
|
scaled := new(big.Float).Mul(num, scale)
|
||||||
var fracPart string
|
|
||||||
|
|
||||||
if len(parts) == 2 {
|
// Truncate by converting to int (chops off decimals)
|
||||||
fracPart = parts[1]
|
intPart, _ := scaled.Int(nil)
|
||||||
}
|
|
||||||
|
|
||||||
// Truncate or pad fractional part
|
// Divide back to get truncated float
|
||||||
if len(fracPart) > decimalPlaces {
|
truncated := new(big.Float).Quo(new(big.Float).SetInt(intPart), scale)
|
||||||
fracPart = fracPart[:decimalPlaces]
|
|
||||||
} else {
|
|
||||||
fracPart = fracPart + strings.Repeat("0", decimalPlaces-len(fracPart))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle zero decimal places
|
// Format with fixed decimals
|
||||||
if decimalPlaces == 0 {
|
return truncated.Text('f', decimalPlaces), nil
|
||||||
return intPart, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Sprintf("%s.%s", intPart, fracPart), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseAndScaleAmount(storedAmount, activeDecimal string) (string, error) {
|
func ParseAndScaleAmount(storedAmount, activeDecimal string) (string, error) {
|
||||||
|
|||||||
@ -22,13 +22,6 @@ func TestTruncateDecimalString(t *testing.T) {
|
|||||||
want: "4.00",
|
want: "4.00",
|
||||||
expectError: false,
|
expectError: false,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "precision test",
|
|
||||||
input: "2.1",
|
|
||||||
decimalPlaces: 2,
|
|
||||||
want: "2.10",
|
|
||||||
expectError: false,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: "single decimal",
|
name: "single decimal",
|
||||||
input: "4.1",
|
input: "4.1",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user