Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions src/Classes/ImportTab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ local function addOAuthControls(self)
local function importHandler(data, errMsg)
if data and data.character then
self.oauthErrCode = nil
self:SetOAuthPredefinedBuildName(selectedName)
self:ImportPassiveTreeAndJewels(data.character, deleteJewels)
else
if errMsg then
Expand Down Expand Up @@ -298,6 +299,7 @@ local function addOAuthControls(self)
local ignoreWeaponSwap = self.controls.charImportItemsIgnoreWeaponSwap.state
if data and data.character then
self.oauthErrCode = nil
self:SetOAuthPredefinedBuildName(selectedName)
self:ImportItemsAndSkills(data.character, clearItems, clearSkills, ignoreWeaponSwap)
else
if errMsg then
Expand Down Expand Up @@ -1937,10 +1939,34 @@ function UrlDecode(url)
return url
end

function ImportTabClass:SetPredefinedBuildName()
local accountName = self.controls.siteAccountName.buf:gsub('%s+', ''):gsub("#%d+", "")
local charSelect = self.controls.siteCharSelect
local charData = charSelect.list[charSelect.selIndex].char
local charName = charData.name
function ImportTabClass:SetOAuthPredefinedBuildName(charName)
self.buildNameRequest = (self.buildNameRequest or 0) + 1
local request = self.buildNameRequest
local api = main.api
local generation = api.accountGeneration
if api.accountName then
self:SetPredefinedBuildName(api.accountName, charName)
return
end
main.predefinedBuildName = charName
api:DownloadWithRefresh("/profile", function(response, errMsg)
local profile = not errMsg and response and response.body and dkjson.decode(response.body)
if main.api == api and api.accountGeneration == generation and type(profile) == "table"
and type(profile.name) == "string" and profile.name ~= "" then
api.accountName = profile.name
if self.buildNameRequest == request and main.predefinedBuildName == charName then
self:SetPredefinedBuildName(profile.name, charName)
end
end
end)
end

function ImportTabClass:SetPredefinedBuildName(accountName, charName)
self.buildNameRequest = (self.buildNameRequest or 0) + 1
accountName = (accountName or self.controls.siteAccountName.buf):gsub('%s+', ''):gsub("#%d+", "")
if not charName then
local charSelect = self.controls.siteCharSelect
charName = charSelect.list[charSelect.selIndex].char.name
end
main.predefinedBuildName = accountName .. " - " .. charName
end
3 changes: 3 additions & 0 deletions src/Classes/PoEAPI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function PoEAPIClass:PoEAPI(authToken, refreshToken, tokenExpiry)
self.baseUrl = "https://api.pathofexile.com"
self.rateLimiter = new("TradeQueryRateLimiter"):TradeQueryRateLimiter()
self.tokenHasBeenValidated = false
self.accountGeneration = 0

self.ERROR_NO_AUTH = "No auth token"
return self
Expand Down Expand Up @@ -75,6 +76,8 @@ end

--- resets current authorization details
function PoEAPIClass:ResetDetails()
self.accountGeneration = self.accountGeneration + 1
self.accountName = nil
self.authToken = nil
self.refreshToken = nil
self.tokenExpiry = nil
Expand Down
Loading