Skip to content

Commit 9220540

Browse files
pathaninoat
andauthored
Fix trader crashes on object-form mods, make Find best return URL only (#5)
* Handle object-form mods from the trade API The trade API migrated item mods from plain strings to objects carrying a description and flags. Commit 2d09769 adapted explicitMods only, so any item whose runeMods/enchantMods/implicitMods were populated crashed with "attempt to call method 'gsub' (a nil value)" — escapeGGGString was handed a table. Use the same format-agnostic idiom already ported into ImportTab.lua, and apply it to pseudoMods too, which crashed the same way one line later on :match. That guard also fixes a pre-existing crash on an empty pseudoMods array, which previously indexed nil rather than falling back to "0". * Make "Find best" return the trade URL without listing items Register the generated search so the short shareable link can be built, then stop. The item listings are no longer fetched, parsed or sorted, so the row stays on [Find best][url][Price Item] instead of flipping to the result dropdown. "Price Item" remains available on that URL for when the items are actually wanted. The URL is set before the error branch so an empty search still yields a link to loosen in the browser. This orphans the Augment/Anoint Behaviour dropdowns in the Find best dialog: their only consumer was the post-fetch item rewriting removed here. Left in place rather than wired into "Price Item", which fires on whatever URL is in the box and would rewrite hand-pasted results based on a dropdown set during an unrelated search. --------- Co-authored-by: oat <plokbowwork@gmail.com>
1 parent 6f167ce commit 9220540

2 files changed

Lines changed: 27 additions & 66 deletions

File tree

src/Classes/TradeQuery.lua

Lines changed: 14 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,70 +1022,28 @@ function TradeQueryClass:PriceItemRowDisplay(row_idx, top_pane_alignment_ref, ro
10221022
controls["uri"..context.row_idx]:SetText(url, true)
10231023
return
10241024
end
1025+
-- Register the search so we get a short shareable link, but stop there: the item
1026+
-- listings are never fetched. Press "Price Item" on the resulting URL to pull them.
10251027
context.controls["priceButton"..context.row_idx].label = "Searching..."
10261028
self.lastQueries[row_idx] = query
1027-
self.tradeQueryRequests:SearchWithQueryWeightAdjusted(self.pbRealm, self.pbLeague, query,
1028-
function(items, errMsg)
1029-
if errMsg then
1030-
self:SetNotice(context.controls.pbNotice, colorCodes.NEGATIVE .. errMsg)
1031-
context.controls["priceButton"..context.row_idx].label = "Price Item"
1032-
return
1033-
else
1034-
self:SetNotice(context.controls.pbNotice, "")
1035-
end
1036-
1037-
local selectedSlot = getSelectedSlot()
1038-
local itemsSafe = self:FilterToSafeItems(items, selectedSlot and selectedSlot.slotName)
1039-
1040-
if self.tradeQueryGenerator.lastAugmentBehaviour == "Copy Current" or self.tradeQueryGenerator.lastAnointBehaviour == "Copy Current" then
1041-
for i, _ in ipairs(itemsSafe) do
1042-
local item = new("Item", itemsSafe[i].item_string)
1043-
-- avoid interacting with badly parsed stuff
1044-
if item.base and item.type then
1045-
self.itemsTab:CopyAnointsAndAugments(item, true, true, context.slotTbl.slotName)
1046-
itemsSafe[i].item_string = item:BuildRaw()
1047-
end
1048-
end
1049-
elseif self.tradeQueryGenerator.lastAugmentBehaviour == "Remove" then
1050-
for item_idx, _ in ipairs(itemsSafe) do
1051-
local item = new("Item", itemsSafe[item_idx].item_string)
1052-
-- sockets are kept as-is so the user can see e.g. exceptional or corrupted sockets
1053-
local validRunes = self.itemsTab:GetValidRunesForItem(item)
1054-
for rune_idx, _ in ipairs(item.runes or {}) do
1055-
if not self.itemsTab:IsSocketBoundRune(item, item.runes[rune_idx], validRunes) then
1056-
item.runes[rune_idx] = "None"
1057-
end
1058-
end
1059-
item:UpdateRunes()
1060-
itemsSafe[item_idx].item_string = item:BuildRaw()
1061-
end
1062-
elseif self.tradeQueryGenerator.lastAnointBehaviour == "Remove" then
1063-
for i, _ in ipairs(itemsSafe) do
1064-
local item = new("Item", itemsSafe[i].item_string)
1065-
item.enchantModLines = {}
1066-
itemsSafe[i].item_string = item:BuildRaw()
1067-
end
1068-
end
1069-
1070-
self.resultTbl[context.row_idx] = itemsSafe
1071-
self:UpdateControlsWithItems(context.row_idx)
1072-
context.controls["priceButton"..context.row_idx].label = "Price Item"
1073-
end,
1074-
{
1075-
callbackQueryId = function(queryId)
1076-
local url = self.tradeQueryRequests:buildUrl(self.hostName .. "trade2/search", self.pbRealm, self.pbLeague, queryId)
1077-
controls["uri"..context.row_idx]:SetText(url, true)
1078-
end
1079-
}
1080-
)
1029+
self.tradeQueryRequests:PerformSearch(self.pbRealm, self.pbLeague, query, function(response, errMsg)
1030+
context.controls["priceButton"..context.row_idx].label = "Price Item"
1031+
-- Set the URL even on error, so an empty search still gives a link to loosen in the browser
1032+
if response and response.id then
1033+
local url = self.tradeQueryRequests:buildUrl(self.hostName .. "trade2/search", self.pbRealm, self.pbLeague, response.id)
1034+
controls["uri"..context.row_idx]:SetText(url, true)
1035+
end
1036+
self:SetNotice(context.controls.pbNotice, errMsg and (colorCodes.NEGATIVE .. errMsg) or "")
1037+
end)
10811038
end)
10821039
end)
10831040
controls["bestButton"..row_idx].shown = function() return not self.resultTbl[row_idx] end
10841041
controls["bestButton"..row_idx].enabled = function() return self.pbLeague end
10851042
controls["bestButton"..row_idx].tooltipText = [[Creates a weighted search to find the highest Stat Value items for this slot.
1086-
Note that even if you are authenticated, you can click this button again to show the search link.
1043+
The trade link is put in the box to the right; the items themselves are not fetched.
1044+
Control + click the link to open the search in your web-browser.
10871045
If you have additional requirements that the trade tool doesn't cover (e.g. Adorned Magic jewels),
1088-
you can add them, copy the link here, and press "Price Item" to evaluate the items.]]
1046+
you can add them, then press "Price Item" to evaluate the items inside Path of Building.]]
10891047
controls["bestButton" .. row_idx].onHover = function()
10901048
local button = controls["bestButton" .. row_idx]
10911049

src/Classes/TradeQueryRequests.lua

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -398,23 +398,23 @@ function TradeQueryRequestsClass:FetchResultBlock(url, callback)
398398
item.explicitMods = item.explicitMods or { }
399399

400400
t_insert(rawLines, "Implicits: " .. (#item.enchantMods + #item.runeMods + #item.implicitMods))
401-
for _, modLine in ipairs(item.enchantMods) do
402-
t_insert(rawLines, "{enchant}" .. escapeGGGString(modLine))
401+
for _, itemMod in ipairs(item.enchantMods) do
402+
t_insert(rawLines, "{enchant}" .. escapeGGGString(itemMod.description or itemMod))
403403
end
404-
for _, modLine in ipairs(item.runeMods) do
405-
t_insert(rawLines, "{enchant}{rune}" .. escapeGGGString(modLine))
404+
for _, itemMod in ipairs(item.runeMods) do
405+
t_insert(rawLines, "{enchant}{rune}" .. escapeGGGString(itemMod.description or itemMod))
406406
end
407-
for _, modLine in ipairs(item.implicitMods) do
408-
t_insert(rawLines, escapeGGGString(modLine))
407+
for _, itemMod in ipairs(item.implicitMods) do
408+
t_insert(rawLines, escapeGGGString(itemMod.description or itemMod))
409409
end
410-
for _, modLine in ipairs(item.explicitMods) do
410+
for _, itemMod in ipairs(item.explicitMods) do
411411
local s = ""
412-
for flagName, flag in pairs(modLine.flags or {}) do
412+
for flagName, flag in pairs(itemMod.flags or {}) do
413413
if flag then
414414
s = s .. string.format("{%s}", flagName)
415415
end
416416
end
417-
t_insert(rawLines, s .. escapeGGGString(modLine.description))
417+
t_insert(rawLines, s .. escapeGGGString(itemMod.description or itemMod))
418418
end
419419
if item.mirrored then
420420
t_insert(rawLines, "Mirrored")
@@ -428,14 +428,17 @@ function TradeQueryRequestsClass:FetchResultBlock(url, callback)
428428
t_insert(rawLines, "Sanctified")
429429
end
430430

431+
local pseudoMod = item.pseudoMods and item.pseudoMods[1]
432+
pseudoMod = pseudoMod and (pseudoMod.description or pseudoMod)
433+
431434
table.insert(items, {
432435
amount = trade_entry.listing.price.amount,
433436
currency = trade_entry.listing.price.currency,
434437
priceType = trade_entry.listing.price.type,
435438
item_string = table.concat(rawLines, "\n"),
436439
whisper = trade_entry.listing.whisper,
437440
trader = trade_entry.listing.account.name,
438-
weight = trade_entry.item.pseudoMods and trade_entry.item.pseudoMods[1]:match("Sum: (.+)") or "0",
441+
weight = pseudoMod and pseudoMod:match("Sum: (.+)") or "0",
439442
id = trade_entry.id
440443
})
441444
end

0 commit comments

Comments
 (0)