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[] let networkList: NetworkConfig[]
try { try {
networkList = JSON.parse(localStorage.getItem('networkList') || '[]') networkList = JSON.parse(localStorage.getItem('networkList') || '[{}]')
networkList = networkList.map((cfg) => { networkList = networkList.map((cfg) => {
return { ...DEFAULT_NETWORK_CONFIG(), ...cfg } as NetworkConfig 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 { catch {
networkList = [DEFAULT_NETWORK_CONFIG()] networkList = [DEFAULT_NETWORK_CONFIG()]