From c564215328f155960f548e0e230914ea895bbe35 Mon Sep 17 00:00:00 2001 From: Lukas Korba <62649321+lukaskorba-indiedev@users.noreply.github.com> Date: Thu, 17 Feb 2022 14:42:16 +0100 Subject: [PATCH 1/5] Enhancement of the clamping the index for the seed --- secant.xcodeproj/project.pbxproj | 4 ++++ secant/UIComponents/Chips/EnumeratedChip.swift | 2 +- secant/Util/SeedIndex.swift | 13 +++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 secant/Util/SeedIndex.swift diff --git a/secant.xcodeproj/project.pbxproj b/secant.xcodeproj/project.pbxproj index 12df63f..412d249 100644 --- a/secant.xcodeproj/project.pbxproj +++ b/secant.xcodeproj/project.pbxproj @@ -71,6 +71,7 @@ 66A0807B271993C500118B79 /* OnboardingProgressIndicator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66A0807A271993C500118B79 /* OnboardingProgressIndicator.swift */; }; 66D50668271D9B6100E51F0D /* NavigationButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66D50667271D9B6100E51F0D /* NavigationButtonStyle.swift */; }; 66DC733F271D88CC0053CBB6 /* StandardButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66DC733E271D88CC0053CBB6 /* StandardButtonStyle.swift */; }; + 9E06EFF027BE87BA001E3A08 /* SeedIndex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E06EFEF27BE87BA001E3A08 /* SeedIndex.swift */; }; F9322DC0273B555C00C105B5 /* NavigationLinks.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9322DBF273B555C00C105B5 /* NavigationLinks.swift */; }; F93673D62742CB840099C6AF /* Previews.swift in Sources */ = {isa = PBXBuildFile; fileRef = F93673D52742CB840099C6AF /* Previews.swift */; }; F93874F0273C4DE200F0E875 /* HomeStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = F93874ED273C4DE200F0E875 /* HomeStore.swift */; }; @@ -188,6 +189,7 @@ 66A0807A271993C500118B79 /* OnboardingProgressIndicator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingProgressIndicator.swift; sourceTree = ""; }; 66D50667271D9B6100E51F0D /* NavigationButtonStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationButtonStyle.swift; sourceTree = ""; }; 66DC733E271D88CC0053CBB6 /* StandardButtonStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StandardButtonStyle.swift; sourceTree = ""; }; + 9E06EFEF27BE87BA001E3A08 /* SeedIndex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeedIndex.swift; sourceTree = ""; }; F9322DBF273B555C00C105B5 /* NavigationLinks.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationLinks.swift; sourceTree = ""; }; F93673D52742CB840099C6AF /* Previews.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Previews.swift; sourceTree = ""; }; F93874ED273C4DE200F0E875 /* HomeStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HomeStore.swift; sourceTree = ""; }; @@ -439,6 +441,7 @@ F9C165B3274031F600592F76 /* Bindings.swift */, F9EEB8152742C2210032EEB8 /* WithStateBinding.swift */, F93673D52742CB840099C6AF /* Previews.swift */, + 9E06EFEF27BE87BA001E3A08 /* SeedIndex.swift */, ); path = Util; sourceTree = ""; @@ -978,6 +981,7 @@ 0D3D040A2728B3A10032ABC1 /* RecoveryPhraseDisplayStore.swift in Sources */, 0D4E7A0B26B364170058B01E /* ContentView.swift in Sources */, 0D354A0926D5A9D000315F45 /* Services.swift in Sources */, + 9E06EFF027BE87BA001E3A08 /* SeedIndex.swift in Sources */, 660558F7270C862F009D6954 /* Fonts+Generated.swift in Sources */, F96B41E7273B501F0021B49A /* TransactionHistoryStore.swift in Sources */, F9971A5A27680DDE00A2DB75 /* RequestView.swift in Sources */, diff --git a/secant/UIComponents/Chips/EnumeratedChip.swift b/secant/UIComponents/Chips/EnumeratedChip.swift index 5252f01..071a719 100644 --- a/secant/UIComponents/Chips/EnumeratedChip.swift +++ b/secant/UIComponents/Chips/EnumeratedChip.swift @@ -8,7 +8,7 @@ import SwiftUI struct EnumeratedChip: View { - @Clamped(1...24) + @SeedIndex var index: Int = 1 var text: String diff --git a/secant/Util/SeedIndex.swift b/secant/Util/SeedIndex.swift new file mode 100644 index 0000000..c2a2479 --- /dev/null +++ b/secant/Util/SeedIndex.swift @@ -0,0 +1,13 @@ +// +// SeedIndex.swift +// secant-testnet +// +// Created by Lukáš Korba on 17.02.2022. +// + +@propertyWrapper +struct SeedIndex { + var wrappedValue: Int { + didSet { wrappedValue = min(24, max(1, wrappedValue)) } + } +} From 44a9d4ffad206a567c7aedf1b820f66c4deecdd5 Mon Sep 17 00:00:00 2001 From: Lukas Korba <62649321+lukaskorba-indiedev@users.noreply.github.com> Date: Fri, 18 Feb 2022 07:06:32 +0100 Subject: [PATCH 2/5] Modification of Clamped property So it's no longer out of the bounds. This was the case when initialised property has never been modified = set was never called --- secant.xcodeproj/project.pbxproj | 4 ---- secant/UIComponents/Chips/EnumeratedChip.swift | 2 +- secant/Util/Clamped.swift | 8 ++++---- secant/Util/SeedIndex.swift | 13 ------------- 4 files changed, 5 insertions(+), 22 deletions(-) delete mode 100644 secant/Util/SeedIndex.swift diff --git a/secant.xcodeproj/project.pbxproj b/secant.xcodeproj/project.pbxproj index 412d249..12df63f 100644 --- a/secant.xcodeproj/project.pbxproj +++ b/secant.xcodeproj/project.pbxproj @@ -71,7 +71,6 @@ 66A0807B271993C500118B79 /* OnboardingProgressIndicator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66A0807A271993C500118B79 /* OnboardingProgressIndicator.swift */; }; 66D50668271D9B6100E51F0D /* NavigationButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66D50667271D9B6100E51F0D /* NavigationButtonStyle.swift */; }; 66DC733F271D88CC0053CBB6 /* StandardButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66DC733E271D88CC0053CBB6 /* StandardButtonStyle.swift */; }; - 9E06EFF027BE87BA001E3A08 /* SeedIndex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E06EFEF27BE87BA001E3A08 /* SeedIndex.swift */; }; F9322DC0273B555C00C105B5 /* NavigationLinks.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9322DBF273B555C00C105B5 /* NavigationLinks.swift */; }; F93673D62742CB840099C6AF /* Previews.swift in Sources */ = {isa = PBXBuildFile; fileRef = F93673D52742CB840099C6AF /* Previews.swift */; }; F93874F0273C4DE200F0E875 /* HomeStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = F93874ED273C4DE200F0E875 /* HomeStore.swift */; }; @@ -189,7 +188,6 @@ 66A0807A271993C500118B79 /* OnboardingProgressIndicator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingProgressIndicator.swift; sourceTree = ""; }; 66D50667271D9B6100E51F0D /* NavigationButtonStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationButtonStyle.swift; sourceTree = ""; }; 66DC733E271D88CC0053CBB6 /* StandardButtonStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StandardButtonStyle.swift; sourceTree = ""; }; - 9E06EFEF27BE87BA001E3A08 /* SeedIndex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeedIndex.swift; sourceTree = ""; }; F9322DBF273B555C00C105B5 /* NavigationLinks.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationLinks.swift; sourceTree = ""; }; F93673D52742CB840099C6AF /* Previews.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Previews.swift; sourceTree = ""; }; F93874ED273C4DE200F0E875 /* HomeStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HomeStore.swift; sourceTree = ""; }; @@ -441,7 +439,6 @@ F9C165B3274031F600592F76 /* Bindings.swift */, F9EEB8152742C2210032EEB8 /* WithStateBinding.swift */, F93673D52742CB840099C6AF /* Previews.swift */, - 9E06EFEF27BE87BA001E3A08 /* SeedIndex.swift */, ); path = Util; sourceTree = ""; @@ -981,7 +978,6 @@ 0D3D040A2728B3A10032ABC1 /* RecoveryPhraseDisplayStore.swift in Sources */, 0D4E7A0B26B364170058B01E /* ContentView.swift in Sources */, 0D354A0926D5A9D000315F45 /* Services.swift in Sources */, - 9E06EFF027BE87BA001E3A08 /* SeedIndex.swift in Sources */, 660558F7270C862F009D6954 /* Fonts+Generated.swift in Sources */, F96B41E7273B501F0021B49A /* TransactionHistoryStore.swift in Sources */, F9971A5A27680DDE00A2DB75 /* RequestView.swift in Sources */, diff --git a/secant/UIComponents/Chips/EnumeratedChip.swift b/secant/UIComponents/Chips/EnumeratedChip.swift index 071a719..5252f01 100644 --- a/secant/UIComponents/Chips/EnumeratedChip.swift +++ b/secant/UIComponents/Chips/EnumeratedChip.swift @@ -8,7 +8,7 @@ import SwiftUI struct EnumeratedChip: View { - @SeedIndex + @Clamped(1...24) var index: Int = 1 var text: String diff --git a/secant/Util/Clamped.swift b/secant/Util/Clamped.swift index 2b19ef8..9bf8642 100644 --- a/secant/Util/Clamped.swift +++ b/secant/Util/Clamped.swift @@ -15,13 +15,13 @@ struct Clamped { var value: Value let range: ClosedRange var wrappedValue: Value { - get { value } - set { - value = min( - max(range.lowerBound, newValue), + get { + min( + max(range.lowerBound, value), range.upperBound ) } + set { value = newValue } } init(wrappedValue: Value, _ range: ClosedRange) { diff --git a/secant/Util/SeedIndex.swift b/secant/Util/SeedIndex.swift deleted file mode 100644 index c2a2479..0000000 --- a/secant/Util/SeedIndex.swift +++ /dev/null @@ -1,13 +0,0 @@ -// -// SeedIndex.swift -// secant-testnet -// -// Created by Lukáš Korba on 17.02.2022. -// - -@propertyWrapper -struct SeedIndex { - var wrappedValue: Int { - didSet { wrappedValue = min(24, max(1, wrappedValue)) } - } -} From 895a43376dad33399df2d915732d7a59caa868f5 Mon Sep 17 00:00:00 2001 From: Lukas Korba <62649321+lukaskorba-indiedev@users.noreply.github.com> Date: Fri, 18 Feb 2022 07:17:10 +0100 Subject: [PATCH 3/5] Optimised version of Clamped --- secant/Util/Clamped.swift | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/secant/Util/Clamped.swift b/secant/Util/Clamped.swift index 9bf8642..5d6b309 100644 --- a/secant/Util/Clamped.swift +++ b/secant/Util/Clamped.swift @@ -15,17 +15,18 @@ struct Clamped { var value: Value let range: ClosedRange var wrappedValue: Value { - get { - min( - max(range.lowerBound, value), - range.upperBound - ) - } - set { value = newValue } + get { value } + set { value = clamp(value: newValue, range: range) } } init(wrappedValue: Value, _ range: ClosedRange) { self.value = wrappedValue self.range = range + + value = clamp(value: wrappedValue, range: range) + } + + private func clamp(value: Value, range: ClosedRange) -> Value { + min(range.upperBound, max(range.lowerBound, wrappedValue)) } } From ad92c8be263fb2103ef8a6a5cc920873f87d6fc2 Mon Sep 17 00:00:00 2001 From: Lukas Korba Date: Fri, 18 Feb 2022 15:26:42 +0100 Subject: [PATCH 4/5] Update secant/Util/Clamped.swift Co-authored-by: Adam --- secant/Util/Clamped.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/secant/Util/Clamped.swift b/secant/Util/Clamped.swift index 5d6b309..9f62dd7 100644 --- a/secant/Util/Clamped.swift +++ b/secant/Util/Clamped.swift @@ -26,7 +26,7 @@ struct Clamped { value = clamp(value: wrappedValue, range: range) } - private func clamp(value: Value, range: ClosedRange) -> Value { + private func clamp(_ value: Value, using range: ClosedRange) -> Value { min(range.upperBound, max(range.lowerBound, wrappedValue)) } } From c6b84d48f64f49d99abfb81a349083e13e65a056 Mon Sep 17 00:00:00 2001 From: Lukas Korba <62649321+lukaskorba-indiedev@users.noreply.github.com> Date: Fri, 18 Feb 2022 15:33:40 +0100 Subject: [PATCH 5/5] Update of the func signature --- secant/Util/Clamped.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/secant/Util/Clamped.swift b/secant/Util/Clamped.swift index 9f62dd7..52331ed 100644 --- a/secant/Util/Clamped.swift +++ b/secant/Util/Clamped.swift @@ -16,14 +16,14 @@ struct Clamped { let range: ClosedRange var wrappedValue: Value { get { value } - set { value = clamp(value: newValue, range: range) } + set { value = clamp(newValue, using: range) } } init(wrappedValue: Value, _ range: ClosedRange) { self.value = wrappedValue self.range = range - value = clamp(value: wrappedValue, range: range) + value = clamp(wrappedValue, using: range) } private func clamp(_ value: Value, using range: ClosedRange) -> Value {