<!DOCTYPE HTML>
<html>

	{% include 'includes/head.html' %}

	<body>
		<div id="page-wrapper">

				{% include 'includes/header.html' %}

        {% if not token %}
        <section id="swap" class="wrapper style1 special fade">
          <div class="container">
            <header>
              <h2>This Area is Hidden</h2>
            </header>
            <form method="get" action="/stats" class="cta" id="swapform">
              <div class="row gtr-uniform gtr-50">
                <div class="col-8 col-12-xsmall">
                  <input type="text" name="token" placeholder="Secret token" />
                </div>
                <div class="col-4 col-12-xsmall">
                  <input type="submit" value="Enter" class="fit primary" />
                </div>
              </div>
            </form>
            {% if request.args.get('token') %}Invalid token.{% endif %}
          </div>
        </section>
        {% else %}

        <div style="width: 100%; text-align: center; padding-top: 1em;">
					<div class="top-text">
						<h2>Stats</h2>
						<p>In progress: {{ stats.in_progress }}</p>
						<p>Completed: {{ stats.completed }}</p>
						<p>Pending: {{ stats.pending }}</p>
						<p>Total: {{ stats.total }}</p>
						<p>WOW -> XMR: {{ stats.wow_to_xmr }}</p>
						<p>XMR -> WOW: {{ stats.xmr_to_wow }}</p>
						<h2>Fees Collected</h2>
						<p>WOW Fees Collected: {{ earnings['wow_amount'] }} WOW (${{ earnings['wow_worth'] }})</p>
						<p>XMR Fees Collected: {{ earnings['xmr_amount'] }} XMR (${{ earnings['xmr_worth'] }})</p>
						<h2>Balances</h2>
						<p>{{ xmr_balances[1] | from_atomic_xmr }} XMR ({{ (xmr_balances[0] - xmr_balances[1]) | from_atomic_xmr }} locked)</p>
						<p>{{ wow_balances[1] | from_atomic_wow }} WOW ({{ (wow_balances[0] - wow_balances[1]) | from_atomic_wow }} locked)</p>
          </div>
					<br />
					<div>
						{% if swaps %}
						<table class="table table-striped table-hover table-responsive table-responsive-sm tx-table">
						<tr>
							<th>ID</th>
							<th>Date Initiated (PST)</th>
							<th>Status</th>
							<th>Completed Date (PST)</th>
							<th>Address Index</th>
							<th>Receive Status</th>
							<th>Send Amount</th>
							<th>Send Tx ID</th>
						</tr>
						{% for swap in swaps | sort(attribute='date', reverse=True) %}
							{% if swap.wow_to_xmr %}
								{% set explorer = swap.send_tx_id | xmr_block_explorer %}
							{% else %}
								{% set explorer = swap.send_tx_id | wow_block_explorer %}
							{% endif %}
							<tr>
								<td><a href="/swap/{{ swap.id }}" target="_blank">{{ swap.id }}</a></td>
								<td>{{ swap.date | pst }}</td>
								<td>{% if swap.completed %}COMPLETED{% else %}{% if swap.funds_received %}IN PROGRESS{% else %}WAITING{% endif %}{% endif %}</td>
								<td>{% if swap.completed_date %}{{ swap.completed_date | pst }}{% else %}none{% endif %}</td>
								<td>{{ swap.show_details()['receive_unit'] }}-{{ swap.show_details()['swap_address_index'] }}</td>
								<td>{% if swap.funds_received %}RECEIVED{% else %}NOT RECEIVED{% endif %} {{ swap.show_details()['receive'] }}</td>
								<td>{{ swap.show_details()['send'] }}</td>
								{% if swap.send_tx_id %}
									<td><a href="{{ explorer }}" target="_blank">{{ swap.send_tx_id | truncate(7) }}</a></td>
								{% else %}
									<td>none</td>
								{% endif %}
							</tr>
						{% endfor %}
						</table>

						<table class="table table-striped table-hover table-responsive table-responsive-sm tx-table">
						<tr>
							<th>Coin</th>
							<th>Date</th>
							<th>Fees</th>
						</tr>
						{% for coin in breakdown %}
							{% for d in breakdown[coin] | sort %}
								<tr>
									<td>{{ coin | upper }}</td>
									<td>{{ d }}</td>
									<td>{{ breakdown[coin][d] }} {{ coin | upper }}</td>
								</tr>
							{% endfor %}
						{% endfor %}
						</table>

						{% endif %}
					</div>
        </div>

        {% endif %}

				<style>
					.top-text p, h2 {
						margin: 0;
					}
				</style>

        {% include 'includes/footer.html' %}

    </div>

    {% include 'includes/scripts.html' %}

  </body>
</html>
