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
+6 -3
View File
@@ -41,6 +41,7 @@ Object.values(conf.value).forEach((imported) => {
// continue only if the page is living
if (imported[i].endpoint) {
loadBalances(
imported[i].chainName,
imported[i].endpoint || '',
imported[i].address
).finally(() => resolve());
@@ -170,15 +171,17 @@ async function addAddress(acc: AccountEntry) {
}
if (acc.endpoint) {
loadBalances(acc.endpoint, acc.address);
loadBalances(acc.chainName, acc.endpoint, acc.address);
}
localStorage.setItem('imported-addresses', JSON.stringify(conf.value));
}
// load balances for an address
async function loadBalances(endpoint: string, address: string) {
const client = CosmosRestClient.newDefault(endpoint);
async function loadBalances(chainName: string, endpoint: string, address: string) {
const endpointObj = chainStore.randomEndpoint(chainName)
const client = CosmosRestClient.newDefault(endpointObj?.address || endpoint);
await client.getBankBalances(address).then((res) => {
balances.value[address] = res.balances.filter((x) => x.denom.length < 10);
});
+4 -2
View File
@@ -4,7 +4,7 @@ import type { Coin, Delegation } from '@/types';
import { ref, watchEffect } from 'vue';
import type { AccountEntry } from './utils';
import { computed } from 'vue';
import { useBaseStore, useFormatter } from '@/stores';
import { useBaseStore, useBlockchain, useFormatter } from '@/stores';
import DonutChart from '@/components/charts/DonutChart.vue';
import ApexCharts from 'vue3-apexcharts';
import { get } from '@/libs';
@@ -17,6 +17,7 @@ const conf = ref(
AccountEntry[]
>
);
const chainStore = useBlockchain();
const balances = ref({} as Record<string, Coin[]>);
const delegations = ref({} as Record<string, Delegation[]>);
const tokenMeta = ref({} as Record<string, AccountEntry>);
@@ -64,7 +65,8 @@ Object.values(conf.value).forEach((imported) => {
imported.forEach((x) => {
if (x.endpoint && x.address) {
loading.value += 1
const client = CosmosRestClient.newDefault(x.endpoint);
const endpoint = chainStore.randomEndpoint(x.chainName)
const client = CosmosRestClient.newDefault(endpoint?.address || x.endpoint);
client.getBankBalances(x.address).then((res) => {
const bal = res.balances.filter((x) => x.denom.length < 10);
if (bal) balances.value[x.address || ""] = bal;