networkList should not be empty after first start

This commit is contained in:
sijie.sun 2024-05-10 23:48:06 +08:00 committed by Sijie.Sun
parent 2deb867678
commit 518b6e277a

View File

@ -76,10 +76,15 @@ export const useNetworkStore = defineStore('networkStore', {
let networkList: NetworkConfig[]
try {
networkList = JSON.parse(localStorage.getItem('networkList') || '[]')
networkList = JSON.parse(localStorage.getItem('networkList') || '[{}]')
networkList = networkList.map((cfg) => {
return { ...DEFAULT_NETWORK_CONFIG(), ...cfg } as NetworkConfig
})
// prevent a empty list from localStorage, should not happen
if (networkList.length === 0) {
networkList = [DEFAULT_NETWORK_CONFIG()]
}
}
catch {
networkList = [DEFAULT_NETWORK_CONFIG()]