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 are SECRET_TOKEN and EMAIL_HASH_SALT.
- Copy sample.database.yml to database.yml
- Run rake db:create db:migrate
- Run rake currency_conversions:populate
- Run foreman start or rails 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 in app/models/address.rb.
- Update lib/tasks/currency_conversions.rake#populate.
- Run rake currency_conversions:populate and rake currency_conversions:update
- Update app/views/addresses/show.json.rabl to have corresponding balance_{{CURRENCY_SHORT_NAME}} node.
- Update gon in app/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 in app/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 corresponding to_{{CURRENCY_SHORT_NAME}} method.
- Update app/models/currency_conversion.rb with a cache_to_{{CURRENCY_NAME}} method.
- Update lib/tasks/currency_conversation.rake#update and then run it.
- Update app/views/addresses/show.json.rabl with corresponding balance_{{CURRENCY_SHORT_NAME}} node.
- Update balances and totals nodes in app/views/users/current_user.json.rabl.
- Update gon.fiat_currencies in app/controllers/application_controller.rb#setup_gon.