From b0d2e2fb05fc294bbf40db64b36721ab01967245 Mon Sep 17 00:00:00 2001 From: vaisest <4550061+vaisest@users.noreply.github.com> Date: Wed, 12 Aug 2026 21:46:41 +0300 Subject: [PATCH 1/2] Add private leagues back into trader --- src/Classes/PoEAPI.lua | 6 ++++ src/Classes/TradeQuery.lua | 50 ++------------------------- src/Classes/TradeQueryRateLimiter.lua | 3 +- src/Classes/TradeQueryRequests.lua | 47 ++++++++++++++++++++++--- 4 files changed, 53 insertions(+), 53 deletions(-) diff --git a/src/Classes/PoEAPI.lua b/src/Classes/PoEAPI.lua index 7a9031df059..70e4e878d1a 100644 --- a/src/Classes/PoEAPI.lua +++ b/src/Classes/PoEAPI.lua @@ -236,3 +236,9 @@ function PoEAPIClass:DownloadCharacter(realm, name, callback) self:DownloadWithRateLimit("character-request-limit", "/character" .. (realm == "pc" and "" or "/" .. realm) .. "/" .. name, callback) end + +---@param realm string Realm to fetch the leagues for +---@param callback DownloadCallback +function PoEAPIClass:FetchLeagues(realm, callback) + self:DownloadWithRateLimit("league-request-limit", "/account/leagues" .. ((realm == "pc") and "" or ("/" .. realm)), callback) +end diff --git a/src/Classes/TradeQuery.lua b/src/Classes/TradeQuery.lua index 7ea2fcedf00..a7ea1dd0262 100644 --- a/src/Classes/TradeQuery.lua +++ b/src/Classes/TradeQuery.lua @@ -71,39 +71,6 @@ function TradeQueryClass:TradeQuery(itemsTab) end - --- Method to pull down and interpret available leagues from PoE -function TradeQueryClass:PullLeagueList() - launch:DownloadPage( - self.hostName .. "api/leagues?type=main&compact=1", - function(response, errMsg) - if errMsg then - self:SetNotice(self.controls.pbNotice, "Error: " .. tostring(errMsg)) - return "POE ERROR", "Error: "..errMsg - else - local json_data = dkjson.decode(response.body) - if not json_data then - self:SetNotice(self.controls.pbNotice, "Failed to Get PoE League List response") - return - end - table.sort(json_data, function(a, b) - if a.endAt == nil then return false end - if b.endAt == nil then return true end - return a.id < b.id - end) - self.itemsTab.leagueDropList = {} - for _, league_data in pairs(json_data) do - if not league_data.id:find("SSF") then - t_insert(self.itemsTab.leagueDropList,league_data.id) - end - end - self.controls.league:SetList(self.itemsTab.leagueDropList) - self.controls.league.selIndex = 1 - self.pbLeague = self.itemsTab.leagueDropList[self.controls.league.selIndex] - end - end) -end - --- @param currencyId string --- @param amount integer --- @return number? @@ -1274,7 +1241,8 @@ you can add them, copy the link here, and press "Price Item" to evaluate the ite local exactQueryStr = dkjson.encode(exactQuery) - local encodedUrl = s_format("https://www.pathofexile.com/trade/search/%s?q=%s", self.pbLeague, urlEncode(exactQueryStr)) + local realmPath = (self.pbRealm ~= "pc") and (self.pbRealm .. "/") or "" + local encodedUrl = s_format("https://www.pathofexile.com/trade/search/%s%s?q=%s", realmPath, self.pbLeague, urlEncode(exactQueryStr)) Copy(encodedUrl) OpenURL(encodedUrl) @@ -1350,20 +1318,8 @@ function TradeQueryClass:UpdateRealms() end -- use trade leagues api to get trade leagues including private leagues is valid. + setRealmDropList() self.allLeagues = {} - for _, realmId in pairs (self.realmIds) do - self.tradeQueryRequests:FetchLeagues(realmId, function(leagues, errMsg) - if errMsg then - self:SetNotice(self.controls.pbNotice, "Using Fallback Error while fetching league list: "..errMsg) - end - for _, league in ipairs(leagues) do - if not self.allLeagues[realmId] then self.allLeagues[realmId] = {} end - t_insert(self.allLeagues[realmId], league) - end - setRealmDropList() - - end) - end -- perform a generic search to make sure the authorization is valid. self.tradeQueryRequests:PerformSearch("pc", "Standard", [[{"query":{"status":{"option":"online"},"stats":[{"type":"and","filters":[]}]},"sort":{"price":"asc"}}]], function(response, errMsg) diff --git a/src/Classes/TradeQueryRateLimiter.lua b/src/Classes/TradeQueryRateLimiter.lua index f98c59f669f..50dbbdbb542 100644 --- a/src/Classes/TradeQueryRateLimiter.lua +++ b/src/Classes/TradeQueryRateLimiter.lua @@ -56,7 +56,8 @@ function TradeQueryRateLimiterClass:TradeQueryRateLimiter() ["trade-search-request-limit"] = {}, ["trade-fetch-request-limit"] = {}, ["character-list-request-limit"] = {}, - ["character-request-limit"] = {} + ["character-request-limit"] = {}, + ["league-request-limit"] = {}, } return self end diff --git a/src/Classes/TradeQueryRequests.lua b/src/Classes/TradeQueryRequests.lua index b0067123807..8b534505af7 100644 --- a/src/Classes/TradeQueryRequests.lua +++ b/src/Classes/TradeQueryRequests.lua @@ -449,8 +449,9 @@ end ---@param realm string ---@param callback fun(query:table, errMsg:string) function TradeQueryRequestsClass:FetchLeagues(realm, callback) - local header = "Authorization: Bearer " .. (main.api.authToken or "") - launch:DownloadPage( + local function fetchStatic() + ConPrintf("fetching static leagues") + launch:DownloadPage( self.hostName .. "api/trade/data/leagues", function(response, errMsg) if errMsg then @@ -472,9 +473,45 @@ function TradeQueryRequestsClass:FetchLeagues(realm, callback) end end callback(leagues, errMsg) - end, - {header = header} - ) + end + ) + end + if main.api.authToken then + main.api:FetchLeagues(realm, function(body, err) + -- fall back to static data on error + if not body or err then + ConPrintf("Failed to fetch oauth leagues: %s", err) + return fetchStatic() + end + if body.error then + local apiError = body.error + local errMsg = apiError or "Failed to parse trade leagues JSON" + if type(apiError) == "table" then + errMsg = apiError.message or (apiError.code and tostring(apiError.code)) or "Failed to parse trade leagues JSON" + end + ConPrintf("Failed to fetch oauth leagues: %s", errMsg) + return fetchStatic() + end + local leagues = {} + for _, value in pairs(body.leagues or {}) do + if value.rules then + -- filter out ssf leagues which might be present in the oauth query + for _, rule in ipairs(value.rules) do + if rule.id == "NoParties" then + goto skipLeague + end + end + end + if value.realm == realm then + table.insert(leagues, value.id) + end + ::skipLeague:: + end + callback(leagues, err) + end) + else + fetchStatic() + end end --- Build search and trade URLs with proper encoding From eb6a7a671500aaef8c55cdbee066b46aedce6b76 Mon Sep 17 00:00:00 2001 From: vaisest <4550061+vaisest@users.noreply.github.com> Date: Wed, 12 Aug 2026 22:08:55 +0300 Subject: [PATCH 2/2] Fix dumb text issue and refetch on auth change --- src/Classes/TradeQuery.lua | 9 ++++++--- src/Classes/TradeQueryRequests.lua | 4 +--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Classes/TradeQuery.lua b/src/Classes/TradeQuery.lua index a7ea1dd0262..1991fba39a6 100644 --- a/src/Classes/TradeQuery.lua +++ b/src/Classes/TradeQuery.lua @@ -278,7 +278,7 @@ function TradeQueryClass:PriceItem() self.clickTime = nil return "Not authenticated" else - return "Logging in... (" .. left .. ") - URL copied to clipboard" + return "Logging in... (" .. left .. ")" end else return colorCodes.WARNING.."Not authenticated" @@ -307,8 +307,10 @@ function TradeQueryClass:PriceItem() main:SaveSettings() TradeQueryClass:SetNotice(self.controls.pbNotice, "") + self:UpdateRealms() else self.loginStatus = colorCodes.WARNING.."Not authenticated" + self:UpdateRealms() end end) self.clickTime = os.time() @@ -321,11 +323,12 @@ function TradeQueryClass:PriceItem() main.tokenExpiry = nil main.api.tokenExpiry = nil main:SaveSettings() + self:UpdateRealms() end end) self.controls.tradeAuthButton.tooltipText = [[ The Trader feature supports two modes of operation depending on the authorization availability. -You can click this button to authorize PoB by logging in. +You can click this button to authorize PoB by logging in. The URL is also copied to your clipboard. ^2Session Mode^7 - Requires authorization on pathofexile.com. @@ -1318,8 +1321,8 @@ function TradeQueryClass:UpdateRealms() end -- use trade leagues api to get trade leagues including private leagues is valid. - setRealmDropList() self.allLeagues = {} + setRealmDropList() -- perform a generic search to make sure the authorization is valid. self.tradeQueryRequests:PerformSearch("pc", "Standard", [[{"query":{"status":{"option":"online"},"stats":[{"type":"and","filters":[]}]},"sort":{"price":"asc"}}]], function(response, errMsg) diff --git a/src/Classes/TradeQueryRequests.lua b/src/Classes/TradeQueryRequests.lua index 8b534505af7..4e625bb64c4 100644 --- a/src/Classes/TradeQueryRequests.lua +++ b/src/Classes/TradeQueryRequests.lua @@ -502,9 +502,7 @@ function TradeQueryRequestsClass:FetchLeagues(realm, callback) end end end - if value.realm == realm then - table.insert(leagues, value.id) - end + table.insert(leagues, value.id) ::skipLeague:: end callback(leagues, err)