Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ Read these. They are the honest edge of what a delay can do.
- The production page loads only its own files and makes no other network requests. The Content Security Policy is `connect-src 'none'`. All chain data comes through your wallet, so no extra party learns which vault you look at.
- Wallets connect through EIP-6963 in the page. There is no WalletConnect relay.
- No service worker and no update prompt. See "Updates" below.
- Alerts are the exception, and you choose them. Our alert service must know who follows a Chronobox to send an alert, and we can see that. If you do not want that, run the alert service yourself. See "Get told" below.

## Get told: calendar and alerts

Expand All @@ -133,7 +134,7 @@ Alerts have two parts. The app has one button. The alert service is a project of

The alert service has no runtime dependencies. It watches every Chronobox on one or more networks and runs a Telegram bot. It sends a message when somebody asks a Chronobox for something, when the wait is over, when a request is cancelled or carried out, and when the Chronobox itself changes. The messages use the words of this app and hold no links. See `watcher/README.md`.

`ALERTS_TELEGRAM` in `src/lib/chains.ts` is the name of the bot: `zodiac_chronobox_bot`. It must be the bot that the alert service runs with. `null` turns the alerts off: a Chronobox then does not show "Get told". With a name set, a Chronobox shows "Get told" with one button, "Get alerts in Telegram". It opens `https://t.me/<bot>?start=<chain id>-<address>`. The person presses Start in Telegram, and the bot sends the alerts of that Chronobox to that chat from then on.
`ALERTS_TELEGRAM` in `src/lib/chains.ts` is the name of the bot: `zodiac_chronobox_bot`. It must be the bot that the alert service runs with. `null` turns the alerts off: a Chronobox then does not show "Get told". With a name set, "Get told" has the way "Telegram", with one button, "Get alerts in Telegram". It opens `https://t.me/<bot>?start=<chain id>-<address>`. The person presses Start in Telegram, and the bot sends the alerts of that Chronobox to that chat from then on.

The registration is in Telegram, not in this app. The app only builds the link, and `connect-src 'none'` stays as it is.

Expand All @@ -145,16 +146,24 @@ What this gives and what it does not:
- A person with your wallet cannot stop the alerts: the subscription belongs to the Telegram chat, not to the wallet. When a chat that followed for a day or more stops, every other chat that follows the same Chronobox is told, once an hour at most. A stranger who follows and stops again cannot ring the phones of the others.
- The bot sends no links and asks for nothing. That makes a fake bot easier to spot. The link to the real bot is in the app, so nobody has to search for it.

### Alerts by email, and your own alert service
### The choice, and what our alert service costs in privacy

The same alert service can send the alerts by email, through Resend. `ALERTS_EMAIL` in `src/lib/chains.ts` is the page of the alert service where a person gives an email address (`<alert service>/api/email`). It is `null` in the source. With it set, "Get told" asks how the person wants to hear about a withdrawal, and "Email" opens that page. The person confirms the address with a link in one email (double opt-in). The app never sees the address.
"Get told" opens with one question: how do you want to hear about it?

- The alert service keeps the email address, the address of the Chronobox and since when, encrypted like the list of chats. Resend gets the address and the text of each email, because it sends them.
- Every alert by email ends with a link that stops the alerts. It is the only link in it.
- **Telegram**: a message from our alert service (`ALERTS_TELEGRAM`).
- **Email**: not there yet. While `ALERTS_EMAIL_SOON` is true and `ALERTS_EMAIL` is `null`, the list shows it as "Coming soon", and it cannot be chosen. `ALERTS_EMAIL` will be the page of the alert service where a person gives an email address. With it set, the row opens that page.
- **Your own alert service**: one button that opens the guide "Run it yourself" in `watcher/README.md` (`ALERTS_GUIDE`).

Under the list, the sheet says it in plain words: our alert service is not private. To send an alert it must know who follows a Chronobox, and we can see that. With Telegram, we can see that a Telegram account follows a Chronobox, and Telegram can see it too. Encryption of the list protects a copy of it, not against us. A person who does not want that runs the alert service on their own. Then we learn nothing about them.

A way whose setting is `null` is not in the list. With one way left and `ALERTS_EMAIL_SOON` false, "Get told" opens on that way, without the question.

`ALERTS_GUIDE` is where a person reads how to run the alert service on a machine of their own. With it set, "Get told" has a third way, "Your own alert service", with one button that opens the guide ("Run it yourself" in `watcher/README.md`). It is `null` in the source.
### Alerts by email

With only one of the three set, "Get told" opens on that one, as before.
The same alert service can send the alerts by email, through Resend. `ALERTS_EMAIL` in `src/lib/chains.ts` is the page of the alert service where a person gives an email address (`<alert service>/api/email`). It is `null` in the source, so "Get told" shows email as "Coming soon". With it set, "Email" opens that page. The person confirms the address with a link in one email (double opt-in). The app never sees the address.

- The alert service keeps the email address, the address of the Chronobox and since when, encrypted like the list of chats. Resend gets the address and the text of each email, because it sends them.
- Every alert by email ends with a link that stops the alerts. It is the only link in it.

## Run it

Expand Down
9 changes: 8 additions & 1 deletion src/lib/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,18 @@ export const ALERTS_TELEGRAM: string | null = "zodiac_chronobox_bot";
*/
export const ALERTS_EMAIL: string | null = null;

/**
* Alerts by email are not there yet, but they will be. While this is true and
* ALERTS_EMAIL is null, "Get told" shows email as "Coming soon". Set it to
* false in a copy of the app that will not have alerts by email.
*/
export const ALERTS_EMAIL_SOON = true;

/**
* Where a person reads how to run the alert service on a machine of their
* own: the guide in the repository. Null means: the app does not point to it.
*/
export const ALERTS_GUIDE: string | null = null;
export const ALERTS_GUIDE: string | null = "https://github.com/zodiaceco/chronobox/tree/main/watcher#run-it-yourself";

/**
* The suggested contribution in US dollars, by how much money is in play:
Expand Down
6 changes: 6 additions & 0 deletions src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -3129,3 +3129,9 @@ button.row-strong:hover .row-hint {
color: var(--muted);
font-size: 0.95rem;
}

/* A way that is not there yet: it cannot be chosen, and it looks like it. */
.row-pick-soon strong {
color: var(--muted);
font-weight: 500;
}
91 changes: 56 additions & 35 deletions src/ui/alerts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,47 @@
* Alerts for one Chronobox: the sheet "Get told".
*
* The first screen asks how the person wants to hear about a withdrawal:
* Telegram or email from the alert service, or an alert service of their own.
* A way that is not set in chains.ts is not in the list. With one way left
* the question is skipped, and with none the Chronobox page does not show
* "Get told".
* Telegram or email from our alert service, or an alert service of their own.
* A way that is not set in chains.ts is not in the list. Email is the one
* exception: while ALERTS_EMAIL_SOON is true and ALERTS_EMAIL is not set, the
* list shows it as "Coming soon", and it cannot be chosen. With one way left
* and nothing coming, the question is skipped. With none, the Chronobox page
* does not show "Get told".
*
* The first screen also says what our alert service costs in privacy: to send
* an alert it must know who follows a Chronobox, and we can see that. A person
* who does not want that runs the alert service on their own.
*
* Every way works the same: the app only builds a link, and the registration
* happens somewhere else (in Telegram, on a page of the alert service, on the
* person's own machine). The app sends nothing, and it never sees an email
* address.
*
* Email is a double opt-in. The person gives the address on the page of the
* alert service. The service sends one email with a link. Alerts start only
* after the person opens that link and confirms.
*/
import type { ComponentChildren } from "preact";
import { useState } from "preact/hooks";
import { telegramLink, telegramStart } from "../lib/alerts.ts";
import { ALERTS_EMAIL, ALERTS_GUIDE, ALERTS_TELEGRAM, type Chain } from "../lib/chains.ts";
import { ALERTS_EMAIL, ALERTS_EMAIL_SOON, ALERTS_GUIDE, ALERTS_TELEGRAM, type Chain } from "../lib/chains.ts";
import type { Address } from "../lib/hex.ts";
import { Button, Modal } from "./common.tsx";
import { Button, Modal, Notice } from "./common.tsx";

/** The dev server shows the sheet with a bot name that is only a stand-in. Put the name of your test bot in ALERTS_TELEGRAM. */
export const BOT: string | null = ALERTS_TELEGRAM ?? (__DEV__ ? "chronobox_alerts_dev_bot" : null);
/** The page of the alert service where a person gives an email address. The dev server expects a watcher on this machine. */
const EMAIL: string | null = ALERTS_EMAIL ?? (__DEV__ ? "http://localhost:8787/api/email" : null);
/** The page of the alert service where a person gives an email address. */
const EMAIL: string | null = ALERTS_EMAIL;
/** The guide to run the alert service yourself. */
const OWN: string | null = ALERTS_GUIDE ?? (__DEV__ ? "https://github.com/zodiaceco/chronobox/tree/main/watcher#run-it-yourself" : null);
const OWN: string | null = ALERTS_GUIDE;

export type Stage = "choose" | "telegram" | "email" | "own";
const WAYS = [BOT ? "telegram" : null, EMAIL ? "email" : null, OWN ? "own" : null].filter(Boolean) as Stage[];
/** Email is not there yet, and the list says so. */
const EMAIL_SOON = ALERTS_EMAIL_SOON && !EMAIL && WAYS.length > 0;
/** The sheet opens with the question, not with the one way there is. */
const CHOICE = WAYS.length > 1 || EMAIL_SOON;

/** The sheet has something to offer. Without it the Chronobox page does not show "Get told". */
export const ALERTS = WAYS.length > 0;
/** What the row "Get told" says: the one way there is, or that there is a choice. */
export const ALERTS_ROW = WAYS.length === 1 ? { telegram: "Alerts in Telegram", email: "Alerts by email", own: "Your own alerts", choose: "" }[WAYS[0]] : "Alerts";
export const ALERTS_ROW = CHOICE ? "Alerts" : { telegram: "Alerts in Telegram", email: "Alerts by email", own: "Your own alerts", choose: "" }[WAYS[0]];

type Screen = { title: string; lead?: string; body: ComponentChildren };
type Ctx = { chain: Chain; safe: Address; go: (stage: Stage) => void };
Expand All @@ -49,24 +55,31 @@ function Chevron() {
);
}

/** One way to choose: a name, one line about it, and a tap that goes on. */
function Pick(props: { title: string; text: string; onClick: () => void }) {
/** One way to choose: a name, one line about it, and a tap that goes on. Without a tap it is a way that is not there yet. */
function Pick(props: { title: string; text: string; onClick?: () => void }) {
const text = (
<span class="row-pick-text">
<strong>{props.title}</strong>
<span>{props.text}</span>
</span>
);
return (
<li>
<button type="button" class="row row-pick" onClick={props.onClick}>
<span class="row-pick-text">
<strong>{props.title}</strong>
<span>{props.text}</span>
</span>
<Chevron />
</button>
{props.onClick ? (
<button type="button" class="row row-pick" onClick={props.onClick}>
{text}
<Chevron />
</button>
) : (
<div class="row row-pick row-pick-soon">{text}</div>
)}
</li>
);
}

/** Back to the choice. Without a choice (one way only) there is nothing to go back to. */
function Back(props: { go: (stage: Stage) => void }) {
if (WAYS.length < 2) return null;
if (!CHOICE) return null;
return (
<Button kind="quiet" onClick={() => props.go("choose")}>
Back
Expand All @@ -87,15 +100,22 @@ function screenOf(stage: Stage, ctx: Ctx): Screen {
<ul class="rows">
{BOT ? <Pick title="Telegram" text="A message from our alert service." onClick={() => go("telegram")} /> : null}
{EMAIL ? <Pick title="Email" text="An email from our alert service." onClick={() => go("email")} /> : null}
{OWN ? <Pick title="Your own alert service" text="You run it. It writes only to you." onClick={() => go("own")} /> : null}
{EMAIL_SOON ? <Pick title="Email" text="Coming soon." /> : null}
{OWN ? <Pick title="Your own alert service" text="You run it on a server. We learn nothing about you." onClick={() => go("own")} /> : null}
</ul>
{BOT || EMAIL ? (
<Notice kind="info" title="Our alert service is not private">
To send you an alert, it must know who follows this Chronobox. We can see that.
{OWN ? " If you do not want that and you can run a server, run your own alert service." : null}
</Notice>
) : null}
</>
),
};
case "telegram":
return {
title: WAYS.length === 1 ? "Get told" : "Alerts in Telegram",
lead: WAYS.length === 1 ? "The wait protects you only if you hear about a withdrawal in time." : "Telegram opens. Press Start there, and you are done.",
title: CHOICE ? "Alerts in Telegram" : "Get told",
lead: CHOICE ? "Telegram opens. Press Start there, and you are done." : "The wait protects you only if you hear about a withdrawal in time.",
body: (
<>
<div class="modal-actions">
Expand All @@ -105,8 +125,9 @@ function screenOf(stage: Stage, ctx: Ctx): Screen {
<Back go={go} />
</div>
<p class="deposit-note">
Telegram opens. Press Start there. The alert service keeps the number of your Telegram chat, the address of this Chronobox,
and since when you follow it. Nothing else. To end the alerts, send /stop there.
{CHOICE ? null : "Telegram opens. Press Start there. "}
Our alert service keeps the number of your Telegram chat, the address of this Chronobox, and since when you follow it. So we
can see that your Telegram account follows this Chronobox, and Telegram can see it too. To end the alerts, send /stop there.
</p>
</>
),
Expand All @@ -124,16 +145,16 @@ function screenOf(stage: Stage, ctx: Ctx): Screen {
<Back go={go} />
</div>
<p class="deposit-note">
The alert service keeps your email address, the address of this Chronobox, and since when you follow it. Nothing else. Every
alert ends with a link that stops them.
Our alert service keeps your email address, the address of this Chronobox, and since when you follow it. So we can see that
your email address follows this Chronobox. Every alert ends with a link that stops them.
</p>
</>
),
};
case "own":
return {
title: "Your own alert service",
lead: "The alert service is open source. You can run it yourself. Then it writes only to you, and it does not need us.",
lead: "The alert service is open source. If you can run a server, you can run it yourself. Then it writes only to you, and we learn nothing about you.",
body: (
<>
<div class="modal-actions">
Expand All @@ -142,16 +163,16 @@ function screenOf(stage: Stage, ctx: Ctx): Screen {
</a>
<Back go={go} />
</div>
<p class="deposit-note">The guide there shows what you can run, and what each way needs.</p>
<p class="deposit-note">The guide there shows what you need, and every step.</p>
</>
),
};
}
}

export function AlertsSheet(props: { chain: Chain; safe: Address; onClose: () => void }) {
// With one way, the sheet opens on it.
const [stage, setStage] = useState<Stage>(WAYS.length === 1 ? WAYS[0] : "choose");
// With one way and nothing coming, the sheet opens on that way.
const [stage, setStage] = useState<Stage>(CHOICE ? "choose" : WAYS[0]);
if (!ALERTS) return null;
const screen = screenOf(stage, { chain: props.chain, safe: props.safe, go: setStage });
return (
Expand Down
Loading
Loading