Skip to content

Commit

Permalink
display doge balance
Browse files Browse the repository at this point in the history
  • Loading branch information
drewtunney committed Mar 1, 2014
1 parent 276a2ba commit a448149
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
15 changes: 15 additions & 0 deletions app/helpers/buy_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ def buy_sell_logic
redirect_to user_path(@user)
end

if -@doge_total > @user.current_doge_balance
flash[:error] = "Can't sell Bitcoins you don't have!"
redirect_to user_path(@user)
end

### protecting against unknown characters ###
if -@usd_total <= 0 && @btc_total > 0
flash[:error] = "Invalid Entry, but nice try"
Expand All @@ -45,6 +50,16 @@ def buy_sell_logic
redirect_to user_path(@user)
end

if -@usd_total <= 0 && @doge_total > 0
flash[:error] = "Invalid Entry, but nice try"
redirect_to user_path(@user)
end

if @usd_total <= 0 && @doge_total < 0
flash[:error] = "Invalid Entry, but nice try"
redirect_to user_path(@user)
end

end

end
6 changes: 3 additions & 3 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ def current_btc_balance
self.btc + Transaction.where(user: self).sum('btc_total').to_f
end

# def current_doge_balance
# self.doge + Transaction.where(user: self).sum('doge').to_f
# end
def current_doge_balance
self.doge + Transaction.where(user: self).sum('doge_total').to_f
end

def get_current_price
from_bitstamp = HTTParty.get("https://www.bitstamp.net/api/ticker/")
Expand Down
1 change: 1 addition & 0 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<h1>Welcome <%= @user.user_name %></h1>
<p class="homepage_menu">USD balance: $<%= number_with_precision(@user.current_usd_balance, :precision => 2, :delimiter => ',') %></p>
<p class="homepage_menu">BTC balance: <%= @user.current_btc_balance %></p>
<p class="homepage_menu">Doge Balance: <%= @user.current_doge_balance %></p>

<p class="homepage_menu">Total Balance: $<%= number_with_precision(@user.total_balance, :precision => 2, :delimiter => ',') %> </p>

Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20140301194306_add_doge_to_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddDogeToUsers < ActiveRecord::Migration
def change
add_column :users, :doge, :integer, default: 0
end
end
13 changes: 11 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,19 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20140224110140) do
ActiveRecord::Schema.define(version: 20140301194306) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

create_table "accounts", force: true do |t|
t.decimal "usd", default: 25000.0
t.decimal "btc"
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "transactions", force: true do |t|
t.decimal "price"
t.decimal "btc_total"
Expand All @@ -24,7 +32,7 @@
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
t.decimal "doge", default: 0.0
t.decimal "doge_total", default: 0.0
end

create_table "users", force: true do |t|
Expand All @@ -35,6 +43,7 @@
t.decimal "btc", default: 0.0
t.datetime "created_at"
t.datetime "updated_at"
t.integer "doge", default: 0
end

end

0 comments on commit a448149

Please sign in to comment.