Add getGift

pull/23/head
Emre KARTAL 1 year ago
parent 2be8faebd0
commit 059b3fec74

@ -19,6 +19,7 @@ struct AllcoinsCounter: View {
.resizable() .resizable()
.frame(width: 17, height: 17, alignment: .leading) .frame(width: 17, height: 17, alignment: .leading)
Text(String(appStateContainer.user?.nbCoins ?? 0)) Text(String(appStateContainer.user?.nbCoins ?? 0))
.contentTransition(.numericText())
.fontWeight(.black) .fontWeight(.black)
.foregroundColor(foregroundColor) .foregroundColor(foregroundColor)
} }

@ -10,6 +10,7 @@ import Model
struct BetLineLoading: View { struct BetLineLoading: View {
@State var showInfos: Bool = false
var participations: [Participation] var participations: [Participation]
var value: CGFloat { var value: CGFloat {
@ -33,7 +34,7 @@ struct BetLineLoading: View {
var body: some View { var body: some View {
GeometryReader { geometry in GeometryReader { geometry in
VStack(alignment: .leading,spacing: 0){ VStack(alignment: .leading,spacing: 0) {
HStack(spacing: 5){ HStack(spacing: 5){
Text("OUI") Text("OUI")
.font(.system(size: 25)) .font(.system(size: 25))
@ -44,7 +45,6 @@ struct BetLineLoading: View {
.font(.system(size: 25)) .font(.system(size: 25))
.fontWeight(.bold) .fontWeight(.bold)
.foregroundColor(AllInColors.pink100) .foregroundColor(AllInColors.pink100)
} }
ZStack(alignment: .leading) { ZStack(alignment: .leading) {
HStack{ HStack{
@ -66,83 +66,104 @@ struct BetLineLoading: View {
} }
} }
VStack(spacing: 1){ .padding(.bottom, 5)
HStack(spacing: 5){
Image("blueAllCoinIcon")
.resizable()
.frame(width:12, height: 12)
Text(yesParticipations.reduce(0, {x,y in x + y.stake}).description)
.font(.system(size: 15))
.fontWeight(.bold)
.foregroundColor(AllInColors.blue200)
Spacer()
Text(noParticipations.reduce(0, {x,y in x + y.stake}).description)
.font(.system(size: 15))
.fontWeight(.bold)
.foregroundColor(AllInColors.pink100)
Image("pinkAllCoinIcon")
.resizable()
.frame(width: 12, height: 12)
}
HStack(spacing: 5){
Image("bluePersonIcon")
.resizable()
.frame(width: 12, height: 12)
Text(yesParticipations.count.description)
.font(.system(size: 15))
.fontWeight(.bold)
.foregroundColor(AllInColors.blue200)
Spacer()
Text(noParticipations.count.description)
.font(.system(size: 15))
.fontWeight(.bold)
.foregroundColor(AllInColors.pink100)
Image("pinkPersonIcon")
.resizable()
.frame(width: 12, height: 12)
}
HStack(spacing: 5){
Image("blueBadgeIcon")
.resizable()
.frame(width: 12, height: 12)
Text(yesParticipations.max(by: { $0.stake < $1.stake })?.stake.description ?? "0")
.font(.system(size: 15))
.fontWeight(.bold)
.foregroundColor(AllInColors.blue200)
Spacer()
Text(noParticipations.max(by: { $0.stake < $1.stake })?.stake.description ?? "0")
.font(.system(size: 15))
.fontWeight(.bold)
.foregroundColor(AllInColors.pink100)
Image("pinkBadgeIcon")
.resizable()
.frame(width: 12, height: 12)
HStack {
Spacer()
Text("Détails")
.textStyle(weight: .medium, color: AllInColors.primaryTextColor, size: 10)
Image(showInfos ? "chevronUpIcon" : "chevronDownIcon")
.resizable()
.frame(width: 10, height: 7)
.scaledToFill()
}
.onTapGesture {
withAnimation {
showInfos.toggle()
} }
HStack(spacing: 5){ }
Image("blueTrophyIcon") .padding(.bottom, 5)
.resizable() .padding(.trailing, 5)
.frame(width: 12, height: 12)
Text("1.2") if showInfos {
.font(.system(size: 15)) VStack(spacing: 1){
.fontWeight(.bold) HStack(spacing: 5){
.foregroundColor(AllInColors.blue200) Image("blueAllCoinIcon")
Spacer() .resizable()
Text("1.2") .frame(width:12, height: 12)
.font(.system(size: 15)) Text(yesParticipations.reduce(0, {x,y in x + y.stake}).description)
.fontWeight(.bold) .font(.system(size: 15))
.foregroundColor(AllInColors.pink100) .fontWeight(.bold)
Image("pinkTrophyIcon") .foregroundColor(AllInColors.blue200)
.resizable() Spacer()
.frame(width:12, height: 12) Text(noParticipations.reduce(0, {x,y in x + y.stake}).description)
.font(.system(size: 15))
.fontWeight(.bold)
.foregroundColor(AllInColors.pink100)
Image("pinkAllCoinIcon")
.resizable()
.frame(width: 12, height: 12)
}
HStack(spacing: 5){
Image("bluePersonIcon")
.resizable()
.frame(width: 12, height: 12)
Text(yesParticipations.count.description)
.font(.system(size: 15))
.fontWeight(.bold)
.foregroundColor(AllInColors.blue200)
Spacer()
Text(noParticipations.count.description)
.font(.system(size: 15))
.fontWeight(.bold)
.foregroundColor(AllInColors.pink100)
Image("pinkPersonIcon")
.resizable()
.frame(width: 12, height: 12)
}
HStack(spacing: 5){
Image("blueBadgeIcon")
.resizable()
.frame(width: 12, height: 12)
Text(yesParticipations.max(by: { $0.stake < $1.stake })?.stake.description ?? "0")
.font(.system(size: 15))
.fontWeight(.bold)
.foregroundColor(AllInColors.blue200)
Spacer()
Text(noParticipations.max(by: { $0.stake < $1.stake })?.stake.description ?? "0")
.font(.system(size: 15))
.fontWeight(.bold)
.foregroundColor(AllInColors.pink100)
Image("pinkBadgeIcon")
.resizable()
.frame(width: 12, height: 12)
}
HStack(spacing: 5){
Image("blueTrophyIcon")
.resizable()
.frame(width: 12, height: 12)
Text("1.2")
.font(.system(size: 15))
.fontWeight(.bold)
.foregroundColor(AllInColors.blue200)
Spacer()
Text("1.2")
.font(.system(size: 15))
.fontWeight(.bold)
.foregroundColor(AllInColors.pink100)
Image("pinkTrophyIcon")
.resizable()
.frame(width:12, height: 12)
}
} }
} }
Spacer()
} }
}
}.frame(height: 140)
} }
} }

@ -7,11 +7,14 @@
import SwiftUI import SwiftUI
import DependencyInjection import DependencyInjection
import Model
struct ContentView: View { struct ContentView: View {
@State private var show = false @State private var show = false
@State private var gain = 0
@Inject var authService: IAuthService @Inject var authService: IAuthService
@Inject var manager: Manager
@ObservedObject var loggedState = AppStateContainer.shared.loggedState @ObservedObject var loggedState = AppStateContainer.shared.loggedState
var body: some View { var body: some View {
@ -30,16 +33,23 @@ struct ContentView: View {
} }
.onAppear { .onAppear {
authService.refreshAuthentication() authService.refreshAuthentication()
DispatchQueue.main.asyncAfter(deadline: .now() + 2) { }
withAnimation { .onChange(of: loggedState.connectedUser) { _ in
show = true if loggedState.connectedUser {
manager.getTodayGifts() { status, gained in
if status == 200 {
withAnimation {
show = true
gain = gained
}
}
} }
} }
} }
.overlay( .overlay(
Group { Group {
if show { if show {
DailyGiftPage(show: $show) DailyGiftPage(show: $show, gain: $gain)
.transition(.opacity) .transition(.opacity)
} }
} }

@ -19,6 +19,7 @@ struct DailyGiftPage: View {
@State private var scale2: CGFloat = 0 @State private var scale2: CGFloat = 0
@State private var rotate: CGFloat = 1 @State private var rotate: CGFloat = 1
@Binding var show: Bool @Binding var show: Bool
@Binding var gain: Int
var body: some View { var body: some View {
GeometryReader { geometry in GeometryReader { geometry in
@ -94,6 +95,9 @@ struct DailyGiftPage: View {
switch step { switch step {
case .first: case .first:
step = .end step = .end
withAnimation {
AppStateContainer.shared.user?.nbCoins += gain
}
case .end: case .end:
show = false show = false
step = .first step = .first
@ -115,6 +119,6 @@ struct DailyGiftPage: View {
struct DailyGiftPage_Previews: PreviewProvider { struct DailyGiftPage_Previews: PreviewProvider {
static var previews: some View { static var previews: some View {
DailyGiftPage(show: .constant(false)) DailyGiftPage(show: .constant(false), gain: .constant(20))
} }
} }

@ -67,8 +67,3 @@ struct MainView: View {
} }
} }
} }
struct MainView_Previews: PreviewProvider {
static var previews: some View {
MainView(page: "Bet")
}
}

@ -212,6 +212,14 @@
/* End PBXFrameworksBuildPhase section */ /* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */ /* Begin PBXGroup section */
EC1D15402B715A7A0094833E /* Protocols */ = {
isa = PBXGroup;
children = (
EC6B96CB2B24B7E500FC1C58 /* IAuthService.swift */,
);
path = Protocols;
sourceTree = "<group>";
};
EC6B968F2B24B4CC00FC1C58 = { EC6B968F2B24B4CC00FC1C58 = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
@ -281,7 +289,7 @@
EC6B96CA2B24B7B300FC1C58 /* Services */ = { EC6B96CA2B24B7B300FC1C58 /* Services */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
EC6B96CB2B24B7E500FC1C58 /* IAuthService.swift */, EC1D15402B715A7A0094833E /* Protocols */,
EC6B96D02B24BAE800FC1C58 /* AuthService.swift */, EC6B96D02B24BAE800FC1C58 /* AuthService.swift */,
); );
path = Services; path = Services;

@ -47,6 +47,31 @@ public struct UserApiManager: UserDataManager {
fatalError("Not implemented yet") fatalError("Not implemented yet")
} }
public func getGifts(completion : @escaping (Int, Int)-> ()) {
let url = URL(string: allInApi + "users/gift")!
var request = URLRequest(url: url)
request.httpMethod = "GET"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization")
URLSession.shared.dataTask(with: request) { data, response, error in
if let data = data {
print ("ALLIN : get gifts of the day")
if let httpResponse = response as? HTTPURLResponse {
if httpResponse.statusCode == 200 {
if let stringValue = String(data: data, encoding: .utf8), let intValue = Int(stringValue) {
completion(httpResponse.statusCode, intValue)
}
} else {
completion(httpResponse.statusCode, 0)
}
print(httpResponse.statusCode)
}
}
}.resume()
}
public func getOldBets(withIndex index: Int, withCount count: Int, completion: @escaping ([Bet]) -> Void) { public func getOldBets(withIndex index: Int, withCount count: Int, completion: @escaping ([Bet]) -> Void) {
fatalError("Not implemented yet") fatalError("Not implemented yet")
} }

@ -51,4 +51,10 @@ public struct Manager {
completion(status) completion(status)
} }
} }
public func getTodayGifts(completion : @escaping (Int, Int)-> ()) {
userDataManager.getGifts() { status, gain in
completion(status, gain)
}
}
} }

@ -11,6 +11,7 @@ public protocol UserDataManager {
func getBets(withIndex index: Int, withCount count: Int) -> [Bet] func getBets(withIndex index: Int, withCount count: Int) -> [Bet]
func addBet(bet: Bet, completion : @escaping (Int)-> ()) func addBet(bet: Bet, completion : @escaping (Int)-> ())
func getFriends() -> [User] func getFriends() -> [User]
func getGifts(completion : @escaping (Int, Int)-> ())
func getOldBets(withIndex index: Int, withCount count: Int, completion: @escaping ([Bet]) -> Void) func getOldBets(withIndex index: Int, withCount count: Int, completion: @escaping ([Bet]) -> Void)
func getCurrentBets(withIndex index: Int, withCount count: Int, completion: @escaping ([Bet]) -> Void) func getCurrentBets(withIndex index: Int, withCount count: Int, completion: @escaping ([Bet]) -> Void)
func addParticipation(withId id: String, withAnswer answer: String, andStake stake: Int, completion : @escaping (Int)-> ()) func addParticipation(withId id: String, withAnswer answer: String, andStake stake: Int, completion : @escaping (Int)-> ())

Loading…
Cancel
Save