Skip to content
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

Release/3.6.3 #406

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat(com): reconnect closed apis when tab made visible again (& ios pwa)
  • Loading branch information
Tucsky committed Nov 28, 2024
commit 90a96f9259274fb9e44356226834818eb0960057
2 changes: 1 addition & 1 deletion src/components/framework/Btn.vue
Original file line number Diff line number Diff line change
@@ -63,7 +63,7 @@ export default class Btn extends Vue {
<style lang="scss" scoped>
.btn {
&__loader {
margin-right: 0.25rem;
margin-right: 0.5rem;
width: 0.5em;
height: 0.5em;

48 changes: 35 additions & 13 deletions src/components/settings/SettingsDialog.vue
Original file line number Diff line number Diff line change
@@ -91,14 +91,16 @@
<i class="icon-upload"></i>
<span>Upload template file</span>
</button>
<button
<Btn
type="button"
class="dropdown-item"
@click="createBlankWorkspace"
class="dropdown-item -cases"
:loading="fetchingWords"
@click.stop="createBlankWorkspace"
@mousedown.prevent
>
<i class="icon-plus"></i>
<span>Create blank template</span>
</button>
</Btn>
</dropdown>
</div>
<table v-if="workspaces.length" class="table mt8 table--inset">
@@ -400,7 +402,7 @@ import AudioSettings from './AudioSettings.vue'
import OtherSettings from './OtherSettings.vue'
import ColorPickerControl from '../framework/picker/ColorPickerControl.vue'
import ToggableSection from '@/components/framework/ToggableSection.vue'

import Btn from '@/components/framework/Btn.vue'
import importService from '@/services/importService'
import workspacesService from '@/services/workspacesService'

@@ -409,6 +411,7 @@ import DialogMixin from '@/mixins/dialogMixin'
export default {
mixins: [DialogMixin],
components: {
Btn,
// eslint-disable-next-line vue/no-reserved-component-names
Dialog,
Exchange,
@@ -423,7 +426,8 @@ export default {
currentWorkspace: null,
workspaces: [],
workspaceDropdownId: null,
workspaceDropdownTrigger: null
workspaceDropdownTrigger: null,
fetchingWords: false
}
},
computed: {
@@ -563,14 +567,32 @@ export default {
},

async createBlankWorkspace() {
const randomName = await fetch(
'https://random-word-api.herokuapp.com/word?number=2'
)
.then(response => response.json())
.catch(() => [])
.then(words =>
words.map(word => word[0].toUpperCase() + word.slice(1)).join('')
const fetchWithTimeout = async (url, options, timeout = 5000) => {
return Promise.race([
fetch(url, options),
new Promise((_, reject) =>
setTimeout(() => reject(new Error('Request timed out')), timeout)
)
])
}

let randomName = 'Untitled'
try {
this.fetchingWords = true
const response = await fetchWithTimeout(
'https://random-word-api.herokuapp.com/word?number=2',
undefined,
3000 // Set timeout to 3 seconds
)
const words = await response.json()
randomName = words
.map(word => word[0].toUpperCase() + word.slice(1))
.join('')
} catch (error) {
console.error('Failed to fetch random name:', error)
} finally {
this.fetchingWords = false
}

const name = await dialogService.prompt({
label: 'Name',
8 changes: 4 additions & 4 deletions src/components/trades/TradesPlaceholder.vue
Original file line number Diff line number Diff line change
@@ -96,13 +96,13 @@ export default class TradesPlaceholder extends Vue {
const minimumLiquidationAmount = this.liquidationsThresholds[0].amount

if (this.showTrades && this.showLiquidations) {
return `Waiting for trades > ${formatAmount(
return `Waiting for trades > ${formatAmount(
minimumTradeAmount
)} or liquidations > ${formatAmount(minimumLiquidationAmount)}`
)} or liquidations > ${formatAmount(minimumLiquidationAmount)}`
} else if (this.showTrades) {
return `Waiting for trades > ${formatAmount(minimumTradeAmount)}`
return `Waiting for trades > ${formatAmount(minimumTradeAmount)}`
} else if (this.showLiquidations) {
return `Waiting for liquidations > ${formatAmount(
return `Waiting for liquidations > ${formatAmount(
minimumLiquidationAmount
)}`
} else {
10 changes: 10 additions & 0 deletions src/services/aggregatorService.ts
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@ class AggregatorService extends EventEmitter {
})

this.listenUtilityEvents()
this.listenVisibilityChange()
}

listenUtilityEvents() {
@@ -263,6 +264,15 @@ class AggregatorService extends EventEmitter {

this.normalizeDecimalsQueue = null
}

listenVisibilityChange() {
document.addEventListener('visibilitychange', () => {
if (document.visibilityState === 'visible') {
console.log('made visible')
this.worker.postMessage({ op: 'clearReconnectionTimeout' })
}
})
}
}

export default new AggregatorService()
6 changes: 3 additions & 3 deletions src/services/productsService.ts
Original file line number Diff line number Diff line change
@@ -619,11 +619,11 @@ export function formatAmount(amount, decimals?: number) {

if (amount >= 1000000000) {
amount =
+(amount / 1000000000).toFixed(isNaN(decimals) ? 1 : decimals) + 'B'
+(amount / 1000000000).toFixed(isNaN(decimals) ? 1 : decimals) + ' B'
} else if (amount >= 1000000) {
amount = +(amount / 1000000).toFixed(isNaN(decimals) ? 1 : decimals) + 'M'
amount = +(amount / 1000000).toFixed(isNaN(decimals) ? 1 : decimals) + ' M'
} else if (amount >= 1000) {
amount = +(amount / 1000).toFixed(isNaN(decimals) ? 1 : decimals) + 'K'
amount = +(amount / 1000).toFixed(isNaN(decimals) ? 1 : decimals) + ' K'
} else {
amount = +amount.toFixed(isNaN(decimals) ? 2 : decimals)
}
10 changes: 8 additions & 2 deletions src/worker/aggregator.ts
Original file line number Diff line number Diff line change
@@ -760,11 +760,11 @@ class Aggregator {

startAggrInterval() {
if (this['_aggrInterval']) {
return
this.clearInterval('aggr')
}
this['_aggrInterval'] = self.setInterval(
this.emitPendingTrades.bind(this),
50
Math.max(settings.aggregationLength, 50)
)
}

@@ -878,6 +878,12 @@ class Aggregator {
data: this.tickers
})
}

clearReconnectionTimeout() {
for (const exchange of exchanges) {
exchange.reconnectAllClosedApis()
}
}
}

export default Aggregator
Loading