-
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.
i add the ngrx for crypto market in token info
- Loading branch information
1 parent
8b2735b
commit f34883f
Showing
16 changed files
with
445 additions
and
230 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
12 changes: 12 additions & 0 deletions
12
src/app/core/store/crypto-prices/actions/crypto.actions.ts
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,12 @@ | ||
import { createAction, props } from '@ngrx/store'; | ||
|
||
export const fetchCryptoPriceList = createAction('[Crypto] Fetch Price List'); | ||
export const fetchCryptoPriceListSuccess = createAction( | ||
'[Crypto] Fetch Price List Success', | ||
props<{ cryptoPriceList: any }>() | ||
); | ||
|
||
export const fetchCryptoPriceListFailure = createAction( | ||
'[Crypto] Fetch Price List Failure', | ||
props<{ error: any }>() | ||
); |
31 changes: 31 additions & 0 deletions
31
src/app/core/store/crypto-prices/effects/crypto.effects.ts
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,31 @@ | ||
import { map, catchError, mergeMap, tap } from 'rxjs/operators'; | ||
import * as CryptoActions from '../actions/crypto.actions'; | ||
import { Actions, createEffect, ofType } from '@ngrx/effects'; | ||
import { WalletFacadeService } from '@app/core/facades/wallet-facade.service'; | ||
import { Injectable } from '@angular/core'; | ||
import { of } from 'rxjs'; | ||
|
||
@Injectable() | ||
export class CryptoEffectsList { | ||
constructor( | ||
private actions$: Actions, | ||
private walletFacadeService: WalletFacadeService | ||
) {} | ||
|
||
fetchCryptoPriceList$ = createEffect(() => | ||
this.actions$.pipe( | ||
ofType(CryptoActions.fetchCryptoPriceList), | ||
// tap(() => console.log('fetchCryptoPriceList action dispatched')), | ||
mergeMap(() => | ||
this.walletFacadeService.getCryptoPriceList().pipe( | ||
map((cryptoPriceList) => | ||
CryptoActions.fetchCryptoPriceListSuccess({ cryptoPriceList }) | ||
), | ||
catchError((error) => { | ||
return of(CryptoActions.fetchCryptoPriceListFailure({ error })); | ||
}) | ||
) | ||
) | ||
) | ||
); | ||
} |
31 changes: 31 additions & 0 deletions
31
src/app/core/store/crypto-prices/reducer/crypto.reducer.ts
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,31 @@ | ||
import { createReducer, on } from '@ngrx/store'; | ||
import * as CryptoActions from '../actions/crypto.actions'; | ||
|
||
export interface CryptoState { | ||
cryptoPriceList: any[] | null; | ||
error: any | null; | ||
} | ||
|
||
export const initialState: CryptoState = { | ||
cryptoPriceList: null, | ||
error: null | ||
}; | ||
|
||
export const cryptoReducerList = createReducer( | ||
initialState, | ||
on( | ||
CryptoActions.fetchCryptoPriceListSuccess, | ||
(state, { cryptoPriceList }) => { | ||
return { | ||
...state, | ||
cryptoPriceList, | ||
error: null, | ||
}; | ||
} | ||
), | ||
on(CryptoActions.fetchCryptoPriceListFailure, (state, { error }) => ({ | ||
...state, | ||
cryptoPriceList: null, | ||
error | ||
})) | ||
); |
9 changes: 9 additions & 0 deletions
9
src/app/core/store/crypto-prices/selectors/crypto.selectors.ts
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,9 @@ | ||
import { createSelector, createFeatureSelector } from '@ngrx/store'; | ||
import { CryptoState } from '../reducer/crypto.reducer'; | ||
|
||
const selectCryptoState = createFeatureSelector<CryptoState>('cryptoPriceList'); | ||
|
||
export const selectCryptoPriceList = createSelector( | ||
selectCryptoState, | ||
(state) => state.cryptoPriceList | ||
); |
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,16 @@ | ||
import { Injectable } from '@angular/core'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class SharedDataService { | ||
private cryptoDetails: any = []; | ||
|
||
setCryptoDetails(data: any): void { | ||
this.cryptoDetails = data; | ||
} | ||
|
||
getCryptoDetails(): any { | ||
return this.cryptoDetails; | ||
} | ||
} |
Oops, something went wrong.