Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

documentation #4 #8

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions ZusExample/App/CreateWalletView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// ContentView.swift
// ZusExample
//
// Created by Aaryan Kothari on 28/12/22.
//

import SwiftUI

struct CreateWalletView: View {
@ObservedObject var zcncoreVM: ZcncoreManager

var body: some View {
GeometryReader { gr in
VStack(alignment: .center) {
Spacer()
Image("zus")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: gr.size.width * 0.7)
Spacer()
Button(action: zcncoreVM.createWallet) {
ZStack(alignment: .trailing) {
Text(zcncoreVM.processTitle)
.padding()
.frame(maxWidth: .infinity)
.background(.blue)
.foregroundColor(.white)
.cornerRadius(12)
.bold()

if zcncoreVM.processing {
ProgressView()
.padding(.trailing,50)
.tint(.white)
}
}
}
Spacer()
} //VStack
.padding(20)
.frame(maxWidth: .infinity)
} //GR
}
}

struct CreateWalletView_Previews: PreviewProvider {
static var previews: some View {
CreateWalletView(zcncoreVM: .shared)
}
}
16 changes: 8 additions & 8 deletions ZusExample/Bolt/App/BoltHome.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@ struct BoltHome: View {
Spacer()
Text("Transaction Date").layoutPriority(1)
Image(systemName: "chevron.right").opacity(0)
}
} //HStack
.bold()
ScrollView(showsIndicators: false) {
ForEach(Array(boltVM.transactions.sorted().enumerated()),id:\.offset) { index, txn in
NavigationLink(destination: TransactionDetails(transaction: txn)) {
TransactionRow(index: index, txn: txn)
}
}
} //NavigationLink
}//ForEach
.listStyle(.plain)
}
}
} //ScrollView
} //VStack
if boltVM.presentPopup {
ZCNToast(type: boltVM.popup,presented: $boltVM.presentPopup)
}
}
}
}//ZStack
}//GR
.padding(20)
.environmentObject(boltVM)
.navigationTitle(Text("Bolt"))
Expand All @@ -60,7 +60,7 @@ struct BoltHome: View {
Spacer()
Text(Date(timeIntervalSince1970: txn.creationDate/1e9).formatted()).layoutPriority(1)
Image(systemName: "chevron.right")
}
} //HStack
.foregroundColor(txn.status == 1 ? .primary : .pink)
.lineLimit(1)
.padding(.vertical,10)
Expand Down
14 changes: 7 additions & 7 deletions ZusExample/Bolt/App/TransactionDetails.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ struct TransactionDetails: View {
ListRow(title: "Client ID:", value: transaction.clientID)
ListRow(title: "To Client ID:", value: transaction.toClientID)
ListRow(title: "Signature:", value: transaction.signature)
}
} //Section

Section("Amount Details") {
ListRow(title: "Status:", value: transaction.status.stringValue)
ListRow(title: "Value:", value: transaction.value?.stringValue)
ListRow(title: "Fee:", value: transaction.fee?.stringValue)
ListRow(title: "Date:", value: transaction.fomattedDate)
}
} //Section

Section("Explorer") {
Link(destination: URL(string: "https://staging-atlus-beta.testnet-0chain.net/transaction-details/\(transaction.hash)")!,label: { Text("View On Explorer").foregroundColor(.teal) })
}
}
} //Section
} //List
.navigationTitle(Text("Transaction Details"))
}

Expand All @@ -39,8 +39,8 @@ struct TransactionDetails: View {
Section(title) {
ForEach(Array(dict.keys).sorted(),id:\.self) { key in
ListRow(title: key, value: String(describing: dict[key]))
}
}
} //ForEach
} //Section
}
}

Expand All @@ -60,7 +60,7 @@ struct ListRow: View {
Text(title)
Text(value ?? "~")
.lineLimit(opened ? 10 : 1)
}
} //HStack
.onTapGesture {
withAnimation {
self.opened.toggle()
Expand Down
9 changes: 9 additions & 0 deletions ZusExample/Bolt/Model/Balance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ struct Balance: Codable, Equatable {
private var _balance: Int?
private var error: String?

/// Initilize core Information
/// - Parameters:
/// - txn: Transaction of balance
/// - round: round of balance
/// - _balance: _balance amount of transaction
/// - error: error of balance
internal init(txn: String? = nil, round: Int? = nil,balance _balance: Int? = nil, error: String? = nil) {
self.txn = txn
self.round = round
Expand All @@ -29,15 +35,18 @@ struct Balance: Codable, Equatable {
case error
}

/// Balance return in integer
var balance: Int {
return _balance ?? 0
}

/// Balance token return with double value
var balanceToken: Double {
get { return balance.tokens }
set { self._balance = Int(exactly: ZcncoreConvertToValue(newValue).doubleValue) }
}

/// usd return with usd string
var usd: String {
let usd: Double = Utils.zcnUsdRate
let amount: Double = balanceToken * usd
Expand Down
42 changes: 21 additions & 21 deletions ZusExample/Bolt/Model/Transaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,28 @@ struct Transaction: Codable, Identifiable, Hashable,Comparable {
return rhs.creationDate < lhs.creationDate
}

/// <#Description#>
/// Initialize Transaction information
/// - Parameters:
/// - id: <#id description#>
/// - createdAt: <#createdAt description#>
/// - updatedAt: <#updatedAt description#>
/// - devaredAt: <#devaredAt description#>
/// - hash: <#hash description#>
/// - blockHash: <#blockHash description#>
/// - round: <#round description#>
/// - version: <#version description#>
/// - clientID: <#clientID description#>
/// - toClientID: <#toClientID description#>
/// - transactionData: <#transactionData description#>
/// - value: <#value description#>
/// - signature: <#signature description#>
/// - creationDate: <#creationDate description#>
/// - fee: <#fee description#>
/// - nonce: <#nonce description#>
/// - transactionType: <#transactionType description#>
/// - transactionOutput: <#transactionOutput description#>
/// - outputHash: <#outputHash description#>
/// - status: <#status description#>
/// - id: id of transaction
/// - createdAt: createdAt of transaction
/// - updatedAt: updatedAt of transaction
/// - devaredAt: devaredAt of transaction
/// - hash: hash of transaction
/// - blockHash: blockHash of transaction
/// - round: round of transaction
/// - version: version of transaction
/// - clientID: clientID of transaction
/// - toClientID: toClientID of transaction
/// - transactionData: transaction data of transaction
/// - value: value of transaction
/// - signature: signature of transaction
/// - creationDate: creation date of transaction
/// - fee: fee of transaction
/// - nonce: nonce of transaction
/// - transactionType: transaction type of transaction
/// - transactionOutput: transaction output of transaction
/// - outputHash: output hash of transaction
/// - status: status of transaction
internal init(id: Int? = nil, createdAt: String? = nil, updatedAt: String? = nil, devaredAt: String? = nil, hash: String, blockHash: String = "", round: Int? = nil, version: String? = nil, clientID: String? = nil, toClientID: String? = nil, transactionData: String? = nil, value: Int? = nil, signature: String? = nil, creationDate: Double, fee: Int? = nil, nonce: Int? = nil, transactionType: Int? = nil, transactionOutput: String? = nil, outputHash: String? = nil, status: Int) {
self.id = id
self.createdAt = createdAt
Expand Down
2 changes: 2 additions & 0 deletions ZusExample/Bolt/Model/Wallet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ struct Wallet: Codable {
var mnemonics: String
let version: String

/// Debug description
/// - Returns: description logs of Api response
func debugDescription() -> String {
return "\n----------Wallet----------\nclient_id: \(client_id)\nclient_key: \(client_key)\npublic_key: \(keys[0].public_key)\nprivate_key: \(keys[0].private_key)\nmnemonics: \(mnemonics)\nversion: \(version)\n--------------------------"
}
Expand Down
8 changes: 4 additions & 4 deletions ZusExample/Bolt/View/AvailableBalanceBlock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import SwiftUI
struct AvailableBalanceBlock: View {
@EnvironmentObject var boltVM: BoltViewModel
@AppStorage(Utils.UserDefaultsKey.balance.rawValue) var balance: Int = 0

var body: some View {
VStack(alignment:.leading,spacing: 5) {

Expand All @@ -23,7 +23,7 @@ struct AvailableBalanceBlock: View {
Text(" ZCN")
.font(.system(size: 14, weight: .regular))
.padding(.bottom, 8)
}
} //HStack
.padding(.top,-10)

HStack {
Expand All @@ -32,11 +32,11 @@ struct AvailableBalanceBlock: View {
Text("$ \(balance.usd)")
.font(.system(size: 16, weight: .bold))

}
} //HStack

Text("1 ZCN ≈ $\(Utils.zcnUsdRate)")
.foregroundColor(.secondary)
}
} //VStack
}
}

Expand Down
8 changes: 4 additions & 4 deletions ZusExample/Bolt/View/WalletActionStack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ struct WalletActionStack: View {
HStack(spacing:0) {
ForEach(WalletActionType.allCases,id:\.self) { action in
WalletActionButton(width: width, action: boltVM.walletAction, button: action)

}
}
} //ForEach
} //HStack
.frame(height:width/4)
.background(Color.tertiarySystemBackground)
.cornerRadius(12)
Expand Down Expand Up @@ -46,7 +46,7 @@ struct WalletActionButton: View {
.frame(width: width/13)
Text(button.title)
.font(.system(size: 13, weight: .semibold))
}
} //VStack
.frame(width: width/3)
.onTapGesture{ self.action(button) }
}
Expand Down
Loading