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 { Actions, ofType, createEffect } from '@ngrx/effects'; | |
import { tap, map } from 'rxjs/operators'; | |
import { ErrorActions } from '../actions'; | |
@Injectable() | |
export class ErrorEffects { | |
constructor(private readonly actions$: Actions) {} | |
handleError$ = createEffect( |
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 const reducers: ActionReducerMap<AppState> = { | |
router: routerReducer, | |
spinner: fromSpinner.reducer, | |
error: fromError.reducer, | |
web3Provider: fromWeb3Provider.reducer, | |
}; |
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, InjectionToken, Inject } from '@angular/core'; | |
import { providers } from 'ethers'; | |
export const MetamaskWeb3Provider = new InjectionToken('Metamask Web3 provider', { | |
providedIn: 'root', | |
factory: () => (window as any).ethereum | |
}); | |
@Injectable({ providedIn: 'root' }) | |
export class Provider extends providers.Web3Provider { |
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, Inject } from '@angular/core'; | |
import { Actions, ofType, createEffect } from '@ngrx/effects'; | |
import { of, from, EMPTY as empty } from 'rxjs'; | |
import { exhaustMap, switchMap, map, tap, catchError } from 'rxjs/operators'; | |
import { MetamaskWeb3Provider } from '../../services/tokens'; | |
import { ProviderService } from '../../services/provider.services'; | |
import { Web3ProviderActions, SpinnerActions, ErrorActions } from '../actions'; |
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 Web3ProviderState { | |
metamaskEnable: boolean; | |
account: string; | |
balance: 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 { 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 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 const init = createAction('[Web3/Provider] Init'); | |
export const initSuccess = createAction('[Web3/Provider] Init Success'); | |
export const account = createAction('[Web3/Provider] Account', props<{ address: string }>()); | |
export const balance = createAction('[Web3/Provider] Balance'); | |
export const balanceSuccess = createAction('[Web3/Provider] Balance Success', props<{ balance: 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 { Injectable, Inject } from '@angular/core'; | |
import { Actions, ofType, createEffect } from '@ngrx/effects'; | |
import { of, from, EMPTY as empty } from 'rxjs'; | |
import { exhaustMap, switchMap, map, tap, catchError } from 'rxjs/operators'; | |
import { MetamaskWeb3Provider } from '../../services/tokens'; | |
import { ProviderService } from '../../services/provider.services'; | |
import { Web3ProviderActions, SpinnerActions, ErrorActions } from '../actions'; |
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, Inject } from '@angular/core'; | |
import { Observable, of, from } from 'rxjs'; | |
import { map, tap, catchError } from 'rxjs/operators'; | |
import { Provider } from './tokens'; | |
import { ethers, Signer } from 'ethers'; | |
@Injectable({ | |
providedIn: 'root' | |
}) |
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 const ipfsToken = new InjectionToken('The IPFS Token', { | |
providedIn: 'root', | |
factory: () => { | |
try { | |
return new (window as any).IpfsHttpClient('ipfs.infura.io', '5001', { | |
protocol: 'https' | |
}); | |
} catch (err) { | |
console.log('Error', err); | |
throw new Error('Unable to access IPFS node daemon on Infura network'); |