This file contains 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 { createEffect } from '@ngrx/effects'; | |
import { tap, map } from 'rxjs/operators'; | |
import * as fromStore from '../reducers'; | |
import { Store, select } from '@ngrx/store'; | |
import { SpinnerOverlayService } from '../../services/spinner-overlay.service'; | |
@Injectable() | |
export class SpinnerEffects { |
This file contains 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 { Overlay, OverlayRef } from '@angular/cdk/overlay'; | |
import { ComponentPortal } from '@angular/cdk/portal'; | |
import { MatSpinner } from '@angular/material'; | |
import { Observable, Subject } from 'rxjs'; | |
import { scan, map, distinctUntilChanged } from 'rxjs/operators'; | |
@Injectable({ | |
providedIn: 'root', |
This file contains 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 { 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 * as fromRoot from '../store'; | |
@Injectable({ | |
providedIn: 'root', | |
}) |
This file contains 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
metaMaskEnabled$ = createEffect(() => | |
this.actions$.pipe( | |
ofType(ROOT_EFFECTS_INIT), | |
map(() => { | |
const ethereum = (window as any).ethereum; | |
// Returns true or false, representing whether the user has MetaMask installed. | |
if (!ethereum || !ethereum.isMetaMask) { | |
return ErrorActions.errorMessage({ errorMsg: `Please install MetaMask.` }); | |
} |
This file contains 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
accountChanged$ = createEffect( | |
() => | |
fromEvent(this.web3Token, 'accountsChanged').pipe( | |
withLatestFrom(this.store$.pipe(select(fromStore.getAccount))), | |
filter(([accounts, currentAccount]) => !!currentAccount && (currentAccount !== accounts[0])), | |
map(([accounts, currentAccount]) => { | |
console.log('new account', accounts[0]); | |
// to reload browser | |
// based onhttps://medium.com/metamask/no-longer-reloading-pages-on-network-change-fbf041942b44 | |
this.document.location.reload(); |
This file contains 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
getAccountInfo$ = createEffect(() => | |
this.actions$.pipe( | |
ofType(Web3ProviderActions.metamaskConnectSuccess), | |
switchMap(() => { | |
return [Web3ProviderActions.getNetwork(), Web3ProviderActions.getAddress(), Web3ProviderActions.getBalance()]; | |
}) | |
) | |
); | |
getAddress$ = createEffect(() => |
This file contains 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 confirmDelivery(contractAddress: string): Observable<string> { | |
const contract: Contract = new ethers.Contract(contractAddress, | |
this.abi, this.provider.getSigner()); | |
const token = contract.buyerConfirmReceived(); | |
return from(token) | |
.pipe( | |
switchMap((tx: any) => { |
This file contains 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
confirmDelivery$ = createEffect( | |
() => | |
this.actions$.pipe( | |
ofType(PurchaseContractActions.confirmDelivery), | |
withLatestFrom(this.store$.pipe(select(fromStore.getSelectedPurchaseContract))), | |
switchMap(([payload, contract]) => { | |
const dialogConfig = new MatDialogConfig(); | |
dialogConfig.width = '420px'; | |
dialogConfig.disableClose = true; |
This file contains 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 confirmPurchase(contractAddress: string, | |
etherValue: string): Observable<string> { | |
const contract: Contract = | |
new ethers.Contract(contractAddress, this.abi, | |
this.provider.getSigner()); | |
const wei = utils.parseEther(etherValue); | |
const token = contract.buyerPurchase({ | |
value: wei |
This file contains 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
confirmBuy$ = createEffect( | |
() => | |
this.actions$.pipe( | |
ofType(PurchaseContractActions.confirmBuy), | |
withLatestFrom( | |
this.store$.pipe(select(fromStore.getSelectedPurchaseContract))), | |
switchMap(([payload, contract]) => { | |
const dialogConfig = new MatDialogConfig(); | |
dialogConfig.width = '420px'; |
NewerOlder