add pool related functions
This commit is contained in:
parent
6532dd89f4
commit
5d8daf56bc
@ -2245,6 +2245,110 @@ func (h *MenuHandlers) GetVoucherDetails(ctx context.Context, sym string, input
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// GetDefaultPool returns the current user's Pool. If none is set, it returns the default config pool.
|
||||
func (h *MenuHandlers) GetDefaultPool(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||
var res resource.Result
|
||||
sessionId, ok := ctx.Value("SessionId").(string)
|
||||
if !ok {
|
||||
return res, fmt.Errorf("missing session")
|
||||
}
|
||||
|
||||
userStore := h.userdataStore
|
||||
activePoolSym, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_POOL_SYM)
|
||||
if err != nil {
|
||||
if db.IsNotFound(err) {
|
||||
// set the default as the response
|
||||
res.Content = config.DefaultPoolSymbol()
|
||||
return res, nil
|
||||
}
|
||||
|
||||
logg.ErrorCtxf(ctx, "failed to read the activePoolSym entry with", "key", storedb.DATA_ACTIVE_POOL_SYM, "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
res.Content = string(activePoolSym)
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// ViewPool retrieves the pool details from the user store
|
||||
// and displays it to the user for them to select it.
|
||||
func (h *MenuHandlers) ViewPool(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||
var res resource.Result
|
||||
sessionId, ok := ctx.Value("SessionId").(string)
|
||||
if !ok {
|
||||
return res, fmt.Errorf("missing session")
|
||||
}
|
||||
|
||||
code := codeFromCtx(ctx)
|
||||
l := gotext.NewLocale(translationDir, code)
|
||||
l.AddDomain("default")
|
||||
|
||||
flag_incorrect_pool, _ := h.flagManager.GetFlag("flag_incorrect_pool")
|
||||
|
||||
inputStr := string(input)
|
||||
|
||||
poolData, err := store.GetPoolData(ctx, h.userdataStore, sessionId, inputStr)
|
||||
if err != nil {
|
||||
return res, fmt.Errorf("failed to retrieve pool data: %v", err)
|
||||
}
|
||||
|
||||
if poolData == nil {
|
||||
flag_api_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)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
if (poolResp == &dataserviceapi.PoolDetails{}) {
|
||||
// If the API does not return the data, set the flag
|
||||
res.FlagSet = append(res.FlagSet, flag_incorrect_pool)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
poolData = poolResp
|
||||
}
|
||||
|
||||
if err := store.StoreTemporaryPool(ctx, h.userdataStore, sessionId, poolData); err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed on StoreTemporaryPool", "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
res.FlagReset = append(res.FlagReset, flag_incorrect_pool)
|
||||
res.Content = l.Get("Name: %s\nSymbol: %s", poolData.PoolName, poolData.PoolSymbol)
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// SetPool retrieves the temp pool data and sets it as the active data.
|
||||
func (h *MenuHandlers) SetPool(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||
var res resource.Result
|
||||
|
||||
sessionId, ok := ctx.Value("SessionId").(string)
|
||||
if !ok {
|
||||
return res, fmt.Errorf("missing session")
|
||||
}
|
||||
|
||||
// Get temporary data
|
||||
tempData, err := store.GetTemporaryPoolData(ctx, h.userdataStore, sessionId)
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed on GetTemporaryPoolData", "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
// Set as active and clear temporary data
|
||||
if err := store.UpdatePoolData(ctx, h.userdataStore, sessionId, tempData); err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed on UpdatePoolData", "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
res.Content = tempData.PoolSymbol
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// CheckTransactions retrieves the transactions from the API using the "PublicKey" and stores to prefixDb.
|
||||
func (h *MenuHandlers) CheckTransactions(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||
var res resource.Result
|
||||
|
@ -112,6 +112,10 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountService)
|
||||
ls.DbRs.AddLocalFunc("view_voucher", appHandlers.ViewVoucher)
|
||||
ls.DbRs.AddLocalFunc("set_voucher", appHandlers.SetVoucher)
|
||||
ls.DbRs.AddLocalFunc("get_voucher_details", appHandlers.GetVoucherDetails)
|
||||
ls.DbRs.AddLocalFunc("get_default_pool", appHandlers.GetDefaultPool)
|
||||
ls.DbRs.AddLocalFunc("get_pools", appHandlers.GetPools)
|
||||
ls.DbRs.AddLocalFunc("view_pool", appHandlers.ViewPool)
|
||||
ls.DbRs.AddLocalFunc("set_pool", appHandlers.SetPool)
|
||||
ls.DbRs.AddLocalFunc("validate_blocked_number", appHandlers.ValidateBlockedNumber)
|
||||
ls.DbRs.AddLocalFunc("retrieve_blocked_number", appHandlers.RetrieveBlockedNumber)
|
||||
ls.DbRs.AddLocalFunc("reset_unregistered_number", appHandlers.ResetUnregisteredNumber)
|
||||
|
Loading…
Reference in New Issue
Block a user