diff --git a/Sources/AllInApp/AllIn/Assets.xcassets/globeImage.imageset/Contents.json b/Sources/AllInApp/AllIn/Assets.xcassets/globeImage.imageset/Contents.json new file mode 100644 index 0000000..f689ec9 --- /dev/null +++ b/Sources/AllInApp/AllIn/Assets.xcassets/globeImage.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "globe.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Sources/AllInApp/AllIn/Assets.xcassets/globeImage.imageset/globe.png b/Sources/AllInApp/AllIn/Assets.xcassets/globeImage.imageset/globe.png new file mode 100644 index 0000000..bb108f6 Binary files /dev/null and b/Sources/AllInApp/AllIn/Assets.xcassets/globeImage.imageset/globe.png differ diff --git a/Sources/AllInApp/AllIn/Components/Menu.swift b/Sources/AllInApp/AllIn/Components/Menu.swift index e56d245..333901e 100644 --- a/Sources/AllInApp/AllIn/Components/Menu.swift +++ b/Sources/AllInApp/AllIn/Components/Menu.swift @@ -11,24 +11,23 @@ import DependencyInjection struct Menu: View { @Inject var authService: IAuthService - + let parameters: [(String, String, String, String)] = [ ("videoGameImage", String(localized: "drawer_create_a_bet"), String(localized: "drawer_create_a_bet_subtitle"), "CreationBet"), + ("globeImage", String(localized: "drawer_public_bets"), String(localized: "drawer_public_bets_subtitle"), "Bet"), + ("moneyImage", String(localized: "drawer_current_bets"), String(localized: "drawer_current_bets_subtitle"), "Current"), ("eyesImage", String(localized: "drawer_bet_history"), String(localized: "drawer_bet_history_subtitle"),"Historic"), ("friendsImage", String(localized: "drawer_friends"), String(localized: "drawer_friends_subtitle"), "Friends"), - ("moneyImage", String(localized: "drawer_public_bets"), String(localized: "drawer_public_bets_subtitle"), "Bet"), ("rankingImage", String(localized: "drawer_ranking"), String(localized: "drawer_ranking_subtitle"), "Ranking"), - ("eyesImage", String(localized: "drawer_current_bets"), String(localized: "drawer_current_bets_subtitle"), "Current") ] var body: some View { VStack(alignment: .leading, spacing: 10) { - HStack() { Spacer() VStack(){ - UserPicture(username: (AppStateContainer.shared.user?.username)!, size: 100) + UserPicture(picture: AppStateContainer.shared.user?.image, username: (AppStateContainer.shared.user?.username)!,size: 100) Text(AppStateContainer.shared.user?.username.capitalized ?? "") .fontWeight(.medium) .font(.system(size: 17)) diff --git a/Sources/AllInApp/AllIn/Components/ResultBanner.swift b/Sources/AllInApp/AllIn/Components/ResultBanner.swift index 441542f..b29f321 100644 --- a/Sources/AllInApp/AllIn/Components/ResultBanner.swift +++ b/Sources/AllInApp/AllIn/Components/ResultBanner.swift @@ -6,26 +6,29 @@ // import SwiftUI +import Model struct ResultBanner: View { + var finalAnswer: Participation + var odds: Float var body: some View { VStack{ HStack{ - Image("BleueTrophyIcon").resizable().frame(maxWidth: 70, maxHeight: 60) - Text("OUI").font(.system(size: 70)).fontWeight(.bold).foregroundStyle(AllInColors.blueGrey800Color) + Image(systemName: "trophy.fill").resizable().frame(maxWidth: 70, maxHeight: 60).foregroundColor(AllInColors.blueGrey800Color) + Text(finalAnswer.answer).font(.system(size: 70)).fontWeight(.bold).foregroundStyle(AllInColors.blueGrey800Color) }.frame(height: 80) HStack(spacing: 20){ HStack{ 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{ 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{ 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) } } } diff --git a/Sources/AllInApp/AllIn/Components/ReviewCard.swift b/Sources/AllInApp/AllIn/Components/ReviewCard.swift index d42d73f..c1825de 100644 --- a/Sources/AllInApp/AllIn/Components/ReviewCard.swift +++ b/Sources/AllInApp/AllIn/Components/ReviewCard.swift @@ -44,13 +44,27 @@ struct ReviewCard: View { VStack(alignment: .center,spacing:0){ HStack(){ Spacer() - if(betDetail.bet.endBetDate < Date()){ - Text("bet_finished") + if(betDetail.userParticipation != nil){ + Text((betDetail.userParticipation?.stake.description ?? "")) .foregroundColor(.white) .font(.system(size: 25)) .fontWeight(.bold) + Image("allcoinWhiteIcon") + .resizable() + .frame(width: 18, height: 20) } - else{ + switch betDetail.bet.status { + case .waiting, .inProgress: + Text("bet_status_stake") + .foregroundColor(.white) + .font(.system(size: 25)) + .fontWeight(.bold) + case .closing: + Text("bet_status_finished") + .foregroundColor(.white) + .font(.system(size: 25)) + .fontWeight(.bold) + case .finished: Text(amountBetted.description) .foregroundColor(.white) .font(.system(size: 25)) @@ -62,6 +76,11 @@ struct ReviewCard: View { .foregroundColor(.white) .font(.system(size: 25)) .fontWeight(.bold) + case .cancelled: + Text("cancelled") + .foregroundColor(.white) + .font(.system(size: 25)) + .fontWeight(.bold) } Spacer() @@ -72,12 +91,19 @@ struct ReviewCard: View { } .frame(width: .infinity) .padding(.all,2) - .background( - isAWin || betDetail.bet.endBetDate < Date() ? - AnyView(AllInColors.primaryGradient) : - AnyView(Color.black) - ) .cornerRadius(20, corners: [.bottomLeft,.bottomRight]) - .border(width: 1, edges: [.top], color: AllInColors.delimiterGrey) + .background({ + switch betDetail.bet.status { + case .inProgress, .waiting, .closing: + return AllInColors.grey50Color + case .finished: + return Color.black + case .cancelled: + return Color.red + } + }()) + + .cornerRadius(20, corners: [.bottomLeft,.bottomRight]) + .border(width: 1, edges: [.top], color: AllInColors.delimiterGrey) } .onTapGesture { showDetails.toggle() diff --git a/Sources/AllInApp/AllIn/Components/userPicture.swift b/Sources/AllInApp/AllIn/Components/userPicture.swift index 0fc7e81..396f06e 100644 --- a/Sources/AllInApp/AllIn/Components/userPicture.swift +++ b/Sources/AllInApp/AllIn/Components/userPicture.swift @@ -8,14 +8,14 @@ import SwiftUI struct UserPicture: View { - var picture: URL? + var picture: String? var username: String var size: CGFloat var body: some View { ZStack { if picture != nil { AsyncImage( - url: picture, + url: URL(string:picture!), content: { image in image .resizable() diff --git a/Sources/AllInApp/AllIn/Ressources/en.lproj/Localizable.strings b/Sources/AllInApp/AllIn/Ressources/en.lproj/Localizable.strings index 2126be0..09abd58 100644 --- a/Sources/AllInApp/AllIn/Ressources/en.lproj/Localizable.strings +++ b/Sources/AllInApp/AllIn/Ressources/en.lproj/Localizable.strings @@ -46,15 +46,13 @@ "drawer_nb_friends" = "Friends"; "drawer_friends" = "FRIENDS"; "drawer_friends_subtitle" = "Challenge your folks by adding them as friends."; -"drawer_public_bets" = "PUBLIC BETS"; +"drawer_public_bets" = "PARTICIPATE"; "drawer_public_bets_subtitle" = "Browse the most popular bets of the moment."; -"drawer_current_bets" = "CURRENT BETS"; -"drawer_current_bets_subtitle" = "View your current bets."; -"drawer_create_a_bet" = "CREATE A BET"; +"drawer_create_a_bet" = "NEW BET"; "drawer_create_a_bet_subtitle" = "Create a net bet and get your friends participating."; -"drawer_bet_history" = "BET HISTORY"; +"drawer_bet_history" = "HISTORY"; "drawer_bet_history_subtitle" = "View your current and finished bets."; -"drawer_current_bets" = "CURRENT BETS"; +"drawer_current_bets" = "MY PARTICIPATIONS"; "drawer_current_bets_subtitle" = "Manage your bets and reward the winners."; "drawer_ranking" = "RANKING"; "drawer_ranking_subtitle" = "Check your ranking among your friends."; @@ -150,6 +148,7 @@ "bet_status_participants_list" = "Participants"; "bet_status_details_drawer" = "Details"; "participation_possible_winnings" = "Possible winnings"; +"bet_status_stake" = "Gambled"; /// Bet history diff --git a/Sources/AllInApp/AllIn/Ressources/fr.lproj/Localizable.strings b/Sources/AllInApp/AllIn/Ressources/fr.lproj/Localizable.strings index 2d595b1..9934153 100644 --- a/Sources/AllInApp/AllIn/Ressources/fr.lproj/Localizable.strings +++ b/Sources/AllInApp/AllIn/Ressources/fr.lproj/Localizable.strings @@ -28,7 +28,6 @@ "network_error_text" = "Assurez-vous d\'être bien connecté au réseau puis réessayez."; /// Bet type - "bet_type_binary" = "Oui / Non"; "bet_type_match" = "Match sportif"; "bet_type_custom" = "Réponses personnalisées"; @@ -46,15 +45,13 @@ "drawer_nb_friends" = "Amis"; "drawer_friends" = "AMIS"; "drawer_friends_subtitle" = "Défiez vos proches en les ajoutant en amis."; -"drawer_public_bets" = "BETS PUBLIQUES"; +"drawer_public_bets" = "PARTICIPER"; "drawer_public_bets_subtitle" = "Parcourez les bets les plus populaires du moment."; -"drawer_current_bets" = "BETS EN COURS"; -"drawer_current_bets_subtitle" = "Consultez vos paris en cours."; -"drawer_create_a_bet" = "CREER UN BET"; +"drawer_create_a_bet" = "NOUVEAU BET"; "drawer_create_a_bet_subtitle" = "Créez un nouveau bet et faites participer vos amis."; -"drawer_bet_history" = "HISTORIQUE DES BETS"; +"drawer_bet_history" = "HISTORIQUE"; "drawer_bet_history_subtitle" = "Consultez vos paris en cours et terminés."; -"drawer_current_bets" = "BETS EN COURS"; +"drawer_current_bets" = "MES PARTICIPATIONS"; "drawer_current_bets_subtitle" = "Gérez vos bets et récompensez les gagnants."; "drawer_ranking" = "CLASSEMENT"; "drawer_ranking_subtitle" = "Consultez votre classement parmis vos amis."; @@ -150,6 +147,7 @@ "bet_status_participants_list" = "Liste des participants"; "bet_status_details_drawer" = "Détails"; "participation_possible_winnings" = "Gains possibles"; +"bet_status_stake" = "Pariés"; /// Bet history diff --git a/Sources/AllInApp/AllIn/Views/DetailsView.swift b/Sources/AllInApp/AllIn/Views/DetailsView.swift index 82ee7ea..53e97dd 100644 --- a/Sources/AllInApp/AllIn/Views/DetailsView.swift +++ b/Sources/AllInApp/AllIn/Views/DetailsView.swift @@ -8,7 +8,7 @@ struct DetailsView: View { @StateObject private var viewModel: DetailsViewModel var isFinished: Bool { - viewModel.betDetail?.finalAnswer == nil ? false : true + viewModel.betDetail?.wonParticipation == nil ? false : true } var StatusValues: (String, Color) { @@ -110,7 +110,7 @@ struct DetailsView: View { .cornerRadius(20, corners: [.topLeft,.topRight]).padding(.bottom,0) if isFinished { - ResultBanner() + ResultBanner(finalAnswer: (viewModel.betDetail?.wonParticipation)!, odds: (viewModel.betDetail?.odds)!) } VStack(alignment: .leading, spacing: 5) { BetLineLoading(participations: viewModel.betDetail?.participations ?? []) diff --git a/Sources/AllInApp/AllInWidgets/Info.plist b/Sources/AllInApp/AllInWidgets/Info.plist index 0f118fb..29c8417 100644 --- a/Sources/AllInApp/AllInWidgets/Info.plist +++ b/Sources/AllInApp/AllInWidgets/Info.plist @@ -7,5 +7,21 @@ NSExtensionPointIdentifier com.apple.widgetkit-extension + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + NSExceptionDomains + + codefirst.iut.uca.fr + + NSExceptionAllowsInsecureHTTPLoads + + NSIncludesSubdomains + + + + + diff --git a/Sources/Api/Sources/Api/Factory/FactoryApiBet.swift b/Sources/Api/Sources/Api/Factory/FactoryApiBet.swift index bc95ae9..18c39fa 100644 --- a/Sources/Api/Sources/Api/Factory/FactoryApiBet.swift +++ b/Sources/Api/Sources/Api/Factory/FactoryApiBet.swift @@ -63,6 +63,8 @@ public class FactoryApiBet: FactoryBet { } var participations: [Participation] = [] + var wonParticipation: Participation? + var userParticipation: Participation? if let participationsJson = json["participations"] as? [[String: Any]] { do { @@ -82,7 +84,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 { diff --git a/Sources/Model/Sources/Model/BetDetail.swift b/Sources/Model/Sources/Model/BetDetail.swift index 8f139f5..8f3f9a9 100644 --- a/Sources/Model/Sources/Model/BetDetail.swift +++ b/Sources/Model/Sources/Model/BetDetail.swift @@ -20,7 +20,19 @@ public class BetDetail: ObservableObject { public private(set) var participations: [Participation] /// 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 /// @@ -29,18 +41,19 @@ public class BetDetail: ObservableObject { /// - answers: Details about the answers available for the bet. /// - participations: List of user participations in the bet. /// - 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.answers = answers self.participations = participations - self.finalAnswer = finalAnswer + self.wonParticipation = wonParticipation + self.userParticipation = userParticipation } /// Updates the final answer selected for the bet. /// /// - Parameter newFinalAnswer: The new final answer for the bet. - public func updateFinalAnswer(newFinalAnswer: String) { - self.finalAnswer = newFinalAnswer + public func updateFinalAnswer(wonParticipation: Participation) { + self.wonParticipation = wonParticipation } /// Adds a new user participation to the list of participations for the bet. diff --git a/Sources/StubLib/Sources/StubLib/Stub.swift b/Sources/StubLib/Sources/StubLib/Stub.swift index d3539ac..6195d0f 100644 --- a/Sources/StubLib/Sources/StubLib/Stub.swift +++ b/Sources/StubLib/Sources/StubLib/Stub.swift @@ -91,7 +91,7 @@ struct Stub { } 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) } }