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

Commit

Permalink
Merge branch 'master' into snyk-upgrade-776cf0591cbf0ff681321393226ee3dd
Browse files Browse the repository at this point in the history
  • Loading branch information
tboeckmann committed Jan 30, 2021
2 parents 970f0ea + baee5ce commit 0499133
Show file tree
Hide file tree
Showing 65 changed files with 3,202 additions and 1,457 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ Run `ng build` to build the project. The build artifacts will be stored in the `

Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).

## Security Review Status: pre-audit

The code in this repository has not been audited.

## License

[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmailchain%2Fmailchain-web.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fmailchain%2Fmailchain-web?ref=badge_large)
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
511 changes: 388 additions & 123 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@angular/router": "~8.2.14",
"@ckeditor/ckeditor5-angular": "^1.2.3",
"@ckeditor/ckeditor5-build-classic": "github:mailchain/ckeditor5-build-classic#mailchain_stable",
"bootstrap": "^4.5.0",
"bootstrap": "^4.5.1",
"core-js": "^2.6.11",
"ethereum-blockies-base64": "^1.0.2",
"font-awesome": "^4.7.0",
Expand All @@ -31,21 +31,21 @@
"popper.js": "^1.16.1",
"rxjs": "~6.6.0",
"semver": "^6.3.0",
"webpack": "^4.43.0",
"tslib": "^1.13.0",
"zone.js": "~0.10.3"
"webpack": "^4.44.0",
"zone.js": "^0.11.3"
},
"devDependencies": {
"@angular-devkit/build-angular": "^0.803.25",
"@angular/cli": "^8.3.22",
"@angular/cli": "^8.3.29",
"@angular/compiler-cli": "~8.2.14",
"@angular/language-service": "~8.2.14",
"@babel/compat-data": "~7.8.0",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"@types/node": "^8.10.54",
"codelyzer": "^5.0.1",
"elliptic": "^6.5.2",
"elliptic": "^6.5.3",
"jasmine-core": "^3.5.0",
"jasmine-spec-reporter": "^5.0.2",
"karma": "^4.4.1",
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

0 comments on commit 0499133

Please sign in to comment.