-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ngrx and fix the chart and search in token info
- Loading branch information
1 parent
55f021a
commit 0038295
Showing
14 changed files
with
447 additions
and
232 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
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { | ||
CanActivate, | ||
ActivatedRouteSnapshot, | ||
RouterStateSnapshot, | ||
Router | ||
} from '@angular/router'; | ||
import { Store } from '@ngrx/store'; | ||
import { Observable, of } from 'rxjs'; | ||
import { catchError, switchMap, take, tap } from 'rxjs/operators'; | ||
import * as CryptoActions from '../../wallet/store/actions/crypto.actions'; | ||
import { selectCryptoData } from '@app/wallet/store/selectors/crypto.selectors'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class CryptoDataGuard implements CanActivate { | ||
constructor(private store: Store, private router: Router) {} | ||
|
||
canActivate( | ||
route: ActivatedRouteSnapshot, | ||
state: RouterStateSnapshot | ||
): Observable<boolean> { | ||
return this.store.select(selectCryptoData).pipe( | ||
take(1), | ||
switchMap((cryptoData) => { | ||
if (cryptoData && cryptoData.length > 0) { | ||
|
||
return of(true); | ||
} else { | ||
|
||
this.store.dispatch(CryptoActions.loadCryptoData()); | ||
|
||
return of(true).pipe( | ||
catchError(() => { | ||
|
||
console.error('Failed to load crypto data.'); | ||
return of(false); | ||
}) | ||
); | ||
} | ||
}) | ||
); | ||
} | ||
} |
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,8 @@ | ||
export interface CryptoData { | ||
id: string; | ||
name: string; | ||
symbol: string; | ||
price: number; | ||
marketCap: number; | ||
} | ||
|
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.