import { Injectable } from '@angular/core' ; import { Router , CanActivate , ActivatedRouteSnapshot , RouterStateSnapshot } from '@angular/router' ; import { Observable } from 'rxjs/Observable' ; import 'rxjs/add/operator/do' ; import 'rxjs/add/operator/first' ; import { KudosTokenFactoryService } from '../kudos-token-factory.service' ; @ Injectable ( ) export class IsTokenGuard implements CanActivate { constructor ( private kudosTokenFactoryService , private router ) { } canActivate ( next , state ) { const tokenAddress = next . params . tokenAddress || next . parent . params . tokenAddress ; const kudosTokenService = this . kudosTokenFactoryService . getKudosTokenServiceAt ( tokenAddress ) ; return kudosTokenService . onIsValid . first ( ) . do ( isValid => { if ( ! isValid ) { this . router . navigate ( [ '/' ] ) ; } } ) ; } }