-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into 'master'
Develop See merge request papers/tezblock/tezblock-frontend!398
- Loading branch information
Showing
100 changed files
with
3,281 additions
and
1,021 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }>()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.