Skip to content

Commit b80838d

Browse files
committed
Allows Proving Trade with Token
1 parent a2db2a0 commit b80838d

File tree

4 files changed

+44
-11
lines changed

4 files changed

+44
-11
lines changed

src/lib/bridge/handlers/handlers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {ExtensionVersion} from './extension_version';
1515
import {SendCookies} from './send_cookies';
1616
import {HasPermissions} from './has_permissions';
1717
import {MetaSettings} from './meta_settings';
18+
import {ProveTradesToken} from './prove_trades_token';
1819

1920
export const HANDLERS_MAP: {[key in RequestType]: RequestHandler<any, any>} = {
2021
[RequestType.EXECUTE_SCRIPT_ON_PAGE]: ExecuteScriptOnPage,
@@ -32,4 +33,5 @@ export const HANDLERS_MAP: {[key in RequestType]: RequestHandler<any, any>} = {
3233
[RequestType.SEND_COOKIES]: SendCookies,
3334
[RequestType.HAS_PERMISSIONS]: HasPermissions,
3435
[RequestType.META_SETTINGS]: MetaSettings,
36+
[RequestType.PROVE_TRADES_TOKEN]: ProveTradesToken,
3537
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import {EmptyRequestHandler, SimpleHandler} from './main';
2+
import {RequestType} from './types';
3+
4+
export interface ProveTradesTokenRequest {
5+
token: string;
6+
}
7+
8+
export interface ProveTradesTokenResponse {
9+
message: string;
10+
}
11+
12+
export const ProveTradesToken = new SimpleHandler<ProveTradesTokenRequest, ProveTradesTokenResponse>(
13+
RequestType.PROVE_TRADES_TOKEN,
14+
async (req) => {
15+
const resp = await fetch(`https://csfloat.com/api/v1/trades/prove-token?token=${req.token}`, {
16+
credentials: 'include',
17+
});
18+
19+
if (resp.status !== 200) {
20+
throw new Error('failed to prove, are you logged into CSFloat?');
21+
}
22+
23+
return resp.json() as Promise<ProveTradesTokenResponse>;
24+
}
25+
);

src/lib/bridge/handlers/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ export enum RequestType {
1414
SEND_COOKIES,
1515
HAS_PERMISSIONS,
1616
META_SETTINGS,
17+
PROVE_TRADES_TOKEN,
1718
}

src/lib/components/trade_history/trade_proof.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ import {CustomElement, InjectAppend, InjectionMode} from '../injectors';
55
import {FloatElement} from '../custom';
66
import {fetchListingTime} from './helpers';
77
import '../common/ui/steam-button';
8+
import {ProveTradesToken} from '../../bridge/handlers/prove_trades_token';
9+
import {ClientSend} from '../../bridge/client';
810

911
@CustomElement()
1012
@InjectAppend('.tradehistoryrow .tradehistory_content', InjectionMode.CONTINUOUS)
1113
export class TradeProof extends FloatElement {
1214
@state()
13-
private proofNumber: number | undefined;
15+
private message: string | undefined;
1416

1517
@state()
1618
private isProcessing = false;
@@ -20,12 +22,12 @@ export class TradeProof extends FloatElement {
2022
}
2123

2224
render() {
23-
return this.proofNumber
24-
? html` <span>Proof: ${this.proofNumber}</span> `
25+
return this.message
26+
? html` <span>${this.message}</span> `
2527
: html`
2628
<csfloat-steam-button
2729
@click="${this.onClick}"
28-
.text="${this.isProcessing ? 'Computing Proof...' : 'CSFloat Proof'}"
30+
.text="${this.isProcessing ? 'Proving...' : 'Prove Trade on CSFloat'}"
2931
>
3032
</csfloat-steam-button>
3133
`;
@@ -34,14 +36,17 @@ export class TradeProof extends FloatElement {
3436
private async onClick() {
3537
this.isProcessing = true;
3638

37-
const index = $J('.tradehistoryrow').index($J(this).parent().parent());
39+
const token = document
40+
.getElementById('application_config')
41+
?.getAttribute('data-loyalty_webapi_token')
42+
?.replace('"', '')
43+
.replace('"', '');
44+
3845
try {
39-
this.proofNumber = await fetchListingTime(index);
40-
} catch (e) {
41-
alert(
42-
"Failed to parse time, make sure you're on an english version of the page by appending ?l=english to the url"
43-
);
46+
const resp = await ClientSend(ProveTradesToken, {token});
47+
this.message = resp.message;
48+
} catch (e: any) {
49+
alert(e.toString());
4450
}
45-
this.isProcessing = false;
4651
}
4752
}

0 commit comments

Comments
 (0)