Compare commits

..

16 Commits

Author SHA1 Message Date
alfred-mk
8dc203d111 use the TemporaryValue to store the user's swap amount input
Some checks failed
release / docker (push) Has been cancelled
2025-05-22 15:18:52 +03:00
alfred-mk
dcadea8737 Convert TokenDecimals (uint8) to string before storing it 2025-05-22 15:09:46 +03:00
alfred-mk
71496d0015 change position of the catch statements
Some checks failed
release / docker (push) Has been cancelled
2025-05-22 12:41:49 +03:00
alfred-mk
d9fc5440c5 prevent access to the swap menu if one does not have a voucher 2025-05-22 12:24:10 +03:00
alfred-mk
0495472530 match the reset_incorrect_pin symbol to the function name 2025-05-22 12:13:50 +03:00
alfred-mk
fd43060021 update the api failure template
Some checks failed
release / docker (push) Has been cancelled
2025-05-21 18:52:05 +03:00
alfred-mk
cf6e105fb9 catch the api call error flag 2025-05-21 18:51:41 +03:00
alfred-mk
91b57fece2 use the ProcessTokens function and remove the unused DATA_POOL_TO_BALANCES 2025-05-21 18:51:10 +03:00
alfred-mk
043c79384c correctly process TokenDetails 2025-05-21 18:39:45 +03:00
alfred-mk
1cc1d00ffe added a function to ProcessTokens from the GetPoolSwappableVouchers 2025-05-21 18:19:23 +03:00
alfred-mk
d7987bf460 use the updated ussd-data-service and sarafu-api with TokenDetails 2025-05-21 18:18:15 +03:00
alfred-mk
21da4b976b use the updated sarafu-api that removes the publicKey from the GetPoolSwappableVouchers
Some checks failed
release / docker (push) Has been cancelled
2025-05-21 15:45:17 +03:00
alfred-mk
169d85e2cb added the INCLUDE_STABLES_PARAM env variable 2025-05-21 15:39:19 +03:00
alfred-mk
3ab76b3d22 use updated sarafu-api with corrected JSON mapping for checkTokenInPool and getSwapFromTokenMaxLimit
Some checks failed
release / docker (push) Has been cancelled
2025-05-20 15:53:12 +03:00
alfred-mk
b428e2e22d add log for the CheckTokenInPool
Some checks failed
release / docker (push) Has been cancelled
2025-05-20 14:02:41 +03:00
1d23a0cc4b Merge pull request 'default-env-pool' (#76) from default-env-pool into master
Some checks failed
release / docker (push) Has been cancelled
Reviewed-on: #76
2025-05-20 12:18:30 +02:00
25 changed files with 90 additions and 45 deletions

View File

@@ -28,3 +28,4 @@ DEFAULT_POOL_SYMBOL=ROLA
DEFAULT_POOL_CONTRACT_ADDRESS=0x48a953cA5cf5298bc6f6Af3C608351f537AAcb9e
DEFAULT_LIMITER_ADDRESS=
DEFAULT_VOUCHER_REGISTRY=
INCLUDE_STABLES_PARAM=false

View File

@@ -15,7 +15,7 @@ import (
const (
changeHeadSrc = `LOAD reset_account_authorized 0
LOAD reset_incorrect 0
LOAD reset_incorrect_pin 0
CATCH incorrect_pin flag_incorrect_pin 1
CATCH pin_entry flag_account_authorized 0
`

4
go.mod
View File

@@ -5,12 +5,12 @@ go 1.23.4
require (
git.defalsify.org/vise.git v0.3.2-0.20250507172020-cb22240f1cb9
git.grassecon.net/grassrootseconomics/common v0.9.0-beta.1.0.20250417111317-2953f4c2f32e
git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250517114512-050998ff82b1
git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250521141246-6c3719e3b652
git.grassecon.net/grassrootseconomics/visedriver v0.9.0-beta.2.0.20250408094335-e2d1f65bb306
git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250129070628-5a539172c694
github.com/alecthomas/assert/v2 v2.2.2
github.com/gofrs/uuid v4.4.0+incompatible
github.com/grassrootseconomics/ussd-data-service v1.4.4-beta
github.com/grassrootseconomics/ussd-data-service v1.4.7-beta
github.com/jackc/pgx/v5 v5.7.1
github.com/peteole/testdata-loader v0.3.0
github.com/stretchr/testify v1.9.0

8
go.sum
View File

@@ -12,6 +12,12 @@ git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250517113706-
git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250517113706-ee434dba6980/go.mod h1:K/TPgZ4OhPHBQq2X0ab3JZs4YjiexzSURZcfHLs9Pf4=
git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250517114512-050998ff82b1 h1:0hvILlGkZnXO8o7nZth4xu77vAS4zVQ6Ae0rb5x/Idg=
git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250517114512-050998ff82b1/go.mod h1:K/TPgZ4OhPHBQq2X0ab3JZs4YjiexzSURZcfHLs9Pf4=
git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250520125035-81fbc2574c30 h1:iZVmR/4xSoxahtkMBXs/z1HUSSnr+x1m+9AxXIgTvb0=
git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250520125035-81fbc2574c30/go.mod h1:R7+mt27mhm4/LCutAHHv87pOsLxXEPO93KXnhP8H6W0=
git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250521124206-343d30a2f27c h1:c2cA5hcYnLgs7kR4fF5tp42W6VQClTukbfKoaeskZu0=
git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250521124206-343d30a2f27c/go.mod h1:R7+mt27mhm4/LCutAHHv87pOsLxXEPO93KXnhP8H6W0=
git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250521141246-6c3719e3b652 h1:MmUQRL6Fjq/jlL53h+cUbJ7WwQ+q/yNy/zT05c7bgNg=
git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250521141246-6c3719e3b652/go.mod h1:wKHPy1mpOCr9ahkRltwm1yi9qH/3m9xb8hMCX5C0L1o=
git.grassecon.net/grassrootseconomics/visedriver v0.9.0-beta.2.0.20250408094335-e2d1f65bb306 h1:Jo+yWysWw/N5BJQtAyEMN8ePVvAyPHv+JG4lQti+1N4=
git.grassecon.net/grassrootseconomics/visedriver v0.9.0-beta.2.0.20250408094335-e2d1f65bb306/go.mod h1:FdLwYtzsjOIcDiW4uDgDYnB4Wdzq12uJUe0QHSSPbSo=
git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250129070628-5a539172c694 h1:DjJlBSz0S13acft5XZDWk7ZYnzElym0xLMYEVgyNJ+E=
@@ -74,6 +80,8 @@ github.com/grassrootseconomics/ussd-data-service v1.4.0-beta h1:4fMd/3h2ZIhRg4Gd
github.com/grassrootseconomics/ussd-data-service v1.4.0-beta/go.mod h1:9sGnorpKaK76FmOGXoh/xv7x5siSFNYdXxQo9BKW4DI=
github.com/grassrootseconomics/ussd-data-service v1.4.4-beta h1:turlyo0i3OLj29mWpWNoB/3Qao8qEngT/5d1jDWTZE4=
github.com/grassrootseconomics/ussd-data-service v1.4.4-beta/go.mod h1:9sGnorpKaK76FmOGXoh/xv7x5siSFNYdXxQo9BKW4DI=
github.com/grassrootseconomics/ussd-data-service v1.4.7-beta h1:yAe1YaOBsdxW2m20jnVU4F0kLmFr+mK/gHCWEdHmE90=
github.com/grassrootseconomics/ussd-data-service v1.4.7-beta/go.mod h1:9sGnorpKaK76FmOGXoh/xv7x5siSFNYdXxQo9BKW4DI=
github.com/graygnuorg/go-gdbm v0.0.0-20220711140707-71387d66dce4 h1:U4kkNYryi/qfbBF8gh7Vsbuz+cVmhf5kt6pE9bYYyLo=
github.com/graygnuorg/go-gdbm v0.0.0-20220711140707-71387d66dce4/go.mod h1:zpZDgZFzeq9s0MIeB1P50NIEWDFFHSFBohI/NbaTD/Y=
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=

View File

@@ -2707,11 +2707,6 @@ func (h *MenuHandlers) LoadSwapToList(ctx context.Context, sym string, input []b
}
userStore := h.userdataStore
publicKey, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY)
if err != nil {
logg.ErrorCtxf(ctx, "failed to read publicKey entry with", "key", storedb.DATA_PUBLIC_KEY, "error", err)
return res, err
}
// get the active address and symbol
activeAddress, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_ADDRESS)
@@ -2762,6 +2757,8 @@ func (h *MenuHandlers) LoadSwapToList(ctx context.Context, sym string, input []b
return res, err
}
logg.InfoCtxf(ctx, "CheckTokenInPool", "response", r, "active_pool_address", activePoolAddress, "address", activeAddress)
if !r.CanSwapFrom {
res.FlagSet = append(res.FlagSet, flag_incorrect_voucher)
res.Content = l.Get(
@@ -2774,8 +2771,8 @@ func (h *MenuHandlers) LoadSwapToList(ctx context.Context, sym string, input []b
res.FlagReset = append(res.FlagReset, flag_incorrect_voucher)
// call the api using the activePoolAddress and publicKey to get a list of SwapToSymbolsData
swapToList, err := h.accountService.GetPoolSwappableVouchers(ctx, string(activePoolAddress), string(publicKey))
// 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)
logg.ErrorCtxf(ctx, "failed on FetchTransactions", "error", err)
@@ -2787,12 +2784,11 @@ func (h *MenuHandlers) LoadSwapToList(ctx context.Context, sym string, input []b
return res, nil
}
data := store.ProcessVouchers(swapToList)
data := store.ProcessTokens(swapToList)
// Store all to list voucher data
// Store all swap_to tokens data
dataMap := map[storedb.DataTyp]string{
storedb.DATA_POOL_TO_SYMBOLS: data.Symbols,
storedb.DATA_POOL_TO_BALANCES: data.Balances,
storedb.DATA_POOL_TO_DECIMALS: data.Decimals,
storedb.DATA_POOL_TO_ADDRESSES: data.Addresses,
}
@@ -2944,6 +2940,12 @@ func (h *MenuHandlers) SwapPreview(ctx context.Context, sym string, input []byte
logg.ErrorCtxf(ctx, "failed to write swap amount entry with", "key", storedb.DATA_ACTIVE_SWAP_AMOUNT, "value", finalAmountStr, "error", err)
return res, err
}
// store the user's 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 swap amount entry with", "key", storedb.DATA_ACTIVE_SWAP_AMOUNT, "value", finalAmountStr, "error", err)
return res, err
}
// call the API to get the quote
r, err := h.accountService.GetPoolSwapQuote(ctx, finalAmountStr, swapData.PublicKey, swapData.ActiveSwapFromAddress, swapData.ActivePoolAddress, swapData.ActiveSwapToAddress)
@@ -3019,7 +3021,7 @@ func (h *MenuHandlers) InitiateSwap(ctx context.Context, sym string, input []byt
res.Content = l.Get(
"Your request has been sent. You will receive an SMS when your %s %s has been swapped for %s.",
swapAmountStr,
swapData.TemporaryValue,
swapData.ActiveSwapFromSym,
swapData.ActiveSwapToSym,
)

View File

@@ -91,7 +91,7 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountService)
ls.DbRs.AddLocalFunc("get_recipient", appHandlers.GetRecipient)
ls.DbRs.AddLocalFunc("get_sender", appHandlers.GetSender)
ls.DbRs.AddLocalFunc("get_amount", appHandlers.GetAmount)
ls.DbRs.AddLocalFunc("reset_incorrect", appHandlers.ResetIncorrectPin)
ls.DbRs.AddLocalFunc("reset_incorrect_pin", appHandlers.ResetIncorrectPin)
ls.DbRs.AddLocalFunc("save_firstname", appHandlers.SaveFirstname)
ls.DbRs.AddLocalFunc("save_familyname", appHandlers.SaveFamilyname)
ls.DbRs.AddLocalFunc("save_gender", appHandlers.SaveGender)
@@ -130,7 +130,7 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountService)
ls.DbRs.AddLocalFunc("confirm_new_alias", appHandlers.ConfirmNewAlias)
ls.DbRs.AddLocalFunc("check_account_created", appHandlers.CheckAccountCreated)
ls.DbRs.AddLocalFunc("reset_api_call_failure", appHandlers.ResetApiCallFailure)
ls.DbRs.AddLocalFunc("swap_to_list", appHandlers.LoadSwapToList)
ls.DbRs.AddLocalFunc("swap_to_list", appHandlers.LoadSwapToList)
ls.DbRs.AddLocalFunc("swap_max_limit", appHandlers.SwapMaxLimit)
ls.DbRs.AddLocalFunc("swap_preview", appHandlers.SwapPreview)
ls.DbRs.AddLocalFunc("initiate_swap", appHandlers.InitiateSwap)

View File

@@ -1 +1 @@
Failed to connect to the custodial service. Please try again.
Your request failed. Please try again later.

View File

@@ -1 +1 @@
Imeshindwa kuunganisha kwenye huduma ya uangalizi. Tafadhali jaribu tena.
Ombi lako halikufaulu. Tafadhali jaribu tena baadaye.

View File

@@ -1,5 +1,5 @@
LOAD reset_account_authorized 0
LOAD reset_incorrect 0
LOAD reset_incorrect_pin 0
CATCH incorrect_pin flag_incorrect_pin 1
CATCH pin_entry flag_account_authorized 0
MOUT english 1

View File

@@ -1,4 +1,4 @@
LOAD reset_incorrect 6
LOAD reset_incorrect_pin 6
LOAD fetch_community_balance 0
CATCH api_failure flag_api_call_error 1
MAP fetch_community_balance

View File

@@ -1 +1 @@
Incorrect PIN. You have: {{.reset_incorrect}} remaining attempt(s).
Incorrect PIN. You have: {{.reset_incorrect_pin}} remaining attempt(s).

View File

@@ -1,6 +1,6 @@
LOAD reset_incorrect 0
RELOAD reset_incorrect
MAP reset_incorrect
LOAD reset_incorrect_pin 0
RELOAD reset_incorrect_pin
MAP reset_incorrect_pin
CATCH blocked_account flag_account_blocked 1
MOUT retry 1
MOUT quit 9

View File

@@ -1 +1 @@
PIN ulioeka sio sahihi, una majaribio: {{.reset_incorrect}} yaliyobaki
PIN ulioeka sio sahihi, una majaribio: {{.reset_incorrect_pin}} yaliyobaki

View File

@@ -1,4 +1,4 @@
LOAD reset_incorrect 6
LOAD reset_incorrect_pin 6
LOAD check_balance 0
CATCH api_failure flag_api_call_error 1
MAP check_balance

View File

@@ -1,4 +1,4 @@
RELOAD reset_incorrect
RELOAD reset_incorrect_pin
MOUT back 0
HALT
INCMP _ 0

View File

@@ -2,7 +2,7 @@ LOAD set_back 6
LOAD authorize_account 16
LOAD reset_allow_update 4
LOAD save_temporary_pin 1
LOAD reset_incorrect 0
LOAD reset_incorrect_pin 0
LOAD reset_invalid_pin 6
MOUT change_pin 1
MOUT reset_pin 2

View File

@@ -1,3 +1,5 @@
LOAD reset_incorrect 6
LOAD reset_incorrect_pin 6
CATCH incorrect_pin flag_incorrect_pin 1
CATCH _ flag_account_authorized 0
LOAD initiate_swap 0
HALT

View File

@@ -1,4 +1,5 @@
RELOAD swap_max_limit
CATCH api_failure flag_api_call_error 1
MAP swap_max_limit
MOUT back 0
HALT

View File

@@ -1,12 +1,12 @@
LOAD swap_preview 0
MAP swap_preview
CATCH api_failure flag_api_call_error 1
MOUT back 0
MOUT quit 9
LOAD authorize_account 6
HALT
RELOAD authorize_account
CATCH incorrect_pin flag_incorrect_pin 1
CATCH . flag_account_authorized 0
INCMP _ 0
INCMP quit 9
INCMP swap_initiated *

View File

@@ -1,3 +1,4 @@
CATCH no_voucher flag_no_active_voucher 1
LOAD swap_to_list 0
RELOAD swap_to_list
MAP swap_to_list

View File

@@ -1,4 +1,4 @@
LOAD reset_incorrect 6
LOAD reset_incorrect_pin 6
CATCH incorrect_pin flag_incorrect_pin 1
CATCH _ flag_account_authorized 0
RELOAD get_amount

View File

@@ -1,6 +1,6 @@
LOAD get_profile_info 0
MAP get_profile_info
LOAD reset_incorrect 6
LOAD reset_incorrect_pin 6
CATCH incorrect_pin flag_incorrect_pin 1
CATCH pin_entry flag_account_authorized 0
MOUT back 0

View File

@@ -1,4 +1,4 @@
LOAD reset_incorrect 6
LOAD reset_incorrect_pin 6
CATCH incorrect_pin flag_incorrect_pin 1
CATCH _ flag_account_authorized 0
LOAD set_voucher 12

View File

@@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"reflect"
"strconv"
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api"
@@ -21,6 +22,7 @@ type SwapData struct {
}
type SwapPreviewData struct {
TemporaryValue string
PublicKey string
ActiveSwapMaxAmount string
ActiveSwapFromDecimal string
@@ -64,6 +66,7 @@ func ReadSwapData(ctx context.Context, store DataStore, sessionId string) (SwapD
func ReadSwapPreviewData(ctx context.Context, store DataStore, sessionId string) (SwapPreviewData, error) {
data := SwapPreviewData{}
fieldToKey := map[string]storedb.DataTyp{
"TemporaryValue": storedb.DATA_TEMPORARY_VALUE,
"PublicKey": storedb.DATA_PUBLIC_KEY,
"ActiveSwapMaxAmount": storedb.DATA_ACTIVE_SWAP_MAX_AMOUNT,
"ActiveSwapFromDecimal": storedb.DATA_ACTIVE_DECIMAL,
@@ -129,8 +132,8 @@ func GetSwapFromVoucherData(ctx context.Context, store DataStore, sessionId stri
}, nil
}
// GetSwapToVoucherData retrieves and matches voucher data
func GetSwapToVoucherData(ctx context.Context, store DataStore, sessionId string, input string) (*dataserviceapi.TokenHoldings, error) {
// GetSwapToVoucherData retrieves and matches token data
func GetSwapToVoucherData(ctx context.Context, store DataStore, sessionId string, input string) (*dataserviceapi.TokenDetails, error) {
keys := []storedb.DataTyp{
storedb.DATA_POOL_TO_SYMBOLS,
storedb.DATA_POOL_TO_BALANCES,
@@ -147,7 +150,7 @@ func GetSwapToVoucherData(ctx context.Context, store DataStore, sessionId string
data[key] = string(value)
}
symbol, balance, decimal, address := MatchVoucher(input,
symbol, _, decimal, address := MatchVoucher(input,
data[storedb.DATA_POOL_TO_SYMBOLS],
data[storedb.DATA_POOL_TO_BALANCES],
data[storedb.DATA_POOL_TO_DECIMALS],
@@ -158,22 +161,31 @@ func GetSwapToVoucherData(ctx context.Context, store DataStore, sessionId string
return nil, nil
}
return &dataserviceapi.TokenHoldings{
TokenSymbol: string(symbol),
Balance: string(balance),
TokenDecimals: string(decimal),
ContractAddress: string(address),
decimalInt, err := strconv.ParseUint(decimal, 0, 64)
if err != nil {
logg.ErrorCtxf(ctx, "Failed to parse decimal to Uint:", "sessionId", sessionId, "decimal", decimal, "error", err)
return nil, nil
}
return &dataserviceapi.TokenDetails{
TokenSymbol: string(symbol),
TokenDecimals: uint8(decimalInt),
TokenAddress: string(address),
}, nil
}
// UpdateSwapToVoucherData updates the active swap to voucher data in the DataStore.
func UpdateSwapToVoucherData(ctx context.Context, store DataStore, sessionId string, data *dataserviceapi.TokenHoldings) error {
logg.TraceCtxf(ctx, "dtal", "data", data)
func UpdateSwapToVoucherData(ctx context.Context, store DataStore, sessionId string, data *dataserviceapi.TokenDetails) error {
logg.TraceCtxf(ctx, "UpdateSwapToVoucherData", "data", data)
// Convert TokenDecimals (uint8) to string
tokenDecimalsStr := strconv.FormatUint(uint64(data.TokenDecimals), 10)
// Active swap to voucher data entries
activeEntries := map[storedb.DataTyp][]byte{
storedb.DATA_ACTIVE_SWAP_TO_SYM: []byte(data.TokenSymbol),
storedb.DATA_ACTIVE_SWAP_TO_DECIMAL: []byte(data.TokenDecimals),
storedb.DATA_ACTIVE_SWAP_TO_ADDRESS: []byte(data.ContractAddress),
storedb.DATA_ACTIVE_SWAP_TO_DECIMAL: []byte(tokenDecimalsStr),
storedb.DATA_ACTIVE_SWAP_TO_ADDRESS: []byte(data.TokenAddress),
}
// Write active data

View File

@@ -47,6 +47,24 @@ func ProcessVouchers(holdings []dataserviceapi.TokenHoldings) VoucherMetadata {
return data
}
// ProcessTokens converts swappable tokens into formatted strings
func ProcessTokens(holdings []dataserviceapi.TokenDetails) VoucherMetadata {
var data VoucherMetadata
var symbols, decimals, addresses []string
for i, h := range holdings {
symbols = append(symbols, fmt.Sprintf("%d:%s", i+1, h.TokenSymbol))
decimals = append(decimals, fmt.Sprintf("%d:%d", i+1, h.TokenDecimals))
addresses = append(addresses, fmt.Sprintf("%d:%s", i+1, h.TokenAddress))
}
data.Symbols = strings.Join(symbols, "\n")
data.Decimals = strings.Join(decimals, "\n")
data.Addresses = strings.Join(addresses, "\n")
return data
}
func ScaleDownBalance(balance, decimals string) string {
// Convert balance and decimals to big.Float
bal := new(big.Float)