Nostro/implementations/Nostro.App-Screens.cpp
Jorijn van der Graaf 2e3739ff7a
fix: close what the security review before the first release found
A review of the tree and its history before they are published found no
key and no bank data in them. It did find these, each closed here.

The password dialog could be emptied (daemon). Shown(), which makes a
payee's name fit for polkit's dialog, let an & through. GNOME's older
agent (polkit-gnome) and MATE's put the message into Pango markup
unescaped, where a bare & fails to parse and leaves the dialog without
a message: paying "Tom & Jerry", or an order an app names so at
checkout, asked for the password and showed no amount and no payee.
Line and paragraph separators passed too. Shown() now shows & as +,
leaves out what draws nothing or places text (control and format
characters, the separators, what Unicode ignores by default, private
use) and makes any run of spaces one space. An address is held to it
instead of made fit: an e-mail address the dialog could not show
unchanged is refused before anyone is asked, since "a&b@..." shown as
"a+b@..." is somebody else's address.

A refused caller could look (daemon). A call that names an account, a
card, a request, a draft or a connector had it looked up, at the bank
where that takes it, before polkit was asked. So a caller polkit
refused was told whether it was there ("no account is called ..."),
and had the bank asked. Such a call now asks for View first
(HandleLookup), a call that only sees looks its account up after its
yes, and the connectors are read, which refreshes the accounts at the
bank, on the first yes instead of on the first call.

An app at checkout was told too much (checkout). The refusal of an
order's reference with another amount named the amount on record, and
a refusal by the bank carried the call it answered, whose path has the
user's and the account's ids at bunq. Neither does now.

A key typed by hand could be read off the screen (app). The line under
a key field showed how the key begins and its last four characters,
which is every character of it as it is typed. It shows how the key
begins and how long it is.

Every change asks for the password (packaging, app). Change, the
action for what changes something and pays nobody, passed without a
password in an active session, so any program of the user's could
cancel a scheduled payment, ask for money in their name or freeze a
card. It asks now (auth_self), a draft saved and a card frozen
included: only View passes as shipped, and loosening is an
administrator's rule, of which the README has an example. The app says
of every change where it is confirmed (AsksPassword is gone), and the
request form sends on its button as the pay form does: its review
sheet would be a second confirmation of what the dialog confirms.

What is built is what was tested (build). Crafter.Network, Crafter.DB
and Crafter.LintRules are named at the commits the tests ran against.
Crafter.Thread still follows its branch, which Crafter.Network's own
project file names, and so does Crafter.Network in the app's debug
build, where Crafter.Debug names it too and crafter-build refuses a
module built twice. lib/json.hpp was nlohmann/json's develop branch at
95e9a593 less its last newline, and called 3.12.0: it is that file
byte for byte now, and called what it is.

The published contract changes with this, before any release (design
rule 10): an e-mail address the dialog cannot show as it is is
refused, a call that looks something up needs View as well as its own
action, the checkout's errors say less, and the policy asks for the
password for Change. The XML, the policy and ShouldServeEveryUser,
which now holds the policy to its defaults, change together.

Reproduced and verified on the fake bus and the fake bunq. The new
checks of ShouldServeEveryUser fail on the worker of before (50 of
them: the & shown, the lookups answered, the bank asked) and pass now.
crafter-build test (17 tests), lint for the library, the app and the
fake system, and tests/coverage.sh (every line, function and region)
pass. Looked at on the made-up system, 360x760 dp at scale 2, dark, on
KDE Wayland: the key form with a key typed, the request form with its
wait and its result, a card frozen, and About. No picture in the
README shows a screen that changed.

Not tried: bunq's sandbox, a real polkit agent, the Flatpak builds.
The README's example rule ran against a stand-in for polkit's rule
engine only.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
2026-11-19 16:09:48 +01:00

783 lines
50 KiB
C++

// SPDX-License-Identifier: GPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
module Nostro.App:Screens_impl;
import std;
import Nostro;
import Nostro.Ui;
import :App;
import :Banks;
import :Format;
import :Forms;
import :Errors;
// The app's screens: each a function from what the app knows to a frame. A window as narrow as a phone shows one
// page at a time, with the app's places along its bottom; a wider one keeps the places, and the accounts themselves
// where there is room, down its left side. A press's action is one of the app's own (Nostro.App-App.cpp), and names
// what it is about by value.
//
// No screen here names a bank, or a way to connect to one, in words of its own: an account's pages are the same
// whichever bank it is with. Where a bank is named, in the settings, the name is what :Banks has for it, and the last
// step of adding a connection, a way's form, is the bank's own to draw (Nostro.App-Bunq.cpp).
namespace Nostro::App {
namespace {
using namespace Ui;
// A box clear of the page's edges on either side.
Box Gutters(const Frame& frame, Box box) {
return box.Inset(Insets::Symmetric(frame.Dp(Size::gutter), 0));
}
// A strip of tabs: from edge to edge on a phone, where its labels need the room, and in line with the page's
// fields in a wider window.
Box Strip(const Frame& frame, Box box) {
return frame.sizeClass == SizeClass::Compact ? box : Gutters(frame, box);
}
// A status with what was said about it, where anything was.
std::string Joined(std::string first, std::string_view second) {
return second.empty() ? first : std::format("{} · {}", first, second);
}
}
Ui::Box App::Padded(const Ui::Frame& frame, Ui::Box box) {
return Gutters(frame, box);
}
void App::Build(Ui::Frame& frame) {
const Ui::Box area = Scaffold(frame);
Content(frame, area);
if(const std::optional<AccountRef> filtered = Find(filtering)) {
FilterSheet(frame, *filtered);
}
if(picking != Picking::None) {
PickSheet(frame);
}
if(dialog) {
DialogSheet(frame);
}
}
std::string App::Title() const {
if(stack.empty()) {
static constexpr std::array<std::string_view, 3> places = {"Accounts", "Cards", "Settings"};
return std::string(places[std::to_underlying(place)]);
}
const Route& top = stack.back();
static constexpr std::array<std::string_view, 9> pages = {"Account", "Pay", "Request", "Bank connections", "Add a connection", "", "", "Pay at checkout", "About and security"};
std::string title(pages[std::to_underlying(top.page)]);
// An account's page is called what the account is.
if(const std::optional<AccountRef> account = Find(top.account)) {
title = account->account->name;
}
// And the steps of adding a connection what was chosen: the bank, and then the way with it.
if(top.bank != nullptr) {
title = top.bank->name;
}
if(top.way != nullptr) {
title = std::format("{} · {}", top.bank->name, top.way->title);
}
return title;
}
Ui::Box App::Scaffold(Ui::Frame& frame) {
Box area = frame.bounds;
const bool compact = frame.sizeClass == SizeClass::Compact;
std::vector<NavItem> items;
items.push_back({.key = "nav.accounts", .label = "Accounts", .selected = place == Place::Accounts && (compact || stack.empty()), .onTap = [this] { Go(Place::Accounts); }});
items.push_back({.key = "nav.cards", .label = "Cards", .selected = place == Place::Cards, .onTap = [this] { Go(Place::Cards); }});
items.push_back({.key = "nav.settings", .label = "Settings", .selected = place == Place::Settings && (compact || stack.empty()), .onTap = [this] { Go(Place::Settings); }});
if(frame.sizeClass == SizeClass::Expanded && !overview.value.empty()) {
// Where there is room, the accounts themselves are a press away.
items.push_back({.key = "side.accounts", .label = "Your accounts", .header = true});
const std::string open = !stack.empty() && stack.back().page == Page::Account ? stack.back().account : std::string();
for(const AccountRef& account : Accounts()) {
items.push_back({.key = std::format("side.{}", account.key), .label = account.account->name, .detail = Money(account.account->balance, account.account->currency), .selected = account.key == open, .onTap = [this, key = account.key] {
place = Place::Accounts;
stack.clear();
Push(Page::Account, key);
}});
}
}
if(!compact) {
area = Sidebar(frame, area, frame.sizeClass == SizeClass::Expanded ? 280.0f : 200.0f, items);
} else if(stack.empty()) {
// A page that was gone into is left by its way back, not sideways.
area = NavBar(frame, area, items);
}
const std::function<void()> refresh = Refresher();
std::vector<BarAction> actions;
if(refresh) {
actions.push_back({.key = "bar.refresh", .label = "Refresh", .onTap = refresh});
// And by the keys a browser has for it.
frame.Shortcut(Key::F5, {}, refresh);
frame.Shortcut(Key::R, {.control = true}, refresh);
}
return TopBar(frame, area, {.title = Title(), .onBack = stack.empty() ? std::function<void()>() : [this] { Back(); }, .actions = std::move(actions)});
}
// What a screen that shows the bank's own state reads again; nothing for one that does not.
std::function<void()> App::Refresher() {
if(!stack.empty() && stack.back().page == Page::Account) {
return [this, key = stack.back().account] {
Refresh();
LoadTab(key, Data(key).tab, true);
};
}
if(stack.empty() && place == Place::Accounts) {
return [this] { Refresh(); };
}
if(stack.empty() && place == Place::Cards) {
return [this] { LoadCards(true); };
}
return nullptr;
}
void App::Content(Ui::Frame& frame, Ui::Box area) {
frame.draw.SetLayer(Layer::Content);
const std::string screen = Screen();
const float offset = frame.BeginScroll(std::format("page:{}", screen.substr(0, screen.find('+'))), area);
// By a finger too: pulled down at its top and let go.
if(const std::function<void()> refresh = Refresher()) {
frame.Refreshable(refresh);
}
const float pulled = frame.Pulled();
if(pulled > 0) {
Label(frame, {area.x, area.y, area.w, pulled}, pulled >= frame.Dp(Size::pull) ? "Let go to refresh" : "Pull down to refresh", {FontFace::Regular, TextSize::label, frame.Colors().muted, TextAlign::Center});
}
const float top = area.y - offset + pulled;
Column column(Centered({area.x, top, area.w, area.h}, frame.Dp(Size::contentMax)), frame.Dp(Size::unit * 3));
column.cursor = top + frame.Dp(Size::unit * 3);
Notes(frame, column);
if(stack.empty()) {
if(place == Place::Accounts) {
HomePage(frame, column);
} else if(place == Place::Cards) {
CardsPage(frame, column, area);
} else {
SettingsPage(frame, column);
}
} else {
const Route& route = stack.back();
switch(route.page) {
case Page::Account:
if(const std::optional<AccountRef> account = Find(route.account)) {
AccountPage(frame, column, *account, area);
}
break;
case Page::Pay: PayPage(frame, column); break;
case Page::Request: RequestPage(frame, column); break;
case Page::Connections: ConnectionsPage(frame, column); break;
case Page::Banks: BanksPage(frame, column); break;
case Page::Ways: WaysPage(frame, column, *route.bank); break;
case Page::Connect:
// The form is the bank's own, one for each of its ways.
switch(route.way->form) {
case ConnectForm::BunqKey: BunqKeyPage(frame, column); break;
case ConnectForm::BunqOAuth: BunqOAuthPage(frame, column); break;
}
break;
case Page::Checkout: CheckoutPage(frame, column); break;
case Page::About: AboutPage(frame, column); break;
}
}
frame.EndScroll(column.cursor - top + frame.Dp(Size::gutter));
}
void App::Notes(Ui::Frame& frame, Ui::Column& column) {
if(notes.empty()) {
return;
}
// What the library warned of while it worked: a connection that could not be reached, an account it skipped.
std::string text;
for(const std::string& note : notes) {
if(!text.empty()) {
text += '\n';
}
text += note;
}
column.Advance(Banner(frame, Padded(frame, column.Next()), {.key = "notes", .kind = BannerKind::Warning, .text = std::move(text), .onDismiss = [this] {
notes.clear();
context.Invalidate();
}}));
}
void App::Trouble(Ui::Frame& frame, Ui::Column& column, const Guidance& guidance, std::string_view key, std::function<void()> retry) {
const bool again = guidance.retry && retry != nullptr;
column.Advance(Banner(frame, Padded(frame, column.Next()), {.key = std::string(key), .kind = BannerKind::Error, .text = std::format("{}\n{}", guidance.title, guidance.detail), .action = again ? "Try again" : "", .onAction = again ? std::move(retry) : std::function<void()>()}));
}
void App::Waiting(Ui::Frame& frame, Ui::Column& column, std::uint32_t rows) {
for(std::uint32_t i = 0; i < rows; i++) {
const Box row = Padded(frame, column.Take(frame.Dp(Size::row - Size::unit * 3)));
Skeleton(frame, {row.x, row.y + frame.Dp(6), row.w, frame.Dp(16)}, 0.5f + 0.1f * static_cast<float>(i % 3));
Skeleton(frame, {row.x, row.y + frame.Dp(30), row.w, frame.Dp(12)}, 0.3f);
}
}
void App::Empty(Ui::Frame& frame, Ui::Column& column, std::string_view text) {
Label(frame, Padded(frame, column.Take(frame.Dp(Size::row))), text, {FontFace::Regular, TextSize::body, frame.Colors().muted, TextAlign::Center});
}
void App::Section(Ui::Frame& frame, Ui::Column& column, std::string_view title) {
Label(frame, Padded(frame, column.Take(frame.Dp(28))), title, {FontFace::Medium, TextSize::label, frame.Colors().muted, TextAlign::Left});
}
void App::Welcome(Ui::Frame& frame, Ui::Column& column) {
const Theme& theme = frame.Colors();
Label(frame, Padded(frame, column.Take(frame.Dp(40))), "Welcome to Nostro", {FontFace::Medium, TextSize::title, theme.text, TextAlign::Left});
column.Advance(Paragraph(frame, Padded(frame, column.Next()), "Nostro shows your bank accounts and pays from them. It talks to your bank directly, and what it needs for that is kept by a service of its own, out of reach of every other program you run, this window included.", Body(frame)));
column.Advance(Paragraph(frame, Padded(frame, column.Next()), "Before money moves, your system's own password dialog says what is about to be paid, to whom and from which account, and asks you to confirm it.", Body(frame)));
column.Advance(Paragraph(frame, Padded(frame, column.Next()), "To begin, connect your bank.", Muted(frame)));
// Which bank, and how, is asked on the pages this leads to: the same ones the settings add a connection with.
// They are gone into from here, so the way back leads here.
Button(frame, Padded(frame, column.Take(frame.Dp(Size::control))), {.key = "welcome.connect", .label = "Connect a bank", .onTap = [this] { Push(Page::Banks); }});
}
void App::HomePage(Ui::Frame& frame, Ui::Column& column) {
const Theme& theme = frame.Colors();
if(overview.state == LoadState::Failed) {
Trouble(frame, column, overview.problem, "overview", [this] { Refresh(); });
return;
}
if(overview.state != LoadState::Loaded) {
Waiting(frame, column, 4);
return;
}
if(overview.value.empty()) {
Welcome(frame, column);
return;
}
Row actions(Padded(frame, column.Take(frame.Dp(Size::control))), frame.Dp(Size::unit * 3));
const bool any = !Accounts().empty();
Button(frame, actions.TakeLeft((actions.area.w - actions.gap) / 2), {.key = "home.pay", .label = "Pay", .enabled = any, .onTap = [this] { OpenPay({}); }});
Button(frame, actions.Rest(), {.key = "home.request", .label = "Request", .kind = ButtonKind::Tonal, .enabled = any, .onTap = [this] { OpenRequest({}); }});
for(const Connection& connection : overview.value) {
// The connection's name, and what is unusual about it.
Row heading(Padded(frame, column.Take(frame.Dp(32))), frame.Dp(Size::unit * 2));
const TextStyle name{FontFace::Medium, TextSize::label, theme.muted, TextAlign::Left};
Label(frame, heading.TakeLeft(std::min(heading.area.w / 2, TextWidth(frame.Measure(), connection.name, name.face, frame.Dp(name.sizeDp)))), connection.name, name);
const auto chip = [&frame, &heading](std::string_view text, Color ground, Color color) {
const Box at = heading.TakeLeft(ChipWidth(frame, text));
Chip(frame, {at.x, at.Center().y - frame.Dp(10), at.w, frame.Dp(20)}, text, ground, color);
};
if(connection.environment == "sandbox") {
chip("Sandbox", theme.surfaceAlt, theme.muted);
}
// It cannot pay anyone but the user: an account's page and the pay form say so in full.
if(connection.ownAccountsOnly) {
chip("Limited", theme.surfaceAlt, theme.muted);
}
if(!connection.working) {
chip("Not working", theme.danger, theme.onDanger);
}
if(connection.accounts.empty()) {
Empty(frame, column, "No accounts");
}
for(const Account& account : connection.accounts) {
const std::string key = AccountKey(account);
ListRow(frame, column.Take(frame.Dp(Size::row)), {.key = std::format("account.{}", key), .title = account.name, .subtitle = GroupIban(account.iban), .trailing = Money(account.balance, account.currency), .chevron = true, .onTap = [this, key] { Push(Page::Account, key); }});
}
}
}
void App::AccountPage(Ui::Frame& frame, Ui::Column& column, const AccountRef& account, Ui::Box viewport) {
const Theme& theme = frame.Colors();
const std::string key = account.key;
AccountData& data = Data(key);
Label(frame, Padded(frame, column.Take(frame.Dp(48))), Money(account.account->balance, account.account->currency), {FontFace::Medium, TextSize::display, theme.text, TextAlign::Left});
if(!account.account->iban.empty()) {
Row line(Padded(frame, column.Take(frame.Dp(Size::touch - Size::unit * 3))), frame.Dp(Size::unit * 2));
Button(frame, line.TakeRight(ButtonWidth(frame, "Copy")), {.key = "account.copy", .label = "Copy", .kind = ButtonKind::Plain, .onTap = [this, iban = account.account->iban] {
context.Copy(iban);
Tell("IBAN copied");
}});
Label(frame, line.Rest(), GroupIban(account.account->iban), Muted(frame));
}
// What its connection cannot do is said before it is tried.
if(account.connection->ownAccountsOnly) {
column.Advance(Paragraph(frame, Padded(frame, column.Next()), "This account's connection pays between your own accounts only.", Muted(frame)));
}
Row actions(Padded(frame, column.Take(frame.Dp(Size::control))), frame.Dp(Size::unit * 3));
Button(frame, actions.TakeLeft((actions.area.w - actions.gap) / 2), {.key = "account.pay", .label = "Pay", .onTap = [this, key] { OpenPay(key); }});
Button(frame, actions.Rest(), {.key = "account.request", .label = "Request", .kind = ButtonKind::Tonal, .onTap = [this, key] { OpenRequest(key); }});
Tabs(frame, Strip(frame, column.Take(frame.Dp(Size::control))), {.key = "tabs", .labels = {"Activity", "Requests", "Incoming", "Scheduled", "Drafts"}, .selected = std::to_underlying(data.tab), .onSelect = [this, key](std::size_t chosen) {
Data(key).tab = static_cast<Tab>(chosen);
LoadTab(key, static_cast<Tab>(chosen));
context.Invalidate();
}});
const std::chrono::system_clock::time_point today = Today();
switch(data.tab) {
case Tab::Activity:
ActivityTab(frame, column, account, data, viewport);
break;
case Tab::Requests:
ListTab(frame, column, key, Tab::Requests, data.requests, "No requests sent from this account", viewport, [this, &key, today](const BunqPaymentRequest& asked) {
return RowOptions{.key = std::format("request.{}", asked.id), .title = PartyName(asked.counterparty), .subtitle = Joined(StatusLabel(asked.status), asked.description), .trailing = Money(asked.amount, asked.currency), .trailingSub = ShortDate(asked.created, today), .chevron = true, .onTap = [this, key, asked] { ShowRequest(key, asked); }};
});
break;
case Tab::Incoming:
ListTab(frame, column, key, Tab::Incoming, data.incoming, "Nobody has asked this account for money", viewport, [this, &key, today](const BunqIncomingRequest& asked) {
return RowOptions{.key = std::format("incoming.{}", asked.id), .title = PartyName(asked.counterparty), .subtitle = Joined(StatusLabel(asked.status), asked.description), .trailing = Money(asked.amount, asked.currency), .trailingSub = ShortDate(asked.created, today), .chevron = true, .onTap = [this, key, asked] { ShowIncoming(key, asked); }};
});
break;
case Tab::Scheduled:
ListTab(frame, column, key, Tab::Scheduled, data.scheduled, "No payments are scheduled from this account", viewport, [this, &key, today](const BunqScheduledPayment& scheduled) {
return RowOptions{.key = std::format("scheduled.{}", scheduled.id), .title = PartyName(scheduled.counterparty), .subtitle = ScheduleLabel(scheduled.schedule, today), .trailing = Money(scheduled.amount, scheduled.currency), .trailingSub = StatusLabel(scheduled.schedule.status), .chevron = true, .onTap = [this, key, scheduled] { ShowScheduled(key, scheduled); }};
});
break;
case Tab::Drafts:
ListTab(frame, column, key, Tab::Drafts, data.drafts, "No draft payments wait for this account", viewport, [this, &key](const BunqDraftPayment& draft) {
// Its payments together, to the first of their payees and however many more.
std::int64_t total = 0;
Currency currency = Currency::Euro;
std::string to;
for(const BunqDraftPayment::Entry& entry : draft.entries) {
total += entry.amount;
currency = entry.currency;
if(to.empty()) {
to = PartyName(entry.counterparty);
}
}
if(draft.entries.size() > 1) {
to += std::format(" and {} more", draft.entries.size() - 1);
}
return RowOptions{.key = std::format("draft.{}", draft.id), .title = to, .subtitle = Joined(StatusLabel(draft.status), draft.createdBy), .trailing = Money(total, currency), .chevron = true, .onTap = [this, key, draft] { ShowDraft(key, draft); }};
});
break;
}
}
void App::ActivityTab(Ui::Frame& frame, Ui::Column& column, const AccountRef& account, AccountData& data, Ui::Box viewport) {
const Theme& theme = frame.Colors();
const std::string key = account.key;
const Currency currency = account.account->currency;
const std::chrono::system_clock::time_point today = Today();
column.Advance(TextField(frame, Padded(frame, column.Next()), data.filter.search, {.key = "search", .placeholder = "Search a name, a description or an IBAN", .onChange = [this, key] { Search(key, false); }, .onSubmit = [this, key] { Search(key, true); }}));
frame.Shortcut(Key::F, {.control = true}, [this] { context.Focus("search"); });
// What is asked for besides the search, and the way to change it.
Row filters(Padded(frame, column.Take(frame.Dp(Size::touch - Size::unit * 3))), frame.Dp(Size::unit * 2));
Button(frame, filters.TakeLeft(ButtonWidth(frame, "Filter")), {.key = "filter", .label = "Filter", .kind = ButtonKind::Tonal, .onTap = [this, key] {
filtering = key;
context.Invalidate();
}});
const std::vector<std::string> chips = data.filter.Chips(currency, today);
for(const std::string& chip : chips) {
const float width = ChipWidth(frame, chip);
if(width <= filters.Rest().w) {
const Box at = filters.TakeLeft(width);
Chip(frame, {at.x, at.Center().y - frame.Dp(10), at.w, frame.Dp(20)}, chip, theme.surfaceAlt, theme.text);
}
}
if(data.activity.state == LoadState::Failed) {
Trouble(frame, column, data.activity.problem, "activity.problem", [this, key] { LoadActivity(key); });
return;
}
if(data.activity.state != LoadState::Loaded) {
Waiting(frame, column, 5);
return;
}
if(data.activity.value.empty()) {
Empty(frame, column, chips.empty() && data.query.search.empty() ? "No payments yet" : "Nothing matches");
return;
}
std::optional<std::int64_t> day;
for(const Transaction& transaction : data.activity.value) {
if(const std::int64_t on = LocalDay(transaction.timePoint); day != on) {
day = on;
Section(frame, column, DayLabel(transaction.timePoint, today));
}
const Box row = column.Take(frame.Dp(Size::row));
// A long list is drawn as far as it is looked at.
if(!row.Overlaps(viewport)) {
continue;
}
const std::string what = transaction.description.empty() ? KindLabel(transaction.kind) : transaction.description;
// By the bank's own number, so a press cannot land on the payment that took this one's place in the list;
// and by its moment and amount, for the payments stored before the number was kept.
ListRow(frame, row, {.key = std::format("tx.{}.{}.{}", transaction.id, transaction.timePoint.time_since_epoch().count(), transaction.amount), .title = transaction.name.empty() ? what : transaction.name, .subtitle = transaction.name.empty() ? std::string() : what, .trailing = SignedMoney(transaction.amount, transaction.currency), .trailingSub = ClockTime(transaction.timePoint), .trailingColor = transaction.amount > 0 ? std::optional<Color>(theme.positive) : std::nullopt, .onTap = [this, key, transaction] { ShowTransaction(key, transaction); }});
}
if(data.more) {
Button(frame, Padded(frame, column.Take(frame.Dp(Size::control))), {.key = "more", .label = "Show more", .kind = ButtonKind::Tonal, .enabled = !data.activity.refreshing, .onTap = [this, key] {
// Older ones, which nostrod has stored: the bank is not asked for them again.
Data(key).query.limit += 100;
LoadActivity(key, true);
context.Invalidate();
}});
}
}
template<typename T, typename Make>
void App::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) {
if(list.state == LoadState::Failed) {
Trouble(frame, column, list.problem, "list.problem", [this, key, tab] { LoadTab(key, tab, true); });
return;
}
if(list.state != LoadState::Loaded) {
Waiting(frame, column, 3);
return;
}
if(list.value.empty()) {
Empty(frame, column, none);
return;
}
for(const T& item : list.value) {
const Box at = column.Take(frame.Dp(Size::row));
if(at.Overlaps(viewport)) {
ListRow(frame, at, row(item));
}
}
}
void App::AccountField(Ui::Frame& frame, Ui::Column& column, std::string_view key, std::string_view label, const std::string& account, Picking which) {
const Theme& theme = frame.Colors();
Label(frame, Padded(frame, column.Take(frame.Dp(20))), label, Muted(frame));
const Box row = Padded(frame, column.Take(frame.Dp(Size::row)));
frame.draw.Rect(RectItem{.box = row, .color = theme.surface, .corners = Corners::All(frame.Dp(Size::controlRadius)), .outline = frame.Dp(1), .outlineColor = theme.divider});
const std::optional<AccountRef> chosen = Find(account);
const auto pick = [this, which] {
picking = which;
context.Invalidate();
};
if(chosen) {
ListRow(frame, row, {.key = std::string(key), .title = chosen->account->name, .subtitle = GroupIban(chosen->account->iban), .trailing = Money(chosen->account->balance, chosen->account->currency), .chevron = true, .divider = false, .onTap = pick});
} else {
ListRow(frame, row, {.key = std::string(key), .title = "Choose an account", .chevron = true, .enabled = !Accounts().empty(), .divider = false, .onTap = pick});
}
}
void App::PayPage(Ui::Frame& frame, Ui::Column& column) {
const std::optional<AccountRef> from = Find(payFrom);
Currency currency = Currency::Euro;
if(from) {
currency = from->account->currency;
}
PaymentOrder unused;
const PaymentForm::Errors errors = payment.tried ? payment.Check(currency, Today(), unused) : PaymentForm::Errors();
AccountField(frame, column, "pay.from", "From", payFrom, Picking::PayFrom);
column.Advance(TextField(frame, Padded(frame, column.Next()), payment.to, {.key = "pay.to", .label = "To", .placeholder = "An IBAN, an e-mail address or a phone number", .error = errors.to, .helper = PartyKind(payment.to.value)}));
column.Advance(TextField(frame, Padded(frame, column.Next()), payment.name, {.key = "pay.name", .label = "Name", .placeholder = "Who the account belongs to", .error = errors.name, .purpose = TextPurpose::Name}));
column.Advance(TextField(frame, Padded(frame, column.Next()), payment.amount, {.key = "pay.amount", .label = "Amount", .prefix = std::string(GetCurrencySymbol(currency)), .error = errors.amount}));
column.Advance(TextField(frame, Padded(frame, column.Next()), payment.description, {.key = "pay.description", .label = "Description", .placeholder = "What it is for"}));
// A connection that pays between the user's own accounts only cannot pay anybody else.
const Read<BunqCounterparty> party = ReadParty(payment.to.value);
const bool limited = from && from->connection->ownAccountsOnly && !(party.value && party.value->type == "IBAN" && Own(party.value->value));
// What the button will do: a payment of such an account to anyone else can only be a draft.
const std::size_t when = limited ? std::size_t{2} : std::to_underlying(payment.when);
Label(frame, Padded(frame, column.Take(frame.Dp(20))), "When", Muted(frame));
Segmented(frame, Padded(frame, column.Take(frame.Dp(Size::control))), {.key = "pay.when", .labels = {"Now", "Scheduled", "Draft"}, .selected = when, .enabled = !limited, .onSelect = [this](std::size_t chosen) {
payment.when = static_cast<When>(chosen);
context.Invalidate();
}});
if(limited) {
column.Advance(Paragraph(frame, Padded(frame, column.Next()), "This account's connection pays between your own accounts only. A payment to anyone else is saved as a draft, to approve in your bank's app.", Muted(frame)));
} else if(payment.when == When::Draft) {
column.Advance(Paragraph(frame, Padded(frame, column.Next()), "A draft is paid once it is accepted, here or in your bank's app.", Muted(frame)));
} else if(payment.when == When::Scheduled) {
column.Advance(TextField(frame, Padded(frame, column.Next()), payment.day, {.key = "pay.day", .label = "First payment", .placeholder = "YYYY-MM-DD", .error = errors.day}));
column.Advance(TextField(frame, Padded(frame, column.Next()), payment.time, {.key = "pay.time", .label = "At", .placeholder = "hh:mm", .error = errors.time, .helper = "Leave empty for the start of the day"}));
std::vector<std::string> units;
for(const ScheduleUnit& unit : scheduleUnits) {
units.emplace_back(unit.label);
}
Tabs(frame, Strip(frame, column.Take(frame.Dp(Size::control))), {.key = "pay.unit", .labels = std::move(units), .selected = payment.unit, .onSelect = [this](std::size_t chosen) {
payment.unit = chosen;
context.Invalidate();
}});
if(payment.unit != 0) {
column.Advance(TextField(frame, Padded(frame, column.Next()), payment.every, {.key = "pay.every", .label = "Every", .placeholder = "1", .error = errors.every, .helper = "2 with Weekly is every other week"}));
column.Advance(TextField(frame, Padded(frame, column.Next()), payment.until, {.key = "pay.until", .label = "Until", .placeholder = "YYYY-MM-DD", .error = errors.until, .helper = "Leave empty to go on until it is cancelled"}));
}
}
// It sends what is filled in, and is named for that. Nothing is asked in between: the system's password dialog
// is what confirms a payment.
static constexpr std::array<std::string_view, 3> does = {"Pay", "Schedule", "Save as draft"};
Button(frame, Padded(frame, column.Take(frame.Dp(Size::control))), {.key = "pay.submit", .label = std::string(does[when]), .enabled = from.has_value(), .onTap = [this] { SubmitPayment(); }});
}
void App::RequestPage(Ui::Frame& frame, Ui::Column& column) {
const std::optional<AccountRef> into = Find(requestInto);
Currency currency = Currency::Euro;
if(into) {
currency = into->account->currency;
}
RequestOrder unused;
const RequestForm::Errors errors = request.tried ? request.Check(currency, unused) : RequestForm::Errors();
AccountField(frame, column, "request.into", "Into", requestInto, Picking::RequestInto);
column.Advance(TextField(frame, Padded(frame, column.Next()), request.from, {.key = "request.from", .label = "From", .placeholder = "An IBAN, an e-mail address or a phone number", .error = errors.from, .helper = PartyKind(request.from.value)}));
column.Advance(TextField(frame, Padded(frame, column.Next()), request.name, {.key = "request.name", .label = "Name", .placeholder = "Who is asked", .error = errors.name, .purpose = TextPurpose::Name}));
column.Advance(TextField(frame, Padded(frame, column.Next()), request.amount, {.key = "request.amount", .label = "Amount", .prefix = std::string(GetCurrencySymbol(currency)), .error = errors.amount}));
column.Advance(TextField(frame, Padded(frame, column.Next()), request.description, {.key = "request.description", .label = "Description", .placeholder = "What it is for"}));
column.Advance(Paragraph(frame, Padded(frame, column.Next()), "Your bank asks them where it can reach them, and gives you a link to pay through where it has one.", Muted(frame)));
// It sends what is filled in, and is named for that, as the pay form's button is: the system's password dialog
// is what confirms a request.
Button(frame, Padded(frame, column.Take(frame.Dp(Size::control))), {.key = "request.submit", .label = "Ask", .enabled = into.has_value(), .onTap = [this] { SubmitRequest(); }});
}
void App::CardsPage(Ui::Frame& frame, Ui::Column& column, Ui::Box viewport) {
const Theme& theme = frame.Colors();
if(cards.state == LoadState::Failed) {
Trouble(frame, column, cards.problem, "cards.problem", [this] { LoadCards(true); });
return;
}
if(cards.state != LoadState::Loaded) {
Waiting(frame, column, 3);
return;
}
bool any = false;
for(const ConnectorCards& connection : cards.value) {
if(connection.cards.empty()) {
continue;
}
any = true;
Section(frame, column, connection.name);
for(const BunqCard& card : connection.cards) {
const Box row = column.Take(frame.Dp(Size::row));
if(!row.Overlaps(viewport)) {
continue;
}
ListRow(frame, row, {.key = std::format("card.{}", card.id), .title = std::format("{} •••• {}", CardProduct(card.productType), card.lastFour), .subtitle = Joined(card.nameOnCard, card.expiry.empty() ? std::string() : std::format("until {}", CardExpiry(card.expiry))), .trailing = StatusLabel(card.State()), .trailingColor = card.State() == "ACTIVE" ? std::optional<Color>(theme.positive) : std::nullopt, .chevron = true, .onTap = [this, card] { ShowCard(card); }});
}
}
if(!any) {
Empty(frame, column, "No cards");
}
}
void App::SettingsPage(Ui::Frame& frame, Ui::Column& column) {
const std::size_t connected = overview.value.size();
ListRow(frame, column.Take(frame.Dp(Size::row)), {.key = "settings.connections", .title = "Bank connections", .subtitle = connected == 1 ? std::string("1 connected") : std::format("{} connected", connected), .chevron = true, .onTap = [this] { Push(Page::Connections); }});
std::string paying = "…";
if(checkout.state == LoadState::Loaded) {
paying = checkout.value ? Joined(checkout.value->name, GroupIban(checkout.value->iban)) : "No account chosen";
} else if(checkout.state == LoadState::Failed) {
paying = checkout.problem.title;
}
ListRow(frame, column.Take(frame.Dp(Size::row)), {.key = "settings.checkout", .title = "Pay at checkout from", .subtitle = std::move(paying), .chevron = true, .onTap = [this] { Push(Page::Checkout); }});
ListRow(frame, column.Take(frame.Dp(Size::row)), {.key = "settings.about", .title = "About and security", .subtitle = host.version.empty() ? std::string("Nostro") : std::format("Nostro {}", host.version), .chevron = true, .onTap = [this] { Push(Page::About); }});
}
void App::ConnectionsPage(Ui::Frame& frame, Ui::Column& column) {
const Theme& theme = frame.Colors();
if(overview.state == LoadState::Failed) {
Trouble(frame, column, overview.problem, "overview", [this] { Refresh(); });
} else if(overview.state != LoadState::Loaded) {
Waiting(frame, column, 2);
} else if(overview.value.empty()) {
Empty(frame, column, "No bank is connected yet");
}
for(const Connection& connection : overview.value) {
// By what tells it from every other: two connections can have one name, and never one account.
ListRow(frame, column.Take(frame.Dp(Size::row)), {.key = std::format("connection.{}.{}", connection.name, connection.accounts.empty() ? std::string() : AccountKey(connection.accounts.front())), .title = connection.name, .subtitle = std::format("{} · {} · {}", BankName(connection.bank), StatusLabel(connection.environment), WayName(connection.bank, connection.auth)), .trailing = connection.working ? "Working" : "Not working", .trailingColor = connection.working ? std::optional<Color>(theme.positive) : std::optional<Color>(theme.danger), .chevron = true, .onTap = [this, connection] { ShowConnection(connection); }});
}
Button(frame, Padded(frame, column.Take(frame.Dp(Size::control))), {.key = "connections.add", .label = "Add a connection", .onTap = [this] { Push(Page::Banks); }});
}
// Adding a connection, its first step: which bank it is with.
void App::BanksPage(Ui::Frame& frame, Ui::Column& column) {
column.Advance(Paragraph(frame, Padded(frame, column.Next()), "Which bank is the account with?", Body(frame)));
for(const Bank& bank : Banks()) {
// Under its name, the ways it can be connected.
std::string ways;
for(const Way& way : bank.ways) {
ways += ways.empty() ? std::string(way.title) : std::format(" · {}", way.title);
}
ListRow(frame, column.Take(frame.Dp(Size::row)), {.key = std::format("bank.{}", bank.id), .title = std::string(bank.name), .subtitle = std::move(ways), .chevron = true, .onTap = [this, chosen = &bank] { Push(Page::Ways, {}, chosen); }});
}
column.Advance(Paragraph(frame, Padded(frame, column.Next()), "A bank that is not listed here cannot be connected yet.", Muted(frame)));
}
// Its second: how to connect to that bank. Each way leads to a form of its own, which is the bank's to draw.
void App::WaysPage(Ui::Frame& frame, Ui::Column& column, const Bank& bank) {
column.Advance(Paragraph(frame, Padded(frame, column.Next()), std::format("How do you want to connect to {}?", bank.name), Body(frame)));
for(const Way& way : bank.ways) {
ListRow(frame, column.Take(frame.Dp(Size::row)), {.key = std::format("way.{}", way.key), .title = std::string(way.title), .subtitle = std::string(way.about), .chevron = true, .onTap = [this, chosen = &bank, how = &way] { Push(Page::Connect, {}, chosen, how); }});
}
}
void App::CheckoutPage(Ui::Frame& frame, Ui::Column& column) {
column.Advance(Paragraph(frame, Padded(frame, column.Next()), "Other apps can ask Nostro to pay an order at their checkout. Every such payment still asks for your password, and says what is paid and to whom. This is the account they are paid from.", Body(frame)));
if(checkout.state == LoadState::Failed) {
Trouble(frame, column, checkout.problem, "checkout.problem", [this] { LoadCheckout(); });
return;
}
if(checkout.state != LoadState::Loaded) {
Waiting(frame, column, 2);
return;
}
if(Accounts().empty()) {
Empty(frame, column, "No accounts to choose from");
}
for(const AccountRef& account : Accounts()) {
const bool chosen = checkout.value && AccountKey(*checkout.value) == account.key;
// A shop is somebody else: not for a connection that pays between the user's own accounts only.
const bool ownOnly = account.connection->ownAccountsOnly;
ListRow(frame, column.Take(frame.Dp(Size::row)), {.key = std::format("checkout.{}", account.key), .title = account.account->name, .subtitle = ownOnly ? std::string("Pays your own accounts only, not a shop") : GroupIban(account.account->iban), .trailing = Money(account.account->balance, account.account->currency), .selected = chosen, .enabled = !ownOnly, .onTap = [this, key = account.key, name = account.account->name] { ChooseCheckout(key, name); }});
}
}
void App::AboutPage(Ui::Frame& frame, Ui::Column& column) {
static constexpr std::array<std::string_view, 5> said = {
"Nostro is a banking client for Linux, phones first. It talks to your bank directly.",
"Programs you run cannot read your bank connections, which belong to a service of Nostro's own, and cannot pay or change anything at your bank without your password. What they can do is look at your accounts and payments. This window is one of those programs: it holds no key and no token.",
"The password dialog is your desktop's. A program running as you could draw one that looks the same, so type your password only for something you asked for, and read what the dialog says.",
"In a session where nothing can ask for your password, whatever needs it is refused.",
"The bank connections are not encrypted on disk: whoever holds the disk can read them. Use full-disk encryption.",
};
for(const std::string_view paragraph : said) {
column.Advance(Paragraph(frame, Padded(frame, column.Next()), paragraph, Body(frame)));
}
column.Advance(Paragraph(frame, Padded(frame, column.Next()), host.version.empty() ? std::string("Nostro, © 2026 Catcrafts. GPL-3.0-only. Set in Noto Sans, under the SIL Open Font License.") : std::format("Nostro {}, © 2026 Catcrafts. GPL-3.0-only. Set in Noto Sans, under the SIL Open Font License.", host.version), Muted(frame)));
}
void App::FilterSheet(Ui::Frame& frame, const AccountRef& account) {
const auto close = [this] {
filtering.clear();
context.Invalidate();
};
const std::string key = account.key;
const Currency currency = account.account->currency;
FilterForm& filter = Data(key).filter;
TransactionQuery unused;
const FilterForm::Errors errors = filter.Check(currency, unused);
const FieldOptions amount{.key = "filter.amount", .label = "An exact amount", .prefix = std::string(GetCurrencySymbol(currency)), .error = errors.amount};
const FieldOptions from{.key = "filter.from", .label = "From", .placeholder = "YYYY-MM-DD", .error = errors.from};
const FieldOptions to{.key = "filter.to", .label = "Until", .placeholder = "YYYY-MM-DD", .error = errors.to};
// As tall as what is in it: the three fields, each with what is wrong with it, the choice and the buttons.
const float gap = frame.Dp(Size::unit * 3);
const float width = SheetBodyWidth(frame);
const float height = FieldHeight(frame, width, amount) + FieldHeight(frame, width, from) + FieldHeight(frame, width, to) + frame.Dp(Size::control) * 2 + gap * 4;
Sheet(frame, {.key = "filter", .title = "Filter", .contentHeight = height, .onDismiss = close}, [&, this](Box body) {
const float offset = frame.BeginScroll("filter.scroll", body);
Column column({body.x, body.y - offset, body.w, body.h}, gap);
column.Advance(TextField(frame, column.Next(), filter.amount, amount));
Segmented(frame, column.Take(frame.Dp(Size::control)), {.key = "filter.direction", .labels = {"Paid", "Received"}, .selected = filter.received ? std::size_t{1} : std::size_t{0}, .onSelect = [this, key](std::size_t chosen) {
Data(key).filter.received = chosen == 1;
context.Invalidate();
}});
column.Advance(TextField(frame, column.Next(), filter.from, from));
column.Advance(TextField(frame, column.Next(), filter.to, to));
Row buttons(column.Take(frame.Dp(Size::control)), gap);
Button(frame, buttons.TakeLeft((buttons.area.w - buttons.gap) / 2), {.key = "filter.show", .label = "Show", .enabled = !errors.Any(), .onTap = [this, key] {
filtering.clear();
Search(key, true);
context.Invalidate();
}});
Button(frame, buttons.Rest(), {.key = "filter.clear", .label = "Clear", .kind = ButtonKind::Tonal, .onTap = [this, key] {
Data(key).filter.Reset();
filtering.clear();
Search(key, true);
context.Invalidate();
}});
frame.EndScroll(column.cursor - (body.y - offset));
});
}
void App::PickSheet(Ui::Frame& frame) {
const std::vector<AccountRef> all = Accounts();
const std::string& current = picking == Picking::PayFrom ? payFrom : requestInto;
const auto close = [this] {
picking = Picking::None;
context.Invalidate();
};
Sheet(frame, {.key = "pick", .title = "Choose an account", .contentHeight = frame.Dp(Size::row) * static_cast<float>(all.size()), .onDismiss = close}, [&, this](Box body) {
const float offset = frame.BeginScroll("pick.scroll", body);
Column column({body.x, body.y - offset, body.w, body.h});
for(const AccountRef& account : all) {
ListRow(frame, column.Take(frame.Dp(Size::row)), {.key = std::format("pick.{}", account.key), .title = account.account->name, .subtitle = Joined(GroupIban(account.account->iban), account.connection->name), .trailing = Money(account.account->balance, account.account->currency), .selected = account.key == current, .onTap = [this, key = account.key] {
(picking == Picking::PayFrom ? payFrom : requestInto) = key;
picking = Picking::None;
context.Invalidate();
}});
}
frame.EndScroll(column.cursor - (body.y - offset));
});
}
void App::DialogSheet(Ui::Frame& frame) {
const Dialog& shown = *dialog;
const float gap = frame.Dp(Size::unit * 3);
// How far a line's row reaches past the text on either side: what is drawn under a press on it.
const float reach = frame.Dp(Size::unit * 2);
const TextStyle label = Muted(frame);
const TextStyle value = Body(frame);
// The lines as rows: a press on one copies what it says.
std::vector<ValueOptions> rows;
for(const Line& line : shown.lines) {
// By what it says; a second line of one label, as a draft's two payments to one payee, by its turn too.
const std::ptrdiff_t earlier = std::ranges::count(std::span(shown.lines).first(rows.size()), line.label, &Line::label);
const auto copy = [this, text = line.copied.empty() ? line.value : line.copied] {
context.Copy(text);
Tell("Copied");
};
rows.push_back({.key = earlier == 0 ? std::format("copy.{}", line.label) : std::format("copy.{}.{}", line.label, earlier + 1), .label = line.label, .value = line.value, .onTap = copy, .onLongPress = copy});
}
// The body is laid out twice with the same sums: once for how tall the sheet is, once to draw it.
const auto layout = [&](Box body, bool draw) {
Column column(body, gap);
for(const std::string& text : shown.text) {
column.Advance(draw ? Paragraph(frame, column.Next(), text, value) : ParagraphHeight(frame, body.w, text, value));
}
if(!rows.empty()) {
// One under the other without the column's gap: each row has its own room.
const float width = body.w + reach * 2;
float tall = 0;
for(const ValueOptions& row : rows) {
tall += ValueRowHeight(frame, width, row);
}
Box at = column.Take(tall);
if(draw) {
for(const ValueOptions& row : rows) {
at.y += ValueRow(frame, {at.x - reach, at.y, width, 0}, row);
}
}
// Said where a line is all there is to press: nothing about a line looks like a button.
if(shown.kind == Dialog::Kind::Detail) {
const std::string_view hint = "Press a line to copy it.";
column.Advance(draw ? Paragraph(frame, column.Next(), hint, Caption(frame)) : ParagraphHeight(frame, body.w, hint, Caption(frame)));
}
}
if(!shown.link.empty()) {
const float height = ParagraphHeight(frame, body.w, shown.link, label);
const Box at = column.Take(height);
Row buttons(column.Take(frame.Dp(Size::control)), gap);
if(draw) {
Paragraph(frame, at, shown.link, label);
Button(frame, buttons.TakeLeft((buttons.area.w - buttons.gap) / 2), {.key = "dialog.copy", .label = "Copy the link", .kind = ButtonKind::Tonal, .onTap = [this, link = shown.link] {
context.Copy(link);
Tell("Link copied");
}});
Button(frame, buttons.Rest(), {.key = "dialog.open", .label = "Open", .kind = ButtonKind::Tonal, .enabled = host.openUri != nullptr, .onTap = [this, link = shown.link] {
host.openUri(link, [this](bool taken) {
if(!taken) {
Tell("No browser could be opened: copy the link instead");
}
});
}});
}
}
for(const Choice& choice : shown.choices) {
const Box at = column.Take(frame.Dp(Size::control));
if(draw) {
Button(frame, at, {.key = choice.key, .label = choice.label, .kind = choice.kind, .enabled = choice.enabled, .onTap = choice.onTap});
}
// Why a thing cannot be done is said under it.
if(!choice.enabled && !choice.reason.empty()) {
column.Advance(draw ? Paragraph(frame, column.Next(), choice.reason, label) : ParagraphHeight(frame, body.w, choice.reason, label));
}
}
return column.Used();
};
// The change under way cannot be sent off: its answer is what says whether money moved.
const std::function<void()> dismiss = shown.kind == Dialog::Kind::Working ? std::function<void()>() : [this] { Close(); };
const float height = layout({0, 0, SheetBodyWidth(frame), 0}, false);
Sheet(frame, {.key = "dialog", .title = shown.title, .contentHeight = height, .onDismiss = dismiss}, [&](Box body) {
// Taller than the window: it scrolls. Its rows are drawn a little wider than its text.
const float offset = frame.BeginScroll("dialog.scroll", {body.x - reach, body.y, body.w + reach * 2, body.h});
frame.EndScroll(layout({body.x, body.y - offset, body.w, body.h}, true));
});
}
}