Created
September 10, 2018 08:53
-
-
Save 9876691/1290770a962e78b6b74f79f72ae84e06 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Bitcoins::Index < BrowserAction | |
get "/bitcoins" do | |
addresses = populate_balances(KeyPairQuery.new.user_id(current_user.id)) | |
render IndexPage, addresses: addresses, form: KeyPairForm.new | |
end | |
private def populate_balances(key_pair_query) | |
just_addresses = key_pair_query.map{ |keypair| keypair.public_key } | |
balances = OnChain::API::Address.get_balances( | |
"testnet3", just_addresses.join(",")) | |
case balances | |
when OnChain::API::Balances | |
return key_pair_query.map{ |keypair| | |
bal = balances.addresses.find { |a| a.address == keypair.public_key } | |
human_bal = "0" | |
human_bal = bal.human_balance.to_s if bal | |
{ keypair.label, keypair.public_key, human_bal } | |
} | |
else | |
puts balances | |
return key_pair_query.map{ |keypair| | |
{ keypair.label, keypair.public_key, "" } | |
} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment