-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Display Metadata on /tradeoffers
-pages
#283
base: master
Are you sure you want to change the base?
Conversation
src/lib/page_scripts/trade_offers.ts
Outdated
* @returns the trade offers | ||
*/ | ||
async function fetchTradeOffers(isSentPage: boolean) { | ||
const g_steamTrades = JSON.parse(localStorage.getItem('g_steamTrades') || '{}') as FetchSteamTradesResponse; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should generally avoid using localStorage within the Steam page since it is untyped and starts to "pollute" a common space for Steam itself and other extensions.
It's preferrable to use extension-specific storage or caching.
src/lib/page_scripts/trade_offers.ts
Outdated
const g_steamTrades = JSON.parse(localStorage.getItem('g_steamTrades') || '{}') as FetchSteamTradesResponse; | ||
let refetchRequired = true; | ||
if (g_steamTrades.sent || g_steamTrades.received) { | ||
const latestTradeId = Number.parseInt(g_steamTrades[isSentPage ? 'sent' : 'received']?.[0].offer_id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of handling cache breaking in a more manual way, perhaps we should pass in the offer_id
of the last element when making the FetchSteamTrades
request.
You can then wrap FetchSteamTrades
as a CachedHandler
, add the trade_offer_id
as a request parameter (perhaps along with the Steam of the user on the page), and then you get caching for "free".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would really like the CachedHandler
to be the solution, but I think can't quite do the job for two reasons:
- sent / received pages display different trade offers, hence the
trade_offer_id
would be different - the cache is not persistent across browser restarts
I gave it a try in 0d4620b, but I couldn't get it to cache the requests correctly even for the same parameters.
Motivation
Closes #143.
Description
This PR adds the well-known enhancements from tradeoffer-popouts to the
/tradeoffers
-overview:FetchSteamTrades
-handler to fetch the data from the Steam API through the access tokentrade_offers.ts
page script:localStorage
as cache to avoid refetching from the API if there are no new trades since the last fetchTradeOfferHolderMetadata
Lit-component, which reads the required properties from the DOMScreenshots
Received tradeoffer example:
Sent tradeoffer example: