Skip to content

Instantly share code, notes, and snippets.

public removePurchaseContract(productKey: string): Observable<string> {
const bytes32Key = utils.formatBytes32String(productKey);
const token = this.contractToken.removeContractByKey(bytes32Key);
return from(token)
.pipe(
switchMap((tx: any) => {
console.log('removeContractByKey Transaction', tx);
removeProduct$ = createEffect(
() =>
this.actions$.pipe(
ofType(PurchaseContractActions.removePurchaseContract),
map(payload => payload.key),
switchMap(key => {
const dialogConfig = new MatDialogConfig();
dialogConfig.width = '420px';
dialogConfig.disableClose = true;
reload$ = createEffect(
() =>
this.actions$.pipe(
ofType(
PurchaseContractActions.abortSelectedPurchaseContractSuccess,
PurchaseContractActions.confirmBuySuccess,
PurchaseContractActions.confirmDeliverySuccess,
PurchaseContractActions.releaseEscrowSuccess,
PurchaseContractActions.withdrawByOwnerSuccess),
withLatestFrom(
public abortPurchaseContract(contractAddress: string): Observable<string> {
const contract: Contract = new ethers.Contract(contractAddress, this.abi, this.provider.getSigner());
// Call the contract method, getting back the transaction tx
const token = contract.abortBySeller();
return from(token)
.pipe(
switchMap((tx: any) => {
console.log('abortBySeller Tx:', tx);
abortContract$ = createEffect(
() =>
this.actions$.pipe(
ofType(PurchaseContractActions.abortSelectedPurchaseContract),
withLatestFrom(
this.store$.pipe(select(fromStore.getSelectedPurchaseContract))),
switchMap(([action, contract]) => {
const dialogConfig = new MatDialogConfig();
dialogConfig.width = '420px';
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) =>
public loadPurchaseContract(contractAddress: string):
Observable<PurchaseContractModel> {
const contract: Contract =
new ethers.Contract(contractAddress, this.abi, this.provider.getSigner());
const crObservable: Observable<number | null> =
from(contract.commissionRate()).pipe(
map((commission: ethers.utils.BigNumber) => commission.toNumber()),
// only account with deployer or seller can retrieve this value,
@alexytiger
alexytiger / truffle-config.js
Last active February 20, 2020 00:54
e-book
const HDWalletProvider = require('@truffle/hdwallet-provider');
const { readFileSync } = require('fs');
const path = require('path');
module.exports = {
networks: {
ganache: {
host: "127.0.0.1",
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 })),
catchError((err: Error) =>
export class ViewPurchaseContractComponent implements OnInit, OnDestroy {
selectedPurchaseContract$: Observable<PurchaseContractModel>;
image$: Observable<Blob>;
constructor(
private store$: Store<fromStore.AppState>,
) { }
ngOnInit() {