Skip to content

Commit

Permalink
feat: update validator logo handling and API endpoint configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
onmax committed Nov 20, 2024
1 parent 40dcf58 commit 78ccb1a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 8 deletions.
11 changes: 10 additions & 1 deletion src/components/staking/ValidatorIcon.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<template>
<img class="validator-icon" v-if="'logo' in validator" :src="validator.logo" :alt="validator.name" />
<img class="validator-icon" v-if="src" :src="src" :alt="validator.name" loading="lazy" />
<Identicon class="validator-icon" v-else :address="validator.address"/>
</template>

<script lang="ts">
import { defineComponent } from '@vue/composition-api';
import { Identicon } from '@nimiq/vue-components';
import { useConfig } from '@/composables/useConfig';
import { Validator } from '../../stores/Staking';
export default defineComponent({
Expand All @@ -15,6 +16,14 @@ export default defineComponent({
required: true,
},
},
setup(props) {
const { config } = useConfig();
return {
src: 'logoPath' in props.validator
? `${config.staking.validatorsEndpoint}}/${props.validator.logoPath}` : undefined,
};
},
components: {
Identicon,
},
Expand Down
2 changes: 1 addition & 1 deletion src/config/config.local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default {
prestakingStartBlock: 3_023_730,
prestakingEndBlock: 3_028_050,
transitionBlock: 3_032_010,
validatorsEndpoint: 'https://validators-api-testnet.nuxt.dev/api/v1/validators?only-known=false',
validatorsEndpoint: 'https://validators-api-testnet.nuxt.dev',
genesis: {
height: 3032010,
date: new Date('2024-11-13T20:00:00Z'),
Expand Down
2 changes: 1 addition & 1 deletion src/config/config.mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default {
prestakingStartBlock: 3_392_200, // 2024-10-06T02:53:18Z
prestakingEndBlock: 3_456_000, // ~2024-11-19T16:00:00Z
transitionBlock: 3_456_000,
validatorsEndpoint: 'https://validators-api-mainnet.nuxt.dev/api/v1/validators?only-known=false',
validatorsEndpoint: 'https://validators-api-mainnet.nuxt.dev',
genesis: {
height: 3456000,
date: new Date('2024-11-19T16:00:00Z'),
Expand Down
2 changes: 1 addition & 1 deletion src/config/config.testnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default {
prestakingStartBlock: 3_023_730,
prestakingEndBlock: 3_028_050,
transitionBlock: 3_032_010,
validatorsEndpoint: 'https://validators-api-testnet.nuxt.dev/api/v1/validators?with-scores=true',
validatorsEndpoint: 'https://validators-api-testnet.nuxt.dev',
genesis: {
height: 3032010,
date: new Date('2024-11-13T20:00:00Z'),
Expand Down
6 changes: 4 additions & 2 deletions src/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ export async function launchNetwork() {
payoutType: 'none' | 'direct' | 'restake',
payoutSchedule: string,
isMaintainedByNimiq: boolean,
icon?: string,
logo?: string,
logoPath?: string,
hasDefaultIcon: boolean,
accentColor: string,
website: string | null,
Expand All @@ -256,8 +257,9 @@ export async function launchNetwork() {
};

const { config } = useConfig();
const url = `${config.staking.validatorsEndpoint}/api/v1/validators?only-known=false`;
const apiValidators = await retry<ApiValidator[]>(
() => fetch(config.staking.validatorsEndpoint).then((res) => res.json()).catch(() => []), 1000, 3,
() => fetch(url).then((res) => res.json()).catch(() => []), 1000, 3,
);
// TODO: Make it work even in the case this request fails
const validatorData: Record<string, ApiValidator> = {};
Expand Down
5 changes: 3 additions & 2 deletions src/stores/Staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export type RegisteredValidator = RawValidator & {
payoutSchedule: string,
isMaintainedByNimiq: boolean,
logo?: string,
logoPath?: string,
hasDefaultIcon: boolean,
accentColor: string,
website: string | null,
Expand Down Expand Up @@ -167,7 +168,7 @@ export const useStakingStore = createStore({
};
},
setStakes(stakes: Stake[]) {
const newStakes: {[address: string]: Stake} = {};
const newStakes: { [address: string]: Stake } = {};

for (const stake of stakes) {
newStakes[stake.address] = stake;
Expand Down Expand Up @@ -197,7 +198,7 @@ export const useStakingStore = createStore({
};
},
setValidators(validators: Validator[]) {
const newValidators: {[address: string]: Validator} = {};
const newValidators: { [address: string]: Validator } = {};

for (const validator of validators) {
newValidators[validator.address] = validator;
Expand Down

0 comments on commit 78ccb1a

Please sign in to comment.