{# 
    tx_item - Transation table row.
    Parameters:
    - tx: The transaction to display
    - wallet: Wallet object
    - specter: Specter object.
    - includeValidatedBlockhash: boolean
 #}
{% macro tx_item(tx, wallet, specter, includeValidatedBlockhash=False) -%}
    {% from 'wallet/components/explorer_link.jinja' import explorer_link %}
    {% set txid = tx['txid'] %}
    <tr class="{%if tx['confirmations'] == 0 %}unconfirmed{%endif%}" onclick="if(window.innerWidth<=600){showPageOverlay(`{{tx['txid']}}_tx_info_popup`)}">
        <td>
            {# coinbase txs are 'immature' until 100 confs #}
            {% if tx['category'] == 'immature' %}
                <img src="{{ url_for('static', filename='img/unconfirmed_receive_icon.svg') }}"/>
            {% else %}
                <img src="{{ url_for('static', filename='img') }}/{% if tx['confirmations'] == 0 %}unconfirmed_{% endif %}{{tx['category']}}_icon.svg"/>
            {% endif %}
        </td>
        <td class="tx scroll optional">
            {{ explorer_link('tx', tx['txid'], tx['txid'], specter.explorer) }}
        </td>
        <td class="tx scroll optional">
            {% if wallet == none %}
                {% set wallet = specter.wallet_manager.get_by_alias(tx['wallet_alias']) %}
            {% endif %}
            {{ explorer_link('address', tx['address'], tx['address'] if wallet == none else wallet.get_address_name(tx['address'], -1), specter.explorer) }}
        </td>
        <td>
            {{ tx['amount'] | btcunitamount }} {% if specter.price_check %}<span class="note">&nbsp;({{ tx['amount'] | altunit }})</span>{% endif %}
        </td>
        <td>
            {%if tx['confirmations'] == 0 %}
                Pending.
                {% if tx['category'] in ['send', 'selftransfer'] and ('bip125-replaceable' in tx and tx['bip125-replaceable'] == 'yes') %}
                    <button style="float: right; padding: 10px 25px;" onclick='showPageOverlay(`{{ tx["txid"] }}_rbf_popup`)' type="button" class="btn optional">Speed up</button>
                    <div id='{{ tx["txid"] }}_rbf_popup' class="hidden">
                        <form action="{{ url_for('wallet_sendnew', wallet_alias=wallet.alias) }}" method="POST">
                            <h1>Speed up the Transaction</h1>
                            <p>You can speedup the transaction by increasing its fee rate:</p>
                            <input type="hidden" name="rbf_tx_id" value='{{ tx["txid"] }}' />
                            <input type="number" min="{{ 2 + (((tx['fee'] * -1) / tx['vsize']) | feerate | int) }}" value="{{ 2 + (((tx['fee'] * -1) / tx['vsize']) | feerate | int) }}" class="fee_rate" name="rbf_fee_rate" id="rbf_fee_rate" min="1" step="any" autocomplete="off"> sat/vbyte
                            <br>
                            <br>
                            <button type="submit" name="action" value="rbf" class="btn centered">Speed up!</button>
                        </form>
                    </div>
                {% endif %}
            {% else %}
                {{ tx['confirmations'] }} conf.
            {% endif %}
            ({{ tx['time'] | datetime }})
        </td>
	{% if includeValidatedBlockhash %}
	  <td class="tx scroll optional">
	      {% if tx['blockhash'] == tx['validated_blockhash'] %}
		  {{ explorer_link('block', tx['blockhash'], tx['blockhash'], specter.explorer) }}
	      {% else %}
		  Unconfirmed
	      {% endif %}
	  </td>
	{% endif %}
    </tr>
    <div id="{{tx['txid']}}_tx_info_popup" class="hidden" style="text-align:left;">
        <h1>Transaction details</h1>
        <p>Category: {{ tx['category'] | title }}&nbsp; {% if tx['category'] == 'immature' %}
            <img src="{{ url_for('static', filename='img/unconfirmed_receive_icon.svg') }}"/>
        {% else %}
            <img src="{{ url_for('static', filename='img') }}/{% if tx['confirmations'] == 0 %}unconfirmed_{% endif %}{{tx['category']}}_icon.svg"/>
        {% endif %}
        </p>
        <p>Transaction ID:</p>
        <p class="tx scroll" style="max-width: 100%; background-color: #0f161f; border-radius: 5px;">
            {{ explorer_link('tx', tx['txid'], tx['txid'], specter.explorer) }}
        </p>
        <p>Address:</p>
        <p class="tx scroll" style="max-width: 100%; background-color: #0f161f; border-radius: 5px;">
            {% if wallet == none %}
                {% set wallet = specter.wallet_manager.get_by_alias(tx['wallet_alias']) %}
            {% endif %}
            {{ explorer_link('address', tx['address'], tx['address'] if wallet == none else wallet.get_address_name(tx['address'], -1), specter.explorer) }}
        </p>
        <p>Amount: {{ tx['amount'] | btcunitamount }}{% if specter.price_check %}<span class="note">{{ tx['amount'] | altunit }}{% endif %}</span></p>
        <p>Status:
        {%if tx['confirmations'] == 0 %}
            Pending.
        {% else %}
            {{ tx['confirmations'] }} conf.
        {% endif %}
        ({{ tx['time'] | datetime }})
        </p>
	{% if includeValidatedBlockhash %}
	  <p>
	      {% if tx['blockhash'] == tx['validated_blockhash'] %}
		  {{ explorer_link('block', tx['blockhash'], tx['blockhash'], specter.explorer) }}
	      {% else %}
		  Unconfirmed
	      {% endif %}
	  </p>
	{% endif %}
    </div>
{%- endmacro %}
