Skip to content

Commit

Permalink
hide skinport price if item is not martketable
Browse files Browse the repository at this point in the history
  • Loading branch information
timche committed Feb 29, 2024
1 parent 3c28930 commit 3c484dd
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/content/steamcommunity/bridge/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SteamItem } from "../lib/items";
import { SteamItem } from "../lib/steam";

function createBridgeAction<
RequestData extends Record<string, unknown>,
Expand Down
2 changes: 1 addition & 1 deletion src/content/steamcommunity/bridge/script.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ParsedRgAsset, bridge } from ".";
import { SteamItem, parseSteamItem } from "../lib/items";
import { SteamItem, parseSteamItem } from "../lib/steam";

function parseRgAsset(rgAsset: RgAsset, mSteamId: string) {
const parsedRgAsset: ParsedRgAsset = {
Expand Down
2 changes: 1 addition & 1 deletion src/content/steamcommunity/components/item-info.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { selectSkinportItemPrice } from "@/lib/skinport";
import { useEffect } from "react";
import { SteamItem } from "../lib/items";
import { SteamItem } from "../lib/steam";
import {
ItemSkinportPrice,
ItemSkinportPriceProps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { formatPrice } from "@/lib/format";
import { I18nMessageKey, getI18nMessage } from "@/lib/i18n";
import { getSkinportItemUrl } from "@/lib/skinport";
import { SteamItem } from "../lib/items";
import { SteamItem } from "../lib/steam";

export interface ItemSkinportPriceProps {
item: SteamItem;
Expand All @@ -31,6 +31,10 @@ export function ItemSkinportPrice({
currency,
tooltipType,
}: ItemSkinportPriceProps) {
if (!item.isMarketable) {
return;
}

if (price === undefined || !currency) {
return <Skeleton className="w-8 h-3 my-0.5" />;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ featureManager.add(
selectedItem.inspectIngameLink,
);

if (!parsedSelectedItem) {
if (!parsedSelectedItem || !parsedSelectedItem.isMarketable) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { create } from "zustand";
import { bridge } from "../bridge";
import { ItemInfo } from "../components/item-info";
import { PricingBySkinportPlus } from "../components/pricing-by-skinport-plus";
import { SteamItem } from "../lib/items";
import { SteamItem } from "../lib/steam";

const tradeOfferItemsInfo: Feature = async ({
setFeatureAttribute,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async function getAllTradeOfferItems(tradeOfferItemElements: HTMLElement[]) {

for (const [tradeOfferItemElement, itemInfoRequest] of itemInfoRequests) {
const itemInfoMatches = (await itemInfoRequest).match(
/"market_hash_name\":"([^"]+)".*"appid":"(\d+)"/,
/"market_hash_name":"([^"]+)".*"marketable":(0|1).*"appid":"(\d+)"/,
);

if (!itemInfoMatches) {
Expand All @@ -65,10 +65,11 @@ async function getAllTradeOfferItems(tradeOfferItemElements: HTMLElement[]) {

const item = parseSteamItem(
JSON.parse(`"${itemInfoMatches[1]}"`),
itemInfoMatches[2],
itemInfoMatches[3],
itemInfoMatches[2] === "1",
);

if (!item) {
if (!item || !item.isMarketable) {
continue;
}

Expand Down
5 changes: 0 additions & 5 deletions src/content/steamcommunity/lib/app-ids.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
export type SteamAppId =
| 730 // cs2
| 440 // tf2
| 570 // dota2
| 252490; // rust

export interface SteamItem {
appId: number;
assetId: string | null;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/steam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export type Item = {
export function parseSteamItem(
name: string,
appId: string,
isMarketable?: boolean,
isMarketable: boolean,
inspectIngameLink?: string,
) {
if (Object.hasOwn(steamAppIdNames, appId)) {
Expand Down

0 comments on commit 3c484dd

Please sign in to comment.