Skip to content

Commit e27d8a3

Browse files
committed
unify equal functions
1 parent e23dcbb commit e27d8a3

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,9 @@ export class TransactionComponent implements OnInit {
5959
}
6060

6161
public getConfirmations() {
62-
this.blocksProvider.getCurrentHeight().subscribe(height => {
63-
this.confirmations =
64-
this.tx.blockheight > 0
65-
? height - this.tx.blockheight + 1
66-
: this.tx.blockheight;
67-
});
62+
this.txProvider
63+
.getConfirmations(this.tx.blockheight)
64+
.subscribe(confirmations => (this.confirmations = confirmations));
6865
}
6966

7067
public goToTx(txId: string, vout?: number, fromVout?: boolean): void {

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ export class TransactionPage {
6060
data => {
6161
this.tx = data.tx;
6262
this.loading = false;
63-
this.getConfirmations();
63+
this.txProvider
64+
.getConfirmations(this.tx.blockheight)
65+
.subscribe(confirmations => (this.confirmations = confirmations));
6466
// Be aware that the tx component is loading data into the tx object
6567
},
6668
err => {
@@ -70,15 +72,6 @@ export class TransactionPage {
7072
);
7173
}
7274

73-
public getConfirmations() {
74-
this.blocksProvider.getCurrentHeight().subscribe(height => {
75-
this.confirmations =
76-
this.tx.blockheight > 0
77-
? height - this.tx.blockheight + 1
78-
: this.tx.blockheight;
79-
});
80-
}
81-
8275
public goToBlock(blockHash: string): void {
8376
this.redirProvider.redir('block-detail', {
8477
blockHash,

packages/insight-previous/src/providers/transactions/transactions.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export class TxsProvider {
116116
public http: Http,
117117
private api: ApiProvider,
118118
public currency: CurrencyProvider,
119-
public blocks: BlocksProvider
119+
public blocksProvider: BlocksProvider
120120
) {}
121121

122122
public getFee(tx: AppTx): number {
@@ -187,4 +187,10 @@ export class TxsProvider {
187187
return data.json() as CoinsApiResponse;
188188
});
189189
}
190+
191+
public getConfirmations(blockheight: number): Observable<number> {
192+
return this.blocksProvider.getCurrentHeight().map(height => {
193+
return blockheight > 0 ? height - blockheight + 1 : blockheight;
194+
});
195+
}
190196
}

0 commit comments

Comments
 (0)