From 2ad875949fe87bb60bcbb09e0cd5730d5bae9917 Mon Sep 17 00:00:00 2001 From: Nico <60229704+Marchand-Nicolas@users.noreply.github.com> Date: Thu, 31 Oct 2024 00:14:49 +0100 Subject: [PATCH] fix: hiding vesu when 0 rewards --- src/endpoints/defi/rewards.rs | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/endpoints/defi/rewards.rs b/src/endpoints/defi/rewards.rs index 75639cd..108405c 100644 --- a/src/endpoints/defi/rewards.rs +++ b/src/endpoints/defi/rewards.rs @@ -1,7 +1,7 @@ use crate::{ models::{ AppState, CommonReward, ContractCall, DefiReward, EkuboRewards, NimboraRewards, - NostraPeriodsResponse, NostraResponse, RewardSource, ZkLendReward, VesuRewards + NostraPeriodsResponse, NostraResponse, RewardSource, VesuRewards, ZkLendReward, }, utils::{check_if_claimed, read_contract, to_hex, to_hex_trimmed}, }; @@ -332,23 +332,32 @@ async fn fetch_vesu_rewards( state: &AppState, ) -> Result, Error> { let vesu_url = format!("https://staging.api.vesu.xyz/users/{}/strk-rewards", addr); - let response = client - .get(&vesu_url) - .headers(get_headers()) - .send() - .await?; - - + let response = client.get(&vesu_url).headers(get_headers()).send().await?; match response.json::().await { Ok(result) => { let strk_token = state.conf.tokens.strk.clone(); let config = &state.conf; - let disctributed_amount : u64 = result.data.distributor_data.distributed_amount.parse().expect("Failed to parse string to integer"); - let claimed_amount : u64 = result.data.distributor_data.claimed_amount.parse().expect("Failed to parse string to integer"); + let disctributed_amount: u64 = result + .data + .distributor_data + .distributed_amount + .parse() + .expect("Failed to parse string to integer"); + let claimed_amount: u64 = result + .data + .distributor_data + .claimed_amount + .parse() + .expect("Failed to parse string to integer"); let amount = disctributed_amount - claimed_amount; + // If amount is 0, return empty vector + if amount == 0 { + return Ok(vec![]); + } + let reward = CommonReward { amount: amount.into(), displayed_amount: amount.into(),