From 08e580ec8bbedbdc056395d09c9d33f689054f0b Mon Sep 17 00:00:00 2001 From: Mark Sinclair Date: Wed, 1 May 2024 17:59:46 +0100 Subject: [PATCH] Wallet delegations list - add an error to each row, and display as a tooltip if present --- common/types/src/delegation.rs | 4 ++- nym-wallet/src-tauri/src/error.rs | 3 --- .../src/operations/mixnet/delegate.rs | 22 ++++++++-------- .../components/Delegation/DelegationItem.tsx | 25 +++++++++++++------ .../Delegation/DelegationList.stories.tsx | 12 +++++++++ nym-wallet/src/context/mocks/delegations.tsx | 2 ++ .../types/rust/DelegationWithEverything.ts | 3 ++- 7 files changed, 48 insertions(+), 23 deletions(-) diff --git a/common/types/src/delegation.rs b/common/types/src/delegation.rs index 550f17a261..e98c56fd40 100644 --- a/common/types/src/delegation.rs +++ b/common/types/src/delegation.rs @@ -50,7 +50,7 @@ pub struct DelegationWithEverything { pub accumulated_by_delegates: Option, pub accumulated_by_operator: Option, pub block_height: u64, - pub delegated_on_iso_datetime: String, + pub delegated_on_iso_datetime: Option, pub cost_params: Option, pub avg_uptime_percent: Option, @@ -60,6 +60,8 @@ pub struct DelegationWithEverything { pub uses_vesting_contract_tokens: bool, pub unclaimed_rewards: Option, + pub errors: Option, + // DEPRECATED, IF POSSIBLE TRY TO DISCONTINUE USE OF IT! pub pending_events: Vec, pub mixnode_is_unbonding: Option, diff --git a/nym-wallet/src-tauri/src/error.rs b/nym-wallet/src-tauri/src/error.rs index b89ecd1fd5..7f542d257c 100644 --- a/nym-wallet/src-tauri/src/error.rs +++ b/nym-wallet/src-tauri/src/error.rs @@ -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 { diff --git a/nym-wallet/src-tauri/src/operations/mixnet/delegate.rs b/nym-wallet/src-tauri/src/operations/mixnet/delegate.rs index 6991c058e8..6d4db9d476 100644 --- a/nym-wallet/src-tauri/src/operations/mixnet/delegate.rs +++ b/nym-wallet/src-tauri/src/operations/mixnet/delegate.rs @@ -154,8 +154,6 @@ pub async fn get_all_mix_delegations( ) -> Result, BackendError> { log::info!(">>> Get all mixnode delegations"); - let mut error_strings: Vec = 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 = Vec::with_capacity(delegations.len()); for delegation in delegations { + let mut error_strings: Vec = 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) } diff --git a/nym-wallet/src/components/Delegation/DelegationItem.tsx b/nym-wallet/src/components/Delegation/DelegationItem.tsx index c405c18d83..895124c3c6 100644 --- a/nym-wallet/src/components/Delegation/DelegationItem.tsx +++ b/nym-wallet/src/components/Delegation/DelegationItem.tsx @@ -45,13 +45,22 @@ export const DelegationItem = ({ {nodeIsUnbonded ? ( '-' ) : ( - + <> + {item.errors && ( + {item.errors}}> + + ⚠️ + + + )} + + )} @@ -70,7 +79,7 @@ export const DelegationItem = ({ {getStakeSaturation(item)} - {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')} diff --git a/nym-wallet/src/components/Delegation/DelegationList.stories.tsx b/nym-wallet/src/components/Delegation/DelegationList.stories.tsx index 9683d268ca..4b24a3dcfe 100644 --- a/nym-wallet/src/components/Delegation/DelegationList.stories.tsx +++ b/nym-wallet/src/components/Delegation/DelegationList.stories.tsx @@ -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, }, ]; diff --git a/nym-wallet/src/context/mocks/delegations.tsx b/nym-wallet/src/context/mocks/delegations.tsx index 2a9609b022..23cb1929a7 100644 --- a/nym-wallet/src/context/mocks/delegations.tsx +++ b/nym-wallet/src/context/mocks/delegations.tsx @@ -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, }, ]; diff --git a/ts-packages/types/src/types/rust/DelegationWithEverything.ts b/ts-packages/types/src/types/rust/DelegationWithEverything.ts index ecf949c5ae..7071f291dd 100644 --- a/ts-packages/types/src/types/rust/DelegationWithEverything.ts +++ b/ts-packages/types/src/types/rust/DelegationWithEverything.ts @@ -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; mixnode_is_unbonding: boolean | null; + errors: string | null; }