-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added blockchain exchange card; updates; fixes
- Loading branch information
1 parent
eeafafc
commit 14e0877
Showing
8 changed files
with
152 additions
and
7 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<template> | ||
<LoadingCardWithButton | ||
heading="Blockchain Exchange Rates" | ||
:loading="loading" | ||
@refresh="fetch" | ||
> | ||
<table v-if="data" class="w-full text-left table-collapse"> | ||
<thead class="bg-white dark:bg-gray-800 sticky-table-header"> | ||
<tr> | ||
<th class="p-2 font-bold"></th> | ||
<th class="p-2 font-bold">Buy</th> | ||
<th class="p-2 font-bold">Sell</th> | ||
</tr> | ||
</thead> | ||
<tbody class="align-baseline"> | ||
<tr v-for="(item, index) in data"> | ||
<td class="py-2 pr-2 font-bold"> | ||
{{ index }} | ||
</td> | ||
<td class="p-2"> | ||
{{ item.symbol }} {{ formatPrice(item.buy) }} | ||
</td> | ||
<td class="p-2"> | ||
{{ item.symbol }} {{ formatPrice(item.sell) }} | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
<div v-else> | ||
{{ __('No Data') }} | ||
</div> | ||
|
||
<div class="py-3 text-xs text-80"> | ||
Via <a href="https://blockchain.info/ticker">Blockchain.com</a> | ||
</div> | ||
</LoadingCardWithButton> | ||
</template> | ||
|
||
<script> | ||
import Polling from '../mixins/Polling.js' | ||
export default { | ||
props: { | ||
card: { | ||
type: Object, | ||
required: true, | ||
}, | ||
}, | ||
mixins: [Polling], | ||
data: () => ({ | ||
data: {}, | ||
endpoint: '/nova-vendor/stepanenko3/nova-cards/blockchain-exchange', | ||
}), | ||
methods: { | ||
success(data) { | ||
this.data = data | ||
}, | ||
formatPrice(value) { | ||
let val = (value/1).toFixed(2).replace('.', ',') | ||
return val.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ".") | ||
} | ||
}, | ||
} | ||
</script> | ||
|
||
<style> | ||
.sticky-table-header { | ||
position: sticky; | ||
top: 0; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Stepanenko3\NovaCards\Cards; | ||
|
||
use Laravel\Nova\Card; | ||
|
||
class BlockchainExchangeCard extends Card | ||
{ | ||
/** | ||
* The width of the card (1/3, 1/2, or full). | ||
* | ||
* @var string | ||
*/ | ||
public $width = '1/3'; | ||
|
||
public function pollingTime(int $ms): static | ||
{ | ||
return $this->withMeta(['pollingTime' => $ms]); | ||
} | ||
|
||
/** | ||
* Get the component name for the element. | ||
* | ||
* @return string | ||
*/ | ||
public function component() | ||
{ | ||
return 'blockchain-exchange-card'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Stepanenko3\NovaCards\Http\Controllers; | ||
|
||
use Cache; | ||
use Http; | ||
|
||
class BlockchainExchangeController | ||
{ | ||
public function __invoke() | ||
{ | ||
$data = Cache::remember( | ||
'blockchain-exchange-rates::ticker', | ||
10, | ||
fn () => Http::get('https://blockchain.info/ticker')->json(), | ||
); | ||
|
||
return response()->json($data); | ||
} | ||
} |