Skip to content
Merged
Show file tree
Hide file tree
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
22 changes: 14 additions & 8 deletions src/database/contested_names.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use crate::context::AppContext;
use crate::database::Database;
use crate::model::contested_name::{Contestant, ContestedName};
use dash_sdk::dpp::dashcore::Network;
use dash_sdk::dpp::data_contract::document_type::DocumentTypeRef;
use dash_sdk::dpp::document::DocumentV0Getters;
use dash_sdk::dpp::identifier::Identifier;
use dash_sdk::dpp::identity::TimestampMillis;
use dash_sdk::dpp::prelude::{BlockHeight, CoreBlockHeight};
use dash_sdk::query_types::Contenders;
use rusqlite::{params, params_from_iter, OptionalExtension, Result};
use rusqlite::{params, params_from_iter, Result};
use std::collections::{BTreeMap, HashMap, HashSet};
use std::fmt::Debug;

impl Database {
pub fn get_contested_names(&self, app_context: &AppContext) -> Result<Vec<ContestedName>> {
Expand Down Expand Up @@ -388,11 +388,12 @@ impl Database {
) -> Result<Vec<String>> {
let network = app_context.network_string();
let conn = self.conn.lock().unwrap();
let mut outdated_names: Vec<(String, Option<i64>)> = Vec::new();
let mut names_to_be_updated: Vec<(String, Option<i64>)> = Vec::new();
let mut new_names: Vec<String> = Vec::new();

// Define the time limit (one hour ago in Unix timestamp format)
let one_hour_ago = chrono::Utc::now().timestamp() - 3600;
let two_weeks_ago = chrono::Utc::now().timestamp() - 1_209_600;

// Chunk the name_contests into smaller groups due to SQL parameter limits
let chunk_size = 900; // Use a safe limit to stay below SQLite's limit
Expand Down Expand Up @@ -427,8 +428,13 @@ impl Database {
for row in rows {
if let Ok((name, last_updated)) = row {
existing_names.insert(name.clone());
if last_updated.is_none() || last_updated.unwrap() < one_hour_ago {
outdated_names.push((name, last_updated));
if last_updated.is_none()
|| (app_context.network == Network::Testnet
&& last_updated.unwrap() < one_hour_ago)
|| (app_context.network == Network::Dash
&& last_updated.unwrap() < two_weeks_ago)
{
names_to_be_updated.push((name, last_updated));
}
}
}
Expand All @@ -454,11 +460,11 @@ impl Database {
}

// Combine the new names and outdated names, sorted by last_updated (oldest first)
outdated_names.extend(new_names.into_iter().map(|name| (name, None)));
outdated_names.sort_by(|a, b| a.1.unwrap_or(0).cmp(&b.1.unwrap_or(0)));
names_to_be_updated.extend(new_names.into_iter().map(|name| (name, None)));
names_to_be_updated.sort_by(|a, b| a.1.unwrap_or(0).cmp(&b.1.unwrap_or(0)));

// Extract the names into a Vec<String>
let result_names = outdated_names
let result_names = names_to_be_updated
.into_iter()
.map(|(name, _)| name)
.collect::<Vec<_>>();
Expand Down
6 changes: 3 additions & 3 deletions src/ui/identities/register_dpns_name_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ impl RegisterDpnsNameScreen {
.show_ui(ui, |ui| {
// Loop through the qualified identities and display each as selectable
for qualified_identity in &self.qualified_identities {
let id = qualified_identity.identity.id(); // Extract the Identifier

// Display each QualifiedIdentity as a selectable item
if ui
.selectable_value(
&mut self.selected_qualified_identity,
Some(qualified_identity.clone()),
id.to_string(Encoding::Base58),
qualified_identity.alias.as_ref().unwrap_or(
&qualified_identity.identity.id().to_string(Encoding::Base58),
),
)
.clicked()
{
Expand Down