Skip to content

Commit

Permalink
documentation #4
Browse files Browse the repository at this point in the history
  • Loading branch information
vijay-kachhadiya committed Jan 4, 2023
1 parent 7a2c089 commit 97941b4
Show file tree
Hide file tree
Showing 18 changed files with 130 additions and 73 deletions.
18 changes: 9 additions & 9 deletions ZusExample/App/AppSelectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ struct AppSelectionView: View {
NavigationLink(destination: VultHome(), isActive: $presentVultHome) { EmptyView() }

Spacer()
}
} //VStack
.frame(maxWidth: .infinity)
.padding(gr.size.width/15)
}
}
} //GR
} //NavigationView
}

@ViewBuilder func AppSelectionBox(icon: String,width:CGFloat,allocationButton:Bool = false) -> some View {
Expand All @@ -62,8 +62,8 @@ struct AppSelectionView: View {
.padding(3)
.background(.blue)
}
}
}
} //VStack
} // ZStack
.frame(maxWidth: .infinity)
.background(.background)
.aspectRatio(2,contentMode: .fit)
Expand All @@ -81,7 +81,7 @@ struct AppSelectionView: View {
Spacer()
Image(systemName: "chevron.right")
.rotationEffect(.degrees(presentWalletDetails ? 90.0 : 0.0))
}
} //HStack
if presentWalletDetails {
ScrollView(.horizontal, showsIndicators: false) {
VStack(alignment: .leading,spacing: 10) {
Expand All @@ -90,10 +90,10 @@ struct AppSelectionView: View {
self.row(title: "Private Key: ", text: wallet.keys.first?.private_key ?? "")
self.row(title: "Public Key: ", text: wallet.keys.first?.public_key ?? "")
self.row(title: "Mnemonics: ", text: wallet.mnemonics)
}
}
} //VStack
} //ScrollView
}
}
} //VStack
.padding(width/10)
.background(RoundedRectangle(cornerRadius: 16).fill(.background).shadow(radius: 5))
.onTapGesture {
Expand Down
8 changes: 4 additions & 4 deletions ZusExample/App/Bolt/BoltHome.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ struct BoltHome: View {
Link(destination: URL(string: "https://staging-atlus-beta.testnet-0chain.net/transaction-details/\(txn.hash)")!,label: { TransactionRow(index: index, txn: txn) })
}
.listStyle(.plain)
}
}
}
} //ScrollView
} //VStack
} //GR
.padding(20)
.environmentObject(boltVM)
.onAppear(perform: boltVM.getTransactions)
Expand All @@ -46,7 +46,7 @@ struct BoltHome: View {
Spacer()
Text(Date(timeIntervalSince1970: txn.creationDate/1e9).formatted()).layoutPriority(1)
Image(systemName: "chevron.right")
}
} //HStack
.foregroundColor(txn.status == 1 ? .black : .pink)
.lineLimit(1)
.padding(.vertical,10)
Expand Down
2 changes: 1 addition & 1 deletion ZusExample/App/CreateWalletView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct CreateWalletView: View {
var body: some View {
VStack {
Button("Create Wallet", action: zcncoreVM.createWallet)
}
} //VStack
.padding()
}
}
Expand Down
6 changes: 3 additions & 3 deletions ZusExample/App/Vult/VultHome.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ struct VultHome: View {
ForEach(vultVM.files) { file in
FileRow(file: file)
}
}
}
} //ScrollView
} //VStack
.padding(22)
}
} //GR
.onAppear(perform: vultVM.listDir)
.background(Color.gray.opacity(0.1))
.onChange(of: vultVM.selectedPhoto, perform: vultVM.uploadImage)
Expand Down
4 changes: 2 additions & 2 deletions ZusExample/App/ZusExampleApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ struct ZusExampleApp: App {
} else {
AppSelectionView()
}
}
} //Group
.environmentObject(zcncoreVM)
.onAppear(perform: zcncoreVM.initialize)
}
} //WindowGroup
}
}
5 changes: 4 additions & 1 deletion ZusExample/Model/Allocation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ struct Allocation: Codable {
case numFailedChallenges = "num_failed_challenges"
case latestClosedChallenge = "latest_closed_challenge"
}


/// Add stats of allocation
/// - Parameter model: model of allocation
mutating func addStats(_ model: Self) {
self.usedSize = model.usedSize
self.numOfWrites = model.numOfWrites
Expand All @@ -44,6 +46,7 @@ struct Allocation: Codable {
self.latestClosedChallenge = model.latestClosedChallenge
}

/// allocation of fraction value
var allocationFraction: Double {
return Double(usedSize ?? 0)/Double(size ?? 1)
}
Expand Down
9 changes: 9 additions & 0 deletions ZusExample/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
21 changes: 21 additions & 0 deletions ZusExample/Model/File.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ class File: NSObject, Codable, Identifiable {
case updatedAt = "updated_at"
}

/// initialize of file allocation
/// - Parameters:
/// - name: name of file
/// - mimetype: mimetype of file
/// - path: path of file
/// - lookupHash: lookup hash of file
/// - type: type of file
/// - size: size of file
/// - numBlocks: number of blocks
/// - actualSize: actual size of file
/// - actualNumBlocks: actual number of blocks
/// - encryptionKey: encryption key of file
/// - createdAt: createdAt of file
/// - updatedAt: updatedAt of file
/// - completedBytes: completed bytes of file
internal init(name: String = "", mimetype: String = "", path: String = "", lookupHash: String = "", type: String = "", size: Int = 0, numBlocks: Int? = 0, actualSize: Int? = 0, actualNumBlocks: Int? = 0, encryptionKey: String? = "", createdAt: Double = 0, updatedAt: Double = 0, completedBytes: Int = 0) {
self.name = name
self.mimetype = mimetype
Expand All @@ -60,30 +75,36 @@ class File: NSObject, Codable, Identifiable {
self.completedBytes = completedBytes
}

/// Local thumbnail path and return with URL
var localThumbnailPath: URL {
return Utils.downloadedThumbnailPath.appendingPathComponent(self.path)
}

/// Local upload path and return with URL
var localUploadPath: URL {
return Utils.uploadPath.appendingPathComponent(self.path)
}

/// Local file path and return with URL
var localFilePath: URL {
return Utils.downloadPath.appendingPathComponent(self.path)
}

/// check local file path is exists or not and isdownload return Bool(True ot False)
var isDownloaded: Bool {
return FileManager.default.fileExists(atPath: localFilePath.path)
}

var completedBytes: Int = 0

/// File status type
enum FileStatus {
case error
case progress
case completed
}

// file size base on file status
var fileSize: String {
switch status {
case .completed: return size.formattedByteCount
Expand Down
7 changes: 7 additions & 0 deletions ZusExample/Model/NetworkConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ struct NetworkConfig: Codable {
case zboxURL
}

/// Initialize core setup
/// - Parameters:
/// - signatureScheme: signature Scheme of network setting
/// - confirmationChainLength: confirmationChainLength of network setting
/// - blockWorker: blockWorker of network setting
/// - zboxURL: zboxURL of network setting
internal init(signatureScheme: String = "bls0chain",
confirmationChainLength: Int = 3,
blockWorker: String, zboxURL: String) {
Expand All @@ -35,6 +41,7 @@ struct NetworkConfig: Codable {
static let potato = NetworkConfig(blockWorker: "https://potato.devnet-0chain.net/dns", zboxURL: "https://0box.potato.devnet-0chain.net")
static let test = NetworkConfig(blockWorker: "https://test.0chain.net/dns", zboxURL: "https://0box.test.0chain.net")

/// Host url of network
var host: String {
return URLComponents(string: blockWorker)?.host ?? ""
}
Expand Down
42 changes: 21 additions & 21 deletions ZusExample/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/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/View/Bolt/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: 10) {

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

HStack {
Text("Total Balance")
.font(.system(size: 16, weight: .regular))
Text("$ \(balance.usd)")
.font(.system(size: 16, weight: .bold))
}
}
} //HStack
} //VStack
}
}

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

}
}
} //HStack
.frame(height:width/4)
.background(Color.white)
.cornerRadius(12)
Expand Down Expand Up @@ -45,7 +45,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
6 changes: 3 additions & 3 deletions ZusExample/View/Vult/AllocationActionStack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct AllocationActionStack: View {
}

WalletActionBlock(icon: "allocation", "Allocation Details")
}
} //HStack
.aspectRatio(2.4, contentMode: .fit)
.shadow(color: .init(white: 0.95), radius: 100, x: 0, y: 0)
}
Expand All @@ -37,13 +37,13 @@ struct AllocationActionStack: View {
.frame(width: gr.size.width/2)
Text(title.split(separator: " ")[0])
Text(title.split(separator: " ")[1])
}
} //VStack
.frame(maxWidth: .infinity,maxHeight: .infinity)
.font(.system(size: 13, weight: .semibold))
.foregroundColor(.primary)
.background(Color.white)
.cornerRadius(12)
}
} //GR
}
}

Expand Down
Loading

0 comments on commit 97941b4

Please sign in to comment.