Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/lib/components/common/item_holder_metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ export abstract class ItemHolderMetadata extends FloatElement {
return $J(this).parent().attr('id')?.split('_')[2];
}

get isTradeProtected(): boolean {
return $J(this).parent().hasClass('provisional_item');
}

abstract get asset(): rgAsset | undefined;
abstract get ownerSteamId(): string | undefined;

Expand Down
12 changes: 11 additions & 1 deletion src/lib/components/inventory/inventory_item_holder_metadata.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {CustomElement, InjectAppend, InjectionMode} from '../injectors';
import {rgAsset} from '../../types/steam';
import {ItemHolderMetadata} from '../common/item_holder_metadata';
import {ContextId} from '../../types/steam_constants';
import {isCAppwideInventory} from '../../utils/checkers';

@CustomElement()
@InjectAppend(
Expand All @@ -11,7 +13,15 @@ export class InventoryItemHolderMetadata extends ItemHolderMetadata {
get asset(): rgAsset | undefined {
if (!this.assetId) return;

return g_ActiveInventory?.m_rgAssets[this.assetId]?.description;
if (!g_ActiveInventory) return;

if (isCAppwideInventory(g_ActiveInventory)) {
const contextId = this.isTradeProtected ? ContextId.PROTECTED : ContextId.PRIMARY;

return g_ActiveInventory.m_rgChildInventories[contextId]?.m_rgAssets[this.assetId]?.description;
} else {
return g_ActiveInventory.m_rgAssets[this.assetId]?.description;
}
}

get ownerSteamId(): string | undefined {
Expand Down
13 changes: 10 additions & 3 deletions src/lib/types/steam.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import $ from 'jquery';
import {AppId, ContextId, Currency} from './steam_constants';
import {AppId, ContextId} from './steam_constants';

type ClassId = string;
type InstanceId = string;
Expand Down Expand Up @@ -116,17 +116,24 @@ export interface mOwner {
strSteamId: string;
}

// g_ActiveInventory
// g_ActiveInventory.m_rgChildInventories[contextId]
export interface CInventory {
initialized: boolean;
m_rgAssets: {[assetId: string]: InventoryAsset};
m_parentInventory: CAppwideInventory | null;
rgInventory: {[assetId: string]: rgAsset};
m_owner?: mOwner;
owner?: mOwner;
selectedItem?: InventoryAsset;
appid?: number;
}

// g_ActiveInventory
export interface CAppwideInventory extends CInventory {
m_rgChildInventories: {[contextId in ContextId]: CInventory};
m_rgContextIds: string[];
}

export interface CAjaxPagingControls {
m_bLoading: boolean;
m_cMaxPages: number;
Expand Down Expand Up @@ -231,7 +238,7 @@ declare global {
const g_rgListingInfo: {[listingId: string]: ListingData};
const g_rgWalletInfo: WalletInfo | undefined; // Not populated when user is signed-out
const g_rgAssets: SteamAssets;
const g_ActiveInventory: CInventory | undefined; // Only populated on Steam inventory pages
const g_ActiveInventory: CAppwideInventory | CInventory | undefined; // Only populated on Steam inventory pages
const g_steamID: string;
const g_oSearchResults: CAjaxPagingControls;
const BuyItemDialog: BuyItemDialog | undefined; // Only populated on Steam Market pages
Expand Down
1 change: 1 addition & 0 deletions src/lib/types/steam_constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export enum AppId {

export enum ContextId {
PRIMARY = 2,
PROTECTED = 16,
}

// https://developer.valvesoftware.com/wiki/Steam_Web_API/IEconService
Expand Down
6 changes: 6 additions & 0 deletions src/lib/utils/checkers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import {CInventory, CAppwideInventory} from '../types/steam';

export function defined(t: string): boolean {
return t !== 'undefined';
}

export function isCAppwideInventory(inventory: CInventory | CAppwideInventory): inventory is CAppwideInventory {
return 'm_rgChildInventories' in inventory;
}