wallet route

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2025-03-15 13:03:04 -04:00
parent c2fbcaa5eb
commit ebec367809
4 changed files with 68 additions and 3 deletions

View File

@@ -20,6 +20,7 @@ use crate::{
profile::EditProfileView, profile::EditProfileView,
search::{FocusState, SearchView}, search::{FocusState, SearchView},
support::SupportView, support::SupportView,
wallet::{WalletAction, WalletView},
RelayView, View, RelayView, View,
}, },
Damus, Damus,
@@ -27,7 +28,7 @@ use crate::{
use egui_nav::{Nav, NavAction, NavResponse, NavUiType}; use egui_nav::{Nav, NavAction, NavResponse, NavUiType};
use nostrdb::Transaction; use nostrdb::Transaction;
use notedeck::{AccountsAction, AppContext}; use notedeck::{AccountsAction, AppContext, WalletState};
use tracing::error; use tracing::error;
#[allow(clippy::enum_variant_names)] #[allow(clippy::enum_variant_names)]
@@ -38,6 +39,7 @@ pub enum RenderNavAction {
NoteAction(NoteAction), NoteAction(NoteAction),
ProfileAction(ProfileAction), ProfileAction(ProfileAction),
SwitchingAction(SwitchingAction), SwitchingAction(SwitchingAction),
WalletAction(WalletAction),
} }
pub enum SwitchingAction { pub enum SwitchingAction {
@@ -194,6 +196,12 @@ impl RenderNavResponse {
.router_mut(), .router_mut(),
); );
} }
RenderNavAction::WalletAction(wallet_action) => {
let router = get_active_columns_mut(ctx.accounts, &mut app.decks_cache)
.column_mut(col)
.router_mut();
wallet_action.process(ctx.accounts, ctx.global_wallet, router)
}
} }
} }
@@ -515,6 +523,55 @@ fn render_nav_body(
} }
action action
} }
Route::Wallet(wallet_type) => {
let state = match wallet_type {
notedeck::WalletType::Auto => 's: {
if let Some(cur_acc) = ctx.accounts.get_selected_account_mut() {
if let Some(wallet) = &mut cur_acc.wallet {
break 's WalletState::Wallet {
wallet,
can_create_local_wallet: false,
};
}
}
let Some(wallet) = &mut ctx.global_wallet.wallet else {
break 's WalletState::NoWallet {
state: &mut ctx.global_wallet.ui_state,
show_local_only: true,
};
};
WalletState::Wallet {
wallet,
can_create_local_wallet: true,
}
}
notedeck::WalletType::Local => 's: {
let Some(cur_acc) = ctx.accounts.get_selected_account_mut() else {
break 's WalletState::NoWallet {
state: &mut ctx.global_wallet.ui_state,
show_local_only: false,
};
};
let Some(wallet) = &mut cur_acc.wallet else {
break 's WalletState::NoWallet {
state: &mut ctx.global_wallet.ui_state,
show_local_only: false,
};
};
WalletState::Wallet {
wallet,
can_create_local_wallet: false,
}
}
};
WalletView::new(state)
.ui(ui)
.map(RenderNavAction::WalletAction)
}
} }
} }

View File

@@ -1,4 +1,5 @@
use enostr::{NoteId, Pubkey}; use enostr::{NoteId, Pubkey};
use notedeck::WalletType;
use std::fmt::{self}; use std::fmt::{self};
use crate::{ use crate::{
@@ -27,6 +28,7 @@ pub enum Route {
NewDeck, NewDeck,
Search, Search,
EditDeck(usize), EditDeck(usize),
Wallet(WalletType),
} }
impl Route { impl Route {
@@ -107,6 +109,9 @@ impl Route {
writer.write_token("deck"); writer.write_token("deck");
writer.write_token("new"); writer.write_token("new");
} }
Route::Wallet(_) => {
writer.write_token("wallet");
}
} }
} }
@@ -232,6 +237,7 @@ impl Route {
Route::EditDeck(_) => ColumnTitle::simple("Edit Deck"), Route::EditDeck(_) => ColumnTitle::simple("Edit Deck"),
Route::EditProfile(_) => ColumnTitle::simple("Edit Profile"), Route::EditProfile(_) => ColumnTitle::simple("Edit Profile"),
Route::Search => ColumnTitle::simple("Search"), Route::Search => ColumnTitle::simple("Search"),
Route::Wallet(_) => ColumnTitle::simple("Wallet"),
} }
} }
} }
@@ -354,6 +360,7 @@ impl fmt::Display for Route {
Route::EditDeck(_) => write!(f, "Edit Deck"), Route::EditDeck(_) => write!(f, "Edit Deck"),
Route::EditProfile(_) => write!(f, "Edit Profile"), Route::EditProfile(_) => write!(f, "Edit Profile"),
Route::Search => write!(f, "Search"), Route::Search => write!(f, "Search"),
Route::Wallet(_) => write!(f, "Wallet"),
} }
} }
} }

View File

@@ -464,6 +464,7 @@ impl<'a> NavTitle<'a> {
Route::Search => { Route::Search => {
ui.add(ui::side_panel::search_button()); ui.add(ui::side_panel::search_button());
} }
Route::Wallet(_) => {}
} }
} }

View File

@@ -17,7 +17,7 @@ impl WalletAction {
&self, &self,
accounts: &mut Accounts, accounts: &mut Accounts,
global_wallet: &mut GlobalWallet, global_wallet: &mut GlobalWallet,
_router: &mut Router<Route>, router: &mut Router<Route>,
) { ) {
match &self { match &self {
WalletAction::SaveURI => { WalletAction::SaveURI => {
@@ -53,7 +53,7 @@ impl WalletAction {
} }
} }
WalletAction::AddLocalOnly => { WalletAction::AddLocalOnly => {
// router.route_to(Route::Wallet(notedeck::WalletType::Local)); router.route_to(Route::Wallet(notedeck::WalletType::Local));
global_wallet.ui_state.for_local_only = true; global_wallet.ui_state.for_local_only = true;
} }
WalletAction::Delete => { WalletAction::Delete => {