Skip to content

Commit b08e82e

Browse files
committed
fixes for chain and network selector
1 parent 71b6c08 commit b08e82e

File tree

12 files changed

+153
-99
lines changed

12 files changed

+153
-99
lines changed

packages/insight-previous/src/app/app.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export class InsightApp {
3030
this.menu = menu;
3131
this.platform = platform;
3232

33-
this.rootPage = HomePage;
3433
this.initializeApp();
3534

3635
// set our app's pages
@@ -43,6 +42,7 @@ export class InsightApp {
4342

4443
private initializeApp(): void {
4544
this.platform.ready().then(() => {
45+
this.rootPage = HomePage;
4646
// cordova ready
4747
});
4848
}

packages/insight-previous/src/components/denomination/denomination.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<ion-avatar item-start>
99
<img src="assets/img/currency_logos/{{ chainNetwork.chain.toLowerCase() }}.svg" class="logo" />
1010
</ion-avatar>
11-
<ion-label color="dark" (click)="changeExplorer(api.networkSettings.value.selectedNetwork)">
11+
<ion-label color="dark" (click)="changeExplorer(chainNetwork)">
1212
<button ion-button small>{{chainNetwork.chain}} {{chainNetwork.network}}</button>
1313
</ion-label>
1414
</ion-item>

packages/insight-previous/src/components/denomination/denomination.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,18 @@ export class DenominationComponent {
2323
public app: App,
2424
public http: Http,
2525
public api: ApiProvider
26-
) {
27-
this.units = [
28-
'USD',
29-
this.api.networkSettings.value.selectedNetwork.chain,
30-
'm' + this.api.networkSettings.value.selectedNetwork.chain
31-
];
26+
) { }
27+
28+
ionViewDidLoad() {
29+
this.api.getAvailableNetworks().subscribe(data => {
30+
const availableNetworks = data.json() as ChainNetwork[];
31+
this.switcherOn = availableNetworks.length > 1 ? true : false;
32+
this.units = [
33+
'USD',
34+
this.api.networkSettings.value.selectedNetwork.chain,
35+
'm' + this.api.networkSettings.value.selectedNetwork.chain
36+
];
37+
})
3238
}
3339

3440
public close(): void {
@@ -37,8 +43,6 @@ export class DenominationComponent {
3743

3844
public changeExplorer(chainNetwork: ChainNetwork): void {
3945
this.selected = chainNetwork;
40-
const { chain, network }: ChainNetwork = chainNetwork;
41-
this.viewCtrl.dismiss();
42-
this.app.getRootNav().push('home', { chain, network });
46+
this.viewCtrl.dismiss(chainNetwork);
4347
}
4448
}

packages/insight-previous/src/components/head-nav/head-nav.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99

1010
<button ion-button (click)="changeCurrency($event)">
1111
<ion-icon name="logo-bitcoin" *ngIf="currency.currencySymbol !== 'USD'"></ion-icon>
12-
<ion-icon name="logo-usd" *ngIf="currency.currencySymbol === 'USD'"></ion-icon>&nbsp;{{ currency.currencySymbol
12+
<ion-icon name="logo-usd" *ngIf="currency.currencySymbol === 'USD'"></ion-icon>&nbsp;{{ currency?.currencySymbol
1313
}}
14+
<i> &nbsp;({{config?.network}})</i>
1415
</button>
1516
<button ion-button icon-only (click)="toggleSearch()">
1617
<ion-icon name="search"></ion-icon>

packages/insight-previous/src/components/head-nav/head-nav.ts

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
import { Component } from '@angular/core';
1+
import { Component, EventEmitter, Output } from '@angular/core';
22
import { Input } from '@angular/core';
33
import { Http } from '@angular/http';
4-
import { ActionSheetController } from 'ionic-angular';
5-
import { ToastController } from 'ionic-angular';
4+
import * as bitcoreLib from 'bitcore-lib';
5+
import * as bitcoreLibCash from 'bitcore-lib-cash';
66
import { PopoverController } from 'ionic-angular';
77
import { NavController } from 'ionic-angular';
8+
import { ToastController } from 'ionic-angular';
9+
import { ActionSheetController } from 'ionic-angular';
810
import { App } from 'ionic-angular/components/app/app';
911
import { ApiProvider, ChainNetwork } from '../../providers/api/api';
1012
import { CurrencyProvider } from '../../providers/currency/currency';
1113
import { PriceProvider } from '../../providers/price/price';
1214
import { DenominationComponent } from '../denomination/denomination';
13-
import * as bitcoreLib from 'bitcore-lib';
14-
import * as bitcoreLibCash from 'bitcore-lib-cash';
1515
@Component({
1616
selector: 'head-nav',
1717
templateUrl: 'head-nav.html'
1818
})
1919
export class HeadNavComponent {
20+
@Output() updateView = new EventEmitter<ChainNetwork>();
2021
public showSearch = false;
2122
public loading: boolean;
2223
@Input()
@@ -34,7 +35,9 @@ export class HeadNavComponent {
3435
public actionSheetCtrl: ActionSheetController,
3536
public popoverCtrl: PopoverController,
3637
public toastCtrl: ToastController
37-
) { }
38+
) {
39+
this.config = this.apiProvider.getConfig();
40+
}
3841

3942
public search(): void {
4043
this.showSearch = false;
@@ -124,25 +127,38 @@ export class HeadNavComponent {
124127
popover.present({
125128
ev: myEvent
126129
});
130+
popover.onDidDismiss(data => {
131+
if (data) {
132+
if (JSON.stringify(data) === JSON.stringify(this.config)) {
133+
return;
134+
}
135+
this.apiProvider.changeNetwork(data);
136+
this.config = this.apiProvider.getConfig();
137+
if (this.navCtrl.getActive().component.name === 'HomePage') {
138+
this.updateView.next(data);
139+
} else {
140+
this.navCtrl.setRoot('home', { chain: this.config.chain, network: this.config.network });
141+
}
142+
}
143+
});
127144
}
128145

129146
public toggleSearch(): void {
130147
this.showSearch = !this.showSearch;
131148
}
132149

133150
public extractAddress(address: string): string {
134-
let extractedAddress = address
151+
const extractedAddress = address
135152
.replace(/^(bitcoincash:|bchtest:|bitcoin:)/i, '')
136153
.replace(/\?.*/, '');
137154
return extractedAddress || address;
138155
}
139156

140157
public isInputValid(inputValue): boolean {
141-
this.config = this.apiProvider.getConfig();
142-
if (this.isValidBlockOrTx(inputValue)) return true;
143-
else if (this.isValidAddress(inputValue)) return true;
144-
else if (this.isValidBlockIndex(inputValue)) return true;
145-
else return false;
158+
if (this.isValidBlockOrTx(inputValue)) { return true; }
159+
else if (this.isValidAddress(inputValue)) { return true; }
160+
else if (this.isValidBlockIndex(inputValue)) { return true; }
161+
else { return false; }
146162
}
147163

148164
private isValidBlockOrTx(inputValue): boolean {
@@ -159,11 +175,11 @@ export class HeadNavComponent {
159175
const network = this.config.network;
160176
const addr = this.extractAddress(inputValue);
161177

162-
if (coin.toLowerCase() == 'btc' && network == 'mainnet') {
178+
if (coin.toLowerCase() === 'btc' && network === 'mainnet') {
163179
return this.isValidBitcoinMainnetAddress(addr);
164-
} else if (coin.toLowerCase() == 'btc' && network == 'testnet') {
180+
} else if (coin.toLowerCase() === 'btc' && network === 'testnet') {
165181
return this.isValidBitcoinTestnetAddress(addr);
166-
} else if (coin.toLowerCase() == 'bch' && network == 'mainnet') {
182+
} else if (coin.toLowerCase() === 'bch' && network === 'mainnet') {
167183
return (
168184
this.isValidBitcoinCashMainnetAddress(addr) ||
169185
this.isValidBitcoinCashLegacyMainnetAddress(addr)

packages/insight-previous/src/components/latest-blocks/latest-blocks.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Component, Input, NgZone, OnDestroy, OnInit } from '@angular/core';
22
import { NavController } from 'ionic-angular';
3+
import { Subscription } from 'rxjs';
34
import { ApiProvider } from '../../providers/api/api';
45
import { BlocksProvider } from '../../providers/blocks/blocks';
56
import { CurrencyProvider } from '../../providers/currency/currency';
@@ -22,6 +23,8 @@ export class LatestBlocksComponent implements OnInit, OnDestroy {
2223
public showTimeAs: string;
2324
private reloadInterval: any;
2425

26+
public subscriber: Subscription;
27+
2528
constructor(
2629
private blocksProvider: BlocksProvider,
2730
private apiProvider: ApiProvider,
@@ -38,9 +41,9 @@ export class LatestBlocksComponent implements OnInit, OnDestroy {
3841
const seconds = 15;
3942
this.ngZone.runOutsideAngular(() => {
4043
this.reloadInterval = setInterval(
41-
function(): void {
44+
function (): void {
4245
this.ngZone.run(
43-
function(): void {
46+
function (): void {
4447
this.loadBlocks.call(this);
4548
}.bind(this)
4649
);
@@ -51,7 +54,7 @@ export class LatestBlocksComponent implements OnInit, OnDestroy {
5154
}
5255

5356
private loadBlocks(): void {
54-
this.blocksProvider.getBlocks(this.numBlocks).subscribe(
57+
this.subscriber = this.blocksProvider.getBlocks(this.numBlocks).subscribe(
5558
({ blocks }) => {
5659
this.blocks = blocks;
5760
this.loading = false;
@@ -97,6 +100,12 @@ export class LatestBlocksComponent implements OnInit, OnDestroy {
97100
});
98101
}
99102

103+
public reloadData() {
104+
this.subscriber.unsubscribe();
105+
this.blocks = [];
106+
this.ngOnInit();
107+
}
108+
100109
ngOnDestroy(): void {
101110
clearInterval(this.reloadInterval);
102111
}

packages/insight-previous/src/components/transaction/transaction.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<div>
3939
<div class="ellipsis">
4040
<p>
41-
<a (click)="goToAddress(vin.addr)">{{ vin.addr }}</a>
41+
<a (click)="goToAddress(vin.address)">{{ vin.address }}</a>
4242
</p>
4343
</div>
4444
<div [hidden]="!expanded">
@@ -128,4 +128,4 @@
128128
</ion-chip>
129129
</ion-col>
130130
</ion-row>
131-
</ion-grid>
131+
</ion-grid>

packages/insight-previous/src/components/transaction/transaction.ts

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { Component } from '@angular/core';
1+
import { Component, OnInit } from '@angular/core';
22
import { Input } from '@angular/core';
33
import { NavController } from 'ionic-angular';
4-
import { CurrencyProvider } from '../../providers/currency/currency';
5-
import { TxsProvider, ApiCoin } from '../../providers/transactions/transactions';
64
import { ApiProvider } from '../../providers/api/api';
5+
import { CurrencyProvider } from '../../providers/currency/currency';
6+
import { ApiCoin, TxsProvider } from '../../providers/transactions/transactions';
77

88
/**
99
* Generated class for the TransactionComponent component.
@@ -15,19 +15,19 @@ import { ApiProvider } from '../../providers/api/api';
1515
selector: 'transaction',
1616
templateUrl: 'transaction.html'
1717
})
18-
export class TransactionComponent {
19-
private COIN: number = 100000000;
18+
export class TransactionComponent implements OnInit {
19+
private COIN = 100000000;
2020

21-
public expanded: boolean = false;
21+
public expanded = false;
2222
@Input() public tx: any = {};
23-
@Input() public showCoins?: boolean = false;
23+
@Input() public showCoins = false;
2424

2525
constructor(
2626
private navCtrl: NavController,
2727
public currency: CurrencyProvider,
2828
public apiProvider: ApiProvider,
2929
public txProvider: TxsProvider
30-
) {}
30+
) { }
3131

3232
public ngOnInit(): void {
3333
if (this.showCoins) {
@@ -56,36 +56,36 @@ export class TransactionComponent {
5656
this.navCtrl.push('transaction', {
5757
chain: this.apiProvider.networkSettings.value.selectedNetwork.chain,
5858
network: this.apiProvider.networkSettings.value.selectedNetwork.network,
59-
txId: txId
59+
txId
6060
});
6161
}
6262

6363
public goToAddress(addrStr: string): void {
6464
this.navCtrl.push('address', {
6565
chain: this.apiProvider.networkSettings.value.selectedNetwork.chain,
6666
network: this.apiProvider.networkSettings.value.selectedNetwork.network,
67-
addrStr: addrStr
67+
addrStr
6868
});
6969
}
7070

7171
public toggleExpanded(): void {
7272
this.expanded = !this.expanded;
7373
}
7474

75-
public aggregateItems(items: Array<any>): Array<any> {
76-
if (!items) return [];
75+
public aggregateItems(items: any[]): any[] {
76+
if (!items) { return []; }
7777

78-
let l: number = items.length;
78+
const l: number = items.length;
7979

80-
let ret: Array<any> = [];
81-
let tmp: any = {};
82-
let u: number = 0;
80+
const ret: any[] = [];
81+
const tmp: any = {};
82+
let u = 0;
8383

84-
for (let i: number = 0; i < l; i++) {
85-
let notAddr: boolean = false;
84+
for (let i = 0; i < l; i++) {
85+
let notAddr = false;
8686
// non standard input
87-
if (items[i].scriptSig && !items[i].addr) {
88-
items[i].addr = 'Unparsed address [' + u++ + ']';
87+
if (items[i].scriptSig && !items[i].address) {
88+
items[i].address = 'Unparsed address [' + u++ + ']';
8989
items[i].notAddr = true;
9090
notAddr = true;
9191
}
@@ -99,36 +99,36 @@ export class TransactionComponent {
9999

100100
// multiple addr at output
101101
if (items[i].scriptPubKey && items[i].scriptPubKey.addresses.length > 1) {
102-
items[i].addr = items[i].scriptPubKey.addresses.join(',');
102+
items[i].address = items[i].scriptPubKey.addresses.join(',');
103103
ret.push(items[i]);
104104
continue;
105105
}
106106

107-
let addr: string = items[i].addr || (items[i].scriptPubKey && items[i].scriptPubKey.addresses[0]);
107+
const address: string = items[i].address || (items[i].scriptPubKey && items[i].scriptPubKey.addresses[0]);
108108

109-
if (!tmp[addr]) {
110-
tmp[addr] = {};
111-
tmp[addr].valueSat = 0;
112-
tmp[addr].count = 0;
113-
tmp[addr].addr = addr;
114-
tmp[addr].items = [];
109+
if (!tmp[address]) {
110+
tmp[address] = {};
111+
tmp[address].valueSat = 0;
112+
tmp[address].count = 0;
113+
tmp[address].address = address;
114+
tmp[address].items = [];
115115
}
116-
tmp[addr].isSpent = items[i].spentTxId;
116+
tmp[address].isSpent = items[i].spentTxId;
117117

118-
tmp[addr].doubleSpentTxID = tmp[addr].doubleSpentTxID || items[i].doubleSpentTxID;
119-
tmp[addr].doubleSpentIndex = tmp[addr].doubleSpentIndex || items[i].doubleSpentIndex;
120-
tmp[addr].dbError = tmp[addr].dbError || items[i].dbError;
121-
tmp[addr].valueSat += Math.round(items[i].value * this.COIN);
122-
tmp[addr].items.push(items[i]);
123-
tmp[addr].notAddr = notAddr;
118+
tmp[address].doubleSpentTxID = tmp[address].doubleSpentTxID || items[i].doubleSpentTxID;
119+
tmp[address].doubleSpentIndex = tmp[address].doubleSpentIndex || items[i].doubleSpentIndex;
120+
tmp[address].dbError = tmp[address].dbError || items[i].dbError;
121+
tmp[address].valueSat += Math.round(items[i].value * this.COIN);
122+
tmp[address].items.push(items[i]);
123+
tmp[address].notAddr = notAddr;
124124

125-
if (items[i].unconfirmedInput) tmp[addr].unconfirmedInput = true;
125+
if (items[i].unconfirmedInput) { tmp[address].unconfirmedInput = true; }
126126

127-
tmp[addr].count++;
127+
tmp[address].count++;
128128
}
129129

130-
for (let v in tmp) {
131-
let obj: any = tmp[v];
130+
for (const v in tmp) {
131+
const obj: any = tmp[v];
132132
obj.value = obj.value || parseInt(obj.valueSat) / this.COIN;
133133
ret.push(obj);
134134
}

packages/insight-previous/src/pages/home/home.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Ionic pages and navigation.
66
-->
77
<ion-header>
8-
<head-nav [title]="'insight'"></head-nav>
8+
<head-nav [title]="'insight'" (updateView)="loadView($event,true)"></head-nav>
99
</ion-header>
1010

1111

@@ -14,7 +14,7 @@
1414

1515
<div class="latest-blocks">
1616
<h1>Latest Blocks</h1>
17-
<latest-blocks [showTimeAs]="'age'" [showAllBlocksButton]="true"></latest-blocks>
17+
<latest-blocks [showTimeAs]="'age'" [showAllBlocksButton]="true" #latestBlocks></latest-blocks>
1818
</div>
1919

2020
<div class="about">

0 commit comments

Comments
 (0)