aboutsummaryrefslogtreecommitdiff
path: root/templates/wallet.html.jinja
blob: 86919e468d497e298fa948871509c5dec9b906bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
{#
  UGE / L2 / Intro to relational databases / Python project prototype
  Author: Pacien TRAN-GIRARD
  Licence: EUPL-1.2
#}

{% extends '_base.html.jinja' %}

{% block title %}My wallet{% endblock %}

{% macro format_operation(transaction) %}
  {% if transaction.operation == 'transfer' %}
    {% if transaction.amount > 0 %}
      Transfer from {{ transaction.source }}
    {% else %}
      Transfer to {{ transaction.recipient }}
    {% endif %}
  {% else %}
    {{ transaction.operation.capitalize() }}
  {% endif %}
{% endmacro %}

{% macro amount_class(transaction) %}
  {{ 'amount-positive' if transaction.amount > 0 else 'amount-negative'}}
{% endmacro %}

{% block content %}
  <div class="pure-g">

    <div class="pure-u-1 pure-u-md-1-3">
      <h2>Deposit</h2>
      <form
        method="post"
        action="/wallet/deposit"
        class="pure-form">
        <fieldset>
          <input
            class="pure-input-1-4"
            type="number"
            name="amount"
            min="0.01"
            step="0.01"
            placeholder="§"
            required />
          <button
            type="submit"
            class="pure-button pure-button-primary dark-blue-bg">
            ⇩ Deposit
          </button>
        </fieldset>
      </form>
    </div>

    <div class="pure-u-1 pure-u-md-1-3">
      <h2>Withdraw</h2>
      <form
        method="post"
        action="/wallet/withdraw"
        class="pure-form">
        <fieldset>
          <input
            class="pure-input-1-4"
            type="number"
            name="amount"
            min="0.01"
            max="{{ user.balance }}"
            step="0.01"
            placeholder="§"
            required />
          <button
            type="submit"
            class="pure-button pure-button-primary dark-blue-bg">
            ⇧ Withdraw
          </button>
        </fieldset>
      </form>
    </div>

    <div class="pure-u-1 pure-u-md-1-3">
      <h2>Transfer</h2>
      <form
        method="post"
        action="/wallet/transfer"
        class="pure-form">
        <fieldset>
          <input
            class="pure-input-1-3"
            type="text"
            name="recipient"
            minlength="4"
            maxlength="16"
            placeholder="Recipient"
            required />
          <input
            class="pure-input-1-4"
            type="number"
            name="amount"
            min="0.01"
            max="{{ user.balance }}"
            step="0.01"
            placeholder="§"
            required />
          <button
            type="submit"
            class="pure-button pure-button-primary light-blue-bg">
            ➤ Send
          </button>
        </fieldset>
      </form>
    </div>

  </div>

  <h2>Transaction history</h2>

  <table class="pure-table pure-table-striped">
    <thead>
      <tr>
        <th>Date</th>
        <th>Operation</th>
        <th class="align-right">Amount</th>
      </tr>
    </thead>
    <tbody>
      {% for transaction in transactions %}
      <tr>
        <td>{{ transaction.datetime.strftime('%Y-%m-%d %H:%M:%S') }}</td>
        <td>{{ format_operation(transaction) }}</td>
        <td class="align-right text-bold {{ amount_class(transaction) }}">
          {{ transaction.amount }} §
        </td>
      </tr>
      {% else %}
      <tr>
        <td colspan="3"><em>No past transaction.</em></td>
      </tr>
      {% endfor %}
    </tbody>
  </table>
{% endblock %}