We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
show total ever given
Suggested [via Twitter](https://twitter.com/tripflex/status/532597015210131456):

> is there no way for me to see the total I have donated?  I know I can see it weekly, but what about overall total?


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `gratipay/utils/history.py`
Content:
```
1 def iter_payday_events(db, participant):
2     """Yields payday events for the given participant.
3     """
4     username = participant.username
5     exchanges = db.all("""
6         SELECT *
7           FROM exchanges
8          WHERE participant=%s
9     """, (username,), back_as=dict)
10     transfers = db.all("""
11         SELECT *
12           FROM transfers
13          WHERE tipper=%(username)s OR tippee=%(username)s
14     """, locals(), back_as=dict)
15 
16     if not (exchanges or transfers):
17         return
18 
19     payday_dates = db.all("""
20         SELECT ts_start::date
21           FROM paydays
22       ORDER BY ts_start ASC
23     """)
24 
25     balance = participant.balance
26     prev_date = None
27     get_timestamp = lambda e: e['timestamp']
28     events = sorted(exchanges+transfers, key=get_timestamp, reverse=True)
29     for event in events:
30 
31         event['balance'] = balance
32 
33         event_date = event['timestamp'].date()
34         if event_date != prev_date:
35             if prev_date:
36                 yield dict(kind='day-close', balance=balance)
37             day_open = dict(kind='day-open', date=event_date, balance=balance)
38             if payday_dates:
39                 while payday_dates and payday_dates[-1] > event_date:
40                     payday_dates.pop()
41                 payday_date = payday_dates[-1] if payday_dates else None
42                 if event_date == payday_date:
43                     day_open['payday_number'] = len(payday_dates) - 1
44             yield day_open
45             prev_date = event_date
46 
47         if 'fee' in event:
48             if event['amount'] > 0:
49                 kind = 'charge'
50                 if event['status'] in (None, 'succeeded'):
51                     balance -= event['amount']
52             else:
53                 kind = 'credit'
54                 if event['status'] != 'failed':
55                     balance -= event['amount'] - event['fee']
56         else:
57             kind = 'transfer'
58             if event['tippee'] == username:
59                 balance -= event['amount']
60             else:
61                 balance += event['amount']
62         event['kind'] = kind
63 
64         yield event
65 
66     yield dict(kind='day-close', balance='0.00')
67
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/gratipay/utils/history.py b/gratipay/utils/history.py
--- a/gratipay/utils/history.py
+++ b/gratipay/utils/history.py
@@ -16,6 +16,13 @@
     if not (exchanges or transfers):
         return
 
+    if transfers:
+        yield dict(
+            kind='totals',
+            given=sum(t['amount'] for t in transfers if t['tipper'] == username),
+            received=sum(t['amount'] for t in transfers if t['tippee'] == username),
+        )
+
     payday_dates = db.all("""
         SELECT ts_start::date
           FROM paydays

{"golden_diff": "diff --git a/gratipay/utils/history.py b/gratipay/utils/history.py\n--- a/gratipay/utils/history.py\n+++ b/gratipay/utils/history.py\n@@ -16,6 +16,13 @@\n     if not (exchanges or transfers):\n         return\n \n+    if transfers:\n+        yield dict(\n+            kind='totals',\n+            given=sum(t['amount'] for t in transfers if t['tipper'] == username),\n+            received=sum(t['amount'] for t in transfers if t['tippee'] == username),\n+        )\n+\n     payday_dates = db.all(\"\"\"\n         SELECT ts_start::date\n           FROM paydays\n", "issue": "show total ever given\nSuggested [via Twitter](https://twitter.com/tripflex/status/532597015210131456):\n\n> is there no way for me to see the total I have donated?  I know I can see it weekly, but what about overall total?\n\n", "before_files": [{"content": "def iter_payday_events(db, participant):\n    \"\"\"Yields payday events for the given participant.\n    \"\"\"\n    username = participant.username\n    exchanges = db.all(\"\"\"\n        SELECT *\n          FROM exchanges\n         WHERE participant=%s\n    \"\"\", (username,), back_as=dict)\n    transfers = db.all(\"\"\"\n        SELECT *\n          FROM transfers\n         WHERE tipper=%(username)s OR tippee=%(username)s\n    \"\"\", locals(), back_as=dict)\n\n    if not (exchanges or transfers):\n        return\n\n    payday_dates = db.all(\"\"\"\n        SELECT ts_start::date\n          FROM paydays\n      ORDER BY ts_start ASC\n    \"\"\")\n\n    balance = participant.balance\n    prev_date = None\n    get_timestamp = lambda e: e['timestamp']\n    events = sorted(exchanges+transfers, key=get_timestamp, reverse=True)\n    for event in events:\n\n        event['balance'] = balance\n\n        event_date = event['timestamp'].date()\n        if event_date != prev_date:\n            if prev_date:\n                yield dict(kind='day-close', balance=balance)\n            day_open = dict(kind='day-open', date=event_date, balance=balance)\n            if payday_dates:\n                while payday_dates and payday_dates[-1] > event_date:\n                    payday_dates.pop()\n                payday_date = payday_dates[-1] if payday_dates else None\n                if event_date == payday_date:\n                    day_open['payday_number'] = len(payday_dates) - 1\n            yield day_open\n            prev_date = event_date\n\n        if 'fee' in event:\n            if event['amount'] > 0:\n                kind = 'charge'\n                if event['status'] in (None, 'succeeded'):\n                    balance -= event['amount']\n            else:\n                kind = 'credit'\n                if event['status'] != 'failed':\n                    balance -= event['amount'] - event['fee']\n        else:\n            kind = 'transfer'\n            if event['tippee'] == username:\n                balance -= event['amount']\n            else:\n                balance += event['amount']\n        event['kind'] = kind\n\n        yield event\n\n    yield dict(kind='day-close', balance='0.00')\n", "path": "gratipay/utils/history.py"}], "after_files": [{"content": "def iter_payday_events(db, participant):\n    \"\"\"Yields payday events for the given participant.\n    \"\"\"\n    username = participant.username\n    exchanges = db.all(\"\"\"\n        SELECT *\n          FROM exchanges\n         WHERE participant=%s\n    \"\"\", (username,), back_as=dict)\n    transfers = db.all(\"\"\"\n        SELECT *\n          FROM transfers\n         WHERE tipper=%(username)s OR tippee=%(username)s\n    \"\"\", locals(), back_as=dict)\n\n    if not (exchanges or transfers):\n        return\n\n    if transfers:\n        yield dict(\n            kind='totals',\n            given=sum(t['amount'] for t in transfers if t['tipper'] == username),\n            received=sum(t['amount'] for t in transfers if t['tippee'] == username),\n        )\n\n    payday_dates = db.all(\"\"\"\n        SELECT ts_start::date\n          FROM paydays\n      ORDER BY ts_start ASC\n    \"\"\")\n\n    balance = participant.balance\n    prev_date = None\n    get_timestamp = lambda e: e['timestamp']\n    events = sorted(exchanges+transfers, key=get_timestamp, reverse=True)\n    for event in events:\n\n        event['balance'] = balance\n\n        event_date = event['timestamp'].date()\n        if event_date != prev_date:\n            if prev_date:\n                yield dict(kind='day-close', balance=balance)\n            day_open = dict(kind='day-open', date=event_date, balance=balance)\n            if payday_dates:\n                while payday_dates and payday_dates[-1] > event_date:\n                    payday_dates.pop()\n                payday_date = payday_dates[-1] if payday_dates else None\n                if event_date == payday_date:\n                    day_open['payday_number'] = len(payday_dates) - 1\n            yield day_open\n            prev_date = event_date\n\n        if 'fee' in event:\n            if event['amount'] > 0:\n                kind = 'charge'\n                if event['status'] in (None, 'succeeded'):\n                    balance -= event['amount']\n            else:\n                kind = 'credit'\n                if event['status'] != 'failed':\n                    balance -= event['amount'] - event['fee']\n        else:\n            kind = 'transfer'\n            if event['tippee'] == username:\n                balance -= event['amount']\n            else:\n                balance += event['amount']\n        event['kind'] = kind\n\n        yield event\n\n    yield dict(kind='day-close', balance='0.00')\n", "path": "gratipay/utils/history.py"}]}