optimize default chain

This commit is contained in:
liangping 2023-06-10 09:29:38 +08:00
parent 2cc8ae4de3
commit c07be3d8fb

View File

@ -252,18 +252,14 @@ export enum ConfigSource {
export const useDashboard = defineStore('dashboard', { export const useDashboard = defineStore('dashboard', {
state: () => { state: () => {
const fav = JSON.parse(
localStorage.getItem('favorite') || '["cosmoshub", "osmosis"]'
);
const favMap = JSON.parse( const favMap = JSON.parse(
localStorage.getItem('favoriteMap') || localStorage.getItem('favoriteMap') ||
'{"cosmoshub":true, "osmosis":true}' '{"cosmos":true, "osmosis":true}'
); );
return { return {
status: LoadingStatus.Empty, status: LoadingStatus.Empty,
source: ConfigSource.MainnetCosmosDirectory, source: ConfigSource.MainnetCosmosDirectory,
networkType: NetworkType.Mainnet, networkType: NetworkType.Mainnet,
favorite: fav as string[],
favoriteMap: favMap as Record<string, boolean>, favoriteMap: favMap as Record<string, boolean>,
chains: {} as Record<string, ChainConfig>, chains: {} as Record<string, ChainConfig>,
prices: {} as Record<string, any>, prices: {} as Record<string, any>,
@ -330,9 +326,10 @@ export const useDashboard = defineStore('dashboard', {
setupDefault() { setupDefault() {
if (this.length > 0) { if (this.length > 0) {
const blockchain = useBlockchain(); const blockchain = useBlockchain();
for (let i = 0; i < this.favorite.length; i++) { const keys = Object.keys(this.favoriteMap)
if (!blockchain.chainName && this.chains[this.favorite[i]]) { for (let i = 0; i < keys.length; i++) {
blockchain.setCurrent(this.favorite[i]); if (!blockchain.chainName && this.chains[keys[i]] && this.favoriteMap[keys[i]]) {
blockchain.setCurrent(keys[i]);
break break
} }
} }