Skip to content

Instantly share code, notes, and snippets.

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(
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;
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 })),
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({
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',
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
};
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) => {
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;
}
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;
}
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 {