Skip to content
This repository has been archived by the owner on Apr 4, 2022. It is now read-only.

Feat: add substrate handling #207

Merged
merged 26 commits into from
Aug 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
08752ab
adjust test
tboeckmann Jul 22, 2020
ec8d145
create stub classes
tboeckmann Jul 22, 2020
cda3e62
DRY: move stubs out of tests to classes
tboeckmann Jul 22, 2020
e1571ac
add getProtocolsByName
tboeckmann Jul 23, 2020
4f770d3
replace `applicationApiConfig.protocols` with a service call
tboeckmann Jul 23, 2020
96a04f0
update calls for localStorageProtocol to be async
tboeckmann Jul 23, 2020
23b9e6c
remove un-required line
tboeckmann Jul 23, 2020
619c25f
surface 'protocol' arguments to from low level in applicationConfig t…
tboeckmann Jul 23, 2020
4629050
add connectivity check for protocols (because this now happens before…
tboeckmann Jul 23, 2020
b052089
make ethereum the default protocol
tboeckmann Jul 23, 2020
94790fa
add settings and move code over
tboeckmann Jul 25, 2020
5ff2515
remove old code from settings
tboeckmann Jul 25, 2020
63a54d4
remove ActivatedRouteStub & Test
tboeckmann Jul 25, 2020
94315a5
clean up tests and debug
tboeckmann Jul 25, 2020
d015efd
add LocalStorageProtocolServiceStub
tboeckmann Jul 26, 2020
a595125
update settings and fix tests
tboeckmann Jul 26, 2020
3f531ab
add protocol & network config setting to footer
tboeckmann Jul 26, 2020
30a29cf
add handling for substrate in addresses response
tboeckmann Jul 26, 2020
6955f4b
add default public-key-kind for protocols
tboeckmann Jul 26, 2020
3597483
handle validation for substrate addresses (relaxed)
tboeckmann Jul 26, 2020
6608516
add protocol to address helper functions and update tests
tboeckmann Aug 1, 2020
cde4813
fix: move image text out of test fix. TS renderer was hanging in vscode.
tboeckmann Aug 1, 2020
ddc42e6
update public-key handling & addresses response
tboeckmann Aug 2, 2020
512ef11
fix tests for addresses and public-key.service
tboeckmann Aug 16, 2020
8ec6820
fix tests for addresses service
tboeckmann Aug 16, 2020
00ac656
update coverage exlusions
tboeckmann Aug 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@
"builder": "@angular-devkit/build-angular:karma",
"options": {
"codeCoverage": true,
"codeCoverageExclude": [
"/**/*mock.ts",
"/**/*stub.ts",
"/**/test-helpers/**",
"src/test/**"
],
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.spec.json",
Expand Down
17 changes: 11 additions & 6 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { Routes, RouterModule, ExtraOptions } from '@angular/router';
import { InboxComponent } from './inbox/inbox.component';
import { FormsModule } from '@angular/forms';
import { CommonModule } from '@angular/common';
Expand All @@ -11,21 +11,26 @@ import { InboxComposeComponent } from './inbox/inbox-compose/inbox-compose.compo
import { InboxMessageComponent } from './inbox/inbox-message/inbox-message.component';
import { InboxMessagesComponent } from './inbox/inbox-messages/inbox-messages.component';
import { CKEditorModule } from '@ckeditor/ckeditor5-angular';
import { SettingsComponent } from './settings/settings/settings.component';


const routes: Routes = [
{
path: '',
component: InboxComponent,
}
{ path: '', component: InboxComponent },
{ path: 'settings', component: SettingsComponent }

];

const routerOptions: ExtraOptions = {
anchorScrolling: 'enabled',
};

@NgModule({
declarations: [
InboxComponent,
InboxMessagesComponent,
InboxMessageComponent,
InboxComposeComponent,
SettingsComponent,
],
imports: [
FormsModule,
Expand All @@ -34,7 +39,7 @@ const routes: Routes = [
ModalModule.forRoot(),
CommonModule,
CKEditorModule,
RouterModule.forRoot(routes)
RouterModule.forRoot(routes, routerOptions)
],
providers: [HttpHelpersService],
exports: [RouterModule]
Expand Down
22 changes: 18 additions & 4 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,23 @@
</div>
<footer class="footer">
<div class="container">
<span class="text-muted">
Made by <a href="https://mailchain.xyz" target="_blank">Mailchain</a>
</span>
<span class="text-muted pull-right">Inbox Version: {{version}} (API Version: {{apiVersion}})</span>

<div class="row">
<div class="col">
<span class="text-muted">
Made by <a href="https://mailchain.xyz" target="_blank">Mailchain</a>
</span>
</div>
<div class="col">
<span *ngIf="currentProtocol" class="text-muted">
<i class="fa fa-bolt"></i>&nbsp;Connected to {{currentNetwork | titlecase}} on {{currentProtocol | titlecase}}
</span>
</div>
<div class="col">
<span class="text-muted pull-right"><i class="fa fa-envelope"></i>&nbsp;Inbox Version: {{version}} (API Version:
{{apiVersion}})</span>
</div>
</div>

</div>
</footer>
18 changes: 9 additions & 9 deletions src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,53 +74,53 @@ describe('AppComponent', () => {

});

describe('handleApiAvailability', () => {
describe('handleApiAddressesAvailability', () => {
it('should handle connection refused error', async () => {
spyOn(connectivityService, 'getApiAvailability').and.returnValue(mailchainTestService.getApiAvailabilityConnectionRefused())
spyOn(connectivityService, 'getApiAddressAvailability').and.returnValue(mailchainTestService.getApiAddressAvailabilityConnectionRefused())

expect(component.errorTitle).toEqual("")
expect(component.errorMessage).toEqual("")

await component.handleApiAvailability()
await component.handleApiAddressesAvailability()

expect(component.errorTitle).toEqual(errorMessages.clientNotRunningErrorTitle)
expect(component.errorMessage).toEqual(errorMessages.clientNotRunningErrorMessage)

});

it('should handle unknown error', async () => {
spyOn(connectivityService, 'getApiAvailability').and.returnValue(mailchainTestService.getApiAvailabilityErrorUnknown())
spyOn(connectivityService, 'getApiAddressAvailability').and.returnValue(mailchainTestService.getApiAddressAvailabilityErrorUnknown())

expect(component.errorTitle).toEqual("")
expect(component.errorMessage).toEqual("")

await component.handleApiAvailability()
await component.handleApiAddressesAvailability()

expect(component.errorTitle).toEqual(errorMessages.unknownErrorTitle)
expect(component.errorMessage).toEqual(errorMessages.unknownErrorMessage)

});

it('should handle status ok, with 0 addresses, error', async () => {
spyOn(connectivityService, 'getApiAvailability').and.returnValue(mailchainTestService.getApiAvailabilitySuccessNoAddresses())
spyOn(connectivityService, 'getApiAddressAvailability').and.returnValue(mailchainTestService.getApiAddressAvailabilitySuccessNoAddresses())

expect(component.errorTitle).toEqual("")
expect(component.errorMessage).toEqual("")

await component.handleApiAvailability()
await component.handleApiAddressesAvailability()

expect(component.errorTitle).toEqual(errorMessages.accountConfigurationErrorTitle)
expect(component.errorMessage).toEqual(errorMessages.accountConfigurationErrorMessage)

});

it('should handle status ok, with addresses', async () => {
spyOn(connectivityService, 'getApiAvailability').and.returnValue(mailchainTestService.getApiAvailabilitySuccess())
spyOn(connectivityService, 'getApiAddressAvailability').and.returnValue(mailchainTestService.getApiAddressAvailabilitySuccess())

expect(component.errorTitle).toEqual("")
expect(component.errorMessage).toEqual("")

await component.handleApiAvailability()
await component.handleApiAddressesAvailability()

expect(component.errorTitle).toEqual("")
expect(component.errorMessage).toEqual("")
Expand Down
93 changes: 67 additions & 26 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { ConnectivityService } from './services/mailchain/connectivity/connectiv
import { BsModalService, BsModalRef } from 'ngx-bootstrap/modal';
import { ModalConnectivityErrorComponent } from './modals/modal-connectivity-error/modal-connectivity-error.component';
import { errorMessages } from './services/helpers/error-messages/error-messages'
import { LocalStorageProtocolService } from './services/helpers/local-storage-protocol/local-storage-protocol.service';
import { LocalStorageServerService } from './services/helpers/local-storage-server/local-storage-server.service';

@Component({
selector: 'app-root',
Expand All @@ -14,16 +16,20 @@ import { errorMessages } from './services/helpers/error-messages/error-messages'
export class AppComponent implements OnInit {
public version: string = environment.version;
public title = 'Mailchain Inbox';
public apiConnectivityInfo = {};
public apiVersionInfo = {};
public errorTitle: string = ""
public errorMessage: string = ""
public apiVersion = "";
public modalConnectivityError: BsModalRef;

public currentNetwork: String;
public currentProtocol: String;

constructor(
private connectivityService: ConnectivityService,
private modalService: BsModalService
private modalService: BsModalService,
private localStorageProtocolService: LocalStorageProtocolService,
private localStorageServerService: LocalStorageServerService,
) {

}
Expand All @@ -33,39 +39,50 @@ export class AppComponent implements OnInit {
}

public async ngOnInit() {
await this.handleApiAvailability()
this.currentNetwork = await this.localStorageServerService.getCurrentNetwork()
this.currentProtocol = await this.localStorageProtocolService.getCurrentProtocol()

await this.handleApiProtocolsAvailability()
await this.handleApiAddressesAvailability()
await this.handleWebConnectivity()
this.setApiVersion()
}

/**
* handleApiAvailability checks if the client is available.
* handleApiAddressesAvailability checks if the client is available.
* Displays an error modal if not able to connect or hides the error modal if able to connect
*/
public async handleApiAvailability() {
this.apiConnectivityInfo = await this.connectivityService.getApiAvailability();
public async handleApiProtocolsAvailability() {
let apiConnectivityInfo = await this.connectivityService.getApiProtocolsAvailability();

if (apiConnectivityInfo["status"] == "error") {
this.handleApiConnectivityError(apiConnectivityInfo)
} else if (apiConnectivityInfo["status"] == "ok") {
if (apiConnectivityInfo["protocols"] == 0) {
// No protocols are configured
this.handleErrorOnPage(
errorMessages.protocolConfigurationErrorTitle,
errorMessages.protocolConfigurationErrorMessage
)
} else {
if (this.modalConnectivityError) {
this.modalConnectivityError.hide()
}
}
}
}

if (this.apiConnectivityInfo["status"] == "error") {
switch (this.apiConnectivityInfo["code"]) {
case 0:
// Could not connect to Mailchain client
this.handleErrorOnPage(
errorMessages.clientNotRunningErrorTitle,
errorMessages.clientNotRunningErrorMessage
)
break;
/**
* handleApiAddressesAvailability checks if the client is available.
* Displays an error modal if not able to connect or hides the error modal if able to connect
*/
public async handleApiAddressesAvailability() {
let apiConnectivityInfo = await this.connectivityService.getApiAddressAvailability();

default:
// Something else happened
this.handleErrorOnPage(
errorMessages.unknownErrorTitle,
errorMessages.unknownErrorMessage
)
console.warn('please add a new error message for this code', this.apiConnectivityInfo["code"]);
break;
}
} else if (this.apiConnectivityInfo["status"] == "ok") {
if (this.apiConnectivityInfo["addresses"] == 0) {
if (apiConnectivityInfo["status"] == "error") {
this.handleApiConnectivityError(apiConnectivityInfo)
} else if (apiConnectivityInfo["status"] == "ok") {
if (apiConnectivityInfo["addresses"] == 0) {
// No addresses are configured
this.handleErrorOnPage(
errorMessages.accountConfigurationErrorTitle,
Expand All @@ -79,6 +96,30 @@ export class AppComponent implements OnInit {
}
}

/**
* handleApiConnectivityError
*/
handleApiConnectivityError(errorBlock) {
switch (errorBlock["code"]) {
case 0:
// Could not connect to Mailchain client
this.handleErrorOnPage(
errorMessages.clientNotRunningErrorTitle,
errorMessages.clientNotRunningErrorMessage
)
break;

default:
// Something else happened
this.handleErrorOnPage(
errorMessages.unknownErrorTitle,
errorMessages.unknownErrorMessage
)
console.warn('please add a new error message for this code', errorBlock["code"]);
break;
}
}

/**
* handleWebConnectivity
*/
Expand Down
1 change: 1 addition & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { SearchPipe } from './pipes/search-pipe/search-pipe.pipe';
import { AddressPipe } from './pipes/address-pipe/address-pipe.pipe';
import { LocationStrategy, HashLocationStrategy, APP_BASE_HREF } from '@angular/common';
import { ModalConnectivityErrorComponent } from './modals/modal-connectivity-error/modal-connectivity-error.component';
import { SettingsComponent } from './settings/settings/settings.component';

@NgModule({
declarations: [
Expand Down
Loading