Skip to content

Commit

Permalink
sync develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Haehnchen committed May 17, 2021
1 parent 9cff205 commit 68e48cb
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 44 deletions.
8 changes: 8 additions & 0 deletions icons.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

DIRECTORY=`dirname $0`

git -C "$DIRECTORY/remotes/pancake-frontend/" pull
git -C "$DIRECTORY/remotes/valuedefi-trustwallet-assets/" pull
git -C "$DIRECTORY/remotes/trustwallet-assets/" pull
git -C "$DIRECTORY/remotes/cryptocurrency-icons/" pull
22 changes: 22 additions & 0 deletions public/assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,26 @@ $(function() {
});
})
}


var $charts = $(".chart-js-token-price");

if ($charts.length > 0) {
$charts.each(function() {
let $1 = $(this);
new Chart($1, {
type: 'line',
data: {
labels: $1.data('label'),
datasets: [{
label: $1.data('title'),
data: $1.data('data'),
fill: false,
borderColor: 'rgb(75, 192, 192)',
tension: 0.2
}]
}
});
});
}
});
17 changes: 5 additions & 12 deletions src/Controller/AddressController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Client\NodeClient;
use App\Pools\FarmPools;
use App\Repository\FarmRepository;
use App\Repository\PlatformRepository;
use App\Symbol\IconResolver;
use App\Utils\RandomAddress;
Expand Down Expand Up @@ -196,22 +197,14 @@ public function jsonWallet(string $address, NodeClient $nodeClient, Environment
/**
* @Route("/farms/0x{address}/{farmId}", name="farm_detail")
*/
public function detail(string $address, string $farmId, NodeClient $nodeClient, IconResolver $iconResolver, FarmPools $farmPools): Response
public function detail(string $address, string $farmId, NodeClient $nodeClient, IconResolver $iconResolver, FarmPools $farmPools, FarmRepository $farmRepository): Response
{
$farm = null;
foreach ($farmPools->generateFarms() as $farm1) {
$id = $farm1['id'] ?? 'foo';
if (md5($id) === $farmId) {
$farm = $farm1;
break;
}
}

$farm = $farmRepository->findFarmIdByHash($farmId);
if (!$farm) {
throw new NotFoundHttpException();
}

$details = $nodeClient->getDetails($address, $farm['id']);
$details = $nodeClient->getDetails($address, $farm->getFarmId());

if (isset($details['lpTokens'])) {
foreach ($details['lpTokens'] as $key => $lpToken) {
Expand All @@ -225,7 +218,7 @@ public function detail(string $address, string $farmId, NodeClient $nodeClient,
$response->setMaxAge(9);

return $this->render('address/details.html.twig', [
'farm' => $farm,
'farm' => $farmPools->generateFarm($farm->getJson()),
'details' => $details,
], $response);
}
Expand Down
20 changes: 18 additions & 2 deletions src/Controller/TokenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,28 @@ public function token(string $token)
$samePairs[] = $item;
}

return $this->render('vault/token.html.twig', [
$parameters = [
'token' => $token,
'vaults' => $others,
'token_card' => $this->getTokenCard($token),
'same_pairs' => $samePairs,
], $response);
];


$candles = [];
foreach ($info['candles'] ?? [] as $candle) {
$format = date_create_from_format('U', $candle['time'])->format('m-d H') . ':00';
$candles[$format] = $candle['close'];
}

if (count($candles) > 0) {
$parameters['chart'] = [
'label' => array_keys($candles),
'data' => array_values($candles),
];
}

return $this->render('vault/token.html.twig', $parameters, $response);
}

private function getTokenCardInfo(array $info): array
Expand Down
74 changes: 44 additions & 30 deletions src/Pools/FarmPools.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,49 @@ public function generateContent(string $template = 'components/farms_mini.html.t
return $farms;
}

public function generateFarm(array $farm, array $hots = [], $new = []): array
{
$cache = $this->cacheItemPool->getItem('generate-farm-single-' . md5(json_encode([$farm['id'], $hots, $new])));

if ($cache->isHit()) {
return $cache->get();
}

$token = $farm['name'];

if (isset($farm['token'])) {
$token = $farm['token'];
}

$farm['icon'] = '?';
if ($token) {
$farm['icon'] = $this->iconResolver->getIcon($token);
}

$farm['provider'] = $this->platformRepository->getPlatform($farm['provider']);

if (isset($farm['yield']['apr']) && $farm['yield']['apr'] > 0) {
$farm['yield']['daily'] = $farm['yield']['apr'] / 365;
} else {
if (isset($farm['yield']['apy']) && $farm['yield']['apy'] > 0) {
$farm['yield']['daily'] = InterestUtil::apyToApr($farm['yield']['apy'] / 100);
}
}

if (in_array($farm['id'], $hots, true)) {
$farm['hot'] = true;
}

if (in_array($farm['id'], $new, true)) {
$farm['new'] = true;
}

$cache->expiresAfter(60 * 1)->set($farm);
$this->cacheItemPool->save($cache);

return $farm;
}

public function generateFarms(): array
{
$cache = $this->cacheItemPool->getItem('generate-farms');
Expand All @@ -98,36 +141,7 @@ public function generateFarms(): array
$myFarms = [];

foreach ($farms as $farm) {
$token = $farm['name'];

if (isset($farm['token'])) {
$token = $farm['token'];
}

$farm['icon'] = '?';
if ($token) {
$farm['icon'] = $this->iconResolver->getIcon($token);
}

$farm['provider'] = $this->platformRepository->getPlatform($farm['provider']);

if (isset($farm['yield']['apr']) && $farm['yield']['apr'] > 0) {
$farm['yield']['daily'] = $farm['yield']['apr'] / 365;
} else {
if (isset($farm['yield']['apy']) && $farm['yield']['apy'] > 0) {
$farm['yield']['daily'] = InterestUtil::apyToApr($farm['yield']['apy'] / 100);
}
}

if (in_array($farm['id'], $hots, true)) {
$farm['hot'] = true;
}

if (in_array($farm['id'], $new, true)) {
$farm['new'] = true;
}

$myFarms[] = $farm;
$myFarms[] = $this->generateFarm($farm, $hots, $new);
}

$cache->expiresAfter(60 * 5)->set($myFarms);
Expand Down
21 changes: 21 additions & 0 deletions src/Repository/FarmRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,27 @@ public function findFarmIdsByToken(string $token): array
return array_keys($result);
}

public function findFarmIdByHash(string $hash): ?Farm
{
$qb = $this->createQueryBuilder('f', 'f.farmId');

$qb->andWhere('f.hash = :hash');
$qb->setParameter('hash', $hash);

$qb->andWhere('f.lastFoundAt >= :lastFoundAtWindow');
$qb->setParameter('lastFoundAtWindow', date_create('today')->modify('-30 day'));

$qb->setMaxResults(1);

$result = $qb->getQuery()
->useQueryCache(true)
->setResultCacheLifetime(60 * 10)
->setResultCacheId('farm-by-v3-hash' . md5($hash))
->getOneOrNullResult();

return $result;
}

/**
* @return string[]
*/
Expand Down

0 comments on commit 68e48cb

Please sign in to comment.