update endpoint stratigy
This commit is contained in:
parent
77cb720bc7
commit
aef6e5f0e3
@ -5,7 +5,7 @@ const baseStore = useBaseStore();
|
|||||||
chainStore.initial();
|
chainStore.initial();
|
||||||
chainStore.$subscribe((m, s) => {
|
chainStore.$subscribe((m, s) => {
|
||||||
if (!Array.isArray(m.events) && m.events.key === 'endpoint') {
|
if (!Array.isArray(m.events) && m.events.key === 'endpoint') {
|
||||||
chainStore.initial();
|
// chainStore.initial();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -13,7 +13,9 @@ router.beforeEach((to) => {
|
|||||||
const { chain } = to.params
|
const { chain } = to.params
|
||||||
if(chain){
|
if(chain){
|
||||||
const blockchain = useBlockchain()
|
const blockchain = useBlockchain()
|
||||||
blockchain.setCurrent(chain.toString())
|
if(chain !== blockchain.chainName) {
|
||||||
|
blockchain.setCurrent(chain.toString())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -122,11 +122,16 @@ export const useBlockchain = defineStore('blockchain', {
|
|||||||
},
|
},
|
||||||
|
|
||||||
async randomSetupEndpoint() {
|
async randomSetupEndpoint() {
|
||||||
const all = this.current?.endpoints?.rest;
|
const end = localStorage.getItem(`endpoint-${this.chainName}`)
|
||||||
if (all) {
|
if(end) {
|
||||||
const rn = Math.random();
|
this.setRestEndpoint(JSON.parse(end))
|
||||||
const endpoint = all[Math.floor(rn * all.length)];
|
} else {
|
||||||
await this.setRestEndpoint(endpoint);
|
const all = this.current?.endpoints?.rest;
|
||||||
|
if (all) {
|
||||||
|
const rn = Math.random();
|
||||||
|
const endpoint = all[Math.floor(rn * all.length)];
|
||||||
|
await this.setRestEndpoint(endpoint);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -134,9 +139,12 @@ export const useBlockchain = defineStore('blockchain', {
|
|||||||
this.connErr = '';
|
this.connErr = '';
|
||||||
this.endpoint = endpoint;
|
this.endpoint = endpoint;
|
||||||
this.rpc = new CosmosRestClient(endpoint.address, DEFAULT);
|
this.rpc = new CosmosRestClient(endpoint.address, DEFAULT);
|
||||||
|
localStorage.setItem(`endpoint-${this.chainName}`, JSON.stringify(endpoint))
|
||||||
},
|
},
|
||||||
setCurrent(name: string) {
|
setCurrent(name: string) {
|
||||||
this.chainName = name;
|
if(name !== this.chainName) {
|
||||||
|
this.chainName = name;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user