Skip to content

Commit dd3f93c

Browse files
committed
fix(quality): resolve mobile v6 Sonar findings
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
1 parent 6f5a81d commit dd3f93c

7 files changed

Lines changed: 20 additions & 18 deletions

File tree

‎.sonarcloud.properties‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sonar.cpd.exclusions=src/locales/**

‎src/components/ChartTradePanel.vue‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ export default {
374374
},
375375
scheduleTradeRefresh() {
376376
if(this.scheduledRefreshTimer)clearTimeout(this.scheduledRefreshTimer)
377-
this.scheduledRefreshTimer=setTimeout(()=>{this.scheduledRefreshTimer=null;if(document.hidden)return;this.refreshTradeData();this.restartOrderBookFeed()},0)
377+
this.scheduledRefreshTimer=setTimeout(()=>{this.scheduledRefreshTimer=null;if(document.hidden)return;void this.refreshTradeData();this.restartOrderBookFeed()},0)
378378
},
379379
stableDataSignature(value) {
380380
try{return JSON.stringify(value??null)}catch{return String(value)}
@@ -589,8 +589,8 @@ export default {
589589
startRestOrderBookFallback() {
590590
if(!this.selectedCredential||!this.isCrypto)return
591591
this.orderBookUsingRestFallback=true
592-
this.refreshOrderBook()
593-
if(!this.orderBookTimer)this.orderBookTimer=window.setInterval(()=>{if(!document.hidden&&!this.submitting)this.refreshOrderBook()},2000)
592+
void this.refreshOrderBook()
593+
if(!this.orderBookTimer)this.orderBookTimer=window.setInterval(()=>{if(!document.hidden&&!this.submitting)void this.refreshOrderBook()},2000)
594594
},
595595
restartOrderBookFeed() {
596596
if(this.orderBookStream)this.orderBookStream.disconnect()
@@ -609,7 +609,7 @@ export default {
609609
this.orderBookStreamStatus='connecting'
610610
this.orderBookUsingRestFallback=false
611611
if(!this.selectedCredential||!this.isCrypto||!exchangeId)return
612-
this.refreshOrderBook()
612+
void this.refreshOrderBook()
613613
this.connectOrderBookStream()
614614
},
615615
async confirmOrder(side) {
@@ -779,7 +779,7 @@ export default {
779779
startPolling() {
780780
this.stopPolling()
781781
this.restartOrderBookFeed()
782-
this.pollTimer=window.setInterval(()=>{if(!document.hidden&&!this.submitting)this.refreshTradeData()},30000)
782+
this.pollTimer=window.setInterval(()=>{if(!document.hidden&&!this.submitting)void this.refreshTradeData()},30000)
783783
},
784784
stopPolling() {
785785
if(this.pollTimer)window.clearInterval(this.pollTimer)

‎src/components/StockTradePanel.vue‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export default {
9595
credentialActions() { return this.credentials.map(item => ({ text: this.accountLabel(item), value: item.id, exchange: item.exchange_id })) },
9696
currency() { return String(this.account?.currency || brokerCurrency(this.selectedCredential?.exchange_id, this.market)).toUpperCase() },
9797
visibleRows() { return this.tab === 'positions' ? this.positions : this.orders },
98-
canSubmit() { return Boolean(this.selectedCredential && this.displaySymbol !== '—' && Number(this.form.quantity) > 0 && (this.form.orderType !== 'limit' || Number(this.form.price) > 0) && !this.busy) }
98+
canSubmit() { return Boolean(this.selectedCredential && String(this.symbol || '').trim() && Number(this.form.quantity) > 0 && (this.form.orderType !== 'limit' || Number(this.form.price) > 0) && !this.busy) }
9999
},
100100
watch: {
101101
credentials: { immediate: true, handler(items) { if (!this.selectedCredentialId && items.length) this.selectedCredentialId = items[0].id } },

‎src/views/indicator/Chart.vue‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ async function warmBaseChart(){
128128
}
129129
async function loadChart(silent=false){
130130
const nextContext=chartContextSignature()
131-
if(displayedChartContext.value!==snapshotContext())warmBaseChart()
131+
if(displayedChartContext.value!==snapshotContext())void warmBaseChart()
132132
if(chartRefreshing.value){
133133
if(silent&&nextContext===activeChartRequestContext)return
134134
queuedChartLoadSilent=queuedChartLoad?queuedChartLoadSilent&&silent:silent
@@ -159,7 +159,7 @@ async function selectIndicator(item){
159159
function selectSymbol(item){form.market=item.market||'Crypto';form.symbol=item.symbol;if(form.market.toLowerCase()==='crypto'){form.exchangeId=item.exchange_id||form.exchangeId;form.marketType=item.market_type||form.marketType;selectedProduct.value={symbol:form.symbol,exchange_id:form.exchangeId,market_type:form.marketType,instrument_id:item.instrument_id||'',settle_currency:item.settle_currency||'',product_type:item.product_type||'',api_family:item.api_family||'',underlying_market:item.underlying_market||'',underlying_symbol:item.underlying_symbol||'',product_meta:item.product_meta||null}}else selectedProduct.value=null;loadChart()}
160160
function onTradeContextChange(context){if(!context.exchangeId)return;if(context.exchangeId===form.exchangeId&&context.marketType===form.marketType)return;form.exchangeId=context.exchangeId;form.marketType=context.marketType;loadChart()}
161161
function openAi(){router.push({path:'/ai',query:{symbol:form.symbol,market:form.market,timeframe:form.timeframe}})}
162-
async function bootstrap(){warmBaseChart();try{const loaded=await indicatorApi.getList();indicators.value=loaded.data||[];const id=Number(route.query.indicator_id||route.query.local_copy_id||0);const preferred=indicators.value.find(x=>Number(x.id)===id)||indicators.value[0];if(preferred)await selectIndicator({indicatorId:Number(preferred.id)});else await loadChart()}catch(e){if(!chartData.value?.candles?.length){error.value=e?.localizedMessage||e?.message||t('audit.loadFailed');await warmBaseChart()}}}
162+
async function bootstrap(){void warmBaseChart();try{const loaded=await indicatorApi.getList();indicators.value=loaded.data||[];const id=Number(route.query.indicator_id||route.query.local_copy_id||0);const preferred=indicators.value.find(x=>Number(x.id)===id)||indicators.value[0];if(preferred)await selectIndicator({indicatorId:Number(preferred.id)});else await loadChart()}catch(e){if(!chartData.value?.candles?.length){error.value=e?.localizedMessage||e?.message||t('audit.loadFailed');await warmBaseChart()}}}
163163
function stopStream(){streamGeneration++;stream?.disconnect();stream=null;lastTick=0;pendingBar=null}
164164
function startStream(){
165165
stopStream()
@@ -177,15 +177,15 @@ function startStream(){
177177
if(result==='ignored')return
178178
lastTick=Date.now();updated.value=lastTick
179179
marketChart.value?.updateBar(bar)
180-
if(bar.isClosed)loadChart(true)
180+
if(bar.isClosed)void loadChart(true)
181181
},
182182
onError(){if(generation===streamGeneration){lastTick=0;requestRecovery()}},
183183
onReconnecting(){if(generation===streamGeneration)lastTick=0},
184184
onReconnected(){if(generation===streamGeneration)requestRecovery()}
185185
},form.exchangeId,{marketType:form.marketType,instrumentId:selectedInstrumentId.value})
186186
if(!connecting)stream=null
187187
}
188-
function requestRecovery(){const now=Date.now();if(now-lastRecovery<5000)return;lastRecovery=now;loadChart(true)}
188+
function requestRecovery(){const now=Date.now();if(now-lastRecovery<5000)return;lastRecovery=now;void loadChart(true)}
189189
function resizeChartAfterActivation(){nextTick(()=>{marketChart.value?.resize();requestAnimationFrame(()=>marketChart.value?.resize());clearTimeout(layoutTimer);layoutTimer=setTimeout(()=>marketChart.value?.resize(),180)})}
190190
function stop(){pageActive=false;clearInterval(timer);timer=null;clearTimeout(layoutTimer);layoutTimer=null;stopStream();queuedChartLoad=false;queuedChartLoadSilent=true;request++;warmRequest++;loading.value=false;chartRefreshing.value=false}
191191
function start(){

‎src/views/trading/CreateStrategy.vue‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -593,9 +593,10 @@ export default {
593593
credentials() {
594594
return this.credentialsStore.items.filter(item => {
595595
const exchange = String(item.exchange_id || '').toLowerCase()
596-
if (this.marketCategory === 'Crypto') return LIVE_CRYPTO_EXCHANGES.has(exchange)
597-
if (this.marketCategory === 'USStock') return ['alpaca', 'ibkr', 'tiger', 'webull'].includes(exchange)
598-
if (this.marketCategory === 'HKStock') return exchange === 'tiger'
596+
const marketCategory = String(this.marketCategory || '')
597+
if (marketCategory === 'Crypto') return LIVE_CRYPTO_EXCHANGES.has(exchange)
598+
if (marketCategory === 'USStock') return ['alpaca', 'ibkr', 'tiger', 'webull'].includes(exchange)
599+
if (marketCategory === 'HKStock') return exchange === 'tiger'
599600
return false
600601
})
601602
},

‎src/views/v2/StrategyHub.vue‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,10 @@ watch(watchlistPageCount, count => { if (watchlistPage.value > count) watchlistP
197197
function selectPreference(value) { preference.value = value }
198198
function loadData() {
199199
restoreHomeCache()
200-
loadStrategies()
201-
loadPortfolio()
202-
loadWatchlist()
203-
loadGlobalIndices()
200+
void loadStrategies()
201+
void loadPortfolio()
202+
void loadWatchlist()
203+
void loadGlobalIndices()
204204
}
205205
async function loadStrategies() {
206206
loading.value = true

‎tests/unit/indicator-refresh-performance.test.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const stores=readFileSync(new URL('../../src/stores/index.js',import.meta.url),'
1010
test('indicator chart avoids repeated full previews while the stream is healthy',()=>{
1111
assert.doesNotMatch(chartView,/Date\.now\(\)-lastPreview/)
1212
assert.match(chartView,/if\(!healthy\)requestRecovery\(\)/)
13-
assert.match(chartView,/if\(bar\.isClosed\)loadChart\(true\)/)
13+
assert.match(chartView,/if\(bar\.isClosed\)void loadChart\(true\)/)
1414
assert.match(chartView,/silent&&nextContext===activeChartRequestContext/)
1515
})
1616

0 commit comments

Comments
 (0)