-
Notifications
You must be signed in to change notification settings - Fork 6
/
AssetListViewController.swift
115 lines (86 loc) · 3.79 KB
/
AssetListViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//
// ViewController.swift
// WavesSDK
//
// Created by rprokofev on 03/04/2019.
// Copyright © 2019 Waves. All rights reserved.
//
import UIKit
import WavesSDK
import WavesSDKCrypto
import RxSwift
final class AssetCell: UITableViewCell {
@IBOutlet var nameLabel: UILabel!
@IBOutlet var balanceLabel: UILabel!
}
final class AssetListViewController: UIViewController {
@IBOutlet var tableView: UITableView!
@IBOutlet var button: UIButton!
private var balances: NodeService.DTO.AddressAssetsBalance?
private var disposeBag: DisposeBag = DisposeBag()
override func viewDidLoad() {
super.viewDidLoad()
WavesSDK.shared.services
.nodeServices
.assetsNodeService
.assetsBalances(address: "3PCAB4sHXgvtu5NPoen6EXR5yaNbvsEA8Fj")
.observeOn(MainScheduler.asyncInstance)
.subscribe(onNext: { [weak self] (balances) in
self?.balances = balances
self?.tableView.reloadData()
})
.disposed(by: disposeBag)
}
@IBAction func actionSend() {
sendTransaction()
}
func sendTransaction() {
let seed = "My seed"
guard let chainId = WavesSDK.shared.enviroment.chainId else { return }
guard let address = WavesCrypto.shared.address(seed: seed, chainId: chainId) else { return }
guard let senderPublicKey = WavesCrypto.shared.publicKey(seed: seed) else { return }
let recipient = address
let fee: Int64 = 100000
let amount: Int64 = 100000
let feeAssetId = "WAVES"
let assetId = "WAVES"
let attachment = ""
let timestamp = Int64(Date().timeIntervalSince1970) * 1000
var queryModel = NodeService.Query.Transaction.Transfer(recipient: recipient,
assetId: assetId,
amount: amount,
fee: fee,
attachment: attachment,
feeAssetId: feeAssetId,
timestamp: timestamp,
senderPublicKey: senderPublicKey,
chainId: chainId)
queryModel.sign(seed: seed)
let send = NodeService.Query.Transaction.transfer(queryModel)
WavesSDK.shared.services
.nodeServices
.transactionNodeService
.transactions(query: send)
.observeOn(MainScheduler.asyncInstance)
.subscribe(onNext: { (tx) in
print(tx)
})
.disposed(by: disposeBag)
}
}
// MARK: UITableViewDataSource
extension AssetListViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return balances?.balances.count ?? 0
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "AssetCell") as! AssetCell
let balance = self.balances?.balances[indexPath.row]
cell.nameLabel.text = balance?.issueTransaction.name
let balanceValue = balance?.balance ?? 0
let decimals = Int(balance?.issueTransaction.decimals ?? 0)
let value = Decimal(balanceValue) / pow(10, decimals)
cell.balanceLabel.text = "\(value)"
return cell
}
}