Skip to content

Commit 7b782b7

Browse files
committed
[CVW-040] Feat, 환율정보 불러오기 에러처리
1 parent 4f086fa commit 7b782b7

File tree

1 file changed

+27
-29
lines changed

1 file changed

+27
-29
lines changed

Projects/Features/Root/Feature/Sources/RootViewModel.swift

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,13 @@ final class RootViewModel: UDFObservableObject, RootViewModelable {
7676
if isFirstAppear {
7777
isFirstAppear = false
7878

79-
// 화면 최초 등장시 1초간의 지연 발생
80-
return Just(Action.appIsLoaded)
81-
.unretained(self)
82-
.asyncTransform { vm, action in
83-
await vm.prepareExchangeRate()
84-
return action
85-
}
86-
.delay(for: 1, scheduler: RunLoop.main)
87-
.eraseToAnyPublisher()
79+
// 환율 정보 가져오기
80+
prepareExchangeRate()
8881
}
82+
case .appIsLoaded:
83+
return Just(action)
84+
.delay(for: 1, scheduler: DispatchQueue.main)
85+
.eraseToAnyPublisher()
8986
default:
9087
break
9188
}
@@ -111,27 +108,28 @@ final class RootViewModel: UDFObservableObject, RootViewModelable {
111108

112109
// MARK: Exchange rate
113110
private extension RootViewModel {
114-
func prepareExchangeRate() async {
115-
do {
116-
try await useCase.prepareExchangeRate()
117-
} catch {
118-
var alertModel = AlertModel(
119-
titleKey: TextKey.Alert.Title.exchangeRateError.rawValue,
120-
messageKey: TextKey.Alert.Message.failedToGetExchangerate.rawValue
121-
)
122-
alertModel.add(action: .init(
123-
titleKey: TextKey.Alert.ActionTitle.retry.rawValue
124-
) {
125-
Task { [weak self] in
111+
func prepareExchangeRate() {
112+
Task {
113+
do {
114+
try await useCase.prepareExchangeRate()
115+
action.send(.appIsLoaded)
116+
} catch {
117+
var alertModel = AlertModel(
118+
titleKey: TextKey.Alert.Title.exchangeRateError.rawValue,
119+
messageKey: TextKey.Alert.Message.failedToGetExchangerate.rawValue
120+
)
121+
alertModel.add(action: .init(
122+
titleKey: TextKey.Alert.ActionTitle.retry.rawValue
123+
) { [weak self] in
126124
guard let self else { return }
127-
await prepareExchangeRate()
128-
}
129-
})
130-
alertModel.add(action: .init(
131-
titleKey: TextKey.Alert.ActionTitle.ignore.rawValue,
132-
role: .cancel
133-
))
134-
alertShooter.shoot(alertModel)
125+
prepareExchangeRate()
126+
})
127+
alertModel.add(action: .init(
128+
titleKey: TextKey.Alert.ActionTitle.ignore.rawValue,
129+
role: .cancel
130+
))
131+
alertShooter.shoot(alertModel)
132+
}
135133
}
136134
}
137135
}

0 commit comments

Comments
 (0)