Skip to content

Commit cf79775

Browse files
committed
Remove the duplicated PnL text in perpetual position details
- position_details built the PnL text and tone by hand, repeating pnl_text; 9d04595 had to apply the same initial-margin fix in both places. It now calls pnl_text, whose tone is GemValueTone::of(pnl) as before. - security transaction scan tests compared a bool with assert_eq!, which fails workspace clippy (bool_assert_comparison).
1 parent f8d68fd commit cf79775

2 files changed

Lines changed: 4 additions & 10 deletions

File tree

‎core/crates/security/src/transaction_scan/evaluate.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ mod tests {
138138

139139
assert_eq!(result.scan.is_malicious, Some(true));
140140
assert_eq!(result.scan.malicious_website.as_deref(), Some("https://bnbdaily.finance/path"));
141-
assert_eq!(result.scan.is_scan_complete, true);
141+
assert!(result.scan.is_scan_complete);
142142
assert_eq!(result.detections[0].provider, ScanProvider::Internal);
143143
assert_eq!(result.new_verdicts, vec![]);
144144
}
@@ -150,7 +150,7 @@ mod tests {
150150

151151
let unmatched = evaluate_transaction_scan(&input, plan_transaction_scan(&input, &HashSet::from([ScanProvider::Internal])), vec![]);
152152
assert_eq!(unmatched.scan.is_malicious, Some(false));
153-
assert_eq!(unmatched.scan.is_scan_complete, false);
153+
assert!(!unmatched.scan.is_scan_complete);
154154

155155
input.payload.website = Some("https://bnbdaily.finance/path".to_string());
156156
let disabled_provider = evaluate_transaction_scan(&input, plan_transaction_scan(&input, &HashSet::new()), vec![]);

‎core/gemstone/src/services/perpetual/rules.rs‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -790,13 +790,7 @@ pub fn details(perpetual: &Perpetual, asset: &Asset, positions: Vec<PerpetualPos
790790
fn position_details(asset: &Asset, position: &PerpetualPosition) -> Vec<GemPerpetualPositionDetail> {
791791
let amount = |title: GemListRowTitle, amount: GemFormattedNumber, info: Option<GemInfoTopic>| GemListRow::Amount { title, amount, info };
792792
let label = |title: GemListRowTitle, text: GemLocalizedText, tone: GemValueTone, info: Option<GemInfoTopic>| GemListRow::Label { title, text, tone, info, progress: false };
793-
let pnl = GemLocalizedText::Pnl {
794-
amount: GemFormattedNumber::signed_usd(position.pnl),
795-
percent: GemFormattedNumber::percentage(
796-
PriceChangeCalculator::pnl_percentage(position.pnl, initial_margin(position.entry_price, position.size, position.leverage)),
797-
GemPercentageStyle::Signed,
798-
),
799-
};
793+
let (pnl, pnl_tone) = pnl_text(position.pnl, initial_margin(position.entry_price, position.size, position.leverage));
800794
let margin = GemLocalizedText::Margin {
801795
amount: GemFormattedNumber::usd(position.margin_amount),
802796
margin_type: position.margin_type.clone(),
@@ -821,7 +815,7 @@ fn position_details(asset: &Asset, position: &PerpetualPosition) -> Vec<GemPerpe
821815
),
822816
};
823817
[
824-
(GemPerpetualPositionDetailRow::Pnl, Some(label(GemListRowTitle::Pnl, pnl, GemValueTone::of(position.pnl), None))),
818+
(GemPerpetualPositionDetailRow::Pnl, Some(label(GemListRowTitle::Pnl, pnl, pnl_tone, None))),
825819
(
826820
GemPerpetualPositionDetailRow::Autoclose,
827821
Some(GemListRow::Lines {

0 commit comments

Comments
 (0)