-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcorb_wallet.rb
96 lines (75 loc) · 1.4 KB
/
corb_wallet.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
require_relative 'config/env'
class CorbWallet < Roda
plugin(:assets,
css: ["style.css"],
js: ["vendor/underscore.js", "vendor/qrcode.js"],
)
# plugin :render, engine: :haml # TODO: PR to Roda to accept hashes
plugin :render, engine: "haml"
plugin :partials
plugin :not_found
def json_route
response['Content-Type'] = 'application/json'
end
def wallet
@@wallet ||= Wallet.new
end
def params
symbolize request.params
end
# monkeypatches
def symbolize(hash)
Hash[hash.map{|(k,v)| [k.to_sym,v]}]
end
# view
def body_class
request.path.split("/")[1]
end
def table_row(text, colspan: 5)
haml_tag(:tr) do
haml_tag(:td, colspan: colspan) do
haml_concat text
end
end
end
route do |r|
r.root do
r.redirect "/receive"
end
r.on "receive" do
r.is do
r.get do
view "receive"
end
end
end
r.on "send" do
r.is do
r.get do
view "send"
end
r.post do
wallet.send params[:to], params[:amount].to_f
end
end
end
r.on "transactions" do
r.is do
r.get do
view "transactions"
end
end
end
r.on "extra" do
r.is do
r.get do
view "extra"
end
end
end
r.assets
end
not_found do
view "not_found"
end
end