diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 95a81c7..2a47765 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -1,6 +1,7 @@ import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; +import { MetamaskNotAllowedNetworkComponent } from './metamask-not-allowed-network'; import { MetamaskNotInstalledComponent } from './metamask-not-installed'; import { MetamaskNotLoggedInComponent } from './metamask-not-logged-in'; import { PageNotFoundComponent } from './page-not-found'; @@ -11,6 +12,10 @@ const routes: Routes = [ redirectTo: '/dashboard/home', pathMatch: 'full' }, + { + path: 'metamask-not-allowed-network', + component: MetamaskNotAllowedNetworkComponent + }, { path: 'metamask-not-installed', component: MetamaskNotInstalledComponent diff --git a/src/app/app.module.ts b/src/app/app.module.ts index f9f266f..866fb5a 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -7,6 +7,7 @@ import { MessageService } from 'primeng/api'; import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; import { DashboardModule } from './dashboard'; +import { MetamaskNotAllowedNetworkComponent } from './metamask-not-allowed-network'; import { MetamaskNotInstalledComponent } from './metamask-not-installed'; import { MetamaskNotLoggedInComponent } from './metamask-not-logged-in'; import { PageNotFoundComponent } from './page-not-found'; @@ -14,6 +15,7 @@ import { PageNotFoundComponent } from './page-not-found'; @NgModule({ declarations: [ AppComponent, + MetamaskNotAllowedNetworkComponent, MetamaskNotInstalledComponent, MetamaskNotLoggedInComponent, PageNotFoundComponent diff --git a/src/app/dashboard/dashboard.component.ts b/src/app/dashboard/dashboard.component.ts index 52bc9e7..54e7453 100644 --- a/src/app/dashboard/dashboard.component.ts +++ b/src/app/dashboard/dashboard.component.ts @@ -46,6 +46,9 @@ export class DashboardComponent implements OnInit { if(errorCode == this.web3Service.CONNECTION_NOT_LOGGED_IN) { this.router.navigate(['metamask-not-logged-in']); } + if(errorCode == this.web3Service.CONNECTION_NOT_ALLOWED_NETWORK) { + this.router.navigate(['metamask-not-allowed-network']); + } } }, (err) => { diff --git a/src/app/metamask-not-allowed-network/index.ts b/src/app/metamask-not-allowed-network/index.ts new file mode 100644 index 0000000..0ca5f18 --- /dev/null +++ b/src/app/metamask-not-allowed-network/index.ts @@ -0,0 +1 @@ +export { MetamaskNotAllowedNetworkComponent } from './metamask-not-allowed-network.component'; diff --git a/src/app/metamask-not-allowed-network/metamask-not-allowed-network.component.css b/src/app/metamask-not-allowed-network/metamask-not-allowed-network.component.css new file mode 100644 index 0000000..e69de29 diff --git a/src/app/metamask-not-allowed-network/metamask-not-allowed-network.component.html b/src/app/metamask-not-allowed-network/metamask-not-allowed-network.component.html new file mode 100644 index 0000000..f5ce7b8 --- /dev/null +++ b/src/app/metamask-not-allowed-network/metamask-not-allowed-network.component.html @@ -0,0 +1,5 @@ +
+ + Please switch your MetaMask to Kovan or Mainnet + +
\ No newline at end of file diff --git a/src/app/metamask-not-allowed-network/metamask-not-allowed-network.component.spec.ts b/src/app/metamask-not-allowed-network/metamask-not-allowed-network.component.spec.ts new file mode 100644 index 0000000..d843798 --- /dev/null +++ b/src/app/metamask-not-allowed-network/metamask-not-allowed-network.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { MetamaskNotAllowedNetworkComponent } from './metamask-not-allowed-network.component'; + +describe('MetamaskNotAllowedNetworkComponent', () => { + let component: MetamaskNotAllowedNetworkComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ MetamaskNotAllowedNetworkComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(MetamaskNotAllowedNetworkComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/metamask-not-allowed-network/metamask-not-allowed-network.component.ts b/src/app/metamask-not-allowed-network/metamask-not-allowed-network.component.ts new file mode 100644 index 0000000..df8cd08 --- /dev/null +++ b/src/app/metamask-not-allowed-network/metamask-not-allowed-network.component.ts @@ -0,0 +1,15 @@ +import { Component, OnInit } from '@angular/core'; + +@Component({ + selector: 'app-metamask-not-allowed-network', + templateUrl: './metamask-not-allowed-network.component.html', + styleUrls: ['./metamask-not-allowed-network.component.css'] +}) +export class MetamaskNotAllowedNetworkComponent implements OnInit { + + constructor() { } + + ngOnInit() { + } + +} diff --git a/src/app/shared/services/web3/web3.service.ts b/src/app/shared/services/web3/web3.service.ts index 724ac21..1e66eaa 100644 --- a/src/app/shared/services/web3/web3.service.ts +++ b/src/app/shared/services/web3/web3.service.ts @@ -16,6 +16,7 @@ export class Web3Service { CONNECTION_NO_ERROR = 0; CONNECTION_NO_PROVIDER = 1; CONNECTION_NOT_LOGGED_IN = 2; + CONNECTION_NOT_ALLOWED_NETWORK = 3; constructor() { } @@ -95,10 +96,20 @@ export class Web3Service { return Observable.create((observer) => { this.getAccounts().subscribe( (accounts) => { - observer.next(accounts.length > 0 ? this.CONNECTION_NO_ERROR : this.CONNECTION_NOT_LOGGED_IN); - }, - (err) => { observer.error(err); }, - () => { observer.complete(); } + if(accounts.length == 0) { + observer.next(this.CONNECTION_NOT_LOGGED_IN); + } else { + // check that user is connected to the allowed network + this.getNetwork().subscribe( + networkName => { + const allowedNetworks = ["main", "kovan", "private"]; + observer.next(allowedNetworks.includes(networkName) ? this.CONNECTION_NO_ERROR : this.CONNECTION_NOT_ALLOWED_NETWORK); + }, + (err) => { observer.error(err); }, + () => { observer.complete(); } + ); + } + } ); }); }