Skip to content

Commit ed50c12

Browse files
committed
hb wallet release
1 parent b74a482 commit ed50c12

28 files changed

+2735
-2155
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2015-2019 Helperbit S.r.l
1+
Copyright (c) 2015-2020 Helperbit S.r.l
22

33
Permission is hereby granted, free of charge, to any person
44
obtaining a copy of this software and associated documentation

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Helperbit Wallet
22

3-
Opensource version of the helperbit wallet.
3+
Opensource version of the helperbit wallet.

STYLEGUIDE.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Style Guide
2+
3+
## Eslint Rules
4+
5+
Check the .eslintrc file for the complete rule list.
6+
7+
8+
## Commenti
9+
Usare sempre i commenti /* */, a meno che non sia un commento in una riga dove c'e' gia' codice, esempio:
10+
11+
```javascript
12+
let ciao = 'mondo' + 'marcio'; // + 'gianni'
13+
```
14+
15+
I commenti sempre in lowercase con iniziali maiuscole. Se un commento tra /* */ serve per separare delle sezioni, usare:
16+
17+
```javascript
18+
/*** Sezione */
19+
let codice = ...;
20+
```
21+
22+
23+
## A capo
24+
Cercare di non mettere troppi a capo dove non servono; in particolare:
25+
26+
- usare un a capo per separare due funzioni
27+
- usare 2 a capo per separare due sezioni (per esempio fields e methods)
28+
- non usare a capo dopo che si apre una funzione
29+
30+
31+
32+
## ES2015
33+
34+
### Var, Let e Const
35+
Seppur il codice transpilato utilizza comunque i var, abituarsi ad usare let e const.
36+
37+
- const lo usiamo quando abbiamo un dato che non deve cambiare
38+
- let lo usiamo per tutto il resto
39+

TESTING_COMPONENT.md

+188
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
For every component, we create 3 type of tests:
2+
- isolated: we only test class logic (with mocks)
3+
- shallow: we test class and template logic (with mocks)
4+
- integrated: we test the integration with other components / services
5+
6+
https://jasmine.github.io/2.0/introduction.html
7+
8+
9+
## Wait for async http
10+
11+
Imports HttpClientTestingModule; use the mock as follow:
12+
13+
```typescript
14+
httpMock = TestBed.get(HttpTestingController);
15+
let balanceRequest = httpMock.expectOne(AppSettings.apiUrl + '/wallet/1MN/balance');
16+
balanceRequest.flush({ balance: 1, received: 2, unconfirmed: 3 });
17+
```
18+
19+
We do not have to wait, the result will appear as expected in sync.
20+
21+
## onChanges
22+
OnChanges should be triggered manually:
23+
24+
```typescript
25+
component.address = "1MN";
26+
component.ngOnChanges({ address: new SimpleChange(null, component.address, true) });
27+
```
28+
29+
## Examples
30+
31+
- home-stats-component
32+
- address-balance-component
33+
34+
```typescript
35+
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
36+
import { By } from '@angular/platform-browser';
37+
import { NO_ERRORS_SCHEMA } from '@angular/core';
38+
import { RouterTestingModule } from '@angular/router/testing';
39+
import { Router } from '@angular/router';
40+
// app
41+
import { CounterComponent } from './counter.component';
42+
import { MenuComponent } from './menu.component';
43+
44+
/**
45+
* This component has some logic in it, and a very simple template.
46+
* For now, we only want to test the class logic. For doing so,
47+
* we will test only the component class without rendering the template.
48+
* This test is an Isolated test.
49+
*/
50+
describe('CounterComponent (isolated test)', () => {
51+
it('should instantiate', () => {
52+
const component: CounterComponent = new CounterComponent();
53+
expect(component).toBeDefined();
54+
});
55+
56+
it('should start with a counter at `0`', () => {
57+
const component: CounterComponent = new CounterComponent();
58+
expect(component.counter).toEqual(0);
59+
});
60+
61+
it('should be able to increment the counter (+1)', () => {
62+
const component: CounterComponent = new CounterComponent();
63+
component.counter = 5;
64+
65+
component.increment();
66+
component.increment();
67+
68+
expect(component.counter).toEqual(7);
69+
});
70+
71+
it('should be able to decrement the counter (-1)', () => {
72+
const component: CounterComponent = new CounterComponent();
73+
component.counter = 5;
74+
75+
component.decrement();
76+
component.decrement();
77+
78+
expect(component.counter).toEqual(3);
79+
});
80+
});
81+
82+
/**
83+
* Now that the inner class' logic is tested.
84+
* To test if the buttons trigger the right logic, we need to test them.
85+
* We need to render the template and trigger some clicks.
86+
* Because this component'template contains another component,
87+
* and we only want to test the relevant part of the template, we will not
88+
* render the child component.
89+
* This is a Shallow test.
90+
*/
91+
describe('CounterComponent (shallow test)', () => {
92+
let component: CounterComponent;
93+
let fixture: ComponentFixture<CounterComponent>;
94+
95+
beforeEach(async(() => {
96+
TestBed.configureTestingModule({
97+
declarations: [CounterComponent],
98+
schemas: [NO_ERRORS_SCHEMA]
99+
}).compileComponents(); // This is not needed if you are in the CLI context
100+
}));
101+
102+
beforeEach(() => {
103+
fixture = TestBed.createComponent(CounterComponent);
104+
component = fixture.componentInstance;
105+
fixture.detectChanges();
106+
});
107+
108+
it('should instantiate', () => {
109+
expect(component).toBeDefined();
110+
});
111+
112+
it('should increment the counter if increment button is clicked (+1)', () => {
113+
const button = fixture.debugElement.nativeElement.querySelector('.button-up');
114+
115+
button.click();
116+
button.click();
117+
118+
expect(component.counter).toEqual(2);
119+
});
120+
121+
it('should decrement the counter if decrement button is clicked (-1)', () => {
122+
component.counter = 5; // Fake some increment clicks before.
123+
const button = fixture.debugElement.nativeElement.querySelector('.button-down');
124+
125+
button.click();
126+
button.click();
127+
128+
expect(component.counter).toEqual(3);
129+
});
130+
131+
it('should reset the counter if reset button is clicked (0)', () => {
132+
component.counter = 3; // Fake some increment clicks before.
133+
const button = fixture.debugElement.nativeElement.querySelector('.button-0');
134+
135+
button.click();
136+
137+
expect(component.counter).toEqual(0);
138+
});
139+
});
140+
141+
/**
142+
* We could now go deeper and test the whole component with its dependencies,
143+
* see if everything is working great.
144+
* This is an Integrated test.
145+
*/
146+
describe('CounterComponent (integrated test)', () => {
147+
let component: CounterComponent;
148+
let fixture: ComponentFixture<CounterComponent>;
149+
let router: Router;
150+
151+
beforeEach(async(() => {
152+
TestBed.configureTestingModule({
153+
declarations: [CounterComponent, MenuComponent],
154+
imports: [RouterTestingModule]
155+
}).compileComponents(); // This is not needed if you are in the CLI context
156+
}));
157+
158+
beforeEach(() => {
159+
fixture = TestBed.createComponent(CounterComponent);
160+
component = fixture.componentInstance;
161+
162+
router = TestBed.get(Router);
163+
spyOn(router, 'navigateByUrl');
164+
165+
fixture.detectChanges();
166+
});
167+
168+
it('should instantiate', () => {
169+
expect(component).toBeDefined();
170+
});
171+
172+
it('should trigger the navigation to `/home`', async(() => {
173+
const link = fixture.debugElement.nativeElement.querySelector('.home-link');
174+
175+
link.click();
176+
177+
expect(router.navigateByUrl).toHaveBeenCalled();
178+
}));
179+
180+
it('should trigger the navigation to `/about`', async(() => {
181+
const link = fixture.debugElement.nativeElement.querySelector('.about-link');
182+
183+
link.click();
184+
185+
expect(router.navigateByUrl).toHaveBeenCalled();
186+
}));
187+
});
188+
```

app/components/dashboard.wallet/bitcoin.service/bitcoin-helper.ts

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { Payment, payments, ECPair, Network, ECPairInterface, address } from 'bi
22
import AES from 'crypto-js/aes';
33
import AppSettings from 'app/app.settings';
44

5+
export const ONESATOSHI = 0.00000001;
6+
57
export interface BitcoinSignService {
68
sign(txhex: string, options: BitcoinSignOptions, callback?): Promise<string>;
79
}

app/components/dashboard.wallet/bitcoin.service/ledger.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import { unwrap } from '../../../models/common';
1010
import AppSettings from '../../../app.settings';
1111
import { Injectable } from '@angular/core';
1212
import { HttpClient } from '@angular/common/http';
13-
import { Observable } from 'rxjs/internal/Observable';
14-
13+
import { Observable } from 'rxjs';
1514

1615
@Injectable()
1716
export class BitcoinLedgerService implements BitcoinSignService {

app/components/dashboard.wallet/feedmultisig/feedmultisig.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { getLocalStorage } from 'app/shared/helpers/utils';
1717
@Component({
1818
selector: 'me-wallet-feed-multisig-component',
1919
templateUrl: 'feedmultisig.html',
20-
styleUrls: ['feedmultisig.scss']
20+
styleUrls: ['../../../sass/main/custom/page.scss', 'feedmultisig.scss']
2121
})
2222
export class MeWalletFeedMultisigComponent extends CreateWallet implements OnInit, AfterViewInit {
2323
@ViewChild(WizardComponent) public wizardHandler: WizardComponent;

app/components/dashboard.wallet/new/new.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { getLocalStorage } from 'app/shared/helpers/utils';
1515
@Component({
1616
selector: 'me-wallet-new-component',
1717
templateUrl: 'new.html',
18-
styleUrls: ['new.scss']
18+
styleUrls: ['../../../sass/main/custom/page.scss', 'new.scss']
1919
})
2020
export class MeWalletNewComponent extends CreateWallet implements OnInit, AfterViewInit {
2121
@ViewChild(WizardComponent) public wizardHandler: WizardComponent;

app/components/dashboard.wallet/newmultisig/newmultisig.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import { ResponseMessageConfig, buildErrorResponseMessage } from 'app/shared/com
1212

1313
@Component({
1414
selector: 'me-wallet-new-multisig-component',
15-
templateUrl: 'newmultisig.html'
15+
templateUrl: 'newmultisig.html',
16+
styleUrls: ['../../../sass/main/custom/page.scss']
1617
})
1718
export class MeWalletNewMultisigComponent implements OnInit {
1819
@ViewChild(WizardComponent) public wizardHandler: WizardComponent;

app/components/dashboard.wallet/restore/restore.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import { ResponseMessageConfig, buildErrorResponseMessage } from 'app/shared/com
88
import { WizardComponent } from 'angular-archwizard';
99
import { ActivatedRoute, Router } from '@angular/router';
1010
import { CurrencyService } from 'app/services/currency';
11-
import { evaluteFee } from '../bitcoin.service/bitcoin-helper';
11+
import { evaluteFee, ONESATOSHI } from '../bitcoin.service/bitcoin-helper';
1212

1313
@Component({
1414
selector: 'me-wallet-restore-component',
1515
templateUrl: 'restore.html',
16+
styleUrls: ['../../../sass/main/custom/page.scss']
1617
})
1718
export class MeWalletRestoreComponent implements OnInit {
1819
@ViewChild(WizardComponent) public wizardHandler: WizardComponent;
@@ -72,7 +73,7 @@ export class MeWalletRestoreComponent implements OnInit {
7273
destination: this.model.destination
7374
};
7475

75-
wreq.value = wreq.value - wreq.fee - 0.00000001;
76+
wreq.value = wreq.value - wreq.fee - ONESATOSHI;
7677

7778
/* Send the refund transaction */
7879
this.walletService.withdraw(this.wallet.address, wreq).subscribe(data => {

app/components/dashboard.wallet/wallet-verify/wallet-verify.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ interface WalletVerificationEx extends WalletVerification {
2828
@Component({
2929
selector: 'me-wallet-verify',
3030
templateUrl: 'wallet-verify.html',
31-
styleUrls: ['wallet-verify.scss']
31+
styleUrls: ['../../../sass/main/custom/page.scss', 'wallet-verify.scss']
3232
})
3333
export class MeWalletVerificationComponent implements OnInit {
3434
pageHeader: PageHeaderConfig;

app/components/dashboard.wallet/wallets/wallets.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { getLocalStorage } from 'app/shared/helpers/utils';
1717
@Component({
1818
selector: 'me-wallet-component',
1919
templateUrl: 'wallets.html',
20-
styleUrls: ['wallets.scss']
20+
styleUrls: ['../../../sass/main/custom/page.scss', 'wallets.scss']
2121
})
2222
export class MeWalletComponent implements OnInit {
2323
baseUrl: string = AppSettings.baseUrl;

app/components/dashboard.wallet/widgets/wallet-list/wallet-list.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { BrowserHelperService } from '../../../../services/browser-helper';
22
import { WalletService, Wallet } from '../../../../models/wallet';
3-
import { Subscription } from 'rxjs/internal/Subscription';
3+
import { Subscription } from 'rxjs';
44
import { Component, Output, Input, EventEmitter, OnDestroy, OnInit } from '@angular/core';
55
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
66
import { WalletDepositModal } from './deposit';

0 commit comments

Comments
 (0)