An app could have nostrod pay an order: it called Pay of net.catcrafts.Nostro1.Checkout on the system bus, and nostrod paid from an account the user had chosen, after a dialog of its own. On 2026-11-22 the owner decided that a link takes its place. The app registers for payto links (RFC 8905), so that an app or a website can hand one to the desktop, and shows a link as its pay form filled in. The link: - The app's desktop entry takes the scheme (Exec=nostro-app %u, MimeType=x-scheme-handler/payto), and nostro-app takes an argument that is no option as a link: it overwrites it in argv and hands it to App::Open once the app has started. - ReadPaymentLink (Nostro.App:Forms) reads payto://iban/<IBAN> with the options amount, receiver-name and message, and refuses a link rather than guess at it, in a sentence of the app's own with nothing of the link in it. Among what it refuses: an IBAN whose check digits do not hold, one of the three options given twice, instruction, a comma in the amount, and a name or a message with a code point that is Unshown, or Blank and no plain space. - A link that is read waits until the accounts are read and DefaultCheckoutAccount has answered or failed, with a line on the accounts' page. Then App::TakeLink fills in the pay form, which says in a banner that a link filled it in, and with more than one account opens it under the choice of accounts that the form's From row has. A link pays nothing: the form's button sends, and polkit's dialog confirms as for any payment (design rule 12, and 14, which is new). - Unshown and Blank are the two tables the worker's Shown() works from. They move into Nostro:Utils, where the app's reader asks them too. The move is within the library. The reader holds a link's name to those two and to no more of Shown(): a name with an & is read, and the dialog shows it with a + as it does any name. The checkout: - nostrod serves one interface under one bus name. Gone are net.catcrafts.Nostro1.Checkout with its XML and its activation file, the polkit action Checkout, the module Nostro.Checkout with --product=checkout, and the worker's record of orders. That changes the published contract after a release, 0.0.0, and design rule 10 records it as the owner's decision. - DefaultCheckoutAccount and SetDefaultCheckoutAccount keep their names and signatures. The account they keep is where a link's pay form starts: nostrod's dialog for choosing it says "have pay links start from", the app's setting reads "Pay links start from", and `nostro checkout account` prints "pay links start from". - The D-Bus policy still lets nostrod own the old name: the nostrod of 0.0.0 asks for it when it starts, and the system files can be newer than the Flatpak it runs from. install.sh removes the old name's activation file. A user's checkouts.cdb is read by nothing any more, and is left where it is. - The Arch package stops installing the checkout's two files, and its pkgrel goes up to 2. Where makepkg -si finds a package of the version already built it installs that one again, which would bring the activation file back. The guide now says that pkgrel goes up with a change to what the package installs. - Bus::Interface goes too: the worker called it in two places, to tell a call to the checkout from one to the main interface. The review's own files follow. gate0 loses the build of --product=checkout, and the three lens sections that named the checkout no longer do, and ask about a link. The README has "Pay links" in place of "Checkout for apps", and AGENTS.consumer.md says what the app reads of a link. Its line on lib/json.hpp no longer gives a release: the file is of none, and the guide names its commit. The pay form and the accounts' page change only by a banner each, shown while a link is in play, which docs/screenshots/take.sh never has: the README's pictures stand. Tests: ShouldValidateForms reads and refuses links and fills the form from one. ShouldDriveTheApp opens links against a real nostrod on the fake bus: before the accounts are known, with no account, with one and with several, with the accounts known and the system bus gone, for a second user whose first connection pays their own accounts only, one that cannot be read, one whose name has an &, and through polkit's dialog to the payment. It now counts nostrod's answers to hold that the account pay links start from is read again once a connection is removed: the check it had there passed without that. ShouldHandleMoneyAndText holds the two tables at the ends of their ranges. ShouldServeEveryUser holds that nostrod serves no checkout, that the bus's policy lets an older nostrod own the old name, and the account pay links start from. ShouldRunCommands holds the CLI's wording. The review's gate0 passes at this commit: the version check, 17 tests, the builds of the CLI, the library, nostrod, the fake system, the app and its --debug-api build, and five lint runs that report nothing. tests/coverage.sh reports lines, functions and regions at 100.00%. Looked at on 2026-11-22 on the made-up system (run fake), on a desktop (KWin at a scale of 1.85). At 420x760, at --scale 3 --size 360x760 and at 1100x720 in the light look: a link's pay form under the choice of accounts, the form after a tap beside that choice, and the accounts' page while a link waits, its line above the rows that stand in for the accounts (--bank-delay 10000). At 420x760: that line above what the page says when the accounts cannot be read (--polkit deny) and above the accounts themselves (--polkit slow, the link opened in the running app), the settings' row and page for the account pay links start from, the sheet for a link that cannot be read, and with --empty the sheet for no account.
357 lines
20 KiB
C++
357 lines
20 KiB
C++
// SPDX-License-Identifier: GPL-3.0-only
|
|
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
|
|
|
export module Nostro.App:App;
|
|
|
|
import std;
|
|
import Nostro;
|
|
import Nostro.Ui;
|
|
import :Banks;
|
|
import :Format;
|
|
import :Forms;
|
|
import :Errors;
|
|
|
|
// Nostro's window without the window: what it knows of the user's banks, where the user is in it, what is being
|
|
// filled in and what is under way, and the screens built from that. It asks nostrod through the asynchronous Client
|
|
// and never waits for it: a call's answer changes the state and asks for a new frame. Nothing here draws or reads a
|
|
// device (that is Nostro.Ui.Shell's), so a test builds a frame, reads what it says and taps it by name.
|
|
//
|
|
// The rules that keep a bank's client honest are here. A press acts on what it went down on, and every action names
|
|
// what it is about by value: an IBAN or the bank's id, never a place in a list. One change at a time: while one is
|
|
// under way its sheet covers the screen, so nothing else can be asked for and nothing is sent twice. A payment from
|
|
// the form, and a request for money from its form, is sent by the form's own button, with no question of the app's
|
|
// before it: what confirms it is the system's password dialog, which nostrod words itself and which every change
|
|
// meets, as nostro is shipped. What the app does ask about first is what one press on a sheet would do (a request or a
|
|
// draft to accept or reject, a schedule to cancel, a card to report), and it shows that built from the same values that
|
|
// are then sent. And an answer that leaves open whether money moved says so, and offers no button to try again.
|
|
//
|
|
// Which bank an account is with makes no difference to any of it. A bank's own is in two places: what :Banks says of
|
|
// it, and the forms a connection to it is made with, which are the last pages of adding a connection in the settings
|
|
// (Nostro.App-Bunq.cpp has bunq's). Everything else says "your bank", and asks :Banks what a connection can do.
|
|
|
|
export namespace Nostro::App {
|
|
// What the app needs of the program around it.
|
|
struct Host {
|
|
// A client for nostrod, attached to the program's event loop. Throws when there is no system bus.
|
|
std::function<Client()> connect;
|
|
// Asks the desktop to open an address in the user's browser; `then` hears whether it took the request.
|
|
std::function<void(std::string_view uri, std::function<void(bool taken)> then)> openUri;
|
|
// The time, for "today" and for what is in the past. The system's clock when left empty.
|
|
std::function<std::chrono::system_clock::time_point()> now;
|
|
// A new state for an OAuth request, which ties the browser's answer to it. Random when left empty.
|
|
std::function<std::string()> oauthState;
|
|
std::string version;
|
|
};
|
|
|
|
// How far the asking for something is.
|
|
enum class LoadState : std::uint8_t {
|
|
Idle, // not asked for yet
|
|
Loading,
|
|
Loaded,
|
|
Failed
|
|
};
|
|
|
|
// Something nostrod is asked for.
|
|
template<typename T>
|
|
struct Loadable {
|
|
LoadState state = LoadState::Idle;
|
|
T value{};
|
|
Guidance problem; // why it failed
|
|
bool refreshing = false; // loaded, and asked for again: the old value shows meanwhile
|
|
};
|
|
|
|
// A bank connection with its accounts: Connectors() and Accounts() joined.
|
|
struct Connection {
|
|
std::string name;
|
|
std::string bank; // as nostrod calls it; BankName() says it as the bank does
|
|
std::string environment; // "production" or "sandbox"
|
|
std::string auth; // the way it was made, as nostrod calls that; WayName() says it in words
|
|
bool working = false;
|
|
std::vector<Account> accounts;
|
|
// It pays between the user's own accounts and nobody else, by what :Banks knows of the way it was made.
|
|
bool ownAccountsOnly = false;
|
|
};
|
|
|
|
// One account, found by its key.
|
|
struct AccountRef {
|
|
const Connection* connection = nullptr;
|
|
const Account* account = nullptr;
|
|
std::string key; // names it in the app: its IBAN, or its name where the bank gave none
|
|
};
|
|
|
|
class App {
|
|
public:
|
|
App(Ui::Context& context, Host host);
|
|
App(const App&) = delete;
|
|
App& operator=(const App&) = delete;
|
|
|
|
// Asks nostrod for the connections and accounts; the first frame shows them loading.
|
|
void Start();
|
|
// Builds the screen the user is on.
|
|
void Build(Ui::Frame& frame);
|
|
|
|
// Whether nostrod is still being waited for: for whoever runs the loop until the app has settled.
|
|
bool Busy() const noexcept;
|
|
// Whether a change is under way. The window may close then, and the process must not: the answer says whether
|
|
// money moved. onSettled is called when it has come.
|
|
bool Changing() const noexcept;
|
|
std::function<void()> onSettled;
|
|
// An answer came, to the method of that name, and whether it was an error: for a log or a debugger. Called once
|
|
// the app has taken the answer in, so what it shows is what the answer led to.
|
|
std::function<void(std::string_view member, bool failed)> onAnswer;
|
|
|
|
// Goes to a place by name: "accounts", "cards", "settings", "connections", "checkout", "about", "account:<IBAN>",
|
|
// or one of the steps of adding a connection: "add" for the banks, "add:<bank>" for a bank's ways and
|
|
// "add:<bank>:<way>" for a way's form, as in "add:bunq:key". False for a name that is none of them, and while
|
|
// a change is under way, which the screen waits out.
|
|
bool Navigate(std::string_view route);
|
|
// Opens a link the program was started with, as a browser hands one on from a website's pay button: a payment
|
|
// to make, which ReadPaymentLink reads. Its pay form opens filled in once the accounts are known, with the
|
|
// choice of which account pays over it where there is more than one, starting from the account the user
|
|
// chose for pay links where they chose one; until then the accounts' page says that it will. That is all a
|
|
// link does.
|
|
// Nothing is sent before the user presses the form's button, and the system's password dialog confirms it as
|
|
// it does any payment: there is no say in a link. One that cannot be read is said to be so, with why. False
|
|
// while a change is under way, which the screen waits out.
|
|
bool Open(std::string_view link);
|
|
// Where the user is, as a name of the same kind, with what is open over it after a '+': "account:NL…+filter".
|
|
std::string Screen() const;
|
|
// The connections and accounts as they are known.
|
|
const Loadable<std::vector<Connection>>& Overview() const noexcept;
|
|
// The state of the OAuth request that is being made, for a test that plays the browser.
|
|
std::string_view OAuthState() const noexcept;
|
|
|
|
private:
|
|
// -- where the user is ---------------------------------------------------------------------------------------
|
|
enum class Place : std::uint8_t {
|
|
Accounts,
|
|
Cards,
|
|
Settings
|
|
};
|
|
enum class Page : std::uint8_t {
|
|
Account,
|
|
Pay,
|
|
Request,
|
|
Connections,
|
|
Banks, // adding a connection: the banks to choose from
|
|
Ways, // the ways to connect to the bank that was chosen
|
|
Connect, // the form of the way that was chosen
|
|
Checkout, // the account pay links start from: named, as its route is, after the wire's DefaultCheckoutAccount
|
|
About
|
|
};
|
|
struct Route {
|
|
Page page = Page::Account;
|
|
std::string account; // the key of the account it is about
|
|
const Bank* bank = nullptr; // of Ways and Connect
|
|
const Way* way = nullptr; // of Connect
|
|
};
|
|
enum class Tab : std::uint8_t {
|
|
Activity,
|
|
Requests,
|
|
Incoming,
|
|
Scheduled,
|
|
Drafts
|
|
};
|
|
|
|
// -- what is known -------------------------------------------------------------------------------------------
|
|
// One account's lists, each asked for when its tab is first shown.
|
|
struct AccountData {
|
|
Tab tab = Tab::Activity;
|
|
FilterForm filter;
|
|
TransactionQuery query; // the filter as it was last asked for
|
|
Loadable<std::vector<Transaction>> activity;
|
|
bool more = false; // the list is as long as was asked for: there may be more
|
|
Loadable<std::vector<BunqPaymentRequest>> requests;
|
|
Loadable<std::vector<BunqIncomingRequest>> incoming;
|
|
Loadable<std::vector<BunqScheduledPayment>> scheduled;
|
|
Loadable<std::vector<BunqDraftPayment>> drafts;
|
|
};
|
|
|
|
// One kind of call at a time, and at most one waiting behind it: the newest. nostrod's worker makes its calls
|
|
// to the bank one after another, and an answer dropped here does not stop it, so a queue of searches the user
|
|
// has already typed past would only use up the bank's patience.
|
|
struct Lane {
|
|
Client::Pending pending;
|
|
bool busy = false;
|
|
std::function<void()> next;
|
|
};
|
|
|
|
// -- what is open over the screen ----------------------------------------------------------------------------
|
|
struct Line {
|
|
std::string label;
|
|
std::string value;
|
|
// What a press on the line puts on the clipboard, where that is not the value as it is shown: an IBAN
|
|
// without the spaces it is read with.
|
|
std::string copied;
|
|
};
|
|
struct Choice {
|
|
std::string key;
|
|
std::string label;
|
|
Ui::ButtonKind kind = Ui::ButtonKind::Tonal;
|
|
bool enabled = true;
|
|
std::string reason; // why it cannot be chosen
|
|
std::function<void()> onTap;
|
|
};
|
|
// What is asked or told over the screen: a thing to look at with what can be done about it, a question before
|
|
// a change, the wait for its answer, and how it went.
|
|
struct Dialog {
|
|
enum class Kind : std::uint8_t {
|
|
Detail, // a row's own sheet
|
|
Ask, // before a change: what will be done, to confirm
|
|
Working, // the change is under way
|
|
Done, // it worked
|
|
Problem // it did not, or may not have
|
|
};
|
|
Kind kind = Kind::Detail;
|
|
std::string name; // for Screen(): "transaction", "confirm", "working"
|
|
std::string title;
|
|
std::vector<std::string> text;
|
|
std::vector<Line> lines;
|
|
std::vector<Choice> choices;
|
|
std::string link; // an address to copy or open
|
|
std::function<void()> onClose; // after it is sent away
|
|
};
|
|
enum class Picking : std::uint8_t {
|
|
None,
|
|
PayFrom,
|
|
RequestInto
|
|
};
|
|
|
|
// -- nostrod -------------------------------------------------------------------------------------------------
|
|
Client& Nostrod();
|
|
void Reconnect();
|
|
void Note(const std::vector<std::string>& notes);
|
|
void Answered(std::string_view member, bool failed);
|
|
// A reading: `start` makes the call, given what to do with its answer, in the lane of that name.
|
|
template<typename T>
|
|
void Fetch(std::string lane, std::string member, std::function<Client::Pending(Client&, Client::Then<T>)> start, std::function<void(Answer<T>)> then);
|
|
// A change: shows the wait, makes the call, and shows how it went. `done` says what to tell the user; what it
|
|
// throws is told as the change having failed. `account` is the account it is about, if any.
|
|
template<typename T>
|
|
void Change(Operation operation, std::string member, std::string title, std::string account, std::function<Client::Pending(Client&, Client::Then<T>)> start, std::function<void(T&)> done);
|
|
void Failed(const Guidance& guidance, Operation operation, const std::string& account);
|
|
void Wait(std::string title);
|
|
|
|
void Refresh(bool again = false);
|
|
void LoadAccounts(std::vector<ConnectorSummary> summaries, bool again);
|
|
void OverviewFailed(const Guidance& guidance);
|
|
void ListFailed(const Guidance& guidance);
|
|
void LoadActivity(const std::string& key, bool stored = false);
|
|
template<typename T>
|
|
void LoadList(const std::string& key, std::string_view member, Loadable<std::vector<T>> AccountData::* list, Client::Pending (Client::* call)(std::string_view, Client::Then<std::vector<T>>));
|
|
void LoadTab(const std::string& key, Tab tab, bool again = false);
|
|
void LoadCards(bool again = false);
|
|
void LoadCheckout();
|
|
void Changed(const std::string& key);
|
|
|
|
// -- going places --------------------------------------------------------------------------------------------
|
|
void Go(Place to);
|
|
void Push(Page page, std::string account = {}, const Bank* bank = nullptr, const Way* way = nullptr);
|
|
void Back();
|
|
void Show(Dialog shown);
|
|
void Close();
|
|
void Tell(std::string_view notice);
|
|
std::chrono::system_clock::time_point Today() const;
|
|
std::optional<AccountRef> Find(std::string_view key) const;
|
|
std::vector<AccountRef> Accounts() const;
|
|
AccountData& Data(const std::string& key);
|
|
bool Own(std::string_view iban) const;
|
|
|
|
// -- what the user asks for ----------------------------------------------------------------------------------
|
|
void OpenPay(std::string account);
|
|
void OpenRequest(std::string account);
|
|
// The pay form for the link that waits, once what it starts from has been read.
|
|
void TakeLink();
|
|
void SubmitPayment();
|
|
void SendPayment(const std::string& key, Currency currency, const PaymentOrder& order);
|
|
void SubmitRequest();
|
|
void SendRequest(const std::string& key, Currency currency, const RequestOrder& order);
|
|
void ShowTransaction(const std::string& key, const Transaction& transaction);
|
|
void ShowRequest(const std::string& key, const BunqPaymentRequest& request);
|
|
void ShowIncoming(const std::string& key, const BunqIncomingRequest& request);
|
|
void ShowScheduled(const std::string& key, const BunqScheduledPayment& scheduled);
|
|
void ShowDraft(const std::string& key, const BunqDraftPayment& draft);
|
|
void ShowCard(const BunqCard& card);
|
|
void ShowConnection(const Connection& connection);
|
|
// A change that needs a yes and no more: asks `question`, makes the change, and tells `told`.
|
|
void Simple(Operation operation, std::string member, std::string question, std::string detail, std::string confirm, std::string told, std::string account, std::function<Client::Pending(Client&, Client::Then<std::monostate>)> start);
|
|
void SetCard(std::uint64_t card, std::string lastFour, Operation operation, std::string status);
|
|
void RemoveConnection(const Connection& connection);
|
|
// What every way's form ends in: nostrod is asked to add the connection, as `start` asks it, and the user is
|
|
// told how that went. For the form's own button: which bank and which way it is are the page's that is open.
|
|
void Connect(std::string member, std::function<Client::Pending(Client&, Client::Then<AddedConnector>)> start);
|
|
void Connected(const AddedConnector& added, const Way& way);
|
|
void ForgetConnecting();
|
|
// bunq's two ways (Nostro.App-Bunq.cpp).
|
|
void ConnectBunqKey();
|
|
void BeginBunqOAuth();
|
|
void ConnectBunqOAuth();
|
|
void ChooseCheckout(const std::string& key, const std::string& name);
|
|
void Search(const std::string& key, bool now);
|
|
|
|
// -- the screens ---------------------------------------------------------------------------------------------
|
|
// A form's column inside a page: the page's rows run from edge to edge, a field keeps clear of the edges.
|
|
static Ui::Box Padded(const Ui::Frame& frame, Ui::Box box);
|
|
Ui::Box Scaffold(Ui::Frame& frame);
|
|
std::function<void()> Refresher();
|
|
std::string Title() const;
|
|
void Content(Ui::Frame& frame, Ui::Box area);
|
|
void Notes(Ui::Frame& frame, Ui::Column& column);
|
|
void Trouble(Ui::Frame& frame, Ui::Column& column, const Guidance& guidance, std::string_view key, std::function<void()> retry);
|
|
void Waiting(Ui::Frame& frame, Ui::Column& column, std::uint32_t rows);
|
|
void Empty(Ui::Frame& frame, Ui::Column& column, std::string_view text);
|
|
void Section(Ui::Frame& frame, Ui::Column& column, std::string_view title);
|
|
void HomePage(Ui::Frame& frame, Ui::Column& column);
|
|
void Welcome(Ui::Frame& frame, Ui::Column& column);
|
|
void AccountPage(Ui::Frame& frame, Ui::Column& column, const AccountRef& account, Ui::Box viewport);
|
|
void ActivityTab(Ui::Frame& frame, Ui::Column& column, const AccountRef& account, AccountData& data, Ui::Box viewport);
|
|
template<typename T, typename Make>
|
|
void ListTab(Ui::Frame& frame, Ui::Column& column, const std::string& key, Tab tab, Loadable<std::vector<T>>& list, std::string_view none, Ui::Box viewport, Make&& row);
|
|
void PayPage(Ui::Frame& frame, Ui::Column& column);
|
|
void RequestPage(Ui::Frame& frame, Ui::Column& column);
|
|
void AccountField(Ui::Frame& frame, Ui::Column& column, std::string_view key, std::string_view label, const std::string& account, Picking picking);
|
|
void CardsPage(Ui::Frame& frame, Ui::Column& column, Ui::Box viewport);
|
|
void SettingsPage(Ui::Frame& frame, Ui::Column& column);
|
|
void ConnectionsPage(Ui::Frame& frame, Ui::Column& column);
|
|
void BanksPage(Ui::Frame& frame, Ui::Column& column);
|
|
void WaysPage(Ui::Frame& frame, Ui::Column& column, const Bank& bank);
|
|
void BunqKeyPage(Ui::Frame& frame, Ui::Column& column);
|
|
void BunqOAuthPage(Ui::Frame& frame, Ui::Column& column);
|
|
void CheckoutPage(Ui::Frame& frame, Ui::Column& column);
|
|
void AboutPage(Ui::Frame& frame, Ui::Column& column);
|
|
void FilterSheet(Ui::Frame& frame, const AccountRef& account);
|
|
void PickSheet(Ui::Frame& frame);
|
|
void DialogSheet(Ui::Frame& frame);
|
|
|
|
Ui::Context& context;
|
|
Host host;
|
|
std::optional<Client> client;
|
|
std::map<std::string, Lane, std::less<>> lanes;
|
|
Client::Pending change; // the one change under way
|
|
bool changing = false;
|
|
std::vector<std::string> notes;
|
|
|
|
Loadable<std::vector<Connection>> overview;
|
|
std::map<std::string, AccountData, std::less<>> accounts;
|
|
Loadable<std::vector<ConnectorCards>> cards;
|
|
// The account a link's pay form starts from, where the user chose one (nostrod's DefaultCheckoutAccount).
|
|
Loadable<std::optional<Account>> checkout;
|
|
|
|
Place place = Place::Accounts;
|
|
std::vector<Route> stack;
|
|
std::optional<Dialog> dialog;
|
|
std::string filtering; // the account whose filter sheet is open
|
|
Picking picking = Picking::None;
|
|
|
|
PaymentForm payment;
|
|
std::string payFrom;
|
|
// A link that was read, whose pay form opens once the accounts are known. It is kept apart from the form until
|
|
// then: a form that holds what a link said is shown as a link's, never found filled in later.
|
|
std::optional<PaymentLink> waiting;
|
|
RequestForm request;
|
|
std::string requestInto;
|
|
BunqKeyForm bunqKey;
|
|
BunqOAuthForm bunqOAuth;
|
|
std::string bunqOAuthError; // what was wrong with the address the browser was sent to
|
|
};
|
|
}
|