Squash merge market-preload into market
This commit is contained in:
parent
8643eecfe7
commit
35d2eba4ac
5 changed files with 141 additions and 9 deletions
65
src/composables/useMarketPreloader.ts
Normal file
65
src/composables/useMarketPreloader.ts
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
import { ref, readonly } from 'vue'
|
||||
import { useMarket } from './useMarket'
|
||||
import { useMarketStore } from '@/stores/market'
|
||||
import { config } from '@/lib/config'
|
||||
|
||||
export function useMarketPreloader() {
|
||||
const isPreloading = ref(false)
|
||||
const isPreloaded = ref(false)
|
||||
const preloadError = ref<string | null>(null)
|
||||
|
||||
const market = useMarket()
|
||||
const marketStore = useMarketStore()
|
||||
|
||||
const preloadMarket = async () => {
|
||||
// Don't preload if already done or currently preloading
|
||||
if (isPreloaded.value || isPreloading.value) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
isPreloading.value = true
|
||||
preloadError.value = null
|
||||
|
||||
const naddr = config.market.defaultNaddr
|
||||
if (!naddr) {
|
||||
console.log('No market naddr configured, skipping preload')
|
||||
return
|
||||
}
|
||||
|
||||
console.log('Preloading market data...')
|
||||
|
||||
// Connect to market
|
||||
await market.connectToMarket()
|
||||
|
||||
// Load market data
|
||||
await market.loadMarket(naddr)
|
||||
|
||||
// Clear any error state since preloading succeeded
|
||||
marketStore.setError(null)
|
||||
|
||||
isPreloaded.value = true
|
||||
console.log('Market data preloaded successfully')
|
||||
|
||||
} catch (error) {
|
||||
console.error('Failed to preload market:', error)
|
||||
preloadError.value = error instanceof Error ? error.message : 'Failed to preload market'
|
||||
// Don't throw error, let the UI handle it gracefully
|
||||
} finally {
|
||||
isPreloading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const resetPreload = () => {
|
||||
isPreloaded.value = false
|
||||
preloadError.value = null
|
||||
}
|
||||
|
||||
return {
|
||||
isPreloading: readonly(isPreloading),
|
||||
isPreloaded: readonly(isPreloaded),
|
||||
preloadError: readonly(preloadError),
|
||||
preloadMarket,
|
||||
resetPreload
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue