-
Notifications
You must be signed in to change notification settings - Fork 37
Display Trade Reversal Status on Steam Profile #371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
02ef4a9
fetch reversal status and inject html
hayesZach cc65167
Merge branch 'master' into feature/reversal-status
hayesZach 0f1fa25
fix reversal status enum value
hayesZach 9e7cc24
use different port
hayesZach a770bdb
remove rw host permissions
hayesZach 7957807
update injected html
hayesZach fb80b52
get steam id from page context
hayesZach 9b7548e
format
hayesZach d7ff9ba
powered by
hayesZach 190c7d6
address more comments
hayesZach ba51d45
address more comments...
hayesZach cb9735f
format
hayesZach b648a7a
dont throw
hayesZach 07752e4
use TTLCachedQueue
hayesZach b93001c
Merge branch 'master' into feature/reversal-status
hayesZach da5c31f
Merge branch 'master' into feature/reversal-status
Step7750 a14da53
address comments
hayesZach b9263df
format
hayesZach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import {RequestType} from './types'; | ||
| import {SimpleHandler} from './main'; | ||
| import {environment} from '../../../environment'; | ||
|
|
||
| export interface FetchReversalStatusRequest { | ||
| steam_id64: string; | ||
| } | ||
|
|
||
| export interface FetchReversalStatusResponse { | ||
| steam_id: string; | ||
| has_reversed: boolean; | ||
| last_reversal_timestamp?: number; | ||
| } | ||
|
|
||
| export interface FetchReversalStatusError { | ||
| code: string; | ||
| message: string; | ||
| details?: string; | ||
| } | ||
|
|
||
| export const FetchReversalStatus = new SimpleHandler<FetchReversalStatusRequest, FetchReversalStatusResponse>( | ||
| RequestType.FETCH_REVERSAL_STATUS, | ||
| async (req) => { | ||
| const resp = await fetch(`${environment.reverse_watch_base_api_url}/v1/users/${req.steam_id64}`); | ||
| const data = (await resp.json()) as FetchReversalStatusResponse | FetchReversalStatusError; | ||
| if (!resp.ok) { | ||
| throw Error((data as FetchReversalStatusError).message ?? 'unknown error'); | ||
| } | ||
| return data as FetchReversalStatusResponse; | ||
| } | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| import {CustomElement, InjectAfter, InjectionMode} from '../injectors'; | ||
| import {FloatElement} from '../custom'; | ||
| import {css, html} from 'lit'; | ||
| import {state} from 'lit/decorators.js'; | ||
| import {FetchReversalStatusResponse} from '../../bridge/handlers/fetch_reversal_status'; | ||
| import {gReversalFetcher} from '../../services/reversal_fetcher'; | ||
| import {defined} from '../../utils/checkers'; | ||
|
|
||
| @CustomElement() | ||
| @InjectAfter( | ||
| '.profile_in_game.persona + .profile_ban_status, .profile_in_game.persona:not(:has(+ .profile_ban_status))', | ||
| InjectionMode.ONCE | ||
| ) | ||
| export class ReversalStatus extends FloatElement { | ||
| @state() | ||
| reversalStatus: FetchReversalStatusResponse | undefined = undefined; | ||
|
|
||
| static styles = [ | ||
| ...FloatElement.styles, | ||
| css` | ||
| .container { | ||
| display: flex; | ||
| align-items: center; | ||
| gap: 6px; | ||
| color: #de6667; | ||
| margin-bottom: 10px; | ||
|
|
||
| .warning { | ||
| display: inline; | ||
|
|
||
| .info-link-container { | ||
| color: #828282; | ||
|
|
||
| .info-link { | ||
| text-decoration: none; | ||
| color: #ebebeb; | ||
|
|
||
| &:hover { | ||
| color: #66c0f4; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| .powered-by-container { | ||
| font-size: 12px; | ||
| color: #828282; | ||
|
|
||
| .powered-by-link { | ||
| text-decoration: none; | ||
| color: #ebebeb; | ||
hayesZach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| &:hover { | ||
| color: #66c0f4; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| `, | ||
| ]; | ||
|
|
||
| get show(): boolean { | ||
| return !!this.reversalStatus?.has_reversed; | ||
| } | ||
hayesZach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| get daysSinceLastReversal(): number | null { | ||
| if (!this.reversalStatus?.last_reversal_timestamp) { | ||
| return null; | ||
| } | ||
|
|
||
| const now = Date.now(); | ||
| const timeSince = now - this.reversalStatus.last_reversal_timestamp; | ||
| return Math.floor(timeSince / (24 * 60 * 60 * 1000)); | ||
hayesZach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| getSteamId(): string | undefined { | ||
| if (defined(typeof g_rgProfileData) && g_rgProfileData) { | ||
| return g_rgProfileData.steamid; | ||
| } | ||
|
|
||
| const match = window.location.pathname.match(/^\/profiles\/(\d+)/); | ||
| if (match) { | ||
| return match[1]; | ||
| } | ||
| } | ||
|
|
||
| async connectedCallback() { | ||
| super.connectedCallback(); | ||
|
|
||
| try { | ||
| const steamId = this.getSteamId(); | ||
| if (!steamId) { | ||
| console.error('failed to get steam id'); | ||
| return; | ||
| } | ||
|
|
||
| this.reversalStatus = await gReversalFetcher.fetch({steam_id64: steamId}); | ||
| } catch (e) { | ||
| console.error('failed to fetch reversal status', e); | ||
| } | ||
| } | ||
|
|
||
| protected render() { | ||
| if (!this.show) { | ||
| return html``; | ||
| } | ||
|
|
||
| const daysSince = this.daysSinceLastReversal ?? 0; | ||
| const message = `${daysSince} day(s) since last trade reversal`; | ||
| return html` | ||
| <div class="container"> | ||
hayesZach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <div class="warning"> | ||
| ${message} | ||
| <span class="info-link-container"> | ||
| | | ||
| <a | ||
| class="info-link" | ||
| href="https://help.steampowered.com/en/faqs/view/365F-4BEE-2AE2-7BDD" | ||
| target="_blank" | ||
| rel="noreferrer" | ||
| > | ||
| Info | ||
| </a> | ||
| </span> | ||
| <span class="powered-by-container" | ||
| >(powered by <a class="powered-by-link" href="https://reverse.watch">reverse.watch</a>)</span | ||
| > | ||
| </div> | ||
| </div> | ||
| `; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import {ClientSend} from '../bridge/client'; | ||
| import { | ||
| FetchReversalStatus, | ||
| FetchReversalStatusRequest, | ||
| FetchReversalStatusResponse, | ||
| } from '../bridge/handlers/fetch_reversal_status'; | ||
| import {GenericJob, TTLCachedQueue} from '../utils/queue'; | ||
|
|
||
| class ReversalFetcher extends TTLCachedQueue<FetchReversalStatusRequest, FetchReversalStatusResponse> { | ||
| constructor(maxConcurrency: number, ttlMs: number) { | ||
| super(maxConcurrency, ttlMs); | ||
| } | ||
|
|
||
| fetch(req: FetchReversalStatusRequest): Promise<FetchReversalStatusResponse> { | ||
| return this.add(new GenericJob(req)); | ||
| } | ||
|
|
||
| protected async process(req: FetchReversalStatusRequest): Promise<FetchReversalStatusResponse> { | ||
| try { | ||
| return await ClientSend(FetchReversalStatus, req); | ||
| } catch (e) { | ||
| console.error('failed to fetch reversal status', e); | ||
| // Stub out to prevent future calls | ||
| return { | ||
| steam_id: '', | ||
| has_reversed: false, | ||
| last_reversal_timestamp: undefined, | ||
| } as FetchReversalStatusResponse; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export const gReversalFetcher = new ReversalFetcher(1, 30 * 60 * 1000 /* 30 minutes */); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.