We are excited to open source Balances and get the community involved! Check out CONTRIBUTING.md for quick guide.
- Run
bundle install
- Copy
.sample.env
to.env
and update with all the necessary credentials. The required ones areSECRET_TOKEN
andEMAIL_HASH_SALT
. - Copy
sample.database.yml
todatabase.yml
- Run
rake db:create db:migrate
- Run
rake currency_conversions:populate
- Run
foreman start
orrails s -p 5000
- Add to
app/modules/currencies/
a file named after the currency. e.g.app/modules/currencies/bitcoin.rb
- Setup your new currency ruby file with
API
,CURRENCY_NAME
,SHORT_NAME
,SYMBOLS
,#info
,#balance
,#valid?
. e.g. see below - Add currency conversion methods to other currencies and base class. e.g.
#to_btc
- Add a currency scope and the currency to the
CURRENCIES
array inapp/models/address.rb
. - Update
lib/tasks/currency_conversions.rake#populate
. - Run
rake currency_conversions:populate
andrake currency_conversions:update
- Update
app/views/addresses/show.json.rabl
to have correspondingbalance_{{CURRENCY_SHORT_NAME}}
node. - Update
gon
inapp/controllers/application_controller.rb#setup_gon
. - Update address templates for the sidebar balances, list, list totals, header and the JS view for list totals.
- Update
@mixin currency-symbols
inapp/assets/stylesheets/mixins_and_variables.scss
.
module Currencies
class Bitcoin < Base
API = 'https://btc.blockr.io/api/v1'
CURRENCY_NAME = 'Bitcoin'
SHORT_NAME = 'BTC'
SYMBOLS = ['1']
class << self
def info(address)
response = get_response("#{API}/address/info/#{address}")
response[:data]
end
def balance(address)
response = get_response("#{API}/address/info/#{address}")
response[:data][:balance]
end
def first_tx_at(address)
response = get_response("#{API}/address/info/#{address}")
response[:data][:first_tx] ? response[:data][:first_tx][:time_utc] : nil
end
def valid?(address)
response = get_response("#{API}/address/info/#{address}")
response[:data][:is_valid]
end
# Conversions
def to_btc(value)
value.to_f
end
end
end
end
- Update
app/modules/currencies.rb
with correspondingto_{{CURRENCY_SHORT_NAME}}
method. - Update
app/models/currency_conversion.rb
with acache_to_{{CURRENCY_NAME}}
method. - Update
lib/tasks/currency_conversation.rake#update
and then run it. - Update
app/views/addresses/show.json.rabl
with correspondingbalance_{{CURRENCY_SHORT_NAME}}
node. - Update
balances
andtotals
nodes inapp/views/users/current_user.json.rabl
. - Update
gon.fiat_currencies
inapp/controllers/application_controller.rb#setup_gon
.