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
| describe('products', async () => { | |
| let transaction, productCount; | |
| before(async () => { | |
| const bytes32Key = web3.utils.fromAscii('sportBikeModelX01'); | |
| const wei = web3.utils.toWei('1.4', 'Ether'); | |
| transaction = await contractInstance.createPurchaseContract(bytes32Key, 'Sport bike', 'ipfsHash001', { | |
| from: seller, | |
| value: wei |
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
| @Injectable({ | |
| providedIn: P2pBazaarAnchorModule | |
| }) | |
| export class ProductsLoadedGuard implements CanActivate { | |
| constructor(private store: Store<fromStore.AppState>) {} | |
| canActivate(): Observable<boolean> { | |
| return this.waitForProductsToLoad().pipe( | |
| switchMap(() => of(true)), | |
| catchError(() => of(false)) |
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 })), | |
| catchError((err: Error) => | |
| of(ErrorActions.errorMessage({ errorMsg: err.message }), |
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 | |
| }; |
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
| this.selectedPurchaseContract$ = this.store$.pipe( | |
| select(fromStore.getSelectedProduct), | |
| filter(product => !!product), | |
| tap(product => this.store$.dispatch(PurchaseContractActions.loadPurchaseContract({ address: product.contractAddress }))), | |
| // we switch from one observable to another | |
| switchMap(() => this.store$.select(fromStore.getSelectedPurchaseContract)), | |
| filter(contract => !!contract), | |
| ); |
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 routes: Routes = [ | |
| { | |
| path: '', | |
| redirectTo: 'products', | |
| pathMatch: 'full', | |
| }, | |
| { | |
| path: 'products', | |
| component: fromComponents.MarketplaceHomeComponent, |
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
| loadPurchaseContract$ = createEffect( | |
| () => | |
| this.actions$.pipe( | |
| ofType(PurchaseContractActions.loadPurchaseContract), | |
| map(action => action.address), | |
| switchMap(address => { | |
| return this.purchaseSrv.loadPurchaseContract(address).pipe( | |
| map(contract => | |
| PurchaseContractActions.loadPurchaseContractSuccess({ contract })), |
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
| public loadPurchaseContract(contractAddress: string): Observable<PurchaseContractModel> { | |
| const contract: Contract = new ethers.Contract(contractAddress, this.abi, this.provider.getSigner()); | |
| return zip( | |
| from(contract.key()), | |
| from(contract.seller()), | |
| from(contract.buyer()), | |
| from(contract.price()), | |
| from(contract.balanceOf()), | |
| from(contract.title()), |
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
| this.image$ = this.store$.pipe( | |
| select(fromStore.getSelectedPurchaseContract), | |
| filter(contract => !!contract), | |
| tap(contract => | |
| this.store$.dispatch(IpfsImageActions.download_image({ ipfsHash: contract.ipfsHash })) | |
| ), | |
| // we switch to another observable | |
| switchMap(() => this.store$.select(fromStore.getImageBlob)), | |
| filter(image => !!image) | |
| ); |