fix error

This commit is contained in:
liangping 2023-05-16 22:42:05 +08:00
parent db7b1a65fc
commit 1c44a04cd4
3 changed files with 49 additions and 40 deletions

View File

@ -87,29 +87,35 @@ export const useIndexModule = defineStore('module-index', {
return useBankStore(); return useBankStore();
}, },
twitter(): string { twitter(): string {
return `https://twitter.com/${this.coinInfo.links.twitter_screen_name}`; if(!this.coinInfo?.links?.twitter_screen_name) return ""
return `https://twitter.com/${this.coinInfo?.links.twitter_screen_name}`;
}, },
homepage(): string { homepage(): string {
const [page1, page2, page3] = this.coinInfo.links?.homepage; if(!this.coinInfo?.links?.homepage) return ""
const [page1, page2, page3] = this.coinInfo?.links?.homepage;
return page1 || page2 || page3; return page1 || page2 || page3;
}, },
github(): string { github(): string {
const [page1, page2, page3] = this.coinInfo.links?.repos_url?.github; if(!this.coinInfo?.links?.repos_url) return ""
const [page1, page2, page3] = this.coinInfo?.links?.repos_url?.github;
return page1 || page2 || page3; return page1 || page2 || page3;
}, },
telegram(): string { telegram(): string {
return `https://t.me/${this.coinInfo.links.telegram_channel_identifier}`; if(!this.coinInfo?.links?.homepage) return ""
return `https://t.me/${this.coinInfo?.links.telegram_channel_identifier}`;
}, },
priceChange(): string { priceChange(): string {
if(!this.coinInfo?.market_data?.price_change_percentage_24h) return ""
const change = const change =
this.coinInfo.market_data?.price_change_percentage_24h || 0; this.coinInfo?.market_data?.price_change_percentage_24h || 0;
return numeral(change).format('+0.[00]'); return numeral(change).format('+0.[00]');
}, },
priceColor(): string { priceColor(): string {
if(!this.coinInfo?.market_data?.price_change_percentage_24h) return ""
const change = const change =
this.coinInfo.market_data?.price_change_percentage_24h || 0; this.coinInfo?.market_data?.price_change_percentage_24h || 0;
switch (true) { switch (true) {
case change > 0: case change > 0:
return 'text-success'; return 'text-success';
@ -120,7 +126,8 @@ export const useIndexModule = defineStore('module-index', {
} }
}, },
trustColor(): string { trustColor(): string {
const change = this.coinInfo.tickers[this.tickerIndex]?.trust_score; if(!this.coinInfo?.tickers) return ""
const change = this.coinInfo?.tickers[this.tickerIndex]?.trust_score;
return colorMap(change); return colorMap(change);
}, },

View File

@ -10,6 +10,15 @@ const blockchain = useBlockchain();
const base = useBaseStore(); const base = useBaseStore();
const nodeInfo = ref({} as NodeInfo); const nodeInfo = ref({} as NodeInfo);
const height = ref(Number(base.latest.block?.header?.height|| 2001))
const hash = ref(toHex(fromBase64(base.latest.block_id.hash)))
if(height.value > 2000) {
height.value = Math.round((height.value - 2000) / 1000) * 1000
base.fetchBlock(height.value).then(res => {
hash.value = toHex(fromBase64(res.block_id.hash)).toUpperCase()
})
}
const state = computed(() => { const state = computed(() => {
const rpcs = blockchain.current?.endpoints?.rpc const rpcs = blockchain.current?.endpoints?.rpc
?.map((x) => x.address) ?.map((x) => x.address)
@ -17,10 +26,8 @@ const state = computed(() => {
return `[statesync] return `[statesync]
enable = true enable = true
rpc_servers = "${rpcs}" rpc_servers = "${rpcs}"
trust_height = ${base.latest.block?.header?.height || 'loading'} trust_height = ${height.value || 'loading'}
trust_hash = "${ trust_hash = "${hash.value}"
base.latest.block_id ? toHex(fromBase64(base.latest.block_id?.hash)) : ''
}"
trust_period = "168h" # 2/3 of unbonding time" trust_period = "168h" # 2/3 of unbonding time"
`; `;
}); });
@ -31,7 +38,6 @@ const appName = computed(() => {
onMounted(() => { onMounted(() => {
blockchain.rpc.getBaseNodeInfo().then((x) => { blockchain.rpc.getBaseNodeInfo().then((x) => {
console.log('node info', x);
nodeInfo.value = x; nodeInfo.value = x;
}); });
}); });

View File

@ -49,24 +49,22 @@ onMounted(() => {
latest.value = Number(b.block.header.height); latest.value = Number(b.block.header.height);
commits.value.unshift(b.block.last_commit); commits.value.unshift(b.block.last_commit);
const height = Number(b.block.header?.height || 0); const height = Number(b.block.header?.height || 0);
if (height === 0) { if (height > 50) {
// constructs sequence for loading blocks // constructs sequence for loading blocks
let promise = Promise.resolve(); let promise = Promise.resolve();
for (let i = height - 1; i > height - 50; i -= 1) { for (let i = height - 1; i > height - 50; i -= 1) {
if (i > height - 48) { promise = promise.then(
promise = promise.then( () =>
() => new Promise((resolve, reject) => {
new Promise((resolve, reject) => { if (live.value && commits2.value.length < 50) {
if (live.value && commits2.value.length < 50) { // continue only if the page is living
// continue only if the page is living baseStore.fetchBlock(i).then((x) => {
baseStore.fetchBlock(i).then((x) => { commits.value.unshift(x.block.last_commit);
commits.value.unshift(x.block.last_commit); resolve();
resolve(); });
}); }
} })
}) );
);
}
} }
} }
}); });
@ -143,28 +141,26 @@ function changeTab(v: string) {
<div :class="tab === '3'?'':'hidden'"> <div :class="tab === '3'?'':'hidden'">
<table class="table table-compact w-full mt-5"> <table class="table table-compact w-full mt-5">
<thead> <thead class=" capitalize">
<tr> <tr>
<td rowspan="2">Validator</td> <td>Validator</td>
<td rowspan="2">Start Height</td> <td>Start Height</td>
<td rowspan="2">Signed Blocks</td> <td>Signed Precommits</td>
<td colspan="2">Missing blocks</td> <td>Missing blocks</td>
<td rowspan="2">Last Jailed Time</td> <td>Last Jailed Time</td>
<td rowspan="2">Tombstoned</td> <td>Tombstoned</td>
</tr>
<tr>
<td>In Window</td>
<td>Over All</td>
</tr> </tr>
</thead> </thead>
<tr v-for="({v, signing}, i) in list"> <tr v-for="({v, signing}, i) in list">
<td>{{ i+1 }}. {{ v.description.moniker }}</td> <td>{{ i+1 }}. {{ v.description.moniker }}</td>
<td>{{ signing?.start_height }}</td> <td>{{ signing?.start_height }}</td>
<td>{{ signing?.index_offset }}</td> <td>
{{ signing?.index_offset }}
<span v-if="signing && signing.jailed_until.startsWith('1970')" class="badge badge-sm">{{ format.percent(Number(signing.index_offset)/(latest-Number(signing.start_height))) }}</span>
</td>
<td> <td>
<span v-if="signing" class="badge badge-sm text-white" :class="Number(signing?.missed_blocks_counter) < 10?'badge-success':'badge-error'">{{ signing?.missed_blocks_counter }}</span> <span v-if="signing" class="badge badge-sm text-white" :class="Number(signing?.missed_blocks_counter) < 10?'badge-success':'badge-error'">{{ signing?.missed_blocks_counter }}</span>
</td> </td>
<td><span v-if="signing && signing.jailed_until.startsWith('1970')">{{ format.percent(Number(signing.index_offset)/(latest-Number(signing.start_height))) }}</span></td>
<td><span v-if="signing && !signing.jailed_until.startsWith('1970')"> <td><span v-if="signing && !signing.jailed_until.startsWith('1970')">
<div class="tooltip" :data-tip="format.toDay(signing?.jailed_until, 'long')"> <div class="tooltip" :data-tip="format.toDay(signing?.jailed_until, 'long')">
<span>{{ format.toDay(signing?.jailed_until, "from") }}</span> <span>{{ format.toDay(signing?.jailed_until, "from") }}</span>