flop-guild 0.2.12 → 0.2.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/econ.js CHANGED
@@ -40,7 +40,21 @@ const DEADLINE_MS = 150_000;
40
40
  * Pages are read four at a time but applied strictly in order; any error, short page, timeout or
41
41
  * page cap marks the read as incomplete. Sessions are counted once per channelId.
42
42
  */
43
- export async function loadDemand(network, explorer, now = Date.now()) {
43
+ export const PAGE_RETRY_WAITS = [2_000, 5_000, 10_000];
44
+ /** One explorer page, retried up to 3 times (2 s, 5 s, 10 s) before the error is passed on. */
45
+ export async function pageWithRetry(base, p, fetchPage = channelPage, sleep = (ms) => new Promise((r) => setTimeout(r, ms)), waits = PAGE_RETRY_WAITS) {
46
+ for (let i = 0;; i++) {
47
+ try {
48
+ return await fetchPage(base, p);
49
+ }
50
+ catch (e) {
51
+ if (i >= waits.length)
52
+ throw e;
53
+ await sleep(waits[i]);
54
+ }
55
+ }
56
+ }
57
+ export async function loadDemand(network, explorer, now = Date.now(), o = {}) {
44
58
  const base = explorer.replace(/\/+$/, "");
45
59
  const start = now - WEEK;
46
60
  const deadline = Date.now() + DEADLINE_MS;
@@ -66,7 +80,7 @@ export async function loadDemand(network, explorer, now = Date.now()) {
66
80
  }
67
81
  const batch = [0, 1, 2, 3].map((k) => next + k).filter((p) => p < MAX_PAGES);
68
82
  next += batch.length;
69
- const pages = await Promise.all(batch.map((p) => channelPage(base, p).then((r) => r, (e) => e)));
83
+ const pages = await Promise.all(batch.map((p) => pageWithRetry(base, p, o.fetchPage, o.sleep).then((r) => r, (e) => e)));
70
84
  for (const p of pages) {
71
85
  if (p instanceof Error) {
72
86
  if (pagesRead === 0)
package/dist/minerpage.js CHANGED
@@ -96,7 +96,8 @@ export const MINER_STYLE = `
96
96
  .chart{width:100%;height:auto;margin:.5rem 0;display:block}.chart .bar{fill:var(--accent)}.chart .tick{fill:var(--muted);font-size:9px;font-family:var(--mono)}
97
97
  .prose table{margin:.6rem 0}.prose td{text-align:right;font-variant-numeric:tabular-nums}.prose th{font-weight:400;color:var(--muted)}
98
98
  #miner-count{font-family:var(--display)}
99
- .note{font-size:.88rem}`;
99
+ .note{font-size:.88rem}.fresh{font-size:.88rem;color:var(--muted);margin:.4rem 0 .8rem}
100
+ .miners-src .prov{margin-left:.3rem}`;
100
101
  export const LOADING = "loading";
101
102
  const utc = (t) => new Date(t).toISOString().slice(0, 16).replace("T", " ");
102
103
  const RETRY = '<p id="retry-wrap"><a class="btn" id="retry" href="/miner" role="button">Retry</a></p>';
@@ -109,15 +110,29 @@ export function demandSection(v, state, err) {
109
110
  <noscript><p>This part loads with JavaScript. Without it, reload the page in a minute.</p></noscript>`
110
111
  : `<p>The explorer is unavailable${err ? ` (${esc(err)})` : " (no answer after 3 tries)"}. Demand and the miner count cannot be shown right now.</p>\n${RETRY}`;
111
112
  }
112
- const partialHtml = v?.partial
113
- ? `<p><strong>${v.shown.complete ? PARTIAL_NOTE : "Partial data, no complete read yet"}</strong> (latest read ${utc(v.latest.fetchedAt)} UTC stopped early: ${esc(v.latest.note ?? "incomplete")}; ${v.latest.pagesRead} pages, ${v.latest.sessions.toLocaleString("en-US")} sessions).</p>`
113
+ const lastComplete = d.complete ? d.fetchedAt : undefined;
114
+ const partialLine = v.partial
115
+ ? `<p class="note">The last check was partial (${esc(v.latest.note ?? "stopped early")}); ${lastComplete ? "the figures come from the last complete read" : "the figures come from that partial read"}.</p>`
114
116
  : "";
115
117
  return `<p>${d.sessions.toLocaleString("en-US")} sessions opened on ${esc(d.network)} between ${utc(d.windowStart)} and ${utc(d.windowEnd)} UTC, about <strong>${d.perHour.toFixed(1)} sessions per hour</strong>.</p>
116
- ${partialHtml}
117
118
  ${chart(d.byHour)}
119
+ <p class="fresh" id="fresh">Last checked ${hhmm(v.latest.fetchedAt)} UTC (${ago(v.latest.fetchedAt)})<br>
120
+ Last complete read ${lastComplete ? `${hhmm(lastComplete)} UTC (${ago(lastComplete)})` : "none yet"}</p>
121
+ ${partialLine}
118
122
  <p>Busiest UTC hours: ${d.busiest.map((b) => `<strong>${hh(b.hour)}</strong> (${b.sessions.toLocaleString("en-US")})`).join(", ")}.</p>
119
- <p class="note">Source: ${esc(d.explorer)}/api/compute-channels, bucketed by the hour each session opened. Updated ${new Date(d.fetchedAt).toISOString().slice(11, 16)} UTC, refreshed every 10 minutes.</p>`;
123
+ <p class="note">Source: ${esc(d.explorer)}/api/compute-channels, bucketed by the hour each session opened. Refreshed every 10 minutes; a failed explorer page is retried 3 times (2 s, 5 s, 10 s).</p>`;
120
124
  }
125
+ const hhmm = (t) => new Date(t).toISOString().slice(11, 16);
126
+ /** "just now", "12 min ago", "2 h 5 min ago". The page script refreshes these every 30 s. */
127
+ export function agoText(ms) {
128
+ const m = Math.max(0, Math.floor(ms / 60_000));
129
+ if (m < 1)
130
+ return "just now";
131
+ if (m < 60)
132
+ return `${m} min ago`;
133
+ return `${Math.floor(m / 60)} h ${m % 60} min ago`;
134
+ }
135
+ const ago = (t, now = Date.now()) => `<span class="ago" data-ts="${t}">${agoText(now - t)}</span>`;
121
136
  export function readInfoHtml(v) {
122
137
  const d = v?.shown;
123
138
  return d ? ` <span class="note">(${d.sessions.toLocaleString("en-US")} sessions read since ${utc(d.windowStart)} UTC, ${d.pagesRead} explorer pages, ${d.complete ? "complete read" : "partial read"})</span>` : "";
@@ -142,6 +157,7 @@ ${demandSection(v, state, err)}
142
157
  </div>
143
158
  <h2>Rent vs airdrop calculator</h2>
144
159
  <form id="calc" class="grid" data-miners="${known ? minerCount : ""}">
160
+ <label>Miners active in the last 7 days<input id="in-miners" type="number" step="1" min="1" value="${known ? minerCount : ""}" placeholder="${known ? "" : countText}"></label>
145
161
  <label>Rent, $ per hour<input id="in-rent" type="number" step="0.01" min="0" value="${CALC_DEFAULTS.rentPerHour}"></label>
146
162
  <label>Hours per day<input id="in-hours" type="number" step="1" min="0" max="24" value="${CALC_DEFAULTS.hoursPerDay}"></label>
147
163
  <label>Days<input id="in-days" type="number" step="1" min="0" value="${CALC_DEFAULTS.days}"></label>
@@ -151,7 +167,8 @@ ${demandSection(v, state, err)}
151
167
  <label>Miner pool, FLOP<input id="in-pool" type="number" step="1" min="0" value="${CALC_DEFAULTS.poolFlop}"></label>
152
168
  <label>Liquid share, %<input id="in-liquid" type="number" step="1" min="0" max="100" value="${CALC_DEFAULTS.liquidShare * 100}"></label>
153
169
  </form>
154
- <p>Miners active in the last 7 days (live from the explorer): <strong id="miner-count">${countText}</strong><span id="read-info">${readInfoHtml(v)}</span></p>
170
+ <p class="miners-src">Live value: <strong id="miner-count">${countText}</strong>, source: explorer <span id="partial-tag" class="prov"${known && !d.complete ? "" : " hidden"}>partial read, count may be low</span><span id="read-info">${readInfoHtml(v)}</span></p>
171
+ <p class="note">No eligibility threshold has been published by Flop; this counts miners active in the last 7 days. Edit the count above to try other values.</p>
155
172
  ${!known && state === "unavailable" ? RETRY : ""}
156
173
  <table><tbody>${calcRows(out, known, state === "loading" ? "waiting for the miner count" : NA)}</tbody></table>
157
174
  <p class="note">Share estimate = your weight / (miner count × average weight) × (hours per day / 24). The share assumes the average miner runs 24 hours a day.</p>
@@ -166,7 +183,8 @@ ${minerCalc.toString()}
166
183
  if (!f) return;
167
184
  var raw = f.getAttribute("data-miners");
168
185
  var known = raw !== "" && raw !== null; // empty: no explorer data yet, never treat as 0 miners
169
- var miners = known ? Number(raw) || 0 : 0;
186
+ var live = known ? Number(raw) || 0 : 0;
187
+ var edited = false;
170
188
  var NA = "n/a (explorer unavailable)";
171
189
  var WAITING = "waiting for the miner count";
172
190
  var missing = WAITING;
@@ -177,12 +195,19 @@ ${minerCalc.toString()}
177
195
  function fl(n) { return Math.round(n).toLocaleString("en-US") + " FLOP"; }
178
196
  function pr(n) { return n === null ? "n/a" : "$" + (n < 0.01 ? n.toPrecision(3) : n.toFixed(4)); }
179
197
  function set(id, t) { $(id).textContent = t; }
198
+ // The reader's count wins; otherwise the live count; with neither, nothing is computed from 0.
199
+ function count() {
200
+ var x = v("in-miners");
201
+ if (x !== undefined && x > 0) return x;
202
+ return known ? live : null;
203
+ }
180
204
  function run() {
205
+ var m = count();
181
206
  var o = minerCalc({ rentPerHour: v("in-rent") || 0, hoursPerDay: v("in-hours") || 0, days: v("in-days") || 0,
182
- gpuWeight: v("in-weight") || 0, avgWeight: v("in-avg") || 0, minerCount: miners,
207
+ gpuWeight: v("in-weight") || 0, avgWeight: v("in-avg") || 0, minerCount: m || 0,
183
208
  poolFlop: v("in-pool") || 0, liquidShare: (v("in-liquid") || 0) / 100, flopPrice: v("in-price") });
184
209
  set("out-rent", usd(o.totalRent));
185
- if (!known) { DEPENDENT.forEach(function (id) { set(id, missing); }); return; }
210
+ if (m === null) { DEPENDENT.forEach(function (id) { set(id, missing); }); return; }
186
211
  set("out-share", (o.share * 100).toPrecision(3) + "%");
187
212
  set("out-airdrop", fl(o.airdropFlop));
188
213
  set("out-liquid", fl(o.liquidFlop));
@@ -191,9 +216,26 @@ ${minerCalc.toString()}
191
216
  set("out-net", o.net === null ? "enter a FLOP price" : usd(o.net));
192
217
  }
193
218
  f.addEventListener("submit", function (e) { e.preventDefault(); });
194
- f.addEventListener("input", run);
219
+ f.addEventListener("input", function (e) {
220
+ if (e.target && e.target.id === "in-miners") edited = $("in-miners").value !== String(live);
221
+ run();
222
+ });
195
223
  run();
196
224
 
225
+ // "x min ago" next to the timestamps, refreshed every 30 s.
226
+ function agoText(ms) {
227
+ var m = Math.max(0, Math.floor(ms / 60000));
228
+ if (m < 1) return "just now";
229
+ if (m < 60) return m + " min ago";
230
+ return Math.floor(m / 60) + " h " + (m % 60) + " min ago";
231
+ }
232
+ function refreshAgo() {
233
+ var els = document.querySelectorAll(".ago[data-ts]");
234
+ for (var i = 0; i < els.length; i++) els[i].textContent = agoText(Date.now() - Number(els[i].getAttribute("data-ts")));
235
+ }
236
+ refreshAgo();
237
+ setInterval(refreshAgo, 30000);
238
+
197
239
  // Background load: /api/miner-stats, 3 tries 3 s apart, then "unavailable" with a Retry button.
198
240
  var box = $("demand");
199
241
  if (!box || box.getAttribute("data-state") === "ready") return;
@@ -206,6 +248,7 @@ ${minerCalc.toString()}
206
248
  box.setAttribute("data-state", "loading");
207
249
  box.innerHTML = '<p class="note">Loading demand data from the explorer. The calculator works meanwhile.</p>';
208
250
  set("miner-count", "loading");
251
+ if (!edited) $("in-miners").placeholder = "loading";
209
252
  missing = WAITING; run();
210
253
  }
211
254
  function unavailable(why) {
@@ -218,6 +261,7 @@ ${minerCalc.toString()}
218
261
  var a = document.createElement("a"); a.className = "btn"; a.id = "retry"; a.href = "/miner"; a.setAttribute("role", "button"); a.textContent = "Retry";
219
262
  w.appendChild(a); box.appendChild(w);
220
263
  set("miner-count", "unavailable");
264
+ if (!edited) $("in-miners").placeholder = "unavailable";
221
265
  missing = NA; run();
222
266
  wireRetry();
223
267
  }
@@ -225,10 +269,13 @@ ${minerCalc.toString()}
225
269
  box.innerHTML = j.fragments.demand;
226
270
  box.setAttribute("data-state", "ready");
227
271
  $("read-info").innerHTML = j.fragments.readInfo;
228
- miners = Number(j.demand.minerCount) || 0;
272
+ live = Number(j.demand.minerCount) || 0;
229
273
  known = true;
230
- f.setAttribute("data-miners", String(miners));
231
- set("miner-count", miners.toLocaleString("en-US"));
274
+ f.setAttribute("data-miners", String(live));
275
+ set("miner-count", live.toLocaleString("en-US"));
276
+ if (!edited) $("in-miners").value = String(live);
277
+ $("partial-tag").hidden = !!j.demand.complete;
278
+ refreshAgo();
232
279
  run();
233
280
  }
234
281
  function load(attempt) {
package/dist/shell.js CHANGED
@@ -64,6 +64,7 @@ export const SHELL_CSS = `${FONT_CSS}
64
64
  :root{${DARK}
65
65
  --display:"Space Mono",ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;--mono:ui-monospace,SFMono-Regular,Menlo,Consolas,"Liberation Mono",monospace}
66
66
  *,*::before,*::after{box-sizing:border-box}
67
+ [hidden]{display:none!important}
67
68
  html{-webkit-text-size-adjust:100%}
68
69
  body{margin:0;background:var(--bg);color:var(--fg);font:15px/1.6 "Inter",system-ui,-apple-system,"Segoe UI",sans-serif;overflow-x:hidden}
69
70
  a{color:var(--accent);text-decoration:none}a:hover{text-decoration:underline}
@@ -84,7 +85,14 @@ code{font-family:var(--mono);font-size:.86em;background:var(--card-2);border:1px
84
85
  .btn{display:inline-block;font:600 .88rem/1 "Inter",system-ui,sans-serif;background:var(--accent);color:var(--on-accent);border:1px solid var(--accent);border-radius:8px;padding:.6rem .9rem;cursor:pointer;white-space:nowrap}
85
86
  .btn:hover{text-decoration:none;filter:brightness(1.08)}
86
87
  .btn.ghost{background:transparent;color:var(--fg);border-color:var(--line-2)}
87
- @media (max-width:640px){.topbar{position:static}.nav{order:3;width:100%;margin-left:0}.topbar .btn{margin-left:auto}}
88
+ @media (max-width:640px){
89
+ .topbar{position:static}.topbar .wrap{gap:.3rem .55rem;min-height:0;padding-top:.75rem;padding-bottom:.55rem}
90
+ .topbar .btn{display:none}
91
+ .topbar .brand img{width:34px;height:34px}.topbar .wm{font-size:1.5rem}
92
+ .topbar .pill{font-size:10px;padding:.1rem .38rem;gap:.25rem;letter-spacing:.06em;color:var(--dim);border-color:var(--line);background:transparent}
93
+ .topbar .pill::before{width:.3rem;height:.3rem}
94
+ .nav{order:3;width:100%;margin-left:0;flex-wrap:nowrap;overflow-x:auto;gap:1.1rem;font-size:.8rem;white-space:nowrap;scrollbar-width:none;padding-bottom:.1rem}
95
+ .nav::-webkit-scrollbar{display:none}.nav a{color:var(--dim)}}
88
96
  main.wrap{padding-top:1.8rem;padding-bottom:3rem}
89
97
  /* cards */
90
98
  .card{background:var(--card);border:1px solid var(--line);border-radius:12px;padding:1.1rem 1.2rem;margin:0 0 1rem;min-width:0}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flop-guild",
3
- "version": "0.2.12",
3
+ "version": "0.2.13",
4
4
  "description": "Technocore guild kit: Ed25519 did:key signing CLI for technocore.chat rooms, plus an agent identity scaffold.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",