Mercurial > public > lazybear
view lazybear/Views/InsiderTransactions.swift @ 113:16f8514cc5e6
Implement insider transactions
author | Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> |
---|---|
date | Mon, 01 Feb 2021 20:19:32 +0100 |
parents | |
children | 4c172ff9af20 |
line wrap: on
line source
// // Insiders.swift // LazyBear // // Created by Dennis Concepción Martín on 1/2/21. // import SwiftUI struct InsiderTransactions: View { var symbol: String @EnvironmentObject var apiAccess: ApiAccess // <--------- API Job ---------> @State private var url = String() { didSet { request(url: url, model: [InsiderTransactionModel].self) { self.data = $0 } }} @State private var data = [InsiderTransactionModel]() // <--------- API Job ---------> var body: some View { VStack(alignment: .leading) { Text("Insider transactions") .font(.title) .fontWeight(.semibold) .padding([.leading, .bottom]) ForEach(data, id: \.self) { data in TransactionRow(data: data) } } .onAppear { getUrl() } } private func getUrl() { // 1 -> Sandbox / 2 -> Production let baseUrl = apiAccess.results[1].url ?? "" let token = apiAccess.results[1].key ?? "" let path = "/stable/stock/\(symbol)/insider-transactions?token=" self.url = baseUrl + path + token print(url) } } struct InsiderTransactions_Previews: PreviewProvider { static var previews: some View { InsiderTransactions(symbol: "aapl") } }