1
1
import { FloatElement } from '../custom' ;
2
2
import { CustomElement , InjectAfter , InjectionMode } from '../injectors' ;
3
- import { html , css , TemplateResult , HTMLTemplateResult , nothing } from 'lit' ;
3
+ import { html , css , TemplateResult , HTMLTemplateResult } from 'lit' ;
4
4
import { state } from 'lit/decorators.js' ;
5
5
import { InventoryAsset } from '../../types/steam' ;
6
6
import { gFloatFetcher } from '../../services/float_fetcher' ;
7
7
import { ItemInfo } from '../../bridge/handlers/fetch_inspect_info' ;
8
- import { formatSeed , getFadePercentage , isSkin , renderClickableRank , floor , isCharm } from '../../utils/skin' ;
8
+ import {
9
+ formatSeed ,
10
+ getFadePercentage ,
11
+ isSkin ,
12
+ renderClickableRank ,
13
+ floor ,
14
+ isCharm ,
15
+ isSellableOnCSFloat ,
16
+ } from '../../utils/skin' ;
9
17
import { Observe } from '../../utils/observers' ;
10
18
import { FetchStallResponse } from '../../bridge/handlers/fetch_stall' ;
11
19
import { gStallFetcher } from '../../services/stall_fetcher' ;
@@ -86,33 +94,40 @@ export class SelectedItemInfo extends FloatElement {
86
94
return html `< div > Loading...</ div > ` ;
87
95
}
88
96
89
- if ( ! this . itemInfo || ! this . asset ?. description ) {
97
+ if ( ! this . asset ?. description ) {
90
98
return html `` ;
91
99
}
92
100
93
- if ( isSkin ( this . asset . description ) ) {
94
- const fadePercentage = this . asset && getFadePercentage ( this . asset . description , this . itemInfo ) ;
95
-
96
- return html `
97
- < div class ="container ">
98
- < div > Float: ${ this . itemInfo . floatvalue . toFixed ( 14 ) } ${ renderClickableRank ( this . itemInfo ) } </ div >
99
- < div > Paint Seed: ${ formatSeed ( this . itemInfo ) } </ div >
100
- ${ fadePercentage !== undefined ? html `< div > Fade: ${ floor ( fadePercentage , 5 ) } %</ div > ` : nothing }
101
- ${ this . renderListOnCSFloat ( ) } ${ this . renderFloatMarketListing ( ) }
102
- </ div >
103
- ` ;
104
- } else if ( isCharm ( this . asset . description ) ) {
105
- return html `
106
- < div class ="container ">
107
- < div >
108
- Pattern:
109
- #${ this . itemInfo . keychains ?. length > 0 ? this . itemInfo . keychains [ 0 ] . pattern : 'Unknown' }
110
- </ div >
111
- </ div >
112
- ` ;
113
- } else {
101
+ const containerChildren : TemplateResult [ ] = [ ] ;
102
+
103
+ if ( isSkin ( this . asset . description ) && this . itemInfo ) {
104
+ containerChildren . push (
105
+ html `< div > Float: ${ this . itemInfo . floatvalue . toFixed ( 14 ) } ${ renderClickableRank ( this . itemInfo ) } </ div > `
106
+ ) ;
107
+
108
+ containerChildren . push ( html `< div > Paint Seed: ${ formatSeed ( this . itemInfo ) } </ div > ` ) ;
109
+
110
+ const fadePercentage = getFadePercentage ( this . asset . description , this . itemInfo ) ;
111
+ if ( fadePercentage !== undefined ) {
112
+ containerChildren . push ( html `< div > Fade: ${ floor ( fadePercentage , 5 ) } %</ div > ` ) ;
113
+ }
114
+ } else if ( isCharm ( this . asset . description ) && this . itemInfo ) {
115
+ containerChildren . push (
116
+ html `< div >
117
+ Pattern: #${ this . itemInfo . keychains ?. length > 0 ? this . itemInfo . keychains [ 0 ] . pattern : 'Unknown' }
118
+ </ div > `
119
+ ) ;
120
+ }
121
+
122
+ if ( isSellableOnCSFloat ( this . asset . description ) ) {
123
+ containerChildren . push ( html `${ this . renderListOnCSFloat ( ) } ${ this . renderFloatMarketListing ( ) } ` ) ;
124
+ }
125
+
126
+ if ( containerChildren . length === 0 ) {
114
127
return html `` ;
115
128
}
129
+
130
+ return html ` < div class ="container "> ${ containerChildren } </ div > ` ;
116
131
}
117
132
118
133
renderFloatMarketListing ( ) : TemplateResult < 1 > {
@@ -146,7 +161,7 @@ export class SelectedItemInfo extends FloatElement {
146
161
147
162
return html `
148
163
< div class ="market-btn-container ">
149
- < a class ="market-btn " href ="https://csfloat.com " target ="_blank ">
164
+ < a class ="market-btn " href ="https://csfloat.com/sell " target ="_blank ">
150
165
< span > List on </ span >
151
166
< img src ="https://csfloat.com/assets/n_full_logo.png " height ="21 " style ="margin-left: 5px; " />
152
167
</ a >
@@ -160,21 +175,19 @@ export class SelectedItemInfo extends FloatElement {
160
175
161
176
if ( ! this . asset ) return ;
162
177
163
- if ( ! isSkin ( this . asset . description ) && ! isCharm ( this . asset . description ) ) return ;
178
+ // Guarantees a re-render for items without inspect links
179
+ this . loading = true ;
164
180
165
- // Commodities won't have inspect links
166
- if ( ! this . inspectLink ) return ;
167
-
168
- try {
169
- this . loading = true ;
170
- this . itemInfo = await gFloatFetcher . fetch ( {
171
- link : this . inspectLink ,
172
- } ) ;
173
- } catch ( e : any ) {
174
- console . error ( `Failed to fetch float for ${ this . asset . assetid } : ${ e . toString ( ) } ` ) ;
175
- } finally {
176
- this . loading = false ;
181
+ if ( this . inspectLink && ( isSkin ( this . asset . description ) || isCharm ( this . asset . description ) ) ) {
182
+ try {
183
+ this . itemInfo = await gFloatFetcher . fetch ( {
184
+ link : this . inspectLink ,
185
+ } ) ;
186
+ } catch ( e : any ) {
187
+ console . error ( `Failed to fetch float for ${ this . asset . assetid } : ${ e . toString ( ) } ` ) ;
188
+ }
177
189
}
190
+ this . loading = false ;
178
191
}
179
192
180
193
connectedCallback ( ) {
0 commit comments