From 2fd140a7def4395ca779da5d2688a88f88df58c3 Mon Sep 17 00:00:00 2001
From: Bruno Muniz Azevedo Filho <bruno@elixxir.io>
Date: Tue, 13 Dec 2022 00:03:36 -0300
Subject: [PATCH] Fix bug w/ input current value subject

---
 Sources/ContactFeature/Controllers/NicknameController.swift | 6 ++++--
 Sources/ContactFeature/ViewModels/NicknameViewModel.swift   | 3 +--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/Sources/ContactFeature/Controllers/NicknameController.swift b/Sources/ContactFeature/Controllers/NicknameController.swift
index 1eb0dc07..154b801f 100644
--- a/Sources/ContactFeature/Controllers/NicknameController.swift
+++ b/Sources/ContactFeature/Controllers/NicknameController.swift
@@ -52,8 +52,10 @@ public final class NicknameController: UIViewController {
       .saveButton
       .publisher(for: .touchUpInside)
       .sink { [unowned self] in
-        dismiss(animated: true)
-        completion(viewModel.getInput())
+        dismiss(animated: true) { [weak self] in
+          guard let self else { return }
+          self.completion(self.viewModel.getInput())
+        }
       }.store(in: &cancellables)
   }
 }
diff --git a/Sources/ContactFeature/ViewModels/NicknameViewModel.swift b/Sources/ContactFeature/ViewModels/NicknameViewModel.swift
index 801a5865..f84d82a8 100644
--- a/Sources/ContactFeature/ViewModels/NicknameViewModel.swift
+++ b/Sources/ContactFeature/ViewModels/NicknameViewModel.swift
@@ -26,8 +26,7 @@ final class NicknameViewModel {
   }
 
   func didInput(_ string: String) {
-    let input = stateSubject.value.input
-      .trimmingCharacters(in: .whitespacesAndNewlines)
+    let input = string.trimmingCharacters(in: .whitespacesAndNewlines)
 
     stateSubject.value.input = input
     stateSubject.value.status = input.count >= 1 ?
-- 
GitLab