Skip to content

Commit

Permalink
refactoring for gnosis, fix rpl collateral
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelsc committed Oct 16, 2023
1 parent 0e150b1 commit b690356
Show file tree
Hide file tree
Showing 24 changed files with 181 additions and 99 deletions.
8 changes: 7 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json"
},
"plugins": [
"@typescript-eslint"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
]
],
"rules": {
"@typescript-eslint/await-thenable": "error"
}
}
9 changes: 8 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* // along with Beaconchain Dashboard. If not, see <http://www.gnu.org/licenses/>.
*/

import { NgModule } from '@angular/core'
import { APP_INITIALIZER, NgModule } from '@angular/core'
import { BrowserModule, HammerModule } from '@angular/platform-browser'
import { RouteReuseStrategy } from '@angular/router'

Expand All @@ -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
Expand Down Expand Up @@ -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],
})
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/block/block.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/dashboard/dashboard.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@
<ion-list class="performances">
<ion-item lines="none" (click)="openBrowser()">
<ion-icon slot="end" name="open-outline"></ion-icon>
<ion-label class="stat-title"> View on beaconcha.in </ion-label>
<ion-label class="stat-title"> View on {{ api.getHostName() }} </ion-label>
</ion-item>
</ion-list>
<div class="bottomFiller"></div>
Expand Down
17 changes: 8 additions & 9 deletions src/app/components/dashboard/dashboard.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -866,16 +870,11 @@ export class DashboardComponent implements OnInit {

async getBrowserURL(): Promise<string> {
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) {
Expand Down
29 changes: 24 additions & 5 deletions src/app/components/help/help.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@

<ion-item lines="none" (click)="login()" *ngIf="!isAlreadyLoggedIn">
<ion-icon slot="start" name="log-in-outline"></ion-icon>
<ion-label>Or login with beaconcha.in</ion-label>
<ion-label>Or login with {{ api.getHostName() }} </ion-label>
</ion-item>
</ion-list>

<ion-list-header class="first-item-group">
<ion-label>Guides & Help</ion-label>
</ion-list-header>

<ion-list>
<ion-list *ngIf="!api.isGnosis; else gnosisFAQ">
<ion-item lines="none" (click)="openBrowser('https://launchpad.ethereum.org/faq')">
<ion-icon slot="start" name="bulb-outline"></ion-icon>
<ion-label>Staking Guide & FAQ</ion-label>
Expand All @@ -61,11 +61,23 @@
</ion-item>
</ion-list>

<ion-list #gnosisFAQ>
<ion-item lines="none" (click)="openBrowser('https://docs.gnosischain.com/node/')">
<ion-icon slot="start" name="bulb-outline"></ion-icon>
<ion-label>Node Guide & FAQ</ion-label>
</ion-item>

<ion-item lines="none" (click)="openBrowser('https://docs.gnosischain.com/node/management/withdrawals')">
<ion-icon slot="start" name="bulb-outline"></ion-icon>
<ion-label>Enable Withdrawals Guide</ion-label>
</ion-item>
</ion-list>

<ion-list-header>
<ion-label>How to set up a Validator</ion-label>
</ion-list-header>

<ion-list>
<ion-list *ngIf="!api.isGnosis; else gnosisSetupGuides">
<ion-item lines="none" (click)="openBrowser('https://someresat.medium.com/guide-to-staking-on-ethereum-ubuntu-lighthouse-773f5d982e03')">
<ion-icon slot="start" name="bulb-outline"></ion-icon>
<ion-label>Setup Guide for Lighthouse</ion-label>
Expand All @@ -92,13 +104,20 @@
</ion-item>
</ion-list>

<ion-list #gnosisSetupGuides>
<ion-item lines="none" (click)="openBrowser('https://docs.gnosischain.com/node/manual/')">
<ion-icon slot="start" name="bulb-outline"></ion-icon>
<ion-label>Interactive Setup Guide</ion-label>
</ion-item>
</ion-list>

<ion-list-header>
<ion-label>Useful Links</ion-label>
</ion-list-header>
<ion-list>
<ion-item lines="none" (click)="openBrowser('https://beaconcha.in')">
<ion-item lines="none" (click)="openBrowser('https://' + api.getHostName())">
<ion-icon slot="start" name="cube-outline"></ion-icon>
<ion-label>beaconcha.in Block Explorer</ion-label>
<ion-label>{{ api.getHostName() }} Block Explorer</ion-label>
</ion-item>

<ion-item lines="none" (click)="openBrowser('https://reddit.com/r/ethstaker')">
Expand Down
9 changes: 8 additions & 1 deletion src/app/components/help/help.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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) => {
Expand Down
8 changes: 8 additions & 0 deletions src/app/models/StorageTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 2 additions & 7 deletions src/app/pages/block-detail/block-detail.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
2 changes: 1 addition & 1 deletion src/app/pages/notifications/notifications.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<ion-content>
<div class="notificationnote" *ngIf="noGoogle" (click)="configureWebhooks()">
<strong>Note: </strong>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.
</div>

<ion-list-header>
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/notifications/notifications.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
8 changes: 5 additions & 3 deletions src/app/pages/subscribe/subscribe.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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]
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
Loading

0 comments on commit b690356

Please sign in to comment.