This file contains hidden or 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
ngAfterViewInit() { | |
const products$ = this.store$.pipe(select(fromStore.getAllProducts)); | |
const filter$ = fromEvent(this.contractKey.nativeElement, 'keyup').pipe( | |
map(event => this.contractKey.nativeElement.value), | |
startWith(''), | |
debounceTime(150), | |
distinctUntilChanged()); | |
this.filteredProducts$ = combineLatest([products$, filter$]).pipe( |
This file contains hidden or 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
private widgetObservable = (id: number): Observable<PurchaseWidgetModel> => | |
from(this.contractToken.getContractKeyAtIndex(id)).pipe( | |
switchMap(key => from(this.contractToken.getContractByKey(key)).pipe( | |
map(address => { | |
const widget: PurchaseWidgetModel = { | |
productKey: utils.parseBytes32String(key as ethers.utils.Arrayish), | |
contractAddress: address as string | |
}; | |
return widget; |
This file contains hidden or 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
loadProducts$ = createEffect(() => | |
this.actions$.pipe( | |
ofType(PurchaseContractActions.loadProducts), | |
switchMap(() => | |
this.fleaSrv.getPurchaseContractList().pipe( | |
tap(products => | |
console.log('purchase contracts:', products)), | |
map(products => | |
PurchaseContractActions.loadProductsSuccess({ products })), |
This file contains hidden or 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
import { Injectable } from '@angular/core'; | |
import { CanActivate } from '@angular/router'; | |
import { Store, select } from '@ngrx/store'; | |
import { Observable, of } from 'rxjs'; | |
import { take, tap, filter, switchMap, catchError } from 'rxjs/operators'; | |
import { MarketPlaceAnchorModule } from '../market-place-anchor.module'; | |
import * as fromStore from '../store/reducers'; | |
import { PurchaseContractActions } from '../store/actions'; | |
@Injectable({ |
This file contains hidden or 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
import { NgModule } from '@angular/core'; | |
import { RouterModule, Routes } from '@angular/router'; | |
import * as fromContainers from './containers'; | |
import * as fromComponents from './components'; | |
import * as guards from './guards'; | |
const routes: Routes = [ | |
{ | |
path: '', | |
redirectTo: 'products', |
This file contains hidden or 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
showSnackbarOnCreateContract$ = createEffect(() => | |
this.actions$.pipe( | |
ofType(PurchaseContractActions.createPurchaseContractSuccess), | |
map((payload) => { | |
const msg: SnackBarInterface = { | |
message: `New smart product contract has been created successfully: Address: ${payload.product.contractAddress}`, | |
color: AppearanceColor.Success | |
}; |
This file contains hidden or 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
createProduct$ = createEffect( | |
() => | |
this.actions$.pipe( | |
ofType(PurchaseContractActions.createPurchaseContract), | |
map(action => action.payload), | |
exhaustMap((payload) => { | |
return this.fleaSrv.createPurchaseContract(payload).pipe( | |
tap(address => console.log('Contract address: ', address)), | |
switchMap((address: string) => { |
This file contains hidden or 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
import {createSelector, createFeatureSelector, Action, combineReducers} | |
from '@ngrx/store'; | |
import * as fromRoot from '../../../core/store/reducers'; | |
import * as fromIpfs from './ipfs-product-image.reducer'; | |
import * as fromProducts from './purchase-contract.reducer'; | |
export interface PurchaseContractState { | |
ipfs: fromIpfs.State; | |
products: fromProducts.State; | |
} |
This file contains hidden or 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
import { createEntityAdapter, EntityAdapter, EntityState } from '@ngrx/entity'; | |
import { createReducer, on } from '@ngrx/store'; | |
import { PurchaseWidgetModel, PurchaseContractModel } from '../../models'; | |
import { PurchaseContractActions } from '../actions'; | |
export interface State extends EntityState<PurchaseWidgetModel> { | |
loaded: boolean; | |
selectedPurchaseContract: PurchaseContractModel; | |
} |
This file contains hidden or 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
import { Injectable } from '@angular/core'; | |
import { MarketPlaceAnchorModule } from '../market-place-anchor.module'; | |
import { FleaMarketContractToken } from './tokens/flea-market-contract-token'; | |
import { Observable, from, of, forkJoin } from 'rxjs'; | |
import { map, tap, switchMap, mergeMap, exhaustMap } from 'rxjs/operators'; | |
import { ethers, utils } from 'ethers'; | |
import { PurchaseWidgetModel } from '../models'; | |
@Injectable({ providedIn: MarketPlaceAnchorModule }) | |
export class FleaMarketContractService { |