Commit 7fadc840 by Florian Shllaku

crypto front end and swap button done

parent bda474aa
......@@ -12,7 +12,7 @@ class updatecrypto extends Command
*
* @var string
*/
protected $signature = 'update:crypto';
protected $signature = 'up:crypto';
/**
* The console command description.
......@@ -47,7 +47,7 @@ class updatecrypto extends Command
$res = $client->request('GET', 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest', [
'query' => [
'limit' => '100',
'limit' => '39',
'convert' => 'EUR'
],
'Filter' => ['data']
......
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class CryptoListing extends Model
{
protected $table = 'crypto';
}
......@@ -15,7 +15,7 @@ class Controller extends BaseController
class CryptoController extends Controller
{
public function convert($convertFrom,$convertFromValue,$convertTo)
public static function convert($convertFrom,$convertFromValue,$convertTo)
{
$dbCryptoTable = 'crypto';
$convertFromRate = DB::table($dbCryptoTable)->where('symbol', $convertFrom)->value('rate');
......
......@@ -2,6 +2,7 @@
namespace App\Providers;
use App\CurrencyListing;
use App\CryptoListing;
use Illuminate\Support\ServiceProvider;
class DynamicClassProvider extends ServiceProvider
......@@ -10,10 +11,20 @@
{
view()->composer('*', function($view){
$view->with('currencies', CurrencyListing::all());
$view
->with('currencies', CurrencyListing::all());
});
view()->composer('*', function($view){
$view->with('cryptos', CryptoListing::all());
});
}
}
\ No newline at end of file
......@@ -6,36 +6,42 @@
<label for="FormControlSelect1">Convert From</label>
<div class="input-group">
<br>
<select class="form-control" id="FormControlSelect1">
<option>BTC</option>
<option>ETH</option>
<option>XRP</option>
<option>ADA</option>
<option>LTC</option>
<option>DASH</option>
<option>USDT</option>
<form action="/crypto" method="GET">
<input type="number" step="0.01" min="0" id="Amount" name="Amount" class="form-control form-control-lg mx-3" value="">
<select class="form-control" id="From" name="From">
@foreach ($cryptos as $item)
<option class="color" value="{{ $item->symbol }}">{{ $item->name }} - {{ $item->symbol }}</option>
@endforeach
</select>
</div>
<input type="number" class="form-control form-control-lg mx-3" value="">
<label for="FormControlSelect1">To</label>
<div class="input-group">
<br> <br>
<select class="form-control" id="FormControlSelect1">
<option>BTC</option>
<option>ETH</option>
<option>XRP</option>
<option>ADA</option>
<option>LTC</option>
<option>DASH</option>
<option>USDT</option>
<select class="form-control" id="To" name="To">
@foreach ($cryptos as $item)
<option class="color" value="{{ $item->symbol }}">{{ $item->name }} - {{ $item->symbol }}</option>
@endforeach
</select>
</div>
<input type="number" class="form-control form-control-lg mx-3" value="">
<br> <br>
<div class="btn">
<span id="result" value=""></span>
<br> <br>
<button class="btn btn--pill" type="submit">Convert!</button>
</form>
<?php
if( isset($_GET["From"]) && isset($_GET["Amount"]) && isset($_GET["To"]))
{
if (!empty($_GET["From"]) && !empty($_GET["Amount"]) && !empty($_GET["To"])) {
$rez = \App\Http\Controllers\CryptoController::convert($_GET["From"],$_GET["Amount"],$_GET["To"]);
if ($rez == null) {
//Something went wrong and function wasnt run
echo "Something went wrong!";
}
echo $rez;
}
}
?>
</div>
</div>
</div>
@include('footer')
@endsection
\ No newline at end of file
......@@ -7,13 +7,15 @@
<div class="input-group">
<br>
<form action="/currency" method="GET">
<input type="number" id="Amount" name="Amount" class="form-control form-control-lg mx-3" value="">
<input type="number" step="0.01" min="0" id="Amount" name="Amount" class="form-control form-control-lg mx-3" value="">
<select class="form-control" id="From" name="From">
@foreach ($currencies as $item)
<option class="color" value="{{ $item->iso }}">{{ $item->name }} - {{ $item->iso }}</option>
@endforeach
</select>
<br> <br>
<br>
<input type="button" id="go" onclick="swapValues()" value="Swap">
<br>
<select class="form-control" id="To" name="To">
@foreach ($currencies as $item)
<option class="color" value="{{ $item->iso }}">{{ $item->name }} - {{ $item->iso }}</option>
......@@ -25,46 +27,32 @@
<button class="btn btn--pill" type="submit">Convert!</button>
</form>
<?php
if( isset($_GET["Amount"]))
if( isset($_GET["From"]))
{
$value = $_GET['Amount'];
$one = $_GET['From'];
$two = $_GET['To'];
//$From = DB::table('currency')->where('iso', $_GET['From'])->pluck('rates');
//$From = DB::select('Select rates from currency')->where('iso', '=', "{$one}")->get();
$users = (DB::table('currency')->select('rates')->where('iso', '=', $one)->get())->pluck('rates');
$From = $users[0];
$arrFrom = (DB::table('currency')->select('rates')->where('iso', '=', $_GET['From'])->get())->pluck('rates');
$From = $arrFrom[0];
$renat = (DB::table('currency')->select('rates')->where('iso', '=', $two)->get())->pluck('rates');
$To = $renat[0];
//$from = DB::table('currency')
//->select(DB::raw('count(*) as user_count, status'))
// ->where('status', '<>', 1)
// ->groupBy('status')
// ->get();
$arrTo = (DB::table('currency')->select('rates')->where('iso', '=', $_GET['To'])->get())->pluck('rates');
$To = $arrTo[0];
//$To = DB::table('currency')->where('iso', $_GET['To'])->pluck('rates');
#$To = DB::select('Select rates from currency')->where('iso', '=', "%{$two}%")->get();
$rez = ($value/$From) * $To;
echo $rez;
echo '<br>';
echo $value;
echo $From;
echo '<br>';
echo $To;
}
else{
echo 'Enter value';
}
?>
?>
</div>
</div>
</div>
<script>
function swapValues(){
var tmp = document.getElementById("From").value;
document.getElementById("From").value = document.getElementById("To").value;
document.getElementById("To").value = tmp;
}
</script>
......
......@@ -9,6 +9,7 @@ return array(
'App\\Admin' => $baseDir . '/app/Admin.php',
'App\\Console\\Commands\\updatecrypto' => $baseDir . '/app/Console/Commands/updatecrypto.php',
'App\\Console\\Kernel' => $baseDir . '/app/Console/Kernel.php',
'App\\CryptoListing' => $baseDir . '/app/CryptoListing.php',
'App\\CurrencyListing' => $baseDir . '/app/CurrencyListing.php',
'App\\Exceptions\\Handler' => $baseDir . '/app/Exceptions/Handler.php',
'App\\Http\\Controllers\\Auth\\ForgotPasswordController' => $baseDir . '/app/Http/Controllers/Auth/ForgotPasswordController.php',
......
......@@ -415,6 +415,7 @@ class ComposerStaticInitaaf7a2d0aa0540e4f74d52dc30d67caa
'App\\Admin' => __DIR__ . '/../..' . '/app/Admin.php',
'App\\Console\\Commands\\updatecrypto' => __DIR__ . '/../..' . '/app/Console/Commands/updatecrypto.php',
'App\\Console\\Kernel' => __DIR__ . '/../..' . '/app/Console/Kernel.php',
'App\\CryptoListing' => __DIR__ . '/../..' . '/app/CryptoListing.php',
'App\\CurrencyListing' => __DIR__ . '/../..' . '/app/CurrencyListing.php',
'App\\Exceptions\\Handler' => __DIR__ . '/../..' . '/app/Exceptions/Handler.php',
'App\\Http\\Controllers\\Auth\\ForgotPasswordController' => __DIR__ . '/../..' . '/app/Http/Controllers/Auth/ForgotPasswordController.php',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment