# Build an app that reads its player's money history

You are building a small app for the phone inside Osogbo Life (https://osogbolife.app), a life-simulation game set in Osogbo, Nigeria, as a developer OUTSIDE the city: it is submitted through an Arena54 developer account. It reads the money history of the player who is using it, with their yes, and shows them something useful about it. Build it in this folder.

NOT OPEN YET: Osogbo Life is not letting apps read a player's money history today. Everything below is built and you can write and test your app now; submitting opens later, through developers.arena54.com.

Ask me what the app should do if I have not said; if you cannot ask, build the first of these. Good first apps: where my money went this month, by kind; a budget with a limit for each kind; how long my balance lasts at this rate.

THE FRAME. Your app is ONE HTML file, at most 200,000 characters (counted as JavaScript counts them, the file's length as a string), with its CSS in <style> and its JavaScript in <script>. It runs inside the player's phone in a locked frame:
- No network at all: no fetch, XMLHttpRequest, WebSocket, no scripts, stylesheets, fonts or images from any address. Pictures go in as data: URLs; the device's own fonts and emoji are fine, though emoji look different from phone to phone.
- No cookies, no localStorage or sessionStorage, no forms that submit (an <input> or a <button> outside a <form> is fine), no new windows, and it cannot move the page. It cannot send anything out. The only way to reach the game is the bridge below.
- Design for a screen about 360 px wide and 416 px tall. That is your app's own area: a strip above it always shows its name and its developer. Taller content scrolls.
- Plain HTML, CSS and JavaScript only. No framework, no build step, no modules, no imports.

THE BRIDGE. The phone adds a global object, ibadan, before your code runs. Every call returns a promise; a refusal rejects it with an Error whose message you can show the player. Use only these calls. There are no others. Your app has NO network, and there is no token or key anywhere in this: the phone answers for the player who is holding it.
- ibadan.ledger.me() resolves with { balance, frozen }: the player's balance now, and whether their wallet is frozen.
- ibadan.ledger.rows({ limit, before }) resolves with { rows: [{ id, at, kind, delta, balance_after }], next }. Rows come newest first, up to 100 a call (50 when you give no limit). For older rows call again with before set to the next you were given; next is null when there are no more. A row is those five fields and nothing else: id and next are numbers; at is a time in UTC as an ISO string; delta is minus for money out; kind is a short word in small letters, sometimes with an underscore (wage, food, rent, transport, starting_cash). There is no list of kinds: show the ones you meet, with a space for the underscore, and count every minus delta as money out. The first row a player ever has is their starting cash, so a balance is the sum of every delta; balance_after can be null on a very old row. A frozen wallet can still be read. You are never told where the player was or who the other side of a movement was.
- ibadan.player() resolves with { name, id }: the player's username and an id made for your app alone.
- ibadan.storage.get(key) and ibadan.storage.set(key, value) keep small strings for this player inside the city (keys up to 40 characters, values up to 2,000, 20 keys per player); get resolves with null for a key never set. Use it for the player's own settings, such as a budget's limits. Do not copy their rows into it.
- ibadan.toast(text) shows a short message for 3 seconds; text past 120 characters is cut. ibadan.close() closes your app. Neither needs a permission.
At most 20 calls in any 10 seconds, and at most 60 ledger calls a minute for one player; past either a call rejects with "Too many requests. Slow down." So read when the app opens and never on a repeating timer. A long history is many pages: read only as far back as the screen needs. For "this month", read page after page until a row is older than the first day of the month, then stop; anything older waits for the player to ask (a "Show older" button).
The money is the game's own, written ₳. Amounts are whole numbers. There is no clock in the bridge: for "this month" use the device's own date and its own time zone. Put a kind or any other text from a row into the page with textContent, never as HTML.

THE PLAYER MUST AGREE, AND MAY SAY NO. The first ledger call brings up the phone's own sheet: "Let it read your money history?". A yes is remembered and the sheet does not come again. A no is NOT remembered: the call rejects with exactly "The player said no.", and the next ledger call would bring the sheet up again. So when you see that message, stop making ledger calls, show a screen that says plainly what the app needs and why, and give one button that tries again. Make one call that may ask at a time and wait for it to settle before the next: a second call that needs a sheet, made while one is up, rejects with "The phone is asking the player something else. Try again." The first ibadan.player() call asks in the same way ("Share your name?"); storage, toast and close never ask.
Other rejections are not a no and carry their own message to show: "Reading your money history from an app is switched off in this city." and "Too many requests. Slow down."

PERMISSIONS. Declare what the app uses, from "ledger", "player" and "storage", and nothing else. They are declared on the submission at Arena54, not in the file: list them for me when you finish. An app that asks for "ledger" is NOT allowed "saves", "boards", "achievements" or "score", and is turned down if it declares one: an app that reads a player's money keeps nothing outside the city. That is what the phone promises the player on the sheet, so it is not a rule to work round. A game cannot ask for "ledger". An app from outside the city cannot charge a player, and nothing here can move money.

WHAT GETS AN APP TURNED DOWN OR TAKEN DOWN. Pretending to be Osogbo Life or its bank. Asking for a password. Showing the player's money to anyone but the player. Giving advice about real money: this is a game's currency, and the app must not suggest otherwise. Heavy work in the background.

A WORKING EXAMPLE, to copy the shape of:
```html
<!doctype html>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>body{font:16px system-ui;margin:16px;color:#2a1a12;background:#f4efe4}button{font:inherit;padding:10px 14px;border-radius:12px;border:0;background:#a44a1f;color:#fff}li{display:flex;justify-content:space-between;padding:4px 0}</style>
<h2>Where it went</h2><p id="a">Reading…</p><ul id="l" style="list-style:none;padding:0"></ul><button id="go" hidden>Try again</button>
<script>
  var a = document.getElementById("a"), l = document.getElementById("l"), go = document.getElementById("go");
  function read() {
    go.hidden = true; a.textContent = "Reading…";
    ibadan.ledger.rows({ limit: 50 }).then(function (r) {
      var out = {}; r.rows.forEach(function (x) { if (x.delta < 0) out[x.kind] = (out[x.kind] || 0) - x.delta; });
      var kinds = Object.keys(out).sort(function (p, q) { return out[q] - out[p]; });
      a.textContent = kinds.length ? "Money out, in your last " + r.rows.length + " movements:" : "No money has gone out yet.";
      l.textContent = ""; kinds.forEach(function (k) { var li = document.createElement("li"), n = document.createElement("span"), v = document.createElement("span"); n.textContent = k; v.textContent = out[k].toLocaleString(); li.append(n, v); l.append(li); });
    }, function (e) {
      a.textContent = e.message === "The player said no." ? "This app shows where your money went, so it needs to read your money history. It cannot move money." : e.message;
      go.hidden = false;
    });
  }
  go.onclick = read; read();
</script>
```

WHAT TO WRITE. Two files (the second writes a third when it runs):
1. app.html: the app. Handle every rejected promise: show the message, never leave a blank screen.
2. check.mjs: exactly the script below. Then run "node check.mjs" and fix app.html until its line starts with "ok:". It looks for these words anywhere in the file, comments and visible text included, so keep them out: fetch, XMLHttpRequest, WebSocket, EventSource, sendBeacon, importScripts, localStorage, sessionStorage, indexedDB, document.cookie. If you cannot open a browser, say so: "ok:" means the file may be submitted, not that you saw it run. It also writes harness.html, which runs the app in a frame like the phone's, with a stand-in for the bridge that has seven sample rows, the newest from today and the oldest from six weeks ago (they add up: the newest balance_after is the balance), and asks the money question as the phone does (a browser box: OK is yes, Cancel is no, and a no is asked again on the next call; its player() does not ask, and it has no rate limit); open that in a browser and try the app both ways. harness.html is for you alone and is never submitted.

```js
// check.mjs: run with  node check.mjs  beside app.html. It prints what the store would turn down, and writes
// harness.html: your app in the same kind of locked frame, with a stand-in for the phone's bridge. Open it in a browser.
import { readFileSync, writeFileSync } from "node:fs";
const src = readFileSync("app.html", "utf8"), bad = [];
if (src.length > 200000) bad.push("over 200000 characters: " + src.length);
if (/<script[^>]+\bsrc\s*=/i.test(src)) bad.push("a script loaded from another file");
if (/<link[^>]+\bhref\s*=\s*["']?(?!data:)/i.test(src)) bad.push("a linked stylesheet or font");
if (/\b(?:src|href|poster)\s*=\s*["']?\s*(?:https?:)?\/\//i.test(src) || /url\(\s*["']?\s*(?:https?:)?\/\//i.test(src)) bad.push("something loaded from another address");
if (/\b(?:fetch|XMLHttpRequest|WebSocket|EventSource|sendBeacon|importScripts)\b/.test(src)) bad.push("a network call");
if (/\b(?:localStorage|sessionStorage|indexedDB|document\.cookie)\b/.test(src)) bad.push("the browser's own storage");
if (/<form\b/i.test(src)) bad.push("a <form>");
console.log(bad.length ? "WOULD BE TURNED DOWN: " + bad.join("; ") : "ok: " + src.length + " characters, one file, no network");
const MOCK = '<script>(function(){var kv={},yes={},g=function(k,q,o){Object.keys(o).forEach(function(n){var f=o[n];o[n]=function(){if(!yes[k]&&!(yes[k]=confirm(q)))return Promise.reject(new Error("The player said no."));return f.apply(null,arguments)}});return o},rows=[[9912,0.2,"wage",4500,15000],[9840,1,"food",-700,10500],[9801,3,"rent",-6000,11200],[9755,7,"wage",4500,17200],[9702,35,"transport",-300,12700],[9650,42,"wage",3000,13000],[9601,43,"starting_cash",10000,10000]].map(function(r){return{id:r[0],at:new Date(Date.now()-r[1]*864e5).toISOString(),kind:r[2],delta:r[3],balance_after:r[4]}}),ok=function(v){return new Promise(function(y){setTimeout(function(){y(v)},60)})};window.ibadan={player:function(){return ok({name:"ade",id:"0123456789abcdef0123456789abcdef"})},storage:{get:function(k){return ok(k in kv?kv[k]:null)},set:function(k,v){kv[k]=String(v);return ok()}},toast:function(t){console.log("toast:",t);return ok()},close:function(){console.log("close");return ok()},ledger:g("ledger","Let it read your money history?",{me:function(){return ok({balance:rows[0].balance_after,frozen:false})},rows:function(o){o=o||{};var n=Math.min(100,Math.max(1,Math.floor(Number(o.limit))||50)),b=Number(o.before)||Infinity,left=rows.filter(function(r){return r.id<b}),page=left.slice(0,n);return ok({rows:page,next:left.length>n?page[page.length-1].id:null})}})};})();<\/script>';
const policy = "default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; img-src data:; font-src data:; media-src data:; connect-src 'none'; form-action 'none'";
const page = '<meta http-equiv="Content-Security-Policy" content="' + policy + '">' + MOCK + src;
// The real frame is sandbox="allow-scripts" only. allow-modals is added HERE alone, for a stand-in that asks a question with confirm().
writeFileSync("harness.html", '<!doctype html><title>harness</title><body style="margin:0;background:#222;display:grid;place-items:center;height:100vh"><iframe sandbox="allow-scripts allow-modals" style="width:360px;height:416px;border:0;border-radius:16px;background:#fff" srcdoc="' + page.replace(/&/g, "&amp;").replace(/"/g, "&quot;") + '"></iframe>');
process.exit(bad.length ? 1 : 0);
```

HOW IT IS SUBMITTED. Through an Arena54 developer account at developers.arena54.com, as kind "app" with the permissions it uses and no others. Only app.html is submitted. Osogbo Life's staff read and try every app before it is listed, and read one that asks for "ledger" with more care. Arena54's own guides and prompts are at https://developers.arena54.com/llms.txt.

When you finish, tell me: what the app shows, which permissions it uses, what it does when the player says no, and what check.mjs printed.
