Skip to content

Commit

Permalink
Improve send screen (#350)
Browse files Browse the repository at this point in the history
* Fix steps with sats unit on send input number

* Add max amount

* Fix precision error in amount check

* Fix show tx details button size

* Fix history table mobile

* Add transaction creator text editing

* Add text amount validation

* Estimated fee calculation

* Fix fee estimation

* Use wight instead of size for calculation

Co-authored-by: Stepan Snigirev <snigirev.stepan@gmail.com>

* Fix input calculation

Co-authored-by: Stepan Snigirev <snigirev.stepan@gmail.com>

* Update src/cryptoadvance/specter/wallet.py

Co-authored-by: Stepan Snigirev <snigirev.stepan@gmail.com>

* docs: update TOC

* Hide add/ remove receipient button when toggling tab

* add subtract from option

* Fix tests

* Update test_wallet_manager.py

* Add text unit and fix fee estimation

* Remove unnecessary fee check

* Fix non rounded sat fee estimation

* Make sure manual rate it as least 1 vbyte

* Fix typo

Co-authored-by: Luke <51127079+PulpCattel@users.noreply.github.com>

* Small cleanups

Co-authored-by: Stepan Snigirev <snigirev.stepan@gmail.com>
Co-authored-by: ben-kaufman <ben-kaufman@users.noreply.github.com>
Co-authored-by: Luke <51127079+PulpCattel@users.noreply.github.com>
  • Loading branch information
4 people committed Sep 8, 2020
1 parent 33d0b55 commit 4ba591a
Show file tree
Hide file tree
Showing 7 changed files with 339 additions and 63 deletions.
48 changes: 38 additions & 10 deletions src/cryptoadvance/specter/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -1008,21 +1008,38 @@ def wallet_sendnew(wallet_alias):
amounts = [0]
fee_rate = 0.0
err = None
ui_option = 'ui'
recipients_txt = ''
if request.method == "POST":
action = request.form['action']
if action == "createpsbt":
i = 0
addresses = []
labels = []
amounts = []
while 'address_{}'.format(i) in request.form:
addresses.append(request.form['address_{}'.format(i)])
amounts.append(float(request.form['btc_amount_{}'.format(i)]))
labels.append(request.form['label_{}'.format(i)])
if request.form['label_{}'.format(i)] != '':
wallet.setlabel(addresses[i], labels[i])
i += 1
ui_option = request.form.get('ui_option')
if 'ui' in ui_option:
while 'address_{}'.format(i) in request.form:
addresses.append(request.form['address_{}'.format(i)])
amounts.append(
float(request.form['btc_amount_{}'.format(i)])
)
labels.append(request.form['label_{}'.format(i)])
if request.form['label_{}'.format(i)] != '':
wallet.setlabel(addresses[i], labels[i])
i += 1
else:
recipients_txt = request.form['recipients']
for output in recipients_txt.splitlines():
addresses.append(output.split(',')[0].strip())
if request.form.get('amount_unit_text') == 'sat':
amounts.append(
float(output.split(',')[1].strip()) / 1e8
)
else:
amounts.append(float(output.split(',')[1].strip()))
subtract = bool(request.form.get("subtract", False))
subtract_from = int(request.form.get("subtract_from", 1)) - 1
fee_unit = request.form.get('fee_unit')
selected_coins = request.form.getlist('coinselect')
app.logger.info("selected coins: {}".format(selected_coins))
Expand All @@ -1033,7 +1050,16 @@ def wallet_sendnew(wallet_alias):
fee_rate = float(request.form.get('fee_rate'))

try:
psbt = wallet.createpsbt(addresses, amounts, subtract=subtract, fee_rate=fee_rate, fee_unit=fee_unit, selected_coins=selected_coins)
psbt = wallet.createpsbt(
addresses,
amounts,
subtract=subtract,
subtract_from=subtract_from,
fee_rate=fee_rate,
fee_unit=fee_unit,
selected_coins=selected_coins,
readonly='estimate_fee' in request.form
)
if psbt is None:
err = "Probably you don't have enough funds, or something else..."
else:
Expand All @@ -1045,6 +1071,8 @@ def wallet_sendnew(wallet_alias):
except Exception as e:
err = e
if err is None:
if 'estimate_fee' in request.form:
return psbt
return render_template("wallet/send/sign/wallet_send_sign_psbt.jinja", psbt=psbt, labels=labels,
wallet_alias=wallet_alias, wallet=wallet,
specter=app.specter, rand=rand)
Expand Down Expand Up @@ -1095,8 +1123,8 @@ def wallet_sendnew(wallet_alias):
return render_template("wallet/send/sign/wallet_send_sign_psbt.jinja", signed_psbt=signed_psbt, psbt=psbt, labels=labels,
wallet_alias=wallet_alias, wallet=wallet,
specter=app.specter, rand=rand)
return render_template("wallet/send/new/wallet_send.jinja", psbt=psbt, labels=labels,
wallet_alias=wallet_alias, wallet=wallet,
return render_template("wallet/send/new/wallet_send.jinja", psbt=psbt, ui_option=ui_option, recipients_txt=recipients_txt,
labels=labels, wallet_alias=wallet_alias, wallet=wallet,
specter=app.specter, rand=rand, error=err)

@app.route('/wallets/<wallet_alias>/send/import')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<th>Amount</th>
<th>Status</th>
{% if includeValidatedBlockhash %}
<th>
<th class="optional">
<div class="tool-tip">{% include "includes/merkletooltip.html" %}</div>
Block Hash
</th>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
<div class="fee_container">
<div>
<label><input type="checkbox" class="inline" name="subtract" value="1"> Subtract fees from amount</label>
<label><input type="checkbox" class="inline" name="subtract" id="subtract" value="1" onchange="toggleSubtractFrom(this)"> Subtract fees from amount</label>
<div class="tool-tip" style="text-align: center;">
<i class="tool-tip__icon">i</i>
<p class="tool-tip__info">
<span class="info">
<span class="info__title">Subtract fees from amount<br><br></span>
If checked, the transaction fees will be payed off from the transaction amount.<br><br>
Otherwise, the fees will be payed as an added cost in addition to the amount sent.
</span>
</p>
</div>
</div>
<span id="subtract_from" class="hidden"><br>Subtract from recipient number: <input id="subtract_from_input" name="subtract_from" type="number" min="1" value="1" step="1" style="width: 80px; min-width: 80px;"><br></span>
<br>
<div>
Fees:
<label><input type="radio" class="inline" style="margin: 0 10px 0 20px;" id="fee_option_dynamic" name="fee_options" value="dynamic" onclick="showFeeOption(this)" checked>dynamic</label>
<label><input type="radio" class="inline" style="margin: 0 10px 0 20px" name="fee_options" value="manual" onclick="showFeeOption(this);">manual</label>
<label><input type="radio" class="inline" style="margin: 0 10px 0 20px;" id="fee_option_dynamic" name="fee_options" value="dynamic" onclick="showFeeOption(this)" checked>dynamic</label>
<label><input type="radio" class="inline" style="margin: 0 10px 0 20px" id="fee_option_manual" name="fee_options" value="manual" onclick="showFeeOption(this);">manual</label>
</div>
<br>
<input type="hidden" id="fee_unit" name="fee_unit" value="BTC_KB">
<div id = "fee_manual" style="display: none">
Fee rate:<br>
<input type="number" class="fee_rate" name="fee_rate" id="fee_rate" max="100" min="0.5" step="0.5" autocomplete="off"> sat/B
<input type="number" class="fee_rate" name="fee_rate" id="fee_rate" max="100" min="1" step="0.5" autocomplete="off"> sat/B
<div class="note">
leave blank to set automatically
</div>
Expand Down Expand Up @@ -75,4 +86,14 @@
document.getElementById('blocks').innerHTML = 'Confirmation time: '.concat(blocks);
}
function toggleSubtractFrom(checkbox) {
if (checkbox.checked && (amounts.length > 1 || !document.getElementById('ui-radio-btn').checked)) {
document.getElementById('subtract_from').style.display = 'block';
document.getElementById('coin-selection-row').style['margin-top'] = '90px';
} else {
document.getElementById('subtract_from').style.display = 'none';
document.getElementById('coin-selection-row').style['margin-top'] = '30px';
}
}
</script>

0 comments on commit 4ba591a

Please sign in to comment.