@@ -4,6 +4,7 @@ import {pingTradeHistory} from './trade_history';
44import { pingCancelTrades , pingSentTradeOffers } from './trade_offer' ;
55import { HasPermissions } from '../bridge/handlers/has_permissions' ;
66import { PingExtensionStatus } from '../bridge/handlers/ping_extension_status' ;
7+ import { AccessToken , getAccessToken } from './access_token' ;
78
89export const PING_CSFLOAT_TRADE_STATUS_ALARM_NAME = 'ping_csfloat_trade_status_alarm' ;
910
@@ -37,26 +38,62 @@ export async function pingTradeStatus() {
3738 return ;
3839 }
3940
40- if ( pendingTrades . length === 0 ) {
41- // No active trades, return early
42- return ;
41+ let access : AccessToken | null = null ;
42+
43+ try {
44+ access = await getAccessToken ( ) ;
45+ } catch ( e ) {
46+ console . error ( 'failed to fetch access token' , e ) ;
47+ }
48+
49+ let errors ;
50+
51+ if ( pendingTrades . length > 0 ) {
52+ errors = await pingUpdates ( pendingTrades ) ;
53+ }
54+
55+ // Ping status of ext + permissions
56+ try {
57+ await PingExtensionStatus . handleRequest (
58+ {
59+ access_token_steam_id : access ?. steam_id ,
60+ history_error : errors ?. history_error ,
61+ trade_offer_error : errors ?. trade_offer_error ,
62+ } ,
63+ { }
64+ ) ;
65+ } catch ( e ) {
66+ console . error ( 'failed to ping extension status to csfloat' , e ) ;
4367 }
68+ }
69+
70+ interface UpdateErrors {
71+ history_error ?: string ;
72+ trade_offer_error ?: string ;
73+ }
74+
75+ async function pingUpdates ( pendingTrades : Trade [ ] ) : Promise < UpdateErrors > {
76+ const errors : UpdateErrors = { } ;
4477
4578 try {
4679 await pingTradeHistory ( pendingTrades ) ;
4780 } catch ( e ) {
4881 console . error ( 'failed to ping trade history' , e ) ;
82+ errors . history_error = ( e as any ) . toString ( ) ;
4983 }
5084
5185 try {
5286 await pingSentTradeOffers ( pendingTrades ) ;
5387 } catch ( e ) {
5488 console . error ( 'failed to ping sent trade offer state' , e ) ;
89+ errors . trade_offer_error = ( e as any ) . toString ( ) ;
5590 }
5691
5792 try {
5893 await pingCancelTrades ( pendingTrades ) ;
5994 } catch ( e ) {
6095 console . error ( 'failed to ping cancel ping trade offers' , e ) ;
6196 }
97+
98+ return errors ;
6299}
0 commit comments