Skip to content

Commit

Permalink
Merge branch 'develop' into 'master'
Browse files Browse the repository at this point in the history
Develop

See merge request papers/tezblock/tezblock-frontend!398
  • Loading branch information
godenzim committed Feb 4, 2020
2 parents 45c80a2 + fb96f80 commit ba2f87e
Show file tree
Hide file tree
Showing 100 changed files with 3,281 additions and 1,021 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
23 changes: 18 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@
"@nguniversal/express-engine": "^8.0.0-rc.1",
"@nguniversal/module-map-ngfactory-loader": "^8.0.0-rc.1",
"@ngx-pwa/local-storage": "^8.2.3",
"@types/lodash": "^4.14.146",
"airgap-coin-lib": "0.6.3",
"airgap-coin-lib": "^0.7.0",
"angular-in-memory-web-api": "github:brandonroberts/in-memory-web-api-bazel#50a34d8",
"angularx-qrcode": "^1.6.4",
"big-number": "^2.0.0",
Expand All @@ -65,7 +64,7 @@
"browserify": "^16.2.3",
"canvas": "^2.5.0",
"chart.js": "^2.8.0",
"core-js": "^2.5.4",
"chartjs-plugin-piechart-outlabels": "^0.1.4",
"cryptocompare": "^1.0.0",
"lodash": "^4.17.15",
"moment": "^2.24.0",
Expand All @@ -86,6 +85,7 @@
"@angular/cli": "^8.0.2",
"@angular/compiler-cli": "^8.0.0",
"@angular/platform-server": "^8.0.0",
"@ngrx/schematics": "^8.6.0",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "^2.0.4",
"@types/lodash": "^4.14.149",
Expand Down
12 changes: 10 additions & 2 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,27 @@ import { BlockDetailComponent } from './pages/block-detail/block-detail.componen
import { DashboardComponent } from './pages/dashboard/dashboard.component'
import { EndorsementDetailComponent } from './pages/endorsement-detail/endorsement-detail.component'
import { ListComponent } from './pages/list/list.component'
import { TransactionDetailComponent } from './pages/transaction-detail/transaction-detail.component'
import { ProtocolConstantComponent } from './pages/protocol-constant/protocol-constant.component'
import { ResourcesWalletsComponent } from './pages/resources-wallets/resources-wallets.component'
import { TransactionDetailComponent } from './pages/transaction-detail/transaction-detail.component'
import { ProposalDetailComponent } from './pages/proposal-detail/proposal-detail.component'
import { ContractDetailComponent } from './pages/contract-detail/contract-detail.component'
import { BakerOverviewComponent } from './pages/baker-overview/baker-overview.component'
import { HealthComponent } from './pages/health/health.component'

const routes: Routes = [
{ path: '', component: DashboardComponent },
{ path: 'resources/wallets', component: ResourcesWalletsComponent },
{ path: 'baker/list', component: BakerOverviewComponent },
{ path: ':route/list', component: ListComponent },
{ path: 'block/:id', component: BlockDetailComponent },
{ path: 'account/:id', component: AccountDetailComponent },
{ path: 'transaction/:id', component: TransactionDetailComponent },
{ path: 'endorsement/:id', component: EndorsementDetailComponent },
{ path: 'proposal/:id', component: ProposalDetailComponent }
{ path: 'constants', component: ProtocolConstantComponent },
{ path: 'proposal/:id', component: ProposalDetailComponent },
{ path: 'contract/:id', component: ContractDetailComponent },
{ path: 'health', component: HealthComponent }
]

@NgModule({
Expand Down
10 changes: 10 additions & 0 deletions src/app/app.actions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { createAction, props } from '@ngrx/store'
import { NavigationEnd } from '@angular/router'

import { Block } from '@tezblock/interfaces/Block'

const featureName = 'App'

export const saveLatestRoute = createAction(`[${featureName}] Save Latest Route`, props<{ navigation: NavigationEnd }>())

export const loadLatestBlock = createAction(`[${featureName}] Load LatestBlock`)
export const loadLatestBlockSucceeded = createAction(`[${featureName}] Load LatestBlock Succeeded`, props<{ latestBlock: Block }>())
export const loadLatestBlockFailed = createAction(`[${featureName}] Load LatestBlock Failed`, props<{ error: any }>())

export const loadFirstBlockOfCycle = createAction(`[${featureName}] Load First Block Of Cycle`, props<{ cycle: number }>())
export const loadFirstBlockOfCycleSucceeded = createAction(`[${featureName}] Load First Block Of Cycle Succeeded`, props<{ firstBlockOfCycle: Block }>())
export const loadFirstBlockOfCycleFailed = createAction(`[${featureName}] Load First Block Of Cycle Failed`, props<{ error: any }>())
1 change: 1 addition & 0 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class AppComponent {
this.router.events
.pipe(filter(e => e instanceof NavigationEnd))
.subscribe(e => this.store$.dispatch(actions.saveLatestRoute({ navigation: <NavigationEnd>e })))
this.store$.dispatch(actions.loadLatestBlock())
}

public navigate(entity: string) {
Expand Down
25 changes: 0 additions & 25 deletions src/app/app.effects.spec.ts

This file was deleted.

94 changes: 92 additions & 2 deletions src/app/app.effects.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,97 @@
import { Injectable } from '@angular/core'
import { Actions, createEffect } from '@ngrx/effects'
import { Actions, createEffect, ofType } from '@ngrx/effects'
import { of, combineLatest } from 'rxjs'
import { catchError, map, switchMap, tap, filter } from 'rxjs/operators'
import { Store } from '@ngrx/store'
import { isNil, negate } from 'lodash'

import * as actions from './app.actions'
import { BaseService, Operation } from '@tezblock/services/base.service'
import { Block } from '@tezblock/interfaces/Block'
import { first } from '@tezblock/services/fp'
import * as fromRoot from '@tezblock/reducers'
import { CacheService, CacheKeys } from '@tezblock/services/cache/cache.service'

@Injectable()
export class AppEffects {
constructor(private actions$: Actions) {}
loadLatestBlock$ = createEffect(() =>
this.actions$.pipe(
ofType(actions.loadLatestBlock),
switchMap(() =>
// replacement for: apiService.getLatestBlocks
this.baseService
.post<Block[]>('blocks', {
orderBy: [
{
field: 'timestamp',
direction: 'desc'
}
],
limit: 1
})
.pipe(
map(first),
map(latestBlock => actions.loadLatestBlockSucceeded({ latestBlock })),
catchError(error => of(actions.loadLatestBlockFailed({ error })))
)
)
)
)

onCurrentCycleLoadFirstBlockOfCycle$ = createEffect(() =>
this.store$.select(fromRoot.app.currentCycle).pipe(
filter(negate(isNil)),
map(cycle => actions.loadFirstBlockOfCycle({ cycle }))
)
)

onCurrentCycleChaneResetCache$ = createEffect(
() =>
combineLatest(this.store$.select(fromRoot.app.currentCycle), this.cacheService.get(CacheKeys.fromCurrentCycle)).pipe(
filter(([currentCycle, cycleCache]) => currentCycle && (!cycleCache || (cycleCache && cycleCache.cycleNumber !== currentCycle))),
tap(([currentCycle, cycleCache]) => {
this.cacheService.set(CacheKeys.fromCurrentCycle, { cycleNumber: currentCycle }).subscribe(() => {})
})
),
{ dispatch: false }
)

loadFirstBlockOfCycle$ = createEffect(() =>
this.actions$.pipe(
ofType(actions.loadFirstBlockOfCycle),
switchMap(({ cycle }) =>
// replacement for: apiService.getCurrentCycleRange
this.baseService
.post<Block[]>('blocks', {
predicates: [
{
field: 'meta_cycle',
operation: Operation.eq,
set: [cycle],
inverse: false
}
],
orderBy: [
{
field: 'timestamp',
direction: 'asc'
}
],
limit: 1
})
.pipe(
map(first),
map(firstBlockOfCycle => actions.loadFirstBlockOfCycleSucceeded({ firstBlockOfCycle })),
catchError(error => of(actions.loadFirstBlockOfCycleFailed({ error })))
)
)
)
)

constructor(
private readonly actions$: Actions,
private readonly baseService: BaseService,
private readonly cacheService: CacheService,
private readonly store$: Store<fromRoot.State>
) {}
}
22 changes: 18 additions & 4 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,23 @@ import { BlockService } from './services/blocks/blocks.service'
import { ChainNetworkService } from './services/chain-network/chain-network.service'
import { ChartDataService } from './services/chartdata/chartdata.service'
import { CryptoPricesService } from './services/crypto-prices/crypto-prices.service'
import { HealthComponent } from './pages/health/health.component'
import { ListEffects } from './pages/list/effects'
import { AccountDetailEffects } from './pages/account-detail/effects'
import { BlockDetailEffects } from './pages/block-detail/effects'
import { TransactionDetailEffects } from './pages/transaction-detail/effects'
import { BakerTableEffects } from './components/baker-table/effects';
import { BakerTableEffects } from './components/baker-table/effects'
import { ContractDetailComponent } from './pages/contract-detail/contract-detail.component'
import { ContractDetailEffects } from './pages/contract-detail/effects'
import { OccurrenceStatisticsComponent } from './components/occurrence-statistics/occurrence-statistics.component'
import { ProposalDetailComponent } from './pages/proposal-detail/proposal-detail.component'
import { ProtocolConstantComponent } from './pages/protocol-constant/protocol-constant.component'
import { ProposalDetailEffects } from './pages/proposal-detail/effects'
import { TezblockTableComponent } from './components/tezblock-table/tezblock-table.component';
import { TezblockTableComponent } from './components/tezblock-table/tezblock-table.component'
import { ClientSideTableComponent } from './components/client-side-table/client-side-table.component'
import { BakerOverviewComponent } from './pages/baker-overview/baker-overview.component'
import { BakersEffects } from './pages/baker-overview/effects'
import { HealthEffects } from './pages/health/effects'

@NgModule({
imports: [
Expand Down Expand Up @@ -117,7 +124,10 @@ import { ClientSideTableComponent } from './components/client-side-table/client-
BakerTableEffects,
BlockDetailEffects,
TransactionDetailEffects,
ProposalDetailEffects
ProposalDetailEffects,
ContractDetailEffects,
BakersEffects,
HealthEffects
]),
StorageModule.forRoot({ IDBNoWrap: true })
],
Expand Down Expand Up @@ -157,12 +167,16 @@ import { ClientSideTableComponent } from './components/client-side-table/client-
ModalCellComponent,
EndorsementDetailComponent,
SearchItemComponent,
ProtocolConstantComponent,
ProposalDetailComponent,
TooltipItemComponent,
SearchItemComponent,
OccurrenceStatisticsComponent,
TezblockTableComponent,
ClientSideTableComponent
ClientSideTableComponent,
ContractDetailComponent,
BakerOverviewComponent,
HealthComponent
],

providers: [BakingService, BlockService, CryptoPricesService, ChartDataService, BsModalService, ChainNetworkService],
Expand Down
16 changes: 16 additions & 0 deletions src/app/app.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,35 @@ import { createReducer, on } from '@ngrx/store'
import { NavigationEnd } from '@angular/router'

import * as actions from './app.actions'
import { Block } from '@tezblock/interfaces/Block'

export interface State {
firstBlockOfCurrentCycle: Block,
latestBlock: Block,
navigationHistory: NavigationEnd[]
}

const initialState: State = {
firstBlockOfCurrentCycle: undefined,
latestBlock: undefined,
navigationHistory: []
}

export const reducer = createReducer(
initialState,
on(actions.loadFirstBlockOfCycleSucceeded, (state, { firstBlockOfCycle }) => ({
...state,
firstBlockOfCurrentCycle: firstBlockOfCycle
})),
on(actions.loadLatestBlockSucceeded, (state, { latestBlock }) => ({
...state,
latestBlock
})),
on(actions.saveLatestRoute, (state, { navigation }) => ({
...state,
navigationHistory: state.navigationHistory.concat(navigation)
}))
)

export const currentCycleSelector = (state: State): number => state.latestBlock ? state.latestBlock.meta_cycle : undefined
export const currentBlockLevelSelector = (state: State): number => state.latestBlock ? state.latestBlock.level : undefined
19 changes: 18 additions & 1 deletion src/app/components/address-item/address-item.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { Component, Input } from '@angular/core'
import { Router } from '@angular/router'

import { getContractByAddress } from '@tezblock/domain/contract'

@Component({
selector: 'address-item',
Expand Down Expand Up @@ -32,5 +35,19 @@ export class AddressItemComponent {
@Input()
isText: boolean

constructor() {}
constructor(private readonly router: Router) {}

public inspectDetail() {
if (!this.isText && this.clickableButton) {
const contract = getContractByAddress(this.address)

if (contract) {
this.router.navigate([`/contract/${this.address}`])

return
}

this.router.navigate([`/account/${this.address}`])
}
}
}
Loading

0 comments on commit ba2f87e

Please sign in to comment.