Skip to content

Commit

Permalink
delegation action in coin selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Stachyra committed Oct 19, 2020
1 parent d3c31c0 commit 2b321fd
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
24 changes: 23 additions & 1 deletion app.rb
Expand Up @@ -112,6 +112,29 @@

# SHELLEY WALLETS

get "/wallets/coin-selection/delegation" do
wallets = @cw.shelley.wallets.list
handle_api_err wallets, session
erb :form_coin_selection_deleg_action, { :locals => { :deleg_action => nil,
:coin_selection => nil,
:wallets => wallets } }
end

post "/wallets/coin-selection/delegation" do
wallets = @cw.shelley.wallets.list
handle_api_err wallets, session
begin
deleg_action = JSON.parse params[:deleg_action]
coin_selection = @cw.shelley.coin_selections.random_deleg(params[:wid], deleg_action)
# handle_api_err coin_selection, session
rescue
session[:error] = "Make sure the 'action' has correct JSON format."
end
erb :form_coin_selection_deleg_action, { :locals => { :deleg_action => params[:deleg_action],
:coin_selection => coin_selection,
:wallets => wallets } }
end

get "/wallets/coin-selection/random" do
wallets = @cw.shelley.wallets.list
handle_api_err wallets, session
Expand All @@ -125,7 +148,6 @@
handle_api_err wallets, session
begin
address_amount = params[:addr_amt].split("\n").map{|a| a.strip.split(":")}.collect{|a| {a.first.strip => a.last.strip}}
puts address_amount
coin_selection = @cw.shelley.coin_selections.random(params[:wid], address_amount)
rescue ArgumentError
session[:error] = "Make sure the input is in the form of address:amount per line."
Expand Down
65 changes: 65 additions & 0 deletions views/form_coin_selection_deleg_action.erb
@@ -0,0 +1,65 @@
<%
url_path = request.env['PATH_INFO'].to_s
wid = params[:wid] if params[:wid]
byron_ep = "/byron-wallets"
shelley_ep = "/wallets"
%>

<div class="list-group">
<div class="list-group-item">
Coin Selection - delegation action
| <small><a href="<%= (url_path.include? "byron") ? byron_ep : shelley_ep %>/<%= wid %>">
go back to wallet
</a></small>
</div>
<div class="list-group-item">
<form action="/wallets/coin-selection/delegation" method="POST">
<div class="form-group">
<label for="wid">Source Wallet</label>
<select class="form-control" name="wid" id="wid">
<% wallets.each do |w| %>
<option <%= wid == w['id'] ? "selected" : "" %> value="<%= w['id'] %>">
<%= "#{w['name']} [id: #{w['id']}, balance available: #{w['balance']['available']['quantity']}]" %>
</option>
<% end %>
</select>
</div>
<div class="form-group">
<label for="deleg_action">Delegation action</label>
<textarea class="form-control" name="deleg_action" id="deleg_action" rows="5"><%= deleg_action if deleg_action %></textarea>
<small id="help" class="form-text text-muted">

<details>
<summary>Join or Quit action.</summary>
<code>
Join:<br/><br/>
{ "action": "join", "pool": "pool_id" }
<br/><br/>Quit:<br/><br/>
{ "action": "quit" }
</code>
</details>

</small>
</div>

<button type="submit" class="btn btn-success">Verify</button>
</form>
</div>

<% if session[:error] %>
<div class="alert alert-danger" role="alert">
<%= session[:error]%>
</div>
<%
session.delete :error
end
%>
<% if coin_selection %>
<div class="list-group-item" >
<small id="coin_selection">
<%= json2table(coin_selection.to_s) %>
</small>
</div>
<% end %>
</div>
1 change: 1 addition & 0 deletions views/wallet.erb
Expand Up @@ -72,6 +72,7 @@
data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">Coin Selection</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="/wallets/coin-selection/random?wid=<%= wal['id'] %>">Random</a>
<a class="dropdown-item" href="/wallets/coin-selection/delegation?wid=<%= wal['id'] %>">Delegation</a>
</div>
</div>
<a class="nav-link" href="/wallets-utxo?wid=<%= wal['id'] %>">UTxO</a>
Expand Down

0 comments on commit 2b321fd

Please sign in to comment.