final banner now working and bind with the wonparticipation on the betdetail

fix/final-view-detail
Lucas DELANIER 8 months ago
parent e1c8d85dd1
commit 7a41d5379f

@ -6,26 +6,29 @@
// //
import SwiftUI import SwiftUI
import Model
struct ResultBanner: View { struct ResultBanner: View {
var finalAnswer: Participation
var odds: Float
var body: some View { var body: some View {
VStack{ VStack{
HStack{ HStack{
Image("BleueTrophyIcon").resizable().frame(maxWidth: 70, maxHeight: 60) Image(systemName: "trophy.fill").resizable().frame(maxWidth: 70, maxHeight: 60).foregroundColor(AllInColors.blueGrey800Color)
Text("OUI").font(.system(size: 70)).fontWeight(.bold).foregroundStyle(AllInColors.blueGrey800Color) Text(finalAnswer.answer).font(.system(size: 70)).fontWeight(.bold).foregroundStyle(AllInColors.blueGrey800Color)
}.frame(height: 80) }.frame(height: 80)
HStack(spacing: 20){ HStack(spacing: 20){
HStack{ HStack{
Image("BlueAllCoinIcon").resizable().frame(maxWidth: 12, maxHeight: 12) Image("BlueAllCoinIcon").resizable().frame(maxWidth: 12, maxHeight: 12)
Text("460").font(.system(size: 16)).fontWeight(.semibold).foregroundStyle(AllInColors.blueGrey800Color) Text(finalAnswer.stake.description).font(.system(size: 16)).fontWeight(.semibold).foregroundStyle(AllInColors.blueGrey800Color)
} }
HStack{ HStack{
Image("BleuePersonIcon").resizable().frame(maxWidth: 15, maxHeight: 12) Image("BleuePersonIcon").resizable().frame(maxWidth: 15, maxHeight: 12)
Text("ImriDu43").font(.system(size: 16)).fontWeight(.semibold).foregroundStyle(AllInColors.blueGrey800Color) Text(finalAnswer.username).font(.system(size: 16)).fontWeight(.semibold).foregroundStyle(AllInColors.blueGrey800Color)
} }
HStack{ HStack{
Image("BleueTrophyIcon").resizable().frame(maxWidth: 15, maxHeight: 12) Image("BleueTrophyIcon").resizable().frame(maxWidth: 15, maxHeight: 12)
Text("x1.2").font(.system(size: 16)).fontWeight(.semibold).foregroundStyle(AllInColors.blueGrey800Color) Text(odds.description).font(.system(size: 16)).fontWeight(.semibold).foregroundStyle(AllInColors.blueGrey800Color)
} }
} }
} }

@ -9,7 +9,7 @@ struct DetailsView: View {
@StateObject private var viewModel: DetailsViewModel @StateObject private var viewModel: DetailsViewModel
var isFinished: Bool { var isFinished: Bool {
viewModel.betDetail?.finalAnswer == nil ? false : true viewModel.betDetail?.wonParticipation == nil ? false : true
} }
var StatusValues: (String, Color) { var StatusValues: (String, Color) {
@ -111,7 +111,7 @@ struct DetailsView: View {
.cornerRadius(20, corners: [.topLeft,.topRight]).padding(.bottom,0) .cornerRadius(20, corners: [.topLeft,.topRight]).padding(.bottom,0)
if isFinished { if isFinished {
ResultBanner() ResultBanner(finalAnswer: (viewModel.betDetail?.wonParticipation)!, odds: (viewModel.betDetail?.odds)!)
} }
VStack(alignment: .leading, spacing: 5) { VStack(alignment: .leading, spacing: 5) {
BetLineLoading(participations: viewModel.betDetail?.participations ?? []) BetLineLoading(participations: viewModel.betDetail?.participations ?? [])

@ -60,6 +60,8 @@ public class FactoryApiBet: FactoryBet {
} }
var participations: [Participation] = [] var participations: [Participation] = []
var wonParticipation: Participation?
var userParticipation: Participation?
if let participationsJson = json["participations"] as? [[String: Any]] { if let participationsJson = json["participations"] as? [[String: Any]] {
do { do {
@ -79,7 +81,22 @@ public class FactoryApiBet: FactoryBet {
} }
} }
return BetDetail(bet: bet, answers: answers, participations: participations) if let participationJson = json["wonParticipation"] as? [String: Any] {
do {
wonParticipation = try JSONDecoder().decode(Participation.self, from: JSONSerialization.data(withJSONObject: participationJson))
} catch {
print("Error decoding participations: \(error)")
}
}
if let participationUserJson = json["userParticipation"] as? [String: Any] {
do {
userParticipation = try JSONDecoder().decode(Participation.self, from: JSONSerialization.data(withJSONObject: participationUserJson))
} catch {
print("Error decoding participations: \(error)")
}
}
return BetDetail(bet: bet, answers: answers, participations: participations, wonParticipation: wonParticipation, userParticipation: userParticipation)
} }
public func betTypeString(fromType type: String) -> String { public func betTypeString(fromType type: String) -> String {

@ -20,7 +20,19 @@ public class BetDetail: ObservableObject {
public private(set) var participations: [Participation] public private(set) var participations: [Participation]
/// The final answer selected for the bet, if available. /// The final answer selected for the bet, if available.
public private(set) var finalAnswer: String? public private(set) var wonParticipation: Participation?
public private(set) var userParticipation: Participation?
public var odds: Float? {
guard let wonParticipation = self.wonParticipation else {
return nil
}
if let matchingAnswer = self.answers.first(where: { $0.response == wonParticipation.answer }) {
return matchingAnswer.odds
} else {
return nil
}
}
/// Custom Constructor /// Custom Constructor
/// ///
@ -29,18 +41,19 @@ public class BetDetail: ObservableObject {
/// - answers: Details about the answers available for the bet. /// - answers: Details about the answers available for the bet.
/// - participations: List of user participations in the bet. /// - participations: List of user participations in the bet.
/// - finalAnswer: The final answer selected for the bet, if available. /// - finalAnswer: The final answer selected for the bet, if available.
public init(bet: Bet, answers: [AnswerDetail], participations: [Participation], finalAnswer: String? = nil) { public init(bet: Bet, answers: [AnswerDetail], participations: [Participation], wonParticipation: Participation? = nil, userParticipation: Participation? = nil) {
self.bet = bet self.bet = bet
self.answers = answers self.answers = answers
self.participations = participations self.participations = participations
self.finalAnswer = finalAnswer self.wonParticipation = wonParticipation
self.userParticipation = userParticipation
} }
/// Updates the final answer selected for the bet. /// Updates the final answer selected for the bet.
/// ///
/// - Parameter newFinalAnswer: The new final answer for the bet. /// - Parameter newFinalAnswer: The new final answer for the bet.
public func updateFinalAnswer(newFinalAnswer: String) { public func updateFinalAnswer(wonParticipation: Participation) {
self.finalAnswer = newFinalAnswer self.wonParticipation = wonParticipation
} }
/// Adds a new user participation to the list of participations for the bet. /// Adds a new user participation to the list of participations for the bet.

@ -95,7 +95,7 @@ struct Stub {
} }
public mutating func add(bet: Bet) { public mutating func add(bet: Bet) {
let newBetDetail = BetDetail(bet: bet, answers: [], participations: [], finalAnswer: "test") let newBetDetail = BetDetail(bet: bet, answers: [], participations: [])
self.betsDetail.append(newBetDetail) self.betsDetail.append(newBetDetail)
} }
} }

Loading…
Cancel
Save