Skip to content

Commit

Permalink
Allows Remotely Disabling Auto Tracker Banner
Browse files Browse the repository at this point in the history
  • Loading branch information
Step7750 committed Apr 4, 2024
1 parent df66c75 commit a2db2a0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/lib/bridge/handlers/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {AnnotateOffer} from './annotate_offer';
import {ExtensionVersion} from './extension_version';
import {SendCookies} from './send_cookies';
import {HasPermissions} from './has_permissions';
import {MetaSettings} from './meta_settings';

export const HANDLERS_MAP: {[key in RequestType]: RequestHandler<any, any>} = {
[RequestType.EXECUTE_SCRIPT_ON_PAGE]: ExecuteScriptOnPage,
Expand All @@ -30,4 +31,5 @@ export const HANDLERS_MAP: {[key in RequestType]: RequestHandler<any, any>} = {
[RequestType.EXTENSION_VERSION]: ExtensionVersion,
[RequestType.SEND_COOKIES]: SendCookies,
[RequestType.HAS_PERMISSIONS]: HasPermissions,
[RequestType.META_SETTINGS]: MetaSettings,
};
18 changes: 18 additions & 0 deletions src/lib/bridge/handlers/meta_settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {EmptyRequestHandler} from './main';
import {RequestType} from './types';

export interface MetaSettingsResponse {
enable_auto_trade: boolean;
}

export const MetaSettings = new EmptyRequestHandler<MetaSettingsResponse>(RequestType.META_SETTINGS, async (req) => {
const resp = await fetch(`https://csfloat.com/api/v1/meta/extension`, {
credentials: 'include',
});

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

return resp.json() as Promise<MetaSettingsResponse>;
});
1 change: 1 addition & 0 deletions src/lib/bridge/handlers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export enum RequestType {
EXTENSION_VERSION,
SEND_COOKIES,
HAS_PERMISSIONS,
META_SETTINGS,
}
8 changes: 7 additions & 1 deletion src/lib/components/trade_offers/auto_track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {ClientSend} from '../../bridge/client';
import {state} from 'lit/decorators.js';
import {FetchPendingTrades} from '../../bridge/handlers/fetch_pending_trades';
import {HasPermissions} from '../../bridge/handlers/has_permissions';
import {MetaSettings} from '../../bridge/handlers/meta_settings';

@CustomElement()
@InjectAfter(
Expand Down Expand Up @@ -56,14 +57,19 @@ export class AutoTrackWidget extends FloatElement {
super.connectedCallback();

try {
const meta = await ClientSend(MetaSettings, {});
if (!meta.enable_auto_trade) {
return;
}

await ClientSend(FetchPendingTrades, {});

const hasPermissions = await ClientSend(HasPermissions, {permissions: ['cookies', 'alarms']});
if (!hasPermissions) {
this.show = true;
}
} catch (e) {
console.info('user is not logged into CSFloat');
console.info('user is not logged into CSFloat or something went wrong');
}
}

Expand Down

0 comments on commit a2db2a0

Please sign in to comment.