Skip to content

Instantly share code, notes, and snippets.

import { Injectable } from '@angular/core';
import { Contract } from 'ethers';
import { EthersWeb3Provider } from '../../../core/services/ethers-web3-provider';
import { MarketPlaceAnchorModule } from '../../market-place-anchor.module';
import { environment } from 'src/environments/environment';
const FLEA_MARKET_CONTRACT_ADDRESS = environment.fleaMarketContractAddress;
const abi = [
'event LogCreatePurchaseContract(address sender, address contractAddress)',
'event LogRemovePurchaseContract(address sender, bytes32 key)',
downloadImage$ = createEffect(
() =>
this.actions$.pipe(
ofType(IpfsImageActions.downloadImage),
map((action) => action.ipfsHash),
switchMap((ipfsHash: string) =>
this.ipfsSrv.getFile(ipfsHash).pipe(
map((image: Blob) => IpfsImageActions.downloadImageSuccess({ image })),
catchError((err: Error) =>
of(this.handleError(err), IpfsImageActions.downloadImageError())
import { ChangeDetectionStrategy, Component, Inject, OnInit, ViewChild , ElementRef } from '@angular/core';
import { MatDialogRef } from '@angular/material';
import { windowRefToken } from '../../../core/services/tokens';
import { Observable } from 'rxjs';
import { withLatestFrom, map, tap, filter, take } from 'rxjs/operators';
import { Store, select } from '@ngrx/store';
import * as fromPurchaseContract from '../../store/reducers';
import * as IpfsActions from '../../store/actions/ipfs-product-image.actions';
@Component({
export enum FileUploadStatus {
Pending = 'Pending',
Success = 'Success',
Error = 'Error',
Progress = 'Progress',
}
export interface State {
status: FileUploadStatus;
ipfsHash: string | null;
uploadImage$ = createEffect(
() =>
this.actions$.pipe(
ofType(IpfsImageActions.uploadImage),
map(action => action.file),
exhaustMap((file) => {
return this.ipfsSrv.addFile(file).pipe(
tap(ipfsHash => console.log(`IPFS file hash: ${ipfsHash}`)),
map(ipfsHash => IpfsImageActions.uploadImageSuccess({ ipfsHash })),
import { Component, ViewChild, ElementRef, OnInit, OnDestroy }
from '@angular/core';
import { FormBuilder, FormGroup, Validators, AbstractControl }
from '@angular/forms';
import { MatDialog, MatDialogConfig } from '@angular/material';
import { Observable } from 'rxjs';
import { tap } from 'rxjs/operators';
import { utils } from 'ethers';
import { Store, select } from '@ngrx/store';
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { DashboardComponent } from './core/components/dashboard/dashboard.component';
import { NotFoundPageComponent } from './core/containers/not-found-page.component';
import * as guards from './core/guards';
export const routes: Routes = [
{ path: '', redirectTo: '/dashboard', pathMatch: 'full' },
{
import { Injectable } from '@angular/core';
import { Actions, ofType, createEffect, ROOT_EFFECTS_INIT } from '@ngrx/effects';
import { serializeError } from 'serialize-error';
import { of } from 'rxjs';
import { switchMap, map, tap, catchError } from 'rxjs/operators';
import { IpfsDaemonService } from '../../services/ipfs-daemon.services';
import { IpfsDaemonActions, ErrorActions } from '../actions';
@Injectable()
const path = require('path');
module.exports = {
node: {
crypto: true,
path: true,
os: true,
stream: true,
buffer: true,
},
import { Injectable, Inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, from, empty } from 'rxjs';
import { switchMap, map, tap } from 'rxjs/operators';
import { ipfsToken } from './tokens';
@Injectable({
providedIn: 'root'
})
export class IpfsDaemonService {