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: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "betterfloat",
"displayName": "BetterFloat",
"version": "3.4.4",
"packageManager": "pnpm@10.32.1",
"packageManager": "pnpm@10.33.0",
"description": "Enhance your website experience on 15+ CS2 skin markets!",
"author": "Rums",
"license": "CC BY NC SA 4.0",
Expand Down Expand Up @@ -44,6 +44,8 @@
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"common-tags": "^1.8.2",
"dexie": "^4.4.2",
"dexie-react-hooks": "^4.4.0",
"framer-motion": "^11.18.2",
"fuse.js": "^7.1.0",
"jose": "^5.10.0",
Expand Down
22 changes: 22 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/contents/csfloat/cache.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Decimal from 'decimal.js';
import type { CSFloat } from '~lib/@typings/FloatTypes';
import { upsertCSFBargainHistoryOffers } from '~lib/db/csfloatBargainHistory';
import { Queue } from '~lib/util/queue';

type CSFloatAPIStorage = {
Expand Down Expand Up @@ -67,6 +68,7 @@ export function cacheCSFHistoryGraph(data: CSFloat.HistoryGraphData[]) {

export function cacheCSFOffers(data: CSFloat.Offer[]) {
CSFLOAT_API_DATA.offers = data;
void upsertCSFBargainHistoryOffers(data);
}

export function cacheCSFHistorySales(data: CSFloat.HistorySalesData[]) {
Expand Down
26 changes: 23 additions & 3 deletions src/contents/csfloat/events.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CSFloat, EventData } from '~lib/@typings/FloatTypes';
import { adjustOfferBubbles } from '~lib/helpers/csfloat_helpers';
import { upsertCSFBargainHistoryCreateResponse, upsertCSFBargainHistoryOffers } from '~lib/db/csfloatBargainHistory';
import { activateSiteEventHandler } from '~lib/shared/events';
import {
cacheCSFBuyOrders,
Expand All @@ -14,13 +14,27 @@ import {
cacheCSFPopupItem,
cacheCSFSimilarItems,
} from './cache';
import { adjustOfferBubbles } from './modules/offers';

type StallData = {
data: CSFloat.ListingData[];
};

function getPathname(url: string) {
try {
return new URL(url).pathname;
} catch {
return '';
}
}

function isOfferHistoryPath(pathname: string) {
return /^\/api\/v1\/offers\/[^/]+\/history$/.test(pathname);
}

function processCSFloatEvent(eventData: EventData<unknown>) {
console.debug('[BetterFloat] Received data from url: ' + eventData.url + ', data:', eventData.data);
const pathname = getPathname(eventData.url);

if (eventData.url.includes('v1/listings?')) {
cacheCSFItems((eventData.data as CSFloat.ListingsResponse).data);
Expand All @@ -34,8 +48,14 @@ function processCSFloatEvent(eventData: EventData<unknown>) {
cacheCSFItems(eventData.data as CSFloat.ListingData[]);
} else if (eventData.url.includes('v1/me/offers-timeline')) {
cacheCSFOffers((eventData.data as CSFloat.OffersTimeline).offers);
} else if (eventData.url.includes('v1/offers/')) {
adjustOfferBubbles(eventData.data as CSFloat.Offer[]);
} else if (pathname === '/api/v1/offers') {
upsertCSFBargainHistoryCreateResponse(eventData.data);
} else if (isOfferHistoryPath(pathname)) {
const offers = Array.isArray(eventData.data) ? (eventData.data as CSFloat.Offer[]) : [];
if (offers.length > 0) {
adjustOfferBubbles(offers);
upsertCSFBargainHistoryOffers(offers);
}
} else if (eventData.url.includes('v1/users/') && eventData.url.includes('/stall')) {
cacheCSFItems((eventData.data as StallData).data);
} else if (eventData.url.includes('v1/history/')) {
Expand Down
Loading
Loading