Skip to content

Commit

Permalink
update(Add): Update toast when past own did (#1539)
Browse files Browse the repository at this point in the history
Co-authored-by: Sara Tavares <29093946+stavares843@users.noreply.github.com>
  • Loading branch information
lgmarchi and stavares843 authored Nov 22, 2023
1 parent 190d4af commit 825b73d
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions ui/src/components/friends/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,26 @@ pub fn AddFriend(cx: Scope) -> Element {
my_id.set(None);
}

let identity = state.read().get_own_identity();
let short_id = identity.short_id();
let did_key = identity.did_key();
let username = identity.username();
let short_name = format!("{}#{}", username, short_id);
let short_name_context = short_name.clone();

let ch = use_coroutine(cx, |mut rx: UnboundedReceiver<(String, Vec<Identity>)>| {
to_owned![request_sent, error_toast, add_in_progress, clear_input];
to_owned![
request_sent,
error_toast,
add_in_progress,
clear_input,
short_name
];
async move {
let warp_cmd_tx = WARP_CMD_CH.tx.clone();
while let Some((id, outgoing_requests)) = rx.next().await {
let id_to_compare = id.clone();

//tokio::time::sleep(std::time::Duration::from_millis(5000)).await;
let (tx, rx) = oneshot::channel::<Result<(), warp::error::Error>>();
if let Err(e) = warp_cmd_tx.send(WarpCmd::MultiPass(MultiPassCmd::RequestFriend {
Expand Down Expand Up @@ -140,22 +155,20 @@ pub fn AddFriend(cx: Scope) -> Element {
error_toast.set(Some(get_local_text("friends.request-exist")));
}
_ => {
error_toast.set(Some(get_local_text("friends.add-failed")));
log::error!("add friend failed: {}", e);
if id_to_compare == short_name {
log::warn!("cannot add self: {}", e);
error_toast.set(Some(get_local_text("friends.cannot-add-self")));
} else {
error_toast.set(Some(get_local_text("friends.add-failed")));
log::error!("add friend failed: {}", e);
}
}
},
}
}
}
});

let identity = state.read().get_own_identity();
let short_id = identity.short_id();
let did_key = identity.did_key();
let username = identity.username();
let short_name = format!("{}#{}", username, short_id);
let short_name_context = short_name.clone();

cx.render(rsx!(
div {
class: "add-friend",
Expand Down

0 comments on commit 825b73d

Please sign in to comment.