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 { NgModule, ModuleWithProviders, Type } from '@angular/core'; | |
import { CommonModule } from '@angular/common'; | |
// Web3 | |
import { WEB3 } from './tokens'; | |
const Web3 = require('web3'); | |
// Services | |
import { AccountsService } from './eth.services'; | |
@NgModule({ |
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
/** Return the list of accounts available */ | |
public getAccounts(): Observable<string[]> { | |
return fromPromise(this.web3.eth.getAccounts()); | |
} |
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
/** Get the current account */ | |
public currentAccount(): Observable<string | Error> { | |
if (this.web3.eth.defaultAccount) { | |
return of(this.web3.eth.defaultAccount); | |
} else { | |
return this.getAccounts().pipe( | |
tap((accounts: string[]) => { | |
if (accounts.length === 0) { throw new Error('No accounts available'); } | |
}), | |
map((accounts: string[]) => accounts[0]), |
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, Inject } from '@angular/core'; | |
// Web3 | |
import { WEB3 } from './tokens'; | |
import Web3 from 'web3'; | |
// RXJS | |
import { Observable } from 'rxjs/Observable'; | |
import { bindNodeCallback } from 'rxjs/observable/bindNodeCallback'; | |
import { of } from 'rxjs/observable/of'; | |
import { map, tap, catchError } from 'rxjs/operators'; |
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 { InjectionToken } from '@angular/core'; | |
import Web3 from ‘web3’; | |
export const WEB3 = new InjectionToken<Web3>('web3'); |
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 { Component, OnInit } from '@angular/core'; | |
import { EthService } from './ethereum/eth.service'; | |
@Component({ | |
selector: 'app-root', | |
template: '<p>Current Account: {{address$ | async}}', | |
styles: [] | |
}) | |
export class AppComponent implements OnInit { | |
public address$: Observable<string>; |
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 { Component, OnInit, OnDestroy, NgZone } from '@angular/core'; | |
import { EthService } from './ethereum/eth.service'; | |
@Component({ | |
selector: 'app-root', | |
template: '<p>Current Account: {{ address }}', | |
styles: [] | |
}) | |
export class AppComponent implements OnInit, OnDestroy { | |
public address: string; |
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 { NgModule } from '@angular/core'; | |
import { CommonModule } from '@angular/common'; | |
import { environment } from './../../environments/environment'; | |
// Web3 | |
import { WEB3 } from './tokens'; | |
const Web3 = require('web3'); | |
// Services | |
import { AccountsService } from './eth.services'; |
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 { Action } from '@ngrx/store'; | |
/** | |
* TYPES | |
*/ | |
export const GET_ACCOUNTS = '[Eth] Get Accounts'; | |
export const GET_ACCOUNTS_SUCCESS = '[Eth] Get Accounts Success'; | |
export const SELECT_ACCOUNT = '[Eth] Select Account'; |
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 { GET_ACCOUNTS_SUCCESS, SELECT_ACCOUNT, AccountsActions } from './eth.actions'; | |
export interface State { | |
selected: string, | |
accounts: string[] | |
} | |
const initialState: State = { | |
selected: null, | |
accounts: [] |
OlderNewer