@@ -1416,7 +1416,7 @@ public function getTokensTop($limit = 50, $criteria = 'trade', $updateCache = fa
1416
1416
'volumePrevious ' => 0
1417
1417
);
1418
1418
$ result = $ this ->oCache ->get ($ cache , false , true );
1419
- if ($ updateCache || ( FALSE === $ result ) ){
1419
+ if ($ updateCache ){
1420
1420
$ aTokens = $ this ->getTokens ();
1421
1421
$ result = array ();
1422
1422
$ total = 0 ;
@@ -1584,11 +1584,21 @@ public function getTokensTop($limit = 50, $criteria = 'trade', $updateCache = fa
1584
1584
if ($ criteria == 'count ' ) $ sortMethod = '_sortByTxCount ' ;
1585
1585
usort ($ result , array ($ this , $ sortMethod ));
1586
1586
1587
+ $ aPrevTotals = $ this ->oCache ->get ('top_tokens_totals ' , FALSE , TRUE );
1588
+ $ prevTokensNum = 0 ;
1589
+ if (FALSE !== $ aPrevTotals ){
1590
+ $ prevTokensNum = $ aPrevTotals ['tokensWithPrice ' ];
1591
+ }
1592
+ if ($ aTotals ['tokensWithPrice ' ] < $ prevTokensNum ) $ aTotals ['tokensWithPrice ' ] = $ prevTokensNum ;
1593
+ if (($ criteria != 'count ' ) && ($ aTotals ['tokensWithPrice ' ] > $ topLimit )){
1594
+ $ tokensLimit = $ aTotals ['tokensWithPrice ' ];
1595
+ }else {
1596
+ $ tokensLimit = $ topLimit ;
1597
+ }
1598
+
1587
1599
$ res = [];
1588
1600
foreach ($ result as $ i => $ item ){
1589
- if ($ i < $ topLimit ){
1590
- // $item['percentage'] = round(($item['volume'] / $total) * 100);
1591
-
1601
+ if ($ i < $ tokensLimit ){
1592
1602
// get tx's other trends
1593
1603
if (($ item ['address ' ] != self ::ADDRESS_ETH ) && $ criteria == 'count ' ){
1594
1604
unset($ aPeriods [0 ]);
@@ -1613,20 +1623,18 @@ public function getTokensTop($limit = 50, $criteria = 'trade', $updateCache = fa
1613
1623
$ res [] = $ item ;
1614
1624
}
1615
1625
}
1626
+
1616
1627
$ aTotals ['ts ' ] = time ();
1617
- $ aPrevTotals = $ this ->oCache ->get ('top_tokens_totals ' , FALSE , TRUE );
1618
- $ prevTokensNum = 0 ;
1619
- if (FALSE !== $ aPrevTotals ){
1620
- $ prevTokensNum = $ aPrevTotals ['tokensWithPrice ' ];
1621
- }
1622
- if ($ aTotals ['tokensWithPrice ' ] < $ prevTokensNum ) $ aTotals ['tokensWithPrice ' ] = $ prevTokensNum ;
1623
1628
$ result = array ('tokens ' => $ res , 'totals ' => $ aTotals );
1624
1629
$ this ->oCache ->save ($ cache , $ result );
1625
1630
$ this ->oCache ->save ('top_tokens_totals ' , $ aTotals );
1626
1631
}
1632
+ if (FALSE === $ result ){
1633
+ $ result = array ('tokens ' => array ());
1634
+ }
1627
1635
1628
1636
$ res = [];
1629
- if ($ limit < $ topLimit ){
1637
+ if ($ limit > 0 && $ limit < $ topLimit ){
1630
1638
foreach ($ result ['tokens ' ] as $ i => $ item ){
1631
1639
if ($ i < $ limit ){
1632
1640
$ res [] = $ item ;
@@ -2127,7 +2135,7 @@ public function getBlockTransactions($block, $showZero = false){
2127
2135
2128
2136
public function getTokenPrice30d ($ address ){
2129
2137
$ result = FALSE ;
2130
- $ aTokensTop = $ this ->getTokensTop (100 , 'cap ' );
2138
+ $ aTokensTop = $ this ->getTokensTop (- 1 , 'cap ' );
2131
2139
if (is_array ($ aTokensTop ) && isset ($ aTokensTop ['tokens ' ])){
2132
2140
foreach ($ aTokensTop ['tokens ' ] as $ aToken ){
2133
2141
if (($ aToken ['address ' ] == $ address ) && isset ($ aToken ['cap-30d-previous ' ]) && $ aToken ['cap-30d-previous ' ] > 0 ){
0 commit comments