Skip to content

Commit 968529b

Browse files
committed
fix: backwards compatibility
1 parent 6d6c7a2 commit 968529b

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/lib/components/inventory/inventory_item_holder_metadata.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {CustomElement, InjectAppend, InjectionMode} from '../injectors';
22
import {rgAsset} from '../../types/steam';
33
import {ItemHolderMetadata} from '../common/item_holder_metadata';
44
import {ContextId} from '../../types/steam_constants';
5+
import { isCAppwideInventory } from '../../utils/checkers';
56

67
@CustomElement()
78
@InjectAppend(
@@ -12,9 +13,15 @@ export class InventoryItemHolderMetadata extends ItemHolderMetadata {
1213
get asset(): rgAsset | undefined {
1314
if (!this.assetId) return;
1415

15-
const contextId = this.isTradeProtected ? ContextId.PROTECTED : ContextId.PRIMARY;
16+
if (!g_ActiveInventory) return;
1617

17-
return g_ActiveInventory?.m_rgChildInventories[contextId]?.m_rgAssets[this.assetId]?.description;
18+
if (isCAppwideInventory(g_ActiveInventory)) {
19+
const contextId = this.isTradeProtected ? ContextId.PROTECTED : ContextId.PRIMARY;
20+
21+
return g_ActiveInventory.m_rgChildInventories[contextId]?.m_rgAssets[this.assetId]?.description;
22+
} else {
23+
return g_ActiveInventory.m_rgAssets[this.assetId]?.description;
24+
}
1825
}
1926

2027
get ownerSteamId(): string | undefined {

src/lib/types/steam.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ declare global {
238238
const g_rgListingInfo: {[listingId: string]: ListingData};
239239
const g_rgWalletInfo: WalletInfo | undefined; // Not populated when user is signed-out
240240
const g_rgAssets: SteamAssets;
241-
const g_ActiveInventory: CAppwideInventory | undefined; // Only populated on Steam inventory pages
241+
const g_ActiveInventory: CAppwideInventory | CInventory | undefined; // Only populated on Steam inventory pages
242242
const g_steamID: string;
243243
const g_oSearchResults: CAjaxPagingControls;
244244
const BuyItemDialog: BuyItemDialog | undefined; // Only populated on Steam Market pages

src/lib/utils/checkers.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
import { CInventory, CAppwideInventory } from '../types/steam';
2+
13
export function defined(t: string): boolean {
24
return t !== 'undefined';
35
}
6+
7+
export function isCAppwideInventory(inventory: CInventory | CAppwideInventory): inventory is CAppwideInventory {
8+
return 'm_rgChildInventories' in inventory;
9+
}

0 commit comments

Comments
 (0)