diff --git a/src/lib/alarms/trade_history.ts b/src/lib/alarms/trade_history.ts index 40613df4..ccd797fe 100644 --- a/src/lib/alarms/trade_history.ts +++ b/src/lib/alarms/trade_history.ts @@ -78,6 +78,7 @@ interface TradeHistoryAPIResponse { status: number; assets_given?: HistoryAsset[]; assets_received?: HistoryAsset[]; + time_init: number; time_escrow_end?: string; time_settlement?: number; rollback_trade?: string; @@ -85,16 +86,54 @@ interface TradeHistoryAPIResponse { }; } -export async function getTradeHistoryFromAPI(maxTrades: number): Promise { +export async function getTradeHistoryFromAPI( + maxTrades: number, + opts?: { + startAfterTime?: number; + startAfterTradeID?: string; + navigatingBack?: boolean; + getDescriptions?: boolean; + includeFailed?: boolean; + includeTotal?: boolean; + language?: string; + } +): Promise { const access = await getAccessToken(); + let url = `https://api.steampowered.com/IEconService/GetTradeHistory/v1/?access_token=${access.token}&max_trades=${maxTrades}`; + + if (opts?.startAfterTime) { + url += `&start_after_time=${opts.startAfterTime}`; + } + + if (opts?.startAfterTradeID) { + url += `&start_after_tradeid=${opts.startAfterTradeID}`; + } + + if (opts?.navigatingBack !== undefined) { + url += `&navigating_back=${opts.navigatingBack}`; + } + + if (opts?.getDescriptions !== undefined) { + url += `&get_descriptions=${opts.getDescriptions}`; + } + + if (opts?.includeFailed !== undefined) { + url += `&include_failed=${opts.includeFailed}`; + } + + if (opts?.includeTotal !== undefined) { + url += `&include_total=${opts.includeTotal}`; + } + + if (opts?.language) { + url += `&language=${opts.language}`; + } + // This only works if they have granted permission for https://api.steampowered.com - const resp = await fetch( - `https://api.steampowered.com/IEconService/GetTradeHistory/v1/?access_token=${access.token}&max_trades=${maxTrades}`, - { - credentials: 'include', - } - ); + const resp = await fetch(url, { + credentials: 'include', + }); if (resp.status !== 200) { throw new Error('invalid status'); @@ -119,6 +158,7 @@ export async function getTradeHistoryFromAPI(maxTrades: number): Promise( RequestType.FETCH_TRADE_HISTORY, async (req) => { - const trades = await getTradeHistoryFromAPI(req.max_trades); + const trades = await getTradeHistoryFromAPI(req.max_trades, { + startAfterTime: req.start_after_time, + startAfterTradeID: req.start_after_tradeid, + navigatingBack: req.navigating_back, + getDescriptions: req.get_descriptions, + includeFailed: req.include_failed, + includeTotal: req.include_total, + language: req.language, + }); return { trades, }; diff --git a/src/lib/bridge/handlers/trade_history_status.ts b/src/lib/bridge/handlers/trade_history_status.ts index 38ce2793..daa4396d 100644 --- a/src/lib/bridge/handlers/trade_history_status.ts +++ b/src/lib/bridge/handlers/trade_history_status.ts @@ -13,6 +13,7 @@ export interface TradeHistoryStatus { other_party_url: string; received_assets: TradeHistoryAsset[]; given_assets: TradeHistoryAsset[]; + time_init: number; time_settlement?: number; rollback_trade?: string; }