We are excited to open source Balances and get the community involved! Check out CONTRIBUTING.md for quick guide.
- Run
bundle install - Copy
.sample.envto.envand update with all the necessary credentials. The required ones areSECRET_TOKENandEMAIL_HASH_SALT. - Copy
sample.database.ymltodatabase.yml - Run
rake db:create db:migrate - Run
rake currency_conversions:populate - Run
foreman startorrails 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
CURRENCIESarray inapp/models/address.rb. - Update
lib/tasks/currency_conversions.rake#populate. - Run
rake currency_conversions:populateandrake currency_conversions:update - Update
app/views/addresses/show.json.rablto have correspondingbalance_{{CURRENCY_SHORT_NAME}}node. - Update
goninapp/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-symbolsinapp/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.rbwith correspondingto_{{CURRENCY_SHORT_NAME}}method. - Update
app/models/currency_conversion.rbwith acache_to_{{CURRENCY_NAME}}method. - Update
lib/tasks/currency_conversation.rake#updateand then run it. - Update
app/views/addresses/show.json.rablwith correspondingbalance_{{CURRENCY_SHORT_NAME}}node. - Update
balancesandtotalsnodes inapp/views/users/current_user.json.rabl. - Update
gon.fiat_currenciesinapp/controllers/application_controller.rb#setup_gon.