From 5a9fdbd580e4869cccec13d78c7ec26fe5130a0c Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Sat, 7 Jun 2025 12:56:41 +0300 Subject: [PATCH] use the stored DATA_ACTIVE_POOL_ADDRESS or fall back to default config.DefaultPoolAddress() in loading the swapToList --- handlers/application/menuhandler.go | 32 +++++++++++++++-------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/handlers/application/menuhandler.go b/handlers/application/menuhandler.go index 6dab472..ebe4308 100644 --- a/handlers/application/menuhandler.go +++ b/handlers/application/menuhandler.go @@ -2820,25 +2820,27 @@ func (h *MenuHandlers) LoadSwapToList(ctx context.Context, sym string, input []b return res, nil } - defaultPool := dataserviceapi.PoolDetails{ - PoolName: config.DefaultPoolName(), - PoolSymbol: config.DefaultPoolSymbol(), - PoolContractAdrress: config.DefaultPoolAddress(), - LimiterAddress: "", - VoucherRegistry: "", - } - - activePoolAddress := defaultPool.PoolContractAdrress - - // set the active pool contract address - err = userStore.WriteEntry(ctx, sessionId, storedb.DATA_ACTIVE_POOL_ADDRESS, []byte(activePoolAddress)) + // Get active pool address or fall back to default + var activePoolAddress []byte + activePoolAddress, err = userStore.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_POOL_ADDRESS) if err != nil { - logg.ErrorCtxf(ctx, "failed to write active PoolContractAdrress entry with", "key", storedb.DATA_ACTIVE_POOL_ADDRESS, "value", activePoolAddress, "error", err) - return res, err + if db.IsNotFound(err) { + defaultPoolAddress := config.DefaultPoolAddress() + // store the default as the active pool address + err = userStore.WriteEntry(ctx, sessionId, storedb.DATA_ACTIVE_POOL_ADDRESS, []byte(defaultPoolAddress)) + if err != nil { + logg.ErrorCtxf(ctx, "failed to write default PoolContractAdrress", "key", storedb.DATA_ACTIVE_POOL_ADDRESS, "value", defaultPoolAddress, "error", err) + return res, err + } + activePoolAddress = []byte(defaultPoolAddress) + } else { + logg.ErrorCtxf(ctx, "failed to read active PoolContractAdrress", "key", storedb.DATA_ACTIVE_POOL_ADDRESS, "error", err) + return res, err + } } // call the api using the ActivePoolAddress and ActiveVoucherAddress to check if it is part of the pool - r, err := h.accountService.CheckTokenInPool(ctx, activePoolAddress, string(activeAddress)) + r, err := h.accountService.CheckTokenInPool(ctx, string(activePoolAddress), string(activeAddress)) if err != nil { res.FlagSet = append(res.FlagSet, flag_api_error) logg.ErrorCtxf(ctx, "failed on CheckTokenInPool", "error", err)