Skip to content

Commit 4b33dac

Browse files
authored
Merge pull request bitpay#2122 from rastajpa/fix/coins
[insight-previous] FIX: show outgoing and incoming txs on address page
2 parents 0bfe369 + c7c5862 commit 4b33dac

File tree

5 files changed

+71
-16
lines changed

5 files changed

+71
-16
lines changed

packages/insight-previous/src/components/coin-list/coin-list.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
<div *ngIf="!loading">
44
<ion-grid>
5-
<ion-row *ngFor="let coin of coins; let i = index">
5+
<ion-row *ngFor="let tx of txs; let i = index">
66
<ion-col col-12 *ngIf="i < limit">
7-
<coin [coin]="coin"></coin>
7+
<coin [coin]="tx"></coin>
88
</ion-col>
99
</ion-row>
10-
<ion-row *ngIf="limit < coins.length">
10+
<ion-row *ngIf="limit < txs.length">
1111
<ion-infinite-scroll (ionInfinite)="loadMore($event)">
1212
<loader [type]="'tx-list'"></loader>
1313
</ion-infinite-scroll>
1414
</ion-row>
15-
<ion-row *ngIf="coins.length === 0" class="no-txs">
15+
<ion-row *ngIf="txs.length === 0" class="no-txs">
1616
<ion-col col-12>
1717
There are no transactions involving this address.
1818
</ion-col>

packages/insight-previous/src/components/coin-list/coin-list.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Component, Input, OnInit } from '@angular/core';
22
import { Events } from 'ionic-angular';
3+
import _ from 'lodash';
34
import { AddressProvider } from '../../providers/address/address';
45
import { Logger } from '../../providers/logger/logger';
56
import { TxsProvider } from '../../providers/transactions/transactions';
@@ -12,7 +13,7 @@ export class CoinListComponent implements OnInit {
1213
@Input()
1314
public addrStr?: string;
1415

15-
public coins: any = [];
16+
public txs: any = [];
1617
public showTransactions: boolean;
1718
public loading;
1819
public limit = 10;
@@ -26,11 +27,12 @@ export class CoinListComponent implements OnInit {
2627
) {}
2728

2829
public ngOnInit(): void {
29-
if (this.coins && this.coins.length === 0) {
30+
if (this.txs && this.txs.length === 0) {
3031
this.loading = true;
3132
this.addrProvider.getAddressActivity(this.addrStr).subscribe(
3233
data => {
33-
this.coins = data.map(this.txsProvider.toAppCoin);
34+
const formattedData = data.map(this.txsProvider.toAppCoin);
35+
this.txs = this.orderByHeight(formattedData);
3436
this.showTransactions = true;
3537
this.loading = false;
3638
this.events.publish('CoinList', { length: data.length });
@@ -44,6 +46,26 @@ export class CoinListComponent implements OnInit {
4446
}
4547
}
4648

49+
orderByHeight(data) {
50+
const unconfirmedTxs = [];
51+
let confirmedTxs = [];
52+
53+
data.forEach(tx => {
54+
const { mintHeight, mintTxid, value, spentHeight, spentTxid } = tx;
55+
56+
mintHeight < 0
57+
? unconfirmedTxs.push({ height: mintHeight, mintTxid, value })
58+
: confirmedTxs.push({ height: mintHeight, mintTxid, value });
59+
60+
spentHeight < 0
61+
? unconfirmedTxs.push({ height: spentHeight, spentTxid, value })
62+
: confirmedTxs.push({ height: spentHeight, spentTxid, value });
63+
});
64+
65+
confirmedTxs = _.orderBy(confirmedTxs, ['height'], ['desc']);
66+
return unconfirmedTxs.concat(confirmedTxs);
67+
}
68+
4769
public loadMore(infiniteScroll) {
4870
this.limit += this.chunkSize;
4971
this.chunkSize *= 2;

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

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,47 @@
11
<ion-grid>
2-
<ion-row>
2+
<ion-row *ngIf="coin?.mintTxid">
33
<ion-col col-7>
44
<div class="ellipsis">
5-
<span>
5+
<span *ngIf="coin.height >= 0">
66
<a (click)="goToTx(coin.mintTxid)">{{ coin.mintTxid }}</a>
77
</span>
8+
<span ion-text color="danger" *ngIf="coin.height === -3">
9+
Invalid
10+
</span>
11+
</div>
12+
</ion-col>
13+
<ion-col col-5 text-right>
14+
<span ion-text>
15+
<ion-icon name="md-add-circle" color="dark"></ion-icon>
16+
{{ currencyProvider.getConvertedNumber(coin.value) | number:'1.0-8' }}
17+
{{ currencyProvider.currencySymbol }}
18+
</span>
19+
</ion-col>
20+
</ion-row>
21+
22+
<ion-row *ngIf="coin?.spentTxid || coin?.spentTxid == ''">
23+
<ion-col col-7>
24+
<div class="ellipsis">
25+
<span *ngIf="coin.height >= -1">
26+
<a (click)="goToTx(coin.spentTxid)">{{ coin.spentTxid }}</a>
27+
</span>
28+
<span *ngIf="coin.height === -2">
29+
Unspent
30+
</span>
31+
<span ion-text color="danger" *ngIf="coin.height === -3">
32+
Invalid
33+
</span>
34+
<span ion-text color="danger" *ngIf="coin.height === -4">
35+
Error
36+
</span>
837
</div>
938
</ion-col>
1039
<ion-col col-5 text-right>
11-
{{ currencyProvider.getConvertedNumber(coin.value) | number:'1.0-8' }} {{ currencyProvider.currencySymbol }}
12-
<a [hidden]="!coin.spentTxid" (click)="goToTx(coin.spentTxid)">
13-
<span ion-text color="danger">(S)</span>
14-
</a>
15-
<span [hidden]="coin.spentTxid">
16-
<span ion-text color="brand">(U)</span>
40+
<span ion-text [color]="!coin.spentTxid ? 'default':'dark-light'">
41+
<ion-icon name="md-remove-circle" [color]="!coin.spentTxid ? 'default':'dark-light'" *ngIf="coin.height >= 0">
42+
</ion-icon>
43+
{{ currencyProvider.getConvertedNumber(coin.value) | number:'1.0-8' }}
44+
{{ currencyProvider.currencySymbol }}
1745
</span>
1846
</ion-col>
1947
</ion-row>

packages/insight-previous/src/components/coin/coin.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ coin {
1010
font-size: 1.1rem;
1111
}
1212

13+
ion-icon {
14+
color: rgba(0, 0, 0, 0.25);
15+
}
16+
1317
}
1418
}
1519
}

packages/insight-previous/src/theme/variables.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ $colors: (
2323
brand: #8dc429,
2424
primary: #2fa4d7,
2525
secondary: #8dc429,
26-
danger: #f53d3d,
26+
danger: #a94442,
2727
warning: #ffa400,
2828
light: #f4f4f4,
29+
dark-light: #a2a2a2,
2930
dark: #373d42
3031
);
3132

0 commit comments

Comments
 (0)