From 94fa2b3975d9c2a33551ec8cad10e49138101b69 Mon Sep 17 00:00:00 2001 From: Terry Yiu <963907+tyiu@users.noreply.github.com> Date: Mon, 2 Sep 2024 01:01:02 +0300 Subject: [PATCH] Prevent most recent inputted amounts to be implicitly overwritten by calculations --- Sources/SatsPrice/SatsViewModel.swift | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Sources/SatsPrice/SatsViewModel.swift b/Sources/SatsPrice/SatsViewModel.swift index 13a0cf7..be6977a 100644 --- a/Sources/SatsPrice/SatsViewModel.swift +++ b/Sources/SatsPrice/SatsViewModel.swift @@ -25,6 +25,10 @@ class SatsViewModel: ObservableObject { btcToUsdStringInternal } set { + guard btcToUsdStringInternal != newValue else { + return + } + btcToUsdStringInternal = newValue if let btc, let btcToUsd { @@ -40,6 +44,10 @@ class SatsViewModel: ObservableObject { satsStringInternal } set { + guard satsStringInternal != newValue else { + return + } + satsStringInternal = newValue if let sats { @@ -66,6 +74,10 @@ class SatsViewModel: ObservableObject { btcStringInternal } set { + guard btcStringInternal != newValue else { + return + } + btcStringInternal = newValue if let btc { @@ -89,6 +101,10 @@ class SatsViewModel: ObservableObject { usdStringInternal } set { + guard usdStringInternal != newValue else { + return + } + usdStringInternal = newValue if let usd {