diff --git a/Sources/AllInApp/AllIn/Components/ReviewCard.swift b/Sources/AllInApp/AllIn/Components/ReviewCard.swift index 34a5612..0521c32 100644 --- a/Sources/AllInApp/AllIn/Components/ReviewCard.swift +++ b/Sources/AllInApp/AllIn/Components/ReviewCard.swift @@ -81,7 +81,7 @@ struct ReviewCard: View { .onTapGesture { showDetails.toggle() }.fullScreenCover(isPresented: $showDetails) { - DetailsView(isModalPresented: $showDetails, isModalParticipated: $showPartipated, id: "1") + DetailsView(isModalPresented: $showDetails, isModalParticipated: $showPartipated, id: betDetail.bet.id) } } } diff --git a/Sources/AllInApp/AllIn/Views/BetEndingValidationView.swift b/Sources/AllInApp/AllIn/Views/BetEndingValidationView.swift index f8c5e15..a3949d5 100644 --- a/Sources/AllInApp/AllIn/Views/BetEndingValidationView.swift +++ b/Sources/AllInApp/AllIn/Views/BetEndingValidationView.swift @@ -76,6 +76,7 @@ struct BetEndingValidationView: View { Spacer() Button { dismiss() + viewModel.post() } label: { Text("Valider") .font(.system(size: 23)) diff --git a/Sources/AllInApp/AllIn/Views/DetailsView.swift b/Sources/AllInApp/AllIn/Views/DetailsView.swift index 7a91b51..70bb1c3 100644 --- a/Sources/AllInApp/AllIn/Views/DetailsView.swift +++ b/Sources/AllInApp/AllIn/Views/DetailsView.swift @@ -17,10 +17,8 @@ struct DetailsView: View { switch betType { case .inProgress: return ("En cours...", AllInColors.darkPurpleColor) - case .waiting: + case .waiting, .closing: return ("En attente...", AllInColors.pink100) - case .closing: - return ("Fin des inscriptions...", AllInColors.grey50Color) case .finished: return ("Terminé", AllInColors.grey100Color) case .cancelled: diff --git a/Sources/Api/Sources/Api/Factory/FactoryApiBet.swift b/Sources/Api/Sources/Api/Factory/FactoryApiBet.swift index 952e3aa..2b45c9d 100644 --- a/Sources/Api/Sources/Api/Factory/FactoryApiBet.swift +++ b/Sources/Api/Sources/Api/Factory/FactoryApiBet.swift @@ -106,7 +106,17 @@ public class FactoryApiBet: FactoryBet { } } - return BetDetail(bet: bet, answers: [], participations: participations) + var answers: [AnswerDetail] = [] + + if let answersJson = json["answers"] as? [[String: Any]], !answersJson.isEmpty { + for answer in answersJson { + if let answer = self.toAnswer(from: answer) { + answers.append(answer) + } + } + } + + return BetDetail(bet: bet, answers: answers, participations: participations) } public func toParticipate(from json: [String: Any]) -> Participation? { @@ -121,6 +131,18 @@ public class FactoryApiBet: FactoryBet { return Participation(id: id, stake: stake, date: Date(), response: answer, user: User(username: username, email: "Email", nbCoins: 0, friends: []), betId: betId) } + public func toAnswer(from json: [String: Any]) -> AnswerDetail? { + guard let response = json["response"] as? String, + let totalStakes = json["totalStakes"] as? Int, + let totalParticipants = json["totalParticipants"] as? Int, + let highestStake = json["highestStake"] as? Int, + let odds = json["odds"] as? Float else { + return nil + } + + return AnswerDetail(response: response, totalStakes: totalStakes, totalParticipants: totalParticipants, highestStake: highestStake, odds: odds) + } + public func betTypeString(fromType type: String) -> String { switch type { case "BinaryBet": diff --git a/Sources/Api/Sources/Api/UserApiManager.swift b/Sources/Api/Sources/Api/UserApiManager.swift index 088dd91..267bf16 100644 --- a/Sources/Api/Sources/Api/UserApiManager.swift +++ b/Sources/Api/Sources/Api/UserApiManager.swift @@ -38,7 +38,6 @@ public struct UserApiManager: UserDataManager { do { if let httpResponse = response as? HTTPURLResponse, let jsonArray = try JSONSerialization.jsonObject(with: data, options: []) as? [[String: Any]] { for json in jsonArray { - print(json) if let bet = FactoryApiBet().toBetDetail(from: json) { bets.append(bet) } @@ -123,6 +122,7 @@ public struct UserApiManager: UserDataManager { do { if let httpResponse = response as? HTTPURLResponse, let jsonArray = try JSONSerialization.jsonObject(with: data, options: []) as? [[String: Any]] { for json in jsonArray { + print(json) if let bet = FactoryApiBet().toBet(from: json) { bets.append(bet) }