AccountData: decouple query from constructor

the ndb query must be as close to the subscription as possible to
avoid events falling through the cracks

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2025-07-08 15:09:03 -04:00
parent 6c951d1a29
commit c99b99ed52
6 changed files with 60 additions and 52 deletions

View File

@@ -94,7 +94,7 @@ pub fn render_accounts_route(
}
}
AccountsRouteResponse::AddAccount(response) => {
let action = process_login_view_response(accounts, decks, col, ndb, response);
let action = process_login_view_response(accounts, decks, col, response);
*login_state = Default::default();
let router = get_active_columns_mut(accounts, decks)
.column_mut(col)
@@ -143,20 +143,17 @@ pub fn process_login_view_response(
manager: &mut Accounts,
decks: &mut DecksCache,
col: usize,
ndb: &Ndb,
response: AccountLoginResponse,
) -> AddAccountAction {
let (r, pubkey) = match response {
AccountLoginResponse::CreateNew => {
let kp = FullKeypair::generate().to_keypair();
let pubkey = kp.pubkey;
let txn = Transaction::new(ndb).expect("txn");
(manager.add_account(ndb, &txn, kp), pubkey)
(manager.add_account(kp), pubkey)
}
AccountLoginResponse::LoginWith(keypair) => {
let pubkey = keypair.pubkey;
let txn = Transaction::new(ndb).expect("txn");
(manager.add_account(ndb, &txn, keypair), pubkey)
(manager.add_account(keypair), pubkey)
}
};

View File

@@ -78,9 +78,11 @@ impl SwitchingAction {
match &self {
SwitchingAction::Accounts(account_action) => match account_action {
AccountsAction::Switch(switch_action) => {
let txn = Transaction::new(ctx.ndb).expect("txn");
ctx.accounts.select_account(
&switch_action.switch_to,
ctx.ndb,
&txn,
ctx.pool,
ui_ctx,
);