Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: block wallets from sending if BN connection stale #5949

Merged
merged 2 commits into from
Nov 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use chrono::Utc;
use minotari_wallet::connectivity_service::{OnlineStatus, WalletConnectivityInterface};
use tui::{
backend::Backend,
Expand Down Expand Up @@ -88,6 +89,8 @@ impl<B: Backend> Component<B> for BaseNode {
)
};

let updated = base_node_state.updated.unwrap_or(Utc::now().naive_utc());

let latency = base_node_state.latency.unwrap_or_default().as_millis();
let latency_color = match latency {
0 => Color::Gray, // offline? default duration is 0
Expand All @@ -96,19 +99,32 @@ impl<B: Backend> Component<B> for BaseNode {
_ => Color::Red,
};

let tip_info = vec![
let mut tip_info = vec![
Span::styled("Chain Tip:", Style::default().fg(Color::Magenta)),
Span::raw(" "),
Span::styled(format!("#{}", tip), Style::default().fg(tip_color)),
Span::raw(" "),
Span::styled(sync_text.to_string(), Style::default().fg(Color::White)),
Span::raw(" "),
Span::styled("Latency", Style::default().fg(Color::White)),
Span::raw(" "),
Span::styled(latency.to_string(), Style::default().fg(latency_color)),
Span::styled(" ms", Style::default().fg(Color::DarkGray)),
];

let mut latency_span = if Utc::now().naive_utc().timestamp() - updated.timestamp() > 15 * 60 {
vec![
Span::styled("Last updated", Style::default().fg(Color::Red)),
Span::raw(" "),
Span::styled(updated.to_string(), Style::default().fg(Color::Red)),
Span::styled(" s", Style::default().fg(Color::Red)),
]
} else {
vec![
Span::styled("Latency", Style::default().fg(Color::White)),
Span::raw(" "),
Span::styled(latency.to_string(), Style::default().fg(latency_color)),
Span::styled(" ms", Style::default().fg(Color::DarkGray)),
]
};
tip_info.append(&mut latency_span);

Spans::from(tip_info)
} else {
Spans::from(vec![
Expand Down
Loading