move error out of AnyZapState
Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -340,10 +340,10 @@ impl Zaps {
|
|||||||
&'a self,
|
&'a self,
|
||||||
sender: &[u8; 32],
|
sender: &[u8; 32],
|
||||||
target: ZapTarget<'a>,
|
target: ZapTarget<'a>,
|
||||||
) -> AnyZapState {
|
) -> Result<AnyZapState, ZappingError> {
|
||||||
let key = ZapKey { sender, target };
|
let key = ZapKey { sender, target };
|
||||||
let Some(ids) = self.zap_keys.get(&key) else {
|
let Some(ids) = self.zap_keys.get(&key) else {
|
||||||
return AnyZapState::None;
|
return Ok(AnyZapState::None);
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut has_confirmed = false;
|
let mut has_confirmed = false;
|
||||||
@@ -363,21 +363,21 @@ impl Zaps {
|
|||||||
}
|
}
|
||||||
ZapState::Pending(p) => {
|
ZapState::Pending(p) => {
|
||||||
if let Err(e) = p {
|
if let Err(e) = p {
|
||||||
return AnyZapState::Error(e.to_owned());
|
return Err(e.to_owned());
|
||||||
}
|
}
|
||||||
return AnyZapState::Pending;
|
return Ok(AnyZapState::Pending);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if has_local_confirmed {
|
if has_local_confirmed {
|
||||||
return AnyZapState::LocalOnly;
|
return Ok(AnyZapState::LocalOnly);
|
||||||
}
|
}
|
||||||
|
|
||||||
if has_confirmed {
|
if has_confirmed {
|
||||||
AnyZapState::Confirmed
|
Ok(AnyZapState::Confirmed)
|
||||||
} else {
|
} else {
|
||||||
AnyZapState::None
|
Ok(AnyZapState::None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -397,11 +397,10 @@ impl Zaps {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub enum AnyZapState {
|
pub enum AnyZapState {
|
||||||
None,
|
None,
|
||||||
Pending,
|
Pending,
|
||||||
#[allow(dead_code)]
|
|
||||||
Error(ZappingError),
|
|
||||||
LocalOnly,
|
LocalOnly,
|
||||||
Confirmed,
|
Confirmed,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -612,22 +612,25 @@ fn render_note_actionbar(
|
|||||||
});
|
});
|
||||||
|
|
||||||
let zap_state = cur_acc.map_or_else(
|
let zap_state = cur_acc.map_or_else(
|
||||||
|| AnyZapState::None,
|
|| Ok(AnyZapState::None),
|
||||||
|kp| zaps.any_zap_state_for(kp.pubkey.bytes(), zap_target),
|
|kp| zaps.any_zap_state_for(kp.pubkey.bytes(), zap_target),
|
||||||
);
|
);
|
||||||
let zap_resp = cur_acc
|
let zap_resp =
|
||||||
.filter(|k| k.secret_key.is_some())
|
cur_acc
|
||||||
.map(|_| match &zap_state {
|
.filter(|k| k.secret_key.is_some())
|
||||||
AnyZapState::None => ui.add(zap_button(false)),
|
.map(|_| match zap_state.clone() {
|
||||||
AnyZapState::Pending => ui.spinner(),
|
Ok(any_zap_state) => match any_zap_state {
|
||||||
AnyZapState::LocalOnly | AnyZapState::Confirmed => ui.add(zap_button(true)),
|
AnyZapState::None => ui.add(zap_button(false)),
|
||||||
AnyZapState::Error(zapping_error) => {
|
AnyZapState::Pending => ui.spinner(),
|
||||||
let (rect, _) =
|
AnyZapState::LocalOnly | AnyZapState::Confirmed => ui.add(zap_button(true)),
|
||||||
ui.allocate_at_least(egui::vec2(10.0, 10.0), egui::Sense::click());
|
},
|
||||||
ui.add(x_button(rect))
|
Err(zapping_error) => {
|
||||||
.on_hover_text(format!("{zapping_error}"))
|
let (rect, _) =
|
||||||
}
|
ui.allocate_at_least(egui::vec2(10.0, 10.0), egui::Sense::click());
|
||||||
});
|
ui.add(x_button(rect))
|
||||||
|
.on_hover_text(format!("{zapping_error}"))
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
let to_noteid = |id: &[u8; 32]| NoteId::new(*id);
|
let to_noteid = |id: &[u8; 32]| NoteId::new(*id);
|
||||||
|
|
||||||
@@ -652,7 +655,7 @@ fn render_note_actionbar(
|
|||||||
zap_recipient: Pubkey::new(*note_pubkey),
|
zap_recipient: Pubkey::new(*note_pubkey),
|
||||||
};
|
};
|
||||||
|
|
||||||
if matches!(zap_state, AnyZapState::Error(_)) {
|
if zap_state.is_err() {
|
||||||
break 's Some(NoteAction::Zap(ZapAction::ClearError(target)));
|
break 's Some(NoteAction::Zap(ZapAction::ClearError(target)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user