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 { P2pBazaarAnchorModule } from '../p2p-bazaar.anchor.module'; | |
| import { Provider } from '../../core/services/tokens'; | |
| import { Observable, from, of, zip } from 'rxjs'; | |
| import { map, tap, switchMap } from 'rxjs/operators'; | |
| import { ethers, Contract, utils } from 'ethers'; | |
| import { PurchaseContractModel, ContractState} from '../models'; | |
| @Injectable({ providedIn: P2pBazaarAnchorModule }) | |
| export class PurchaseContractService { | 
  
    
      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
    
  
  
    
  | export enum ContractState{ | |
| 'Created' = 0, | |
| 'Locked', | |
| 'Inactive' | |
| }; | |
| export interface PurchaseContractModel { | |
| productKey: string; | |
| contractAddress: string; | |
| sellerAddress: 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 * as fromRoot from '../../../core/store/reducers'; | |
| import * as fromIpfsUpload from './ipfs-upload.reducer'; | |
| import * as fromProducts from './purchase-contract.reducer'; | |
| export interface PurchaseContractState { | |
| ipfsUpload: fromIpfsUpload.State; | |
| products: fromProducts.State | |
| } | |
| export interface AppState extends fromRoot.AppState { | 
  
    
      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
    
  
  
    
  | 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
    
  
  
    
  | addProduct$ = createEffect(() => | |
| this.actions$.pipe( | |
| ofType(PurchaseContractActions.createPurchaseContractSuccess), | |
| switchMap((payload) => { | |
| return this.productSrv.loadPurchaseContract(payload.address).pipe( | |
| tap(product => console.log('purchase contract:', product)), | |
| map(product => PurchaseContractActions.addProduct({product})), | |
| catchError((err: Error) => | 
  
    
      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
    
  
  
    
  | export interface PurchaseWidgetModel { | |
| productKey: string; | |
| contractAddress: 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
    
  
  
    
  | pragma solidity 0.5.11; | |
| import "./HitchensUnorderedKeySet.sol"; | |
| contract FleaMarket { | |
| using HitchensUnorderedKeySetLib for HitchensUnorderedKeySetLib.Set; | |
| HitchensUnorderedKeySetLib.Set widgetSet; | |
| struct WidgetStruct { | |
| address contractAddress; | 
  
    
      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
    
  
  
    
  | compilers: { | |
| solc: { | |
| version: "0.5.11", | |
| // docker: true, | |
| settings: { | |
| optimizer: { | |
| enabled: true, | |
| runs: 200 | |
| }, | |
| } | 
  
    
      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
    
  
  
    
  | const FleaMarket = artifacts.require("../contracts/FleaMarket"); | |
| const SafeRemotePurchase = artifacts.require("../build/contracts/SafeRemotePurchase"); | |
| var BN = web3.utils.BN; | |
| var chai = require('chai'); | |
| var chaiAsPromised = require('chai-as-promised'); | |
| chai.use(chaiAsPromised).should(); | |
| contract("FleaMarket", accounts => { |