Skip to content

Commit d0c3dde

Browse files
committed
New scene: Buy & Sell tokens with links to stocks.
1 parent 77fa274 commit d0c3dde

File tree

16 files changed

+250
-12
lines changed

16 files changed

+250
-12
lines changed

Adamant.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@
181181
E965A53420B833A00041A3EA /* StateAsset.swift in Sources */ = {isa = PBXBuildFile; fileRef = E965A53320B833A00041A3EA /* StateAsset.swift */; };
182182
E965A53620B8370C0041A3EA /* TransactionAsset.swift in Sources */ = {isa = PBXBuildFile; fileRef = E965A53520B8370C0041A3EA /* TransactionAsset.swift */; };
183183
E96BBE3121F70F5E009AA738 /* ReadonlyTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E96BBE3021F70F5E009AA738 /* ReadonlyTextView.swift */; };
184+
E96BBE3321F71290009AA738 /* BuyAndSellViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E96BBE3221F71290009AA738 /* BuyAndSellViewController.swift */; };
184185
E96E86B821679C120061F80A /* EthTransactionDetailsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E96E86B721679C120061F80A /* EthTransactionDetailsViewController.swift */; };
185186
E971591A21681D6900A5F904 /* TransactionStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = E971591921681D6900A5F904 /* TransactionStatus.swift */; };
186187
E971591C2168209800A5F904 /* EthWalletService+RichMessageProviderWithStatusCheck.swift in Sources */ = {isa = PBXBuildFile; fileRef = E971591B2168209800A5F904 /* EthWalletService+RichMessageProviderWithStatusCheck.swift */; };
@@ -497,6 +498,7 @@
497498
E965A53320B833A00041A3EA /* StateAsset.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StateAsset.swift; sourceTree = "<group>"; };
498499
E965A53520B8370C0041A3EA /* TransactionAsset.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransactionAsset.swift; sourceTree = "<group>"; };
499500
E96BBE3021F70F5E009AA738 /* ReadonlyTextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReadonlyTextView.swift; sourceTree = "<group>"; };
501+
E96BBE3221F71290009AA738 /* BuyAndSellViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BuyAndSellViewController.swift; sourceTree = "<group>"; };
500502
E96E86B721679C120061F80A /* EthTransactionDetailsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EthTransactionDetailsViewController.swift; sourceTree = "<group>"; };
501503
E971591921681D6900A5F904 /* TransactionStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransactionStatus.swift; sourceTree = "<group>"; };
502504
E971591B2168209800A5F904 /* EthWalletService+RichMessageProviderWithStatusCheck.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "EthWalletService+RichMessageProviderWithStatusCheck.swift"; sourceTree = "<group>"; };
@@ -968,6 +970,7 @@
968970
E9B1AA5A21283E0F00080A2A /* AdmTransferViewController.swift */,
969971
64F085D820E2D7600006DE68 /* AdmTransactionsViewController.swift */,
970972
E9DFB71B21624C9200CF8C7C /* AdmTransactionDetailsViewController.swift */,
973+
E96BBE3221F71290009AA738 /* BuyAndSellViewController.swift */,
971974
);
972975
path = Adamant;
973976
sourceTree = "<group>";
@@ -1572,6 +1575,7 @@
15721575
E9B3D3A9202082450019EB36 /* AdamantTransfersProvider.swift in Sources */,
15731576
648BCA6B213D37A900875EB5 /* AdamantAvatarService.swift in Sources */,
15741577
E9A174B72057F1B3003667CD /* AdamantChatsProvider+backgroundFetch.swift in Sources */,
1578+
E96BBE3321F71290009AA738 /* BuyAndSellViewController.swift in Sources */,
15751579
E9E7CDB32002B9FB00DFC4DB /* LoginRoutes.swift in Sources */,
15761580
E941CCDE20E7B70200C96220 /* WalletCollectionViewCell.swift in Sources */,
15771581
E9AA8BFA212C166600F9249F /* EthWalletService+Send.swift in Sources */,
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"filename" : "bitz_row_logo.png",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"filename" : "bitz_row_logo@2x.png",
11+
"scale" : "2x"
12+
},
13+
{
14+
"idiom" : "universal",
15+
"filename" : "bitz_row_logo@3x.png",
16+
"scale" : "3x"
17+
}
18+
],
19+
"info" : {
20+
"version" : 1,
21+
"author" : "xcode"
22+
},
23+
"properties" : {
24+
"template-rendering-intent" : "template"
25+
}
26+
}
Loading
Loading
Loading
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"filename" : "idcm_row_logo.png",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"filename" : "idcm_row_logo@2x.png",
11+
"scale" : "2x"
12+
},
13+
{
14+
"idiom" : "universal",
15+
"filename" : "idcm_row_logo@3x.png",
16+
"scale" : "3x"
17+
}
18+
],
19+
"info" : {
20+
"version" : 1,
21+
"author" : "xcode"
22+
},
23+
"properties" : {
24+
"template-rendering-intent" : "template"
25+
}
26+
}
Loading
Loading
Loading

Adamant/Assets/l18n/de.lproj/Localizable.strings

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
"AccountTab.Row.Balance" = "Kontostand";
114114

115115
/* Account tab: 'Buy tokens' button */
116-
"AccountTab.Row.BuyTokens" = "Kaufe token";
116+
"AccountTab.Row.BuyTokens" = "Token kaufen & verkaufen";
117117

118118
/* Account tab: 'Logout' button */
119119
"AccountTab.Row.Logout" = "Ausloggen";
@@ -133,6 +133,9 @@
133133
/* Account tab: 'Send ETH tokens' button */
134134
"AccountTab.Row.SendLsk" = "LSK senden";
135135

136+
/* Account tab: Anonymously buy ADM tokens */
137+
"AccountTab.Row.AnonymouslyBuyADM" = "Kaufen Sie ADM anonym";
138+
136139
/* Account tab: 'Address' row */
137140
"AccountTab.Row.Address" = "Addresse";
138141

Adamant/Assets/l18n/en.lproj/Localizable.strings

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
"AccountTab.Row.Balance" = "Balance";
111111

112112
/* Account tab: 'Buy tokens' button */
113-
"AccountTab.Row.BuyTokens" = "Buy tokens";
113+
"AccountTab.Row.BuyTokens" = "Buy & Sell tokens";
114114

115115
/* Account tab: 'Logout' button */
116116
"AccountTab.Row.Logout" = "Logout";
@@ -130,6 +130,9 @@
130130
/* Account tab: 'Send ETH tokens' button */
131131
"AccountTab.Row.SendLsk" = "Send LSK";
132132

133+
/* Account tab: Anonymously buy ADM tokens */
134+
"AccountTab.Row.AnonymouslyBuyADM" = "Buy ADM anonymously";
135+
133136
/* Account tab: 'Address' row */
134137
"AccountTab.Row.Address" = "Address";
135138

Adamant/Assets/l18n/ru.lproj/Localizable.strings

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
"AccountTab.Row.Balance" = "Баланс";
111111

112112
/* Account tab: 'Buy tokens' button */
113-
"AccountTab.Row.BuyTokens" = "Купить токены";
113+
"AccountTab.Row.BuyTokens" = "Купить и продать токены";
114114

115115
/* Account tab: 'Logout' button */
116116
"AccountTab.Row.Logout" = "Выход";
@@ -130,6 +130,9 @@
130130
/* Account tab: 'Send ETH tokens' button */
131131
"AccountTab.Row.SendLsk" = "Отправить LSK";
132132

133+
/* Account tab: Anonymously buy ADM tokens */
134+
"AccountTab.Row.AnonymouslyBuyADM" = "Купить ADM анонимно";
135+
133136
/* Account tab: 'Address' row */
134137
"AccountTab.Row.Address" = "Адрес";
135138

Adamant/Wallets/Adamant/AdmWalletRoutes.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ extension AdamantScene.Wallets {
1414
static let wallet = AdamantScene(identifier: "AdmWalletViewController") { r in
1515
let c = AdmWalletViewController(nibName: "WalletViewControllerBase", bundle: nil)
1616
c.dialogService = r.resolve(DialogService.self)
17+
c.router = r.resolve(Router.self)
1718
return c
1819
}
1920

@@ -47,6 +48,14 @@ extension AdamantScene.Wallets {
4748
c.router = r.resolve(Router.self)
4849
return c
4950
})
51+
52+
/// Buy and Sell options
53+
static let buyAndSell = AdamantScene(identifier: "BuyAndSell") { r in
54+
let c = BuyAndSellViewController()
55+
c.accountService = r.resolve(AccountService.self)
56+
c.dialogService = r.resolve(DialogService.self)
57+
return c
58+
}
5059

5160
private init() {}
5261
}

Adamant/Wallets/Adamant/AdmWalletViewController.swift

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ extension String.adamantLocalized.wallets {
1515

1616
static let sendAdm = NSLocalizedString("AccountTab.Row.SendAdm", comment: "Account tab: 'Send ADM tokens' button")
1717

18+
static let buyAdmTokens = NSLocalizedString("AccountTab.Row.AnonymouslyBuyADM", comment: "Account tab: Anonymously buy ADM tokens")
19+
1820
// URLs
1921
static func getFreeTokensUrl(for address: String) -> String {
2022
return String.localizedStringWithFormat(NSLocalizedString("AccountTab.FreeTokens.UrlFormat", comment: "Account tab: A full 'Get free tokens' link, with %@ as address"), address)
@@ -55,6 +57,10 @@ class AdmWalletViewController: WalletViewControllerBase {
5557
}
5658
}
5759

60+
// MARK: - Props & Deps
61+
62+
var router: Router!
63+
5864
var hideFreeTokensRow = false
5965

6066
// MARK: - Lifecycle
@@ -76,16 +82,54 @@ class AdmWalletViewController: WalletViewControllerBase {
7682

7783
// MARK: Rows
7884

79-
let buyTokens = buildUrlRow(title: Rows.buyTokens.localized, value: nil, tag: Rows.buyTokens.tag, urlRaw: String.adamantLocalized.wallets.buyTokensUrl(for: address), image: Rows.buyTokens.image)
80-
81-
let freeTokens = buildUrlRow(title: Rows.freeTokens.localized, value: nil, tag: Rows.freeTokens.tag, urlRaw: String.adamantLocalized.wallets.getFreeTokensUrl(for: address), image: Rows.freeTokens.image)
85+
let buyTokensRow = LabelRow() {
86+
$0.tag = Rows.buyTokens.tag
87+
$0.title = Rows.buyTokens.localized
88+
$0.cell.imageView?.image = Rows.buyTokens.image
89+
$0.cell.imageView?.tintColor = UIColor.adamant.tableRowIcons
90+
$0.cell.selectionStyle = .gray
91+
}.cellUpdate { (cell, _) in
92+
cell.accessoryType = .disclosureIndicator
93+
}.onCellSelection { [weak self] (_, row) in
94+
guard let vc = self?.router.get(scene: AdamantScene.Wallets.Adamant.buyAndSell) else {
95+
fatalError("Failed to get BuyAndSell scele")
96+
}
97+
98+
row.deselect()
99+
100+
if let split = self?.splitViewController {
101+
let details = UINavigationController(rootViewController:vc)
102+
split.showDetailViewController(details, sender: self)
103+
} else {
104+
self?.navigationController?.pushViewController(vc, animated: true )
105+
}
106+
}
82107

83-
freeTokens.hidden = Condition.function([], { [weak self] _ -> Bool in
84-
return self?.hideFreeTokensRow ?? true
85-
})
108+
let freeTokensRow = LabelRow() {
109+
$0.tag = Rows.freeTokens.tag
110+
$0.title = Rows.freeTokens.localized
111+
$0.cell.imageView?.image = Rows.freeTokens.image
112+
$0.cell.imageView?.tintColor = UIColor.adamant.tableRowIcons
113+
$0.cell.selectionStyle = .gray
114+
$0.hidden = Condition.function([], { [weak self] _ -> Bool in
115+
return self?.hideFreeTokensRow ?? true
116+
})
117+
}.cellUpdate { (cell, _) in
118+
cell.accessoryType = .disclosureIndicator
119+
}.onCellSelection { [weak self] (_, _) in
120+
let urlRaw = String.adamantLocalized.wallets.getFreeTokensUrl(for: address)
121+
guard let url = URL(string: urlRaw) else {
122+
self?.dialogService.showError(withMessage: "Failed to create URL with string: \(urlRaw)", error: nil)
123+
return
124+
}
125+
126+
let safari = SFSafariViewController(url: url)
127+
safari.preferredControlTintColor = UIColor.adamant.primary
128+
self?.present(safari, animated: true, completion: nil)
129+
}
86130

87-
section.append(buyTokens)
88-
section.append(freeTokens)
131+
section.append(buyTokensRow)
132+
section.append(freeTokensRow)
89133

90134
// Notifications
91135
if let service = service {
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
//
2+
// BuyAndSellViewController.swift
3+
// Adamant
4+
//
5+
// Created by Anokhov Pavel on 22/01/2019.
6+
// Copyright © 2019 Adamant. All rights reserved.
7+
//
8+
9+
import UIKit
10+
import Eureka
11+
import SafariServices
12+
13+
class BuyAndSellViewController: FormViewController {
14+
// MARK: Rows
15+
enum Rows {
16+
case adamant
17+
case bitz
18+
case idcm
19+
20+
var tag: String {
21+
switch self {
22+
case .adamant: return "adm"
23+
case .bitz: return "bitz"
24+
case .idcm: return "idcm"
25+
}
26+
}
27+
28+
var image: UIImage? {
29+
switch self {
30+
case .adamant: return #imageLiteral(resourceName: "row_logo")
31+
case .bitz: return #imageLiteral(resourceName: "bitz_row_logo.png")
32+
case .idcm: return #imageLiteral(resourceName: "idcm_row_logo.png")
33+
}
34+
}
35+
36+
var localized: String {
37+
switch self {
38+
case .adamant: return String.adamantLocalized.wallets.buyAdmTokens
39+
case .bitz: return "Bit-Z"
40+
case .idcm: return "IDCM"
41+
}
42+
}
43+
44+
var url: String {
45+
switch self {
46+
case .adamant: return "https://adamant.im/buy-tokens/"
47+
case .bitz: return "https://www.bit-z.com/exchange/adm_usdt"
48+
case .idcm: return "https://www.idcm.io/trading/ADM_BTC"
49+
}
50+
}
51+
}
52+
53+
// MARK: - Props & Dependencies
54+
55+
var accountService: AccountService!
56+
var dialogService: DialogService!
57+
58+
// MARK: - Lifecycle
59+
60+
override func viewDidLoad() {
61+
super.viewDidLoad()
62+
63+
navigationItem.title = AdmWalletViewController.Rows.buyTokens.localized
64+
65+
let section = Section()
66+
67+
// MARK: Adamant
68+
let admUrl: String
69+
70+
if let account = accountService.account {
71+
admUrl = String.adamantLocalized.wallets.buyTokensUrl(for: account.address)
72+
} else {
73+
admUrl = Rows.adamant.url
74+
}
75+
76+
let admRow = buildUrlRow(title: Rows.adamant.localized, value: nil, tag: Rows.adamant.tag, urlRaw: admUrl, image: Rows.adamant.image)
77+
78+
section.append(admRow)
79+
80+
// MARK: Bit-Z
81+
let bitzRow = buildUrlRow(for: .bitz)
82+
section.append(bitzRow)
83+
84+
// MARK: IDCM
85+
let idcmRow = buildUrlRow(for: .idcm)
86+
section.append(idcmRow)
87+
88+
form.append(section)
89+
}
90+
91+
// MARK: - Tools
92+
93+
private func buildUrlRow(for row: Rows) -> LabelRow {
94+
return buildUrlRow(title: row.localized, value: nil, tag: row.tag, urlRaw: row.url, image: row.image)
95+
}
96+
97+
private func buildUrlRow(title: String, value: String?, tag: String, urlRaw: String, image: UIImage?) -> LabelRow {
98+
let row = LabelRow() {
99+
$0.tag = tag
100+
$0.title = title
101+
$0.value = value
102+
$0.cell.imageView?.image = image
103+
$0.cell.imageView?.tintColor = UIColor.adamant.tableRowIcons
104+
$0.cell.selectionStyle = .gray
105+
}.cellUpdate { (cell, _) in
106+
cell.accessoryType = .disclosureIndicator
107+
}.onCellSelection { [weak self] (_, _) in
108+
guard let url = URL(string: urlRaw) else {
109+
self?.dialogService.showError(withMessage: "Failed to create URL with string: \(urlRaw)", error: nil)
110+
return
111+
}
112+
113+
let safari = SFSafariViewController(url: url)
114+
safari.preferredControlTintColor = UIColor.adamant.primary
115+
self?.present(safari, animated: true, completion: nil)
116+
}
117+
118+
return row
119+
}
120+
}

Adamant/Wallets/WalletViewControllerBase.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class WalletViewControllerBase: FormViewController, WalletViewController {
3232
var localized: String {
3333
switch self {
3434
case .address: return NSLocalizedString("AccountTab.Row.Address", comment: "Account tab: 'Address' row")
35-
case . balance: return NSLocalizedString("AccountTab.Row.Balance", comment: "Account tab: Balance row title")
35+
case .balance: return NSLocalizedString("AccountTab.Row.Balance", comment: "Account tab: Balance row title")
3636
case .send: return NSLocalizedString("AccountTab.Row.SendTokens", comment: "Account tab: 'Send tokens' button")
3737
}
3838
}

0 commit comments

Comments
 (0)