- 
                Notifications
    
You must be signed in to change notification settings  - Fork 33
 
          Display Metadata on /tradeoffers-pages
          #283
        
          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
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            16 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      27b7e07
              
                Display item metadata on /tradeoffers
              
              
                GODrums c1a09b7
              
                chore: run format
              
              
                GODrums 869b3c9
              
                Remove csfloat check for offer tracking
              
              
                GODrums 1bbab1d
              
                Merge branch 'master' into 143-metadata-trade-offers-pages
              
              
                GODrums 32673f5
              
                fix: avoid circular dependency
              
              
                GODrums fbf8517
              
                clarify variable names
              
              
                GODrums 16d228b
              
                Move config parsing to utility
              
              
                GODrums bbb6d72
              
                Handle access token caching
              
              
                GODrums a652c77
              
                simplify tradeoffer types
              
              
                GODrums 6923b43
              
                update variable names
              
              
                GODrums 0d4620b
              
                rework caching with CachedHandler
              
              
                GODrums aeb8c4d
              
                Merge branch 'master' into 143-metadata-trade-offers-pages
              
              
                GODrums 48bf2b6
              
                Handle case of no open trades
              
              
                GODrums 3806f9e
              
                Rename variables and update references
              
              
                GODrums 42685e6
              
                Revert tracking prerequisite
              
              
                GODrums c47c675
              
                Apply review suggestions
              
              
                GODrums File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import {getTradeOffersWithDescriptionFromAPI, TradeOffersAPIOffer} from '../../alarms/trade_offer'; | ||
| import {rgDescription} from '../../types/steam'; | ||
| import {CachedHandler} from '../wrappers/cached'; | ||
| import {SimpleHandler} from './main'; | ||
| import {RequestType} from './types'; | ||
| 
     | 
||
| interface FetchSteamTradesRequest { | ||
| steam_id?: string; | ||
| // Used for caching the request uniquely, does not affect the return results | ||
| trade_offer_id?: number; | ||
| } | ||
| 
     | 
||
| export interface FetchSteamTradesResponse { | ||
| received: TradeOffersAPIOffer[]; | ||
| sent: TradeOffersAPIOffer[]; | ||
| descriptions: rgDescription[]; | ||
| steam_id?: string | null; | ||
| } | ||
| 
     | 
||
| export const FetchSteamTrades = new CachedHandler( | ||
| new SimpleHandler<FetchSteamTradesRequest, FetchSteamTradesResponse>( | ||
| RequestType.FETCH_STEAM_TRADES, | ||
| async (req) => { | ||
| const resp = await getTradeOffersWithDescriptionFromAPI(req.steam_id); | ||
| if (!resp) { | ||
| throw new Error('Error fetching Steam trade offers from API'); | ||
| } | ||
| 
     | 
||
| return resp; | ||
| } | ||
| ), | ||
| 1, | ||
| 10 * 60 * 1000 | ||
| ); | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
          
            25 changes: 25 additions & 0 deletions
          
          25 
        
  src/lib/components/trade_offers/trade_offer_holder_metadata.ts
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import {CustomElement, InjectAppend, InjectionMode} from '../injectors'; | ||
| import {ItemHolderMetadata} from '../common/item_holder_metadata'; | ||
| import {rgAsset} from '../../types/steam'; | ||
| 
     | 
||
| // Annotates item info (float, seed, etc...) in boxes on the Trade Offers Page | ||
| @CustomElement() | ||
| // Items in received/sent trade offers | ||
| @InjectAppend('.tradeoffer .trade_item', InjectionMode.CONTINUOUS) | ||
| export class TradeOfferHolderMetadata extends ItemHolderMetadata { | ||
| get assetId(): string | undefined { | ||
| return $J(this).parent().attr('data-csfloat-assetid'); | ||
| } | ||
| 
     | 
||
| get asset(): rgAsset | undefined { | ||
| const dataDescription = $J(this).parent().attr('data-csfloat-description'); | ||
| 
     | 
||
| if (!dataDescription) return undefined; | ||
| 
     | 
||
| return JSON.parse(dataDescription) as rgAsset; | ||
| } | ||
| 
     | 
||
| get ownerSteamId(): string | undefined { | ||
| return $J(this).parent().attr('data-csfloat-owner-steamid'); | ||
| } | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| interface UserInfo { | ||
| account_name: string; | ||
| accountid: number; | ||
| country_code: string; | ||
| is_limited: boolean; | ||
| is_partner_member: boolean; | ||
| is_support: boolean; | ||
| logged_in: boolean; | ||
| steamid: string; | ||
| } | ||
| 
     | 
||
| export function getUserInfo() { | ||
| const configUserInfo = document.getElementById('application_config')?.dataset?.userinfo; | ||
| if (!configUserInfo) { | ||
| return null; | ||
| } | ||
| return JSON.parse(configUserInfo) as UserInfo; | ||
| } | ||
| 
     | 
||
| export function getUserSteamID() { | ||
| const userInfo = getUserInfo(); | ||
| if (!userInfo?.logged_in) { | ||
| return null; | ||
| } | ||
| return userInfo.steamid; | ||
| } | ||
| 
     | 
||
| /** | ||
| * Converts a SteamID32 to a SteamID64 | ||
| * @param steamID32 number | ||
| * @returns SteamID64 | ||
| */ | ||
| export function convertSteamID32To64(steamID32: number) { | ||
| return (BigInt('76561197960265728') + BigInt(steamID32)).toString(); | ||
| } | 
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.