Skip to content

Commit

Permalink
Updates pending trades endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Step7750 committed Apr 10, 2024
1 parent 5843a57 commit 8fda8ef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 27 deletions.
32 changes: 9 additions & 23 deletions src/lib/bridge/handlers/fetch_pending_trades.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,21 @@ import {RequestType} from './types';
export interface FetchPendingTradesRequest {}

export interface FetchPendingTradesResponse {
trades_to_send: Trade[];
trades_to_receive: Trade[];
count: number;
trades: Trade[];
}

export const FetchPendingTrades = new SimpleHandler<FetchPendingTradesRequest, FetchPendingTradesResponse>(
RequestType.FETCH_PENDING_TRADES,
async (req) => {
try {
const resp = await fetch(`https://csfloat.com/api/v1/me/pending-trades`, {
credentials: 'include',
});
const resp = await fetch(`https://csfloat.com/api/v1/me/trades?state=pending&limit=100&page=0`, {
credentials: 'include',
});

if (resp.status !== 200) {
throw new Error('invalid status');
}

return resp.json() as Promise<FetchPendingTradesResponse>;
} catch (e) {
// Try the old CSGOFloat URL (in case they have an old session from there)
// Of note, this can be removed ~1 week after the migration.
const resp = await fetch(`https://csgofloat.com/api/v1/me/pending-trades`, {
credentials: 'include',
});

if (resp.status !== 200) {
throw new Error('invalid status');
}

return resp.json();
if (resp.status !== 200) {
throw new Error('invalid status');
}

return resp.json() as Promise<FetchPendingTradesResponse>;
}
);
6 changes: 2 additions & 4 deletions src/lib/components/trade_offer/auto_fill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export class AutoFill extends FloatElement {
}

const hasItemWithNoSale = g_rgCurrentTradeStatus.me.assets.find(
(a) => !this.pendingTradesResponse?.trades_to_send.find((b) => b.contract.item.asset_id === a.assetid)
(a) => !this.pendingTradesResponse?.trades.find((b) => b.contract.item.asset_id === a.assetid)
);

if (!hasItemWithNoSale) {
Expand Down Expand Up @@ -192,9 +192,7 @@ export class AutoFill extends FloatElement {
protected render(): HTMLTemplateResult {
if (!this.pendingTradesResponse) return html``;

const tradesToBuyer = this.pendingTradesResponse.trades_to_send.filter(
(e) => e.buyer_id === UserThem?.strSteamId
);
const tradesToBuyer = this.pendingTradesResponse.trades.filter((e) => e.buyer_id === UserThem?.strSteamId);

return html`
${this.renderBulkAutoFillDialog(tradesToBuyer)} ${tradesToBuyer.map((e) => this.renderAutoFillDialog(e))}
Expand Down

0 comments on commit 8fda8ef

Please sign in to comment.