aboutsummaryrefslogtreecommitdiffstats
path: root/static/js/index.coffee
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2017-01-15 18:24:09 -0800
committerAdam Soltys <[email protected]>2017-01-15 18:24:09 -0800
commit7762ceaa7e2bb34f8758e17a4c8f512fa6a81b9e (patch)
tree91bb1d1b8fe6ad77a48f0e429d9bfd35834c78d9 /static/js/index.coffee
parent0ae266bf88f9f79c7e99b272688126898303daa4 (diff)
downloadcoinos-server-7762ceaa7e2bb34f8758e17a4c8f512fa6a81b9e.tar.gz
coinos-server-7762ceaa7e2bb34f8758e17a4c8f512fa6a81b9e.zip
Initial Vueification
Diffstat (limited to 'static/js/index.coffee')
-rw-r--r--static/js/index.coffee44
1 files changed, 44 insertions, 0 deletions
diff --git a/static/js/index.coffee b/static/js/index.coffee
new file mode 100644
index 00000000..090abbe2
--- /dev/null
+++ b/static/js/index.coffee
@@ -0,0 +1,44 @@
+#= require js/jquery-1.8.2.min.js
+#= require js/bootstrap.min.js
+
+g = exports ? this
+
+$(->
+ fetchExchangeRate('ask')
+ fetchExchangeRate('bid')
+
+ $('#username').blur(->
+ $.get(
+ "/#{$(this).val()}/exists",
+ username: $(this).val(),
+ (data) ->
+ if data is "true"
+ $('#username').prev().css('color', 'red').html('Username (taken)')
+ g.preventSubmit = true
+ else
+ $('#username').prev().css('color', 'black').html('Username')
+ g.preventSubmit = false
+ )
+ )
+
+ $('#signup').submit(->
+ return false if g.preventSubmit
+ return true
+ )
+)
+
+fetchExchangeRate = (type) ->
+ commission = 0.015
+ commission *= -1 if type is 'bid'
+
+ $.ajax(
+ url: "/ticker?symbol=virtexCAD&type=#{type}&amount=100",
+ success: (exchange) ->
+ if not exchange?
+ exchange = '??'
+
+ exchange = exchange - exchange * commission
+ $("##{type}").html(exchange.toFixed(2))
+ error: ->
+ $("##{type}").html('??')
+ )