diff --git a/.eslintrc b/.eslintrc index 11643ef3..829b7b59 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,6 +1,9 @@ { "root": true, "parser": "@typescript-eslint/parser", + "parserOptions": { + "project": "./tsconfig.json" + }, "plugins": [ "@typescript-eslint" ], @@ -8,5 +11,8 @@ "eslint:recommended", "plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/recommended" - ] + ], + "rules": { + "@typescript-eslint/await-thenable": "error" + } } diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 23479878..59f0ae2a 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -18,7 +18,7 @@ * // along with Beaconchain Dashboard. If not, see . */ -import { NgModule } from '@angular/core' +import { APP_INITIALIZER, NgModule } from '@angular/core' import { BrowserModule, HammerModule } from '@angular/platform-browser' import { RouteReuseStrategy } from '@angular/router' @@ -30,6 +30,7 @@ import { PipesModule } from './pipes/pipes.module' import { HammerGestureConfig, HAMMER_GESTURE_CONFIG } from '@angular/platform-browser' import { BrowserAnimationsModule } from '@angular/platform-browser/animations' import 'hammerjs' +import { ApiService, initializeApiService } from './services/api.service' // eslint-disable-next-line @typescript-eslint/no-explicit-any declare let Hammer: any @@ -59,6 +60,12 @@ export class MyHammerConfig extends HammerGestureConfig { provide: HAMMER_GESTURE_CONFIG, useClass: MyHammerConfig, }, + { + provide: APP_INITIALIZER, + useFactory: initializeApiService, + deps: [ApiService], + multi: true, + }, ], bootstrap: [AppComponent], }) diff --git a/src/app/components/block/block.component.ts b/src/app/components/block/block.component.ts index bd811873..365fd352 100644 --- a/src/app/components/block/block.component.ts +++ b/src/app/components/block/block.component.ts @@ -31,7 +31,7 @@ export class BlockComponent implements OnInit { async ngOnChanges() { this.imgData = this.getBlockies() this.timestamp = this.block.timestamp * 1000 - this.producerReward = await await this.blockUtils.getBlockRewardWithShare(this.block) + this.producerReward = await this.blockUtils.getBlockRewardWithShare(this.block) this.resolvedName = null this.feeRecipient = this.block.feeRecipient diff --git a/src/app/components/dashboard/dashboard.component.html b/src/app/components/dashboard/dashboard.component.html index 428281d8..7fd3a232 100644 --- a/src/app/components/dashboard/dashboard.component.html +++ b/src/app/components/dashboard/dashboard.component.html @@ -877,7 +877,7 @@ - View on beaconcha.in + View on {{ api.getHostName() }}
diff --git a/src/app/components/dashboard/dashboard.component.ts b/src/app/components/dashboard/dashboard.component.ts index 7d1df8bc..c33b59e3 100644 --- a/src/app/components/dashboard/dashboard.component.ts +++ b/src/app/components/dashboard/dashboard.component.ts @@ -161,7 +161,7 @@ export class DashboardComponent implements OnInit { this.drawProposalChart() }, 500) - this.beaconChainUrl = await this.getBaseBrowserUrl() + this.beaconChainUrl = this.api.getBaseUrl() await Promise.all([ this.updateRplDisplay(), @@ -438,7 +438,11 @@ export class DashboardComponent implements OnInit { updateRplDisplay() { if (this.rplState == '%') { - this.rplDisplay = this.data.rocketpool.currentRpl.dividedBy(this.data.rocketpool.maxRpl).multipliedBy(new BigNumber(150)).decimalPlaces(1) + const rplPrice = this.unit.getRPLPrice() + const currentETH = this.data.rocketpool.currentRpl.multipliedBy(rplPrice) + const minETH = this.data.rocketpool.minRpl.multipliedBy(rplPrice).multipliedBy(10) // since collateral is 10% of borrowed eth, multiply by 10 to get to the borrowed eth amount + + this.rplDisplay = currentETH.dividedBy(minETH).multipliedBy(100).decimalPlaces(1).toNumber() } else { this.rplDisplay = this.data.rocketpool.currentRpl } @@ -866,16 +870,11 @@ export class DashboardComponent implements OnInit { async getBrowserURL(): Promise { if (this.data.foreignValidator) { - return (await this.getBaseBrowserUrl()) + '/validator/' + this.data.foreignValidatorItem.pubkey + return this.api.getBaseUrl() + '/validator/' + this.data.foreignValidatorItem.pubkey } else { - return (await this.getBaseBrowserUrl()) + '/dashboard?validators=' + this.data.lazyChartValidators + return this.api.getBaseUrl() + '/dashboard?validators=' + this.data.lazyChartValidators } } - - async getBaseBrowserUrl() { - const net = (await this.api.networkConfig).net - return 'https://' + net + 'beaconcha.in' - } } function getRandomInt(max) { diff --git a/src/app/components/help/help.component.html b/src/app/components/help/help.component.html index 32804afe..b683ec35 100644 --- a/src/app/components/help/help.component.html +++ b/src/app/components/help/help.component.html @@ -26,7 +26,7 @@ - Or login with beaconcha.in + Or login with {{ api.getHostName() }} @@ -34,7 +34,7 @@ Guides & Help - + Staking Guide & FAQ @@ -61,11 +61,23 @@ + + + + Node Guide & FAQ + + + + + Enable Withdrawals Guide + + + How to set up a Validator - + Setup Guide for Lighthouse @@ -92,13 +104,20 @@ + + + + Interactive Setup Guide + + + Useful Links - + - beaconcha.in Block Explorer + {{ api.getHostName() }} Block Explorer diff --git a/src/app/components/help/help.component.ts b/src/app/components/help/help.component.ts index 5cda2daf..af50f02c 100644 --- a/src/app/components/help/help.component.ts +++ b/src/app/components/help/help.component.ts @@ -25,6 +25,7 @@ import { OAuthUtils } from 'src/app/utils/OAuthUtils' import { ValidatorUtils } from 'src/app/utils/ValidatorUtils' import { Browser } from '@capacitor/browser' +import { ApiService } from 'src/app/services/api.service' @Component({ selector: 'app-help', @@ -35,7 +36,13 @@ export class HelpComponent implements OnInit { @Input() onlyGuides: boolean isAlreadyLoggedIn = false - constructor(private oauthUtils: OAuthUtils, private validator: ValidatorUtils, private storage: StorageService, private router: Router) {} + constructor( + private oauthUtils: OAuthUtils, + private validator: ValidatorUtils, + private storage: StorageService, + private router: Router, + public api: ApiService + ) {} ngOnInit() { this.storage.isLoggedIn().then((result) => { diff --git a/src/app/models/StorageTypes.ts b/src/app/models/StorageTypes.ts index a5e34487..beb75ecd 100644 --- a/src/app/models/StorageTypes.ts +++ b/src/app/models/StorageTypes.ts @@ -34,6 +34,14 @@ export interface ApiNetwork { onlyDebug: boolean active: boolean genesisTs: number + elCurrency: Currency + clCurrency: Currency +} + +export enum Currency { + ETH = 'ETH', + GNO = 'GNO', + xDAI = 'xDAI', } export interface NetworkPreferences { diff --git a/src/app/pages/block-detail/block-detail.page.ts b/src/app/pages/block-detail/block-detail.page.ts index c77f482a..8a2f52d3 100644 --- a/src/app/pages/block-detail/block-detail.page.ts +++ b/src/app/pages/block-detail/block-detail.page.ts @@ -90,20 +90,15 @@ export class BlockDetailPage implements OnInit { async openBlock() { await Browser.open({ - url: (await this.getBaseBrowserUrl()) + '/block/' + this.block.blockNumber, + url: this.api.getBaseUrl() + '/block/' + this.block.blockNumber, toolbarColor: '#2f2e42', }) } async openFeeRecipient() { await Browser.open({ - url: (await this.getBaseBrowserUrl()) + '/address/' + this.feeRecipient, + url: this.api.getBaseUrl() + '/address/' + this.feeRecipient, toolbarColor: '#2f2e42', }) } - - async getBaseBrowserUrl() { - const net = (await this.api.networkConfig).net - return 'https://' + net + 'beaconcha.in' - } } diff --git a/src/app/pages/notifications/notifications.page.html b/src/app/pages/notifications/notifications.page.html index 5c7a7ea8..1e16da12 100644 --- a/src/app/pages/notifications/notifications.page.html +++ b/src/app/pages/notifications/notifications.page.html @@ -10,7 +10,7 @@
Note: You are using the No-Google version of this app. Push notifications will not work, but you can configure webhook - notifications on beaconcha.in directly or by clicking here. + notifications on {{ api.getHostName() }} directly or by clicking here.
diff --git a/src/app/pages/notifications/notifications.page.ts b/src/app/pages/notifications/notifications.page.ts index 09232113..772a1900 100644 --- a/src/app/pages/notifications/notifications.page.ts +++ b/src/app/pages/notifications/notifications.page.ts @@ -73,7 +73,7 @@ export class NotificationsPage extends NotificationBase implements OnInit { } async configureWebhooks() { - await Browser.open({ url: 'https://beaconcha.in/user/webhooks', toolbarColor: '#2f2e42' }) + await Browser.open({ url: this.api.getBaseUrl() + '/user/webhooks', toolbarColor: '#2f2e42' }) } async ionViewWillEnter() { diff --git a/src/app/pages/subscribe/subscribe.page.ts b/src/app/pages/subscribe/subscribe.page.ts index 1a582937..65b4c347 100644 --- a/src/app/pages/subscribe/subscribe.page.ts +++ b/src/app/pages/subscribe/subscribe.page.ts @@ -9,6 +9,7 @@ import { Toast } from '@capacitor/toast' import FlavorUtils from 'src/app/utils/FlavorUtils' import { Browser } from '@capacitor/browser' +import { ApiService } from 'src/app/services/api.service' @Component({ selector: 'app-subscribe', @@ -32,7 +33,8 @@ export class SubscribePage implements OnInit { private oauth: OAuthUtils, private alertService: AlertService, private platform: Platform, - private flavor: FlavorUtils + private flavor: FlavorUtils, + private api: ApiService ) { this.selectedPackage = this.merchant.PACKAGES[2] } @@ -80,7 +82,7 @@ export class SubscribePage implements OnInit { 'Yes', async () => { if (isNoGoogle) { - await Browser.open({ url: 'https://beaconcha.in/premium', toolbarColor: '#2f2e42' }) + await Browser.open({ url: this.api.getBaseUrl() + '/premium', toolbarColor: '#2f2e42' }) } else { this.merchant.purchase(this.selectedPackage.purchaseKey) } @@ -90,7 +92,7 @@ export class SubscribePage implements OnInit { } if (isNoGoogle) { - await Browser.open({ url: 'https://beaconcha.in/premium', toolbarColor: '#2f2e42' }) + await Browser.open({ url: this.api.getBaseUrl() + '/premium', toolbarColor: '#2f2e42' }) } else { this.merchant.purchase(this.selectedPackage.purchaseKey) } diff --git a/src/app/services/api.service.ts b/src/app/services/api.service.ts index 47df85c3..d546ee20 100644 --- a/src/app/services/api.service.ts +++ b/src/app/services/api.service.ts @@ -38,7 +38,9 @@ const SERVER_TIMEOUT = 25000 providedIn: 'root', }) export class ApiService extends CacheModule { - networkConfig: Promise + private isInitialized = false + + networkConfig: ApiNetwork public connectionStateOK = true @@ -74,7 +76,7 @@ export class ApiService extends CacheModule { }) this.lastCacheInvalidate = Date.now() //this.registerLogMiddleware() - this.updateNetworkConfig() + this.initialize() //this.isIOS15().then((result) => { this.forceNativeAll = result }) } @@ -91,27 +93,26 @@ export class ApiService extends CacheModule { } } - async updateNetworkConfig() { - this.networkConfig = this.storage.getNetworkPreferences().then((config) => { + async initialize() { + this.networkConfig = await this.storage.getNetworkPreferences().then((config) => { const temp = findConfigForKey(config.key) if (temp) { return temp } return config }) - - await this.networkConfig + this.isInitialized = true } networkName = null async getNetworkName(): Promise { - const temp = (await this.networkConfig).key + const temp = this.networkConfig.key this.networkName = temp return temp } async getNetwork(): Promise { - const temp = await this.networkConfig + const temp = this.networkConfig return temp } @@ -158,7 +159,7 @@ export class ApiService extends CacheModule { const formBody = new FormData() formBody.set('grant_type', 'refresh_token') formBody.set('refresh_token', user.refreshToken) - const url = await this.getResourceUrl(req.resource, req.endPoint) + const url = this.getResourceUrl(req.resource, req.endPoint) // use js here for the request since the native http plugin performs inconsistent across platforms with non json requests const resp = await fetch(url, { @@ -195,16 +196,16 @@ export class ApiService extends CacheModule { this.awaitingResponses[resource].release() } - async isNotMainnet(): Promise { - const test = (await this.networkConfig).net != '' + isNotMainnet(): boolean { + const test = this.networkConfig.net != '' return test } - private async getCacheKey(request: APIRequest): Promise { + private getCacheKey(request: APIRequest): string { if (request.method == Method.GET) { - return request.method + (await this.getResourceUrl(request.resource, request.endPoint)) + return request.method + this.getResourceUrl(request.resource, request.endPoint) } else if (request.cacheablePOST) { - return request.method + (await this.getResourceUrl(request.resource, request.endPoint)) + JSON.stringify(request.postData) + return request.method + this.getResourceUrl(request.resource, request.endPoint) + JSON.stringify(request.postData) } return null } @@ -217,7 +218,7 @@ export class ApiService extends CacheModule { } // If cached and not stale, return cache - const cached = (await this.getCache(await this.getCacheKey(request))) as Response + const cached = (await this.getCache(this.getCacheKey(request))) as Response if (cached) { if (this.lastRefreshed == 0) this.lastRefreshed = Date.now() cached.cached = true @@ -281,7 +282,7 @@ export class ApiService extends CacheModule { } if ((request.method == Method.GET || request.cacheablePOST) && result && result.status == 200 && result.data) { - this.putCache(await this.getCacheKey(request), result, request.maxCacheAge) + this.putCache(this.getCacheKey(request), result, request.maxCacheAge) } if (request.updatesLastRefreshState) this.updateLastRefreshed(result) @@ -295,7 +296,7 @@ export class ApiService extends CacheModule { } async clearSpecificCache(request: APIRequest) { - this.putCache(await this.getCacheKey(request), null, request.maxCacheAge) + this.putCache(this.getCacheKey(request), null, request.maxCacheAge) } private updateLastRefreshed(response: Response) { @@ -306,7 +307,7 @@ export class ApiService extends CacheModule { private async get(resource: string, endpoint = 'default', ignoreFails = false, options: HttpOptions = { url: null, headers: {} }) { const getOptions = { - url: await this.getResourceUrl(resource, endpoint), + url: this.getResourceUrl(resource, endpoint), method: 'get', headers: options.headers, } @@ -324,7 +325,7 @@ export class ApiService extends CacheModule { } const postOptions = { - url: await this.getResourceUrl(resource, endpoint), + url: this.getResourceUrl(resource, endpoint), headers: options.headers, data: this.formatPostData(data), method: 'post', @@ -339,7 +340,7 @@ export class ApiService extends CacheModule { private async legacyGet(resource: string, endpoint = 'default', ignoreFails = false, options: HttpOptions = { url: null, headers: {} }) { return this.httpLegacy - .get(await this.getResourceUrl(resource, endpoint), options) + .get(this.getResourceUrl(resource, endpoint), options) .catch((err) => { this.updateConnectionState(ignoreFails, false) console.warn('Connection err', err) @@ -366,7 +367,7 @@ export class ApiService extends CacheModule { }) .then((response: AxiosResponse) => this.validateResponseLegacy(ignoreFails, response)); */ - const resp = await fetch(await this.getResourceUrl(resource, endpoint), { + const resp = await fetch(this.getResourceUrl(resource, endpoint), { method: 'POST', body: JSON.stringify(this.formatPostData(data)), headers: options.headers, @@ -427,23 +428,23 @@ export class ApiService extends CacheModule { return response } - async getResourceUrl(resource: string, endpoint = 'default'): Promise { - const base = await this.getBaseUrl() + getResourceUrl(resource: string, endpoint = 'default'): string { + const base = this.getBaseUrl() if (endpoint == 'default') { - return (await this.getApiBaseUrl()) + '/' + resource + return this.getApiBaseUrl() + '/' + resource } else { const substitute = endpoint.replace('{$BASE}', base) return substitute + '/' + resource } } - async getApiBaseUrl() { - const cfg = await this.networkConfig - return (await this.getBaseUrl()) + cfg.endpoint + cfg.version + getApiBaseUrl() { + const cfg = this.networkConfig + return this.getBaseUrl() + cfg.endpoint + cfg.version } - async getBaseUrl(): Promise { - const cfg = await this.networkConfig + getBaseUrl(): string { + const cfg = this.networkConfig return cfg.protocol + '://' + cfg.net + cfg.host } @@ -460,6 +461,7 @@ export class ApiService extends CacheModule { for (const entry of MAP) { if (entry.key == 'main') continue + if (entry.key == 'gnosis') continue if (!entry.active) continue if (entry.onlyDebug && !debug) continue re.push([this.capitalize(entry.key) + ' (Testnet)', entry.key]) @@ -470,6 +472,15 @@ export class ApiService extends CacheModule { capitalize(text) { return text.charAt(0).toUpperCase() + text.slice(1) } + + getHostName() { + const network = this.networkConfig + return network.host + } + + isGnosis() { + return this.networkConfig.key == 'gnosis' + } } export interface Response extends HttpResponse { @@ -479,3 +490,7 @@ export interface Response extends HttpResponse { export interface DevModeEnabled { enabled: boolean } + +export function initializeApiService(service: ApiService): () => Promise { + return () => service.initialize() +} diff --git a/src/app/services/storage.service.ts b/src/app/services/storage.service.ts index e21022a3..e123e441 100644 --- a/src/app/services/storage.service.ts +++ b/src/app/services/storage.service.ts @@ -139,7 +139,7 @@ export class StorageService extends CacheModule { } async openLogSession(modalCtr, offset: number) { - let lastLogSession = parseInt(await window.localStorage.getItem('last_log_session')) + let lastLogSession = parseInt(window.localStorage.getItem('last_log_session')) if (isNaN(lastLogSession)) lastLogSession = 0 const modal = await modalCtr.create({ diff --git a/src/app/services/sync.service.ts b/src/app/services/sync.service.ts index a80c7a30..07e02395 100644 --- a/src/app/services/sync.service.ts +++ b/src/app/services/sync.service.ts @@ -293,7 +293,7 @@ export class SyncService { if (success) this.lastNotifySync = Date.now() for (let j = 0; j < splice.length; j++) { - await splice[j].onComplete(success) + splice[j].onComplete(success) } } } @@ -372,7 +372,7 @@ export class SyncService { } async changeNotifyEvent(key: string, event: string, value: boolean, filter: string = null, threshold: number = null) { - const net = (await this.api.networkConfig).net + const net = this.api.networkConfig.net this.storage.setBooleanSetting(net + key, value) this.setLastChanged(net + key, event, filter, threshold, value ? 'subscribe' : 'unsubscribe') } @@ -421,7 +421,7 @@ export class SyncService { lastChanged: current.lastChanged, lastSynced: value, eventName: event, - network: await this.api.getApiBaseUrl(), + network: this.api.getApiBaseUrl(), eventFilter: current.eventFilter, eventThreshold: current.eventThreshold, subscribeAction: subscribeAction, @@ -441,7 +441,7 @@ export class SyncService { lastChanged: value, lastSynced: current.lastSynced, eventName: event, - network: await this.api.getApiBaseUrl(), + network: this.api.getApiBaseUrl(), eventFilter: filter, eventThreshold: threshold, subscribeAction: subscribeAction, @@ -463,7 +463,7 @@ export class SyncService { lastChanged: 0, lastSynced: 0, eventName: '', - network: await this.api.getApiBaseUrl(), + network: this.api.getApiBaseUrl(), eventFilter: null, eventThreshold: null, subscribeAction: 'subscribe', diff --git a/src/app/services/unitconv.service.ts b/src/app/services/unitconv.service.ts index af0e9376..9b6d6dcd 100644 --- a/src/app/services/unitconv.service.ts +++ b/src/app/services/unitconv.service.ts @@ -116,6 +116,12 @@ export class UnitconvService { unitStored.value = convertEthUnits(price, MAPPING.get('WEI'), Unit.ETHER) } + getRPLPrice() { + const unitStored: Unit = MAPPING.get('RPL') + if (!unitStored) return + return unitStored.value + } + setRETHPrice(price: BigNumber) { const unitStored: Unit = MAPPING.get('RETH') if (!unitStored) return diff --git a/src/app/tab-preferences/notification-base.ts b/src/app/tab-preferences/notification-base.ts index 7a4706b6..02042c98 100644 --- a/src/app/tab-preferences/notification-base.ts +++ b/src/app/tab-preferences/notification-base.ts @@ -97,7 +97,7 @@ export class NotificationBase implements OnInit { async loadAllToggles() { if (!(await this.storage.isLoggedIn())) return - const net = (await this.api.networkConfig).net + const net = this.api.networkConfig.net const request = new NotificationGetRequest() const response = await this.api.execute(request) @@ -166,7 +166,7 @@ export class NotificationBase implements OnInit { // locking toggle so we dont execute onChange when setting initial values const preferences = await this.storage.loadPreferencesToggles(net) - if (await this.api.isNotMainnet()) { + if (this.api.isNotMainnet()) { this.notify = preferences this.notifyInitialized = true this.disableToggleLock() @@ -208,10 +208,10 @@ export class NotificationBase implements OnInit { } } - const net = (await this.api.networkConfig).net + const net = this.api.networkConfig.net this.storage.setBooleanSetting(net + SETTING_NOTIFY, this.notify) this.settingsChanged = true - if (!(await this.api.isNotMainnet())) { + if (!this.api.isNotMainnet()) { this.sync.changeGeneralNotify(this.notify) } diff --git a/src/app/tab-preferences/tab-preferences.page.html b/src/app/tab-preferences/tab-preferences.page.html index 95232011..239dab64 100644 --- a/src/app/tab-preferences/tab-preferences.page.html +++ b/src/app/tab-preferences/tab-preferences.page.html @@ -211,6 +211,7 @@ Mainnet + Gnosis {{ item[0] }}
@@ -249,7 +250,7 @@ Login
- + Delete Account @@ -259,18 +260,18 @@ Legal - + Privacy Policy - + Terms of Service Open Source Licences - + Imprint diff --git a/src/app/tab-preferences/tab-preferences.page.ts b/src/app/tab-preferences/tab-preferences.page.ts index 6931ee67..443b2c2c 100644 --- a/src/app/tab-preferences/tab-preferences.page.ts +++ b/src/app/tab-preferences/tab-preferences.page.ts @@ -316,7 +316,7 @@ export class Tab3Page { await this.validatorUtils.clearCache() await this.storage.setNetworkPreferences(newConfig) - await this.api.updateNetworkConfig() + await this.api.initialize() await this.notificationBase.loadAllToggles() this.validatorUtils.notifyListeners() } diff --git a/src/app/utils/CacheModule.ts b/src/app/utils/CacheModule.ts index cdc16266..c2bb19bb 100644 --- a/src/app/utils/CacheModule.ts +++ b/src/app/utils/CacheModule.ts @@ -88,15 +88,15 @@ export class CacheModule { } } - clearCache() { - this.clearHardCache() + async clearCache() { + await this.clearHardCache() this.cache.clear() this.hotOnly.clear() } - clearHardCache() { + async clearHardCache() { if (this.hardStorage) { - this.hardStorage.setObject('cachemodule2_' + this.keyPrefix, null) + await this.hardStorage.setObject('cachemodule2_' + this.keyPrefix, null) } } diff --git a/src/app/utils/MerchantUtils.ts b/src/app/utils/MerchantUtils.ts index bdd85860..5b6f8d11 100644 --- a/src/app/utils/MerchantUtils.ts +++ b/src/app/utils/MerchantUtils.ts @@ -386,7 +386,7 @@ export class MerchantUtils { const currentProduct = this.findProduct(currentPlan) if (currentProduct == null) return 100 - const notMainnet = await this.api.isNotMainnet() + const notMainnet = this.api.isNotMainnet() if (notMainnet) return currentProduct.maxTestnetValidators return currentProduct.maxValidators } @@ -395,7 +395,7 @@ export class MerchantUtils { const currentProduct = this.findProduct(MAX_PRODUCT) if (currentProduct == null) return 100 - const notMainnet = await this.api.isNotMainnet() + const notMainnet = this.api.isNotMainnet() if (notMainnet) return currentProduct.maxTestnetValidators return currentProduct.maxValidators } diff --git a/src/app/utils/NetworkData.ts b/src/app/utils/NetworkData.ts index a671f291..eee4abf0 100644 --- a/src/app/utils/NetworkData.ts +++ b/src/app/utils/NetworkData.ts @@ -18,7 +18,7 @@ * // along with Beaconchain Dashboard. If not, see . */ -import { ApiNetwork } from '../models/StorageTypes' +import { ApiNetwork, Currency } from '../models/StorageTypes' export const MAP: ApiNetwork[] = [ { @@ -31,6 +31,21 @@ export const MAP: ApiNetwork[] = [ onlyDebug: false, active: true, genesisTs: 1606824023, + clCurrency: Currency.ETH, + elCurrency: Currency.ETH, + }, + { + key: 'gnosis', + protocol: 'https', + host: 'gnosischa.in', + net: '', + endpoint: '/api/', + version: 'v1', + onlyDebug: false, + active: true, + genesisTs: 1638993340, + clCurrency: Currency.GNO, + elCurrency: Currency.xDAI, }, { key: 'prater', @@ -42,6 +57,8 @@ export const MAP: ApiNetwork[] = [ onlyDebug: false, active: true, genesisTs: 1616508000, + clCurrency: Currency.ETH, + elCurrency: Currency.ETH, }, { key: 'sepolia', @@ -53,6 +70,8 @@ export const MAP: ApiNetwork[] = [ onlyDebug: false, active: true, genesisTs: 1655733600, + clCurrency: Currency.ETH, + elCurrency: Currency.ETH, }, { key: 'holesky', @@ -64,6 +83,8 @@ export const MAP: ApiNetwork[] = [ onlyDebug: false, active: true, genesisTs: 1695902400, + clCurrency: Currency.ETH, + elCurrency: Currency.ETH, }, { key: 'local dev', @@ -75,6 +96,8 @@ export const MAP: ApiNetwork[] = [ onlyDebug: true, active: true, genesisTs: 1606824023, + clCurrency: Currency.ETH, + elCurrency: Currency.ETH, }, { key: 'invalid (no connection)', @@ -86,6 +109,8 @@ export const MAP: ApiNetwork[] = [ onlyDebug: true, active: true, genesisTs: 1606824023, + clCurrency: Currency.ETH, + elCurrency: Currency.ETH, }, ] diff --git a/src/app/utils/OAuthUtils.ts b/src/app/utils/OAuthUtils.ts index bb07859f..42886080 100644 --- a/src/app/utils/OAuthUtils.ts +++ b/src/app/utils/OAuthUtils.ts @@ -122,7 +122,7 @@ export class OAuthUtils { private async getOAuthOptions() { const api = this.api - const endpointUrl = await api.getResourceUrl('user/token') + const endpointUrl = api.getResourceUrl('user/token') const info = await Device.getId().catch(() => { return { identifier: 'iduno' } @@ -142,7 +142,7 @@ export class OAuthUtils { } return { - authorizationBaseUrl: (await api.getBaseUrl()) + '/user/authorize', + authorizationBaseUrl: api.getBaseUrl() + '/user/authorize', accessTokenEndpoint: endpointUrl, web: { appId: clientID, diff --git a/src/app/utils/ValidatorUtils.ts b/src/app/utils/ValidatorUtils.ts index 0fcaee89..6899fe4c 100644 --- a/src/app/utils/ValidatorUtils.ts +++ b/src/app/utils/ValidatorUtils.ts @@ -306,9 +306,8 @@ export class ValidatorUtils extends CacheModule { } async updateValidatorStates(validators: Validator[]) { - const epoch = await this.getRemoteCurrentEpoch() validators.forEach((item) => { - item.state = this.getValidatorState(item, epoch) + item.state = this.getValidatorState(item) }) } @@ -328,22 +327,15 @@ export class ValidatorUtils extends CacheModule { return result } - getValidatorState(item: Validator, currentEpoch: EpochResponse): ValidatorState { - if ( - item.data.slashed == false && - item.data.lastattestationslot >= (currentEpoch.epoch - 2) * 32 && // online since last two epochs - item.data.exitepoch >= currentEpoch.epoch && - item.data.activationepoch <= currentEpoch.epoch - ) { + getValidatorState(item: Validator): ValidatorState { + if (item.data.slashed) return ValidatorState.SLASHED + if (item.data.status == 'exited') return ValidatorState.EXITED + if (item.data.status == 'deposited') return ValidatorState.ELIGABLE + if (item.data.status == 'pending') return ValidatorState.WAITING + if (item.data.slashed == false && item.data.status.indexOf('online') > 0) { return ValidatorState.ACTIVE } - if (item.data.slashed) return ValidatorState.SLASHED - if (item.data.exitepoch < currentEpoch.epoch) return ValidatorState.EXITED - if (item.data.activationeligibilityepoch > currentEpoch.epoch) return ValidatorState.ELIGABLE - if (item.data.activationepoch > currentEpoch.epoch) return ValidatorState.WAITING - if (item.data.lastattestationslot < (currentEpoch.epoch - 2) * 32) return ValidatorState.OFFLINE - // default case return ValidatorState.OFFLINE }