Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
guru
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DeStream-public
guru
Commits
94650068
Commit
94650068
authored
Nov 08, 2018
by
Clint.Network
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finishing Automatic Conversion from the Browser Currency
parent
82e71439
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
101 additions
and
26 deletions
+101
-26
ApiController.cs
Stratis.Guru/Controllers/ApiController.cs
+31
-4
HomeController.cs
Stratis.Guru/Controllers/HomeController.cs
+33
-2
Ticker.cs
Stratis.Guru/Models/Ticker.cs
+1
-1
FixerService.cs
Stratis.Guru/Services/FixerService.cs
+6
-5
Startup.cs
Stratis.Guru/Startup.cs
+23
-8
Index.cshtml
Stratis.Guru/Views/Home/Index.cshtml
+7
-6
No files found.
Stratis.Guru/Controllers/ApiController.cs
View file @
94650068
using
System
;
using
System.Globalization
;
using
System.Security.Cryptography.X509Certificates
;
using
Microsoft.AspNetCore.Localization
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.Extensions.Caching.Memory
;
using
Microsoft.Extensions.Options
;
using
NBitcoin
;
using
NBitcoin.Networks
;
using
Newtonsoft.Json
;
using
Newtonsoft.Json.Linq
;
using
RestSharp
;
using
Stratis.Guru.Models
;
using
Stratis.Guru.Settings
;
...
...
@@ -27,22 +30,46 @@ namespace Stratis.Guru.Controllers
[
HttpGet
]
[
Route
(
"price"
)]
public
ActionResult
<
object
>
Price
(
bool
stringify
,
double
amount
=
1
)
public
ActionResult
<
object
>
Price
(
bool
notApi
=
false
,
double
amount
=
1
)
{
try
{
dynamic
coinmarketcap
=
JsonConvert
.
DeserializeObject
(
_memoryCache
.
Get
(
"Coinmarketcap"
).
ToString
());
if
(
stringify
)
if
(
notApi
)
{
var
rqf
=
Request
.
HttpContext
.
Features
.
Get
<
IRequestCultureFeature
>();
double
displayPrice
=
0
;
if
(
rqf
.
RequestCulture
.
UICulture
.
ThreeLetterISOLanguageName
.
Equals
(
"eng"
))
{
displayPrice
=
coinmarketcap
.
data
.
quotes
.
USD
.
price
;
}
else
{
dynamic
fixerApiResponse
=
JsonConvert
.
DeserializeObject
(
_memoryCache
.
Get
(
"Fixer"
).
ToString
());
var
dollarRate
=
fixerApiResponse
.
rates
.
USD
;
try
{
var
regionInfo
=
new
RegionInfo
(
rqf
.
RequestCulture
.
UICulture
.
Name
.
ToUpper
());
var
browserCurrencyRate
=
(
double
)
((
JObject
)
fixerApiResponse
.
rates
)[
regionInfo
.
ISOCurrencySymbol
];
displayPrice
=
1
/
(
double
)
dollarRate
*
(
double
)
coinmarketcap
.
data
.
quotes
.
USD
.
price
*
browserCurrencyRate
;
}
catch
{
// ignored
}
}
return
new
TickerApi
{
UsdPrice
=
(
coinmarketcap
.
data
.
quotes
.
USD
.
p
rice
*
amount
).
ToString
(
"C"
),
UsdPrice
=
(
displayP
rice
*
amount
).
ToString
(
"C"
),
Last24Change
=
(
coinmarketcap
.
data
.
quotes
.
USD
.
percent_change_24h
/
100
).
ToString
(
"P2"
)
};
}
return
new
Ticker
{
Usd
Price
=
coinmarketcap
.
data
.
quotes
.
USD
.
price
*
amount
,
Display
Price
=
coinmarketcap
.
data
.
quotes
.
USD
.
price
*
amount
,
Last24Change
=
coinmarketcap
.
data
.
quotes
.
USD
.
percent_change_24h
/
100
};
}
...
...
Stratis.Guru/Controllers/HomeController.cs
View file @
94650068
...
...
@@ -4,13 +4,17 @@ using System.Data;
using
System.Diagnostics
;
using
System.Drawing
;
using
System.Drawing.Imaging
;
using
System.Globalization
;
using
System.IO
;
using
System.Linq
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Microsoft.AspNetCore.Localization
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.Extensions.Caching.Memory
;
using
NBitcoin
;
using
Newtonsoft.Json
;
using
Newtonsoft.Json.Linq
;
using
QRCoder
;
using
Stratis.Guru.Models
;
using
Stratis.Guru.Modules
;
...
...
@@ -30,11 +34,38 @@ namespace Stratis.Guru.Controllers
public
IActionResult
Index
()
{
var
rqf
=
Request
.
HttpContext
.
Features
.
Get
<
IRequestCultureFeature
>();
double
displayPrice
=
0
;
double
last24Change
=
0
;
dynamic
coinmarketcap
=
JsonConvert
.
DeserializeObject
(
_memoryCache
.
Get
(
"Coinmarketcap"
).
ToString
());
last24Change
=
coinmarketcap
.
data
.
quotes
.
USD
.
percent_change_24h
/
100
;
if
(
rqf
.
RequestCulture
.
UICulture
.
ThreeLetterISOLanguageName
.
Equals
(
"eng"
))
{
displayPrice
=
coinmarketcap
.
data
.
quotes
.
USD
.
price
;
}
else
{
dynamic
fixerApiResponse
=
JsonConvert
.
DeserializeObject
(
_memoryCache
.
Get
(
"Fixer"
).
ToString
());
var
dollarRate
=
fixerApiResponse
.
rates
.
USD
;
try
{
var
regionInfo
=
new
RegionInfo
(
rqf
.
RequestCulture
.
UICulture
.
Name
.
ToUpper
());
var
browserCurrencyRate
=
(
double
)
((
JObject
)
fixerApiResponse
.
rates
)[
regionInfo
.
ISOCurrencySymbol
];
displayPrice
=
1
/
(
double
)
dollarRate
*
(
double
)
coinmarketcap
.
data
.
quotes
.
USD
.
price
*
browserCurrencyRate
;
}
catch
{
// ignored
}
}
return
View
(
new
Ticker
{
UsdPrice
=
coinmarketcap
.
data
.
quotes
.
USD
.
p
rice
,
Last24Change
=
coinmarketcap
.
data
.
quotes
.
USD
.
percent_change_24h
/
100
DisplayPrice
=
displayP
rice
,
Last24Change
=
last24Change
});
}
...
...
Stratis.Guru/Models/Ticker.cs
View file @
94650068
...
...
@@ -2,7 +2,7 @@ namespace Stratis.Guru.Models
{
public
class
Ticker
{
public
double
Usd
Price
{
get
;
set
;
}
public
double
Display
Price
{
get
;
set
;
}
public
double
Last24Change
{
get
;
set
;
}
}
}
\ No newline at end of file
Stratis.Guru/Services/FixerService.cs
View file @
94650068
...
...
@@ -2,6 +2,7 @@ using System;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Microsoft.Extensions.Caching.Distributed
;
using
Microsoft.Extensions.Caching.Memory
;
using
Microsoft.Extensions.Hosting
;
using
Microsoft.Extensions.Options
;
using
Newtonsoft.Json
;
...
...
@@ -12,14 +13,14 @@ namespace Stratis.Guru.Services
{
public
class
FixerService
:
IHostedService
,
IDisposable
{
private
FixerApiSettings
_options
;
private
IDistributedCache
_distributedCache
;
private
Timer
_timer
;
private
readonly
FixerApiSettings
_options
;
private
readonly
IMemoryCache
_memoryCache
;
public
FixerService
(
IOptions
<
FixerApiSettings
>
options
,
I
DistributedCache
distributed
Cache
)
public
FixerService
(
IOptions
<
FixerApiSettings
>
options
,
I
MemoryCache
memory
Cache
)
{
_options
=
options
.
Value
;
_
distributedCache
=
distributed
Cache
;
_
memoryCache
=
memory
Cache
;
}
public
Task
StartAsync
(
CancellationToken
cancellationToken
)
...
...
@@ -34,7 +35,7 @@ namespace Stratis.Guru.Services
var
rq
=
new
RestRequest
(
Method
.
GET
);
rs
.
ExecuteAsync
(
rq
,
delegate
(
IRestResponse
response
)
{
_
distributedCache
.
SetString
(
"Fixer"
,
response
.
Content
);
_
memoryCache
.
Set
(
"Fixer"
,
response
.
Content
);
});
}
...
...
Stratis.Guru/Startup.cs
View file @
94650068
...
...
@@ -7,8 +7,8 @@ using System.Threading;
using
System.Threading.Tasks
;
using
Microsoft.AspNetCore.Builder
;
using
Microsoft.AspNetCore.Hosting
;
using
Microsoft.AspNetCore.Http
;
using
Microsoft.AspNetCore.HttpsPolicy
;
using
Microsoft.AspNetCore.Localization
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.Extensions.Configuration
;
using
Microsoft.Extensions.DependencyInjection
;
...
...
@@ -18,32 +18,31 @@ using Stratis.Guru.Models;
using
Stratis.Guru.Modules
;
using
Stratis.Guru.Services
;
using
Stratis.Guru.Settings
;
using
static
Microsoft
.
AspNetCore
.
Http
.
SameSiteMode
;
namespace
Stratis.Guru
{
public
class
Startup
{
p
ublic
IConfiguration
Configuration
{
get
;
}
p
rivate
IConfiguration
Configuration
{
get
;
}
public
Startup
(
IConfiguration
configuration
)
{
Configuration
=
configuration
;
}
// This method gets called by the runtime. Use this method to add services to the container.
public
void
ConfigureServices
(
IServiceCollection
services
)
{
services
.
Configure
<
CookiePolicyOptions
>(
options
=>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options
.
CheckConsentNeeded
=
context
=>
true
;
options
.
MinimumSameSitePolicy
=
SameSiteMode
.
None
;
options
.
MinimumSameSitePolicy
=
None
;
});
services
.
Configure
<
NakoApiSettings
>(
Configuration
.
GetSection
(
"NakoApi"
));
services
.
Configure
<
FixerApiSettings
>(
Configuration
.
GetSection
(
"FixerApi"
));
Thread
.
CurrentThread
.
CurrentCulture
=
new
CultureInfo
(
"en-US"
);
Thread
.
CurrentThread
.
CurrentUICulture
=
new
CultureInfo
(
"en-US"
);
/*
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
*/
services
.
AddMemoryCache
();
...
...
@@ -59,7 +58,6 @@ namespace Stratis.Guru
services
.
AddSignalR
();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public
void
Configure
(
IApplicationBuilder
app
,
IHostingEnvironment
env
)
{
if
(
env
.
IsDevelopment
())
...
...
@@ -94,6 +92,23 @@ namespace Stratis.Guru
DefaultFilesOptions
=
{
DefaultFileNames
=
{
"index.html"
}}
});
var
supportedCultures
=
new
[]
{
new
CultureInfo
(
"en"
),
new
CultureInfo
(
"fr"
),
new
CultureInfo
(
"ru"
),
new
CultureInfo
(
"it"
),
new
CultureInfo
(
"de"
),
new
CultureInfo
(
"cn"
)
};
app
.
UseRequestLocalization
(
new
RequestLocalizationOptions
{
DefaultRequestCulture
=
new
RequestCulture
(
"en-US"
),
SupportedCultures
=
supportedCultures
,
SupportedUICultures
=
supportedCultures
});
app
.
UseSignalR
(
routes
=>
{
routes
.
MapHub
<
UpdateHub
>(
"/update"
);
...
...
Stratis.Guru/Views/Home/Index.cshtml
View file @
94650068
@model Ticker
@using System.Globalization
@model Ticker
@{
ViewBag.Title = "Online Stratis ($STRAT) price ticker";
}
...
...
@@ -12,8 +13,8 @@
<div class="d-inline-block align-middle">
<span class="click-edit" spellcheck="false">1</span> STRAT <span class="d-none d-lg-inline-block">=</span>
</div>
<span class="align-middle display-1 font-weight-bold" id="amount">@(Model.
Usd
Price.ToString("C2"))</span>
<span id="lastchange" class="d-block d-lg-inline-block change-@(Model.Last24Change > 0 ? "success":"danger") font-weight-bold"><sup> <span class="d-none d-lg-inline-block">@((Model.Last24Change > 0 ? "+":""))</span>
@(Model.Last24Change.ToString("P2"))
</sup></span>
<span class="align-middle display-1 font-weight-bold" id="amount">@(Model.
Display
Price.ToString("C2"))</span>
<span id="lastchange" class="d-block d-lg-inline-block change-@(Model.Last24Change > 0 ? "success":"danger") font-weight-bold"><sup> <span class="d-none d-lg-inline-block">@((Model.Last24Change > 0 ? "+":""))</span>
<span class="inner">@(Model.Last24Change.ToString("P2"))</span>
</sup></span>
</h1>
<a asp-controller="BlockExplorer" asp-action="Index" class="btn-secondary-box"><i class="fa fa-cube"></i> Go to Block Explorer</a>
</div>
...
...
@@ -26,13 +27,13 @@
<script src="~/npm/@@aspnet/signalr/dist/browser/signalr.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var stratisPrice = @Model.
UsdPrice
;
var stratisPrice = @Model.
DisplayPrice.ToString("N", new CultureInfo("en-US"))
;
var stratisAmount = 1;
function UpdateTicker() {
NProgress.start();
$.getJSON("/api/price?
stringify
=true&amount=" + stratisAmount, function(e) {
$.getJSON("/api/price?
notApi
=true&amount=" + stratisAmount, function(e) {
$("#amount").text(e.usdPrice);
$("#lastchange").text(e.last24Change);
$("#lastchange").
find(".inner").
text(e.last24Change);
NProgress.done();
});
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment