11import { Trade } from '../types/float_market' ;
22import { TradeHistoryStatus , TradeHistoryType } from '../bridge/handlers/trade_history_status' ;
3- import { AppId } from '../types/steam_constants' ;
3+ import { AppId , TradeStatus } from '../types/steam_constants' ;
44import { clearAccessTokenFromStorage , getAccessToken } from './access_token' ;
55
6- export async function pingTradeHistory ( pendingTrades : Trade [ ] ) {
6+ export async function pingTradeHistory ( pendingTrades : Trade [ ] ) : Promise < TradeHistoryStatus [ ] > {
77 const { history, type} = await getTradeHistory ( ) ;
88
99 // premature optimization in case it's 100 trades
@@ -25,15 +25,17 @@ export async function pingTradeHistory(pendingTrades: Trade[]) {
2525 } ) ;
2626
2727 if ( historyForCSFloat . length === 0 ) {
28- return ;
28+ return history ;
2929 }
3030
3131 await TradeHistoryStatus . handleRequest ( { history : historyForCSFloat , type} , { } ) ;
32+
33+ return history ;
3234}
3335
3436async function getTradeHistory ( ) : Promise < { history : TradeHistoryStatus [ ] ; type : TradeHistoryType } > {
3537 try {
36- const history = await getTradeHistoryFromAPI ( ) ;
38+ const history = await getTradeHistoryFromAPI ( 250 ) ;
3739 if ( history . length > 0 ) {
3840 // Hedge in case this endpoint gets killed, only return if there are results, fallback to HTML parser
3941 return { history, type : TradeHistoryType . API } ;
@@ -63,16 +65,18 @@ interface TradeHistoryAPIResponse {
6365 assets_given ?: HistoryAsset [ ] ;
6466 assets_received ?: HistoryAsset [ ] ;
6567 time_escrow_end ?: string ;
68+ time_settlement ?: number ;
69+ rollback_trade ?: string ;
6670 } [ ] ;
6771 } ;
6872}
6973
70- async function getTradeHistoryFromAPI ( ) : Promise < TradeHistoryStatus [ ] > {
74+ export async function getTradeHistoryFromAPI ( maxTrades : number ) : Promise < TradeHistoryStatus [ ] > {
7175 const access = await getAccessToken ( ) ;
7276
7377 // This only works if they have granted permission for https://api.steampowered.com
7478 const resp = await fetch (
75- `https://api.steampowered.com/IEconService/GetTradeHistory/v1/?access_token=${ access . token } &max_trades=200 ` ,
79+ `https://api.steampowered.com/IEconService/GetTradeHistory/v1/?access_token=${ access . token } &max_trades=${ maxTrades } ` ,
7680 {
7781 credentials : 'include' ,
7882 }
@@ -84,7 +88,7 @@ async function getTradeHistoryFromAPI(): Promise<TradeHistoryStatus[]> {
8488
8589 const data = ( await resp . json ( ) ) as TradeHistoryAPIResponse ;
8690 return ( data . response ?. trades || [ ] )
87- . filter ( ( e ) => e . status === 3 ) // Ensure we only count _complete_ trades (k_ETradeStatus_Complete)
91+ . filter ( ( e ) => e . status === TradeStatus . Complete || e . status === TradeStatus . TradeProtectionRollback ) // Ensure we only count _complete_ trades (k_ETradeStatus_Complete) or rolled back (for reporting )
8892 . filter ( ( e ) => ! e . time_escrow_end || new Date ( parseInt ( e . time_escrow_end ) * 1000 ) . getTime ( ) < Date . now ( ) )
8993 . map ( ( e ) => {
9094 return {
@@ -99,6 +103,10 @@ async function getTradeHistoryFromAPI(): Promise<TradeHistoryStatus[]> {
99103 . map ( ( e ) => {
100104 return { asset_id : e . assetid , new_asset_id : e . new_assetid } ;
101105 } ) ,
106+ trade_id : e . tradeid ,
107+ time_settlement : e . time_settlement ,
108+ status : e . status ,
109+ rollback_trade : e . rollback_trade ,
102110 } as TradeHistoryStatus ;
103111 } )
104112 . filter ( ( e ) => {
@@ -132,6 +140,10 @@ function parseTradeHistoryHTML(body: string): TradeHistoryStatus[] {
132140 other_party_url : `https://steamcommunity.com/${ e [ 1 ] } ` ,
133141 received_assets : [ ] ,
134142 given_assets : [ ] ,
143+ trade_id : '' ,
144+ time_settlement : 0 ,
145+ status : 0 ,
146+ rollback_trade : '' ,
135147 } as TradeHistoryStatus ;
136148 } ) ;
137149
0 commit comments