Wallet delegations list - add an error to each row, and display as a tooltip if present

This commit is contained in:
Mark Sinclair
2024-05-01 17:59:46 +01:00
parent ad86ec9315
commit 08e580ec8b
7 changed files with 48 additions and 23 deletions
+3 -1
View File
@@ -50,7 +50,7 @@ pub struct DelegationWithEverything {
pub accumulated_by_delegates: Option<DecCoin>,
pub accumulated_by_operator: Option<DecCoin>,
pub block_height: u64,
pub delegated_on_iso_datetime: String,
pub delegated_on_iso_datetime: Option<String>,
pub cost_params: Option<MixNodeCostParams>,
pub avg_uptime_percent: Option<u8>,
@@ -60,6 +60,8 @@ pub struct DelegationWithEverything {
pub uses_vesting_contract_tokens: bool,
pub unclaimed_rewards: Option<DecCoin>,
pub errors: Option<String>,
// DEPRECATED, IF POSSIBLE TRY TO DISCONTINUE USE OF IT!
pub pending_events: Vec<DelegationEvent>,
pub mixnode_is_unbonding: Option<bool>,
-3
View File
@@ -155,9 +155,6 @@ pub enum BackendError {
#[error("This command ({name}) has been removed. Please try to use {alternative} instead.")]
RemovedCommand { name: String, alternative: String },
#[error("Unable to get list of delegations, errors: {0}")]
DelegationsListError(String),
}
impl Serialize for BackendError {
@@ -154,8 +154,6 @@ pub async fn get_all_mix_delegations(
) -> Result<Vec<DelegationWithEverything>, BackendError> {
log::info!(">>> Get all mixnode delegations");
let mut error_strings: Vec<String> = vec![];
let guard = state.read().await;
let client = guard.current_client()?;
let reg = guard.registered_coins()?;
@@ -174,7 +172,6 @@ pub async fn get_all_mix_delegations(
.get_all_delegator_delegations(&address)
.await
.tap_err(|err| {
error_strings.push(format!("{}", err));
log::error!(" <<< Failed to get delegations. Error: {}", err);
})?;
log::info!(" <<< {} delegations", delegations.len());
@@ -183,7 +180,6 @@ pub async fn get_all_mix_delegations(
get_pending_delegation_events(state.clone())
.await
.tap_err(|err| {
error_strings.push(format!("{}", err));
log::error!(" <<< Failed to get pending delegations. Error: {}", err);
})?;
@@ -195,6 +191,8 @@ pub async fn get_all_mix_delegations(
let mut with_everything: Vec<DelegationWithEverything> = Vec::with_capacity(delegations.len());
for delegation in delegations {
let mut error_strings: Vec<String> = vec![];
let d = Delegation::from_mixnet_contract(delegation.clone(), reg).tap_err(|err| {
log::error!(
" <<< Failed to get delegation for mix id {} from contract. Error: {}",
@@ -370,8 +368,8 @@ pub async fn get_all_mix_delegations(
let str_err = format!("Failed to get block timestamp for height = {} for delegation to mix_id = {}. Error: {}", d.height, d.mix_id, err);
log::error!(" <<< {}", str_err);
error_strings.push(str_err);
})?;
let delegated_on_iso_datetime = timestamp.to_rfc3339();
}).ok();
let delegated_on_iso_datetime = timestamp.map(|ts| ts.to_rfc3339());
log::trace!(
" <<< timestamp = {:?}, delegated_on_iso_datetime = {:?}",
timestamp,
@@ -391,6 +389,9 @@ pub async fn get_all_mix_delegations(
mixnode_is_unbonding
);
error_strings.push("Oh no!".to_string());
error_strings.push("Oh no, Again!".to_string());
with_everything.push(DelegationWithEverything {
owner: d.owner,
mix_id: d.mix_id,
@@ -409,14 +410,15 @@ pub async fn get_all_mix_delegations(
unclaimed_rewards: accumulated_rewards,
pending_events,
mixnode_is_unbonding,
errors: if error_strings.is_empty() {
None
} else {
Some(error_strings.join("\n"))
},
})
}
log::trace!("<<< {:?}", with_everything);
if !error_strings.is_empty() {
return Err(BackendError::DelegationsListError(error_strings.join("\n")));
}
Ok(with_everything)
}
@@ -45,13 +45,22 @@ export const DelegationItem = ({
{nodeIsUnbonded ? (
'-'
) : (
<Link
target="_blank"
href={`${explorerUrl}/network-components/mixnode/${item.mix_id}`}
text={`${item.node_identity.slice(0, 6)}...${item.node_identity.slice(-6)}`}
color="text.primary"
noIcon
/>
<>
{item.errors && (
<Tooltip title={<pre>{item.errors}</pre>}>
<Typography mr={1} component="span">
</Typography>
</Tooltip>
)}
<Link
target="_blank"
href={`${explorerUrl}/network-components/mixnode/${item.mix_id}`}
text={`${item.node_identity.slice(0, 6)}...${item.node_identity.slice(-6)}`}
color="text.primary"
noIcon
/>
</>
)}
</TableCell>
<TableCell sx={{ color: 'inherit' }}>
@@ -70,7 +79,7 @@ export const DelegationItem = ({
</TableCell>
<TableCell sx={{ color: 'inherit' }}>{getStakeSaturation(item)}</TableCell>
<TableCell sx={{ color: 'inherit' }}>
{format(new Date(item.delegated_on_iso_datetime), 'dd/MM/yyyy')}
{item.delegated_on_iso_datetime && format(new Date(item.delegated_on_iso_datetime), 'dd/MM/yyyy')}
</TableCell>
<TableCell sx={{ color: 'inherit' }}>
<Typography style={{ textTransform: 'uppercase', fontSize: 'inherit' }}>
@@ -34,6 +34,7 @@ export const items: DelegationWithEverything[] = [
uses_vesting_contract_tokens: false,
pending_events: [],
mixnode_is_unbonding: true,
errors: null,
},
{
mix_id: 2,
@@ -57,6 +58,7 @@ export const items: DelegationWithEverything[] = [
uses_vesting_contract_tokens: true,
pending_events: [],
mixnode_is_unbonding: true,
errors: null,
},
{
mix_id: 3,
@@ -80,6 +82,7 @@ export const items: DelegationWithEverything[] = [
uses_vesting_contract_tokens: true,
pending_events: [],
mixnode_is_unbonding: true,
errors: null,
},
{
mix_id: 4,
@@ -103,6 +106,7 @@ export const items: DelegationWithEverything[] = [
uses_vesting_contract_tokens: true,
pending_events: [],
mixnode_is_unbonding: true,
errors: null,
},
{
mix_id: 5,
@@ -126,6 +130,7 @@ export const items: DelegationWithEverything[] = [
uses_vesting_contract_tokens: true,
pending_events: [],
mixnode_is_unbonding: true,
errors: null,
},
{
mix_id: 6,
@@ -149,6 +154,7 @@ export const items: DelegationWithEverything[] = [
uses_vesting_contract_tokens: true,
pending_events: [],
mixnode_is_unbonding: true,
errors: null,
},
{
mix_id: 7,
@@ -172,6 +178,7 @@ export const items: DelegationWithEverything[] = [
uses_vesting_contract_tokens: false,
pending_events: [],
mixnode_is_unbonding: true,
errors: null,
},
{
mix_id: 8,
@@ -195,6 +202,7 @@ export const items: DelegationWithEverything[] = [
uses_vesting_contract_tokens: true,
pending_events: [],
mixnode_is_unbonding: true,
errors: null,
},
{
mix_id: 9,
@@ -218,6 +226,7 @@ export const items: DelegationWithEverything[] = [
uses_vesting_contract_tokens: true,
pending_events: [],
mixnode_is_unbonding: true,
errors: null,
},
{
mix_id: 10,
@@ -241,6 +250,7 @@ export const items: DelegationWithEverything[] = [
uses_vesting_contract_tokens: true,
pending_events: [],
mixnode_is_unbonding: true,
errors: null,
},
{
mix_id: 11,
@@ -264,6 +274,7 @@ export const items: DelegationWithEverything[] = [
uses_vesting_contract_tokens: true,
pending_events: [],
mixnode_is_unbonding: true,
errors: null,
},
{
mix_id: 12,
@@ -287,6 +298,7 @@ export const items: DelegationWithEverything[] = [
uses_vesting_contract_tokens: true,
pending_events: [],
mixnode_is_unbonding: true,
errors: null,
},
];
@@ -37,6 +37,7 @@ let mockDelegations: DelegationWithEverything[] = [
uses_vesting_contract_tokens: false,
pending_events: [],
mixnode_is_unbonding: false,
errors: null,
},
{
mix_id: 5678,
@@ -60,6 +61,7 @@ let mockDelegations: DelegationWithEverything[] = [
uses_vesting_contract_tokens: true,
pending_events: [],
mixnode_is_unbonding: false,
errors: null,
},
];
@@ -11,7 +11,7 @@ export interface DelegationWithEverything {
accumulated_by_delegates: DecCoin | null;
accumulated_by_operator: DecCoin | null;
block_height: bigint;
delegated_on_iso_datetime: string;
delegated_on_iso_datetime: string | null;
cost_params: MixNodeCostParams | null;
avg_uptime_percent: number | null;
stake_saturation: string | null;
@@ -19,4 +19,5 @@ export interface DelegationWithEverything {
unclaimed_rewards: DecCoin | null;
pending_events: Array<DelegationEvent>;
mixnode_is_unbonding: boolean | null;
errors: string | null;
}