random pick endpoints

This commit is contained in:
liangping
2023-11-10 15:34:06 +08:00
parent 586f819d41
commit ce7abefa84
3 changed files with 19 additions and 9 deletions
+9 -4
View File
@@ -147,20 +147,25 @@ export const useBlockchain = defineStore('blockchain', {
useBlockModule().initial();
},
async randomSetupEndpoint() {
const end = localStorage.getItem(`endpoint-${this.chainName}`);
randomEndpoint(chainName: string) : Endpoint | undefined {
const end = localStorage.getItem(`endpoint-${chainName}`);
if (end) {
this.setRestEndpoint(JSON.parse(end));
return JSON.parse(end);
} else {
const all = this.current?.endpoints?.rest;
if (all) {
const rn = Math.random();
const endpoint = all[Math.floor(rn * all.length)];
await this.setRestEndpoint(endpoint);
return endpoint
}
}
},
async randomSetupEndpoint() {
const endpoint = this.randomEndpoint(this.chainName)
if(endpoint) await this.setRestEndpoint(endpoint);
},
async setRestEndpoint(endpoint: Endpoint) {
this.connErr = '';
this.endpoint = endpoint;