Skip to content

Commit

Permalink
Deeplink handling - cleanup (#917)
Browse files Browse the repository at this point in the history
- Removed dead code related to deeplink handling
- Replaced broken navigation triggered by old deeplink handler
  • Loading branch information
TruszczynskiA authored May 29, 2023
1 parent 0ddc576 commit 1e81bcd
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 82 deletions.
8 changes: 4 additions & 4 deletions MobileWallet/Common/AppRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ enum AppRouter {

// MARK: - TabBar Actions

static func moveToTransactionSend(deeplink: TransactionsSendDeeplink?) {
tabBar?.homeViewController.onSend(deeplink: deeplink)
static func moveToContactBook() {
tabBar?.setTab(.contactBook)
}

static func moveToProfile() {
tabBar?.setTab(.profile)
present(controller: ProfileViewController())
}

// MARK: - Modal Actions
Expand Down Expand Up @@ -156,7 +156,7 @@ enum AppRouter {
}

static func presentSendTransaction(paymentInfo: PaymentInfo) {
let controller = AddAmountViewController(paymentInfo: paymentInfo, deeplink: nil)
let controller = AddAmountViewController(paymentInfo: paymentInfo)
let navigationController = AlwaysPoppableNavigationController(rootViewController: controller)
navigationController.isNavigationBarHidden = true
tabBar?.presentOnFullScreen(navigationController)
Expand Down
7 changes: 5 additions & 2 deletions MobileWallet/Common/Data Models/PaymentInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
*/

struct PaymentInfo {
let address: TariAddress
let yatID: String?
let address: String
let yatID: String?
let amount: MicroTari?
let feePerGram: MicroTari?
let note: String?
}
14 changes: 13 additions & 1 deletion MobileWallet/Common/Deep Links/DeeplinkHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ enum DeeplinkHandler {
let deeplink = try DeepLinkFormatter.model(type: TransactionsSendDeeplink.self, deeplink: transactionSendDeeplink)

guard let handler = handler else {
AppRouter.moveToTransactionSend(deeplink: deeplink)
showTransactionFlow(deeplink: deeplink)
return
}

Expand All @@ -89,6 +89,18 @@ enum DeeplinkHandler {
}
}

private static func showTransactionFlow(deeplink: TransactionsSendDeeplink) {

var amount: MicroTari?

if let rawAmount = deeplink.amount {
amount = MicroTari(rawAmount)
}

let paymentInfo = PaymentInfo(address: deeplink.receiverAddress, yatID: nil, amount: amount, feePerGram: nil, note: deeplink.note)
AppRouter.presentSendTransaction(paymentInfo: paymentInfo)
}

private static func handle(baseNodesAddDeeplink: URL, handler: DeeplinkHandlable?) throws {

do {
Expand Down
2 changes: 1 addition & 1 deletion MobileWallet/Common/Managers/ShortcutsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ final class ShortcutsManager {
case .showQR:
AppRouter.moveToProfile()
case .send:
AppRouter.moveToTransactionSend(deeplink: nil)
AppRouter.moveToContactBook()
}
}

Expand Down
10 changes: 6 additions & 4 deletions MobileWallet/Common/Managers/WalletTransactionsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ final class WalletTransactionsManager {
case unsucessfulTransaction
case noInternetConnection
case timeout
case missingInputData
}

enum State {
Expand All @@ -61,7 +62,7 @@ final class WalletTransactionsManager {

// MARK: - Actions

func performTransactionPublisher(address: TariAddress, amount: MicroTari, feePerGram: MicroTari, message: String, isOneSidedPayment: Bool) -> AnyPublisher<State, TransactionError> {
func performTransactionPublisher(address: String, amount: MicroTari, feePerGram: MicroTari, message: String, isOneSidedPayment: Bool) -> AnyPublisher<State, TransactionError> {

let subject = CurrentValueSubject<State, TransactionError>(.connectionCheck)

Expand Down Expand Up @@ -108,11 +109,12 @@ final class WalletTransactionsManager {
.store(in: &cancellables)
}

private func sendTransactionToBlockchain(address: TariAddress, amount: MicroTari, feePerGram: MicroTari, message: String, isOneSidedPayment: Bool, result: @escaping (Result<Void, TransactionError>) -> Void) {
private func sendTransactionToBlockchain(address: String, amount: MicroTari, feePerGram: MicroTari, message: String, isOneSidedPayment: Bool, result: @escaping (Result<Void, TransactionError>) -> Void) {

do {
let tariAddress = try TariAddress(hex: address)
let transactionID = try Tari.shared.transactions.send(
toAddress: address,
toAddress: tariAddress,
amount: amount.rawValue,
feePerGram: feePerGram.rawValue,
message: message,
Expand All @@ -123,7 +125,7 @@ final class WalletTransactionsManager {
result(.success)
return
}
startListeningForWalletEvents(transactionID: transactionID, recipientHex: try address.byteVector.hex, result: result)
startListeningForWalletEvents(transactionID: transactionID, recipientHex: address, result: result)
} catch {
result(.failure(.transactionError(error: error)))
}
Expand Down
4 changes: 2 additions & 2 deletions MobileWallet/Screens/Contact Book/List/ContactBookModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,13 @@ final class ContactBookModel {

func sendTokensRequest() {

guard let enteredAddress else {
guard let enteredAddress, let hex = try? enteredAddress.byteVector.hex else {
Logger.log(message: "No Address on 'send tokens' request.", domain: .navigation, level: .error)
errorModel = ErrorMessageManager.errorModel(forError: nil)
return
}

let paymentInfo = PaymentInfo(address: enteredAddress, yatID: yatID)
let paymentInfo = PaymentInfo(address: hex, yatID: yatID, amount: nil, feePerGram: nil, note: nil)
action = .sendTokens(paymentInfo: paymentInfo)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@ extension ContactsManager.Model {
var paymentInfo: PaymentInfo? {
get throws {
guard let internalModel else { return nil }
let address = try TariAddress(hex: internalModel.hex)
return PaymentInfo(address: address, yatID: nil)
return PaymentInfo(address: internalModel.hex, yatID: nil, amount: nil, feePerGram: nil, note: nil)
}
}
}
16 changes: 0 additions & 16 deletions MobileWallet/Screens/Home/Home/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -352,22 +352,6 @@ final class HomeViewController: DynamicThemeViewController {
)
}
}

func onSend(deeplink: TransactionsSendDeeplink? = nil) {
// FIXME: Deeplink Handler

// let sendVC = TransactionsViewController()
// let navigationController = AlwaysPoppableNavigationController(rootViewController: sendVC)
// navigationController.setNavigationBarHidden(true, animated: false)
// navigationController.modalPresentationStyle = .fullScreen
//
// DispatchQueue.main.async {
// UIApplication.shared.menuTabBarController?.present(navigationController, animated: true) {
// guard let deeplink = deeplink else { return }
// sendVC.update(deeplink: deeplink)
// }
// }
}
}

// MARK: - TxTableDelegateMethods
Expand Down
38 changes: 16 additions & 22 deletions MobileWallet/Screens/Send/AddAmount/AddAmountViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import Combine
final class AddAmountViewController: DynamicThemeViewController {

private let paymentInfo: PaymentInfo
private let deeplink: TransactionsSendDeeplink?

private let navigationBar = NavigationBar()
@View private var emojiIdView = EmojiIdView()
Expand Down Expand Up @@ -149,9 +148,8 @@ final class AddAmountViewController: DynamicThemeViewController {
private var isBalanceExceeded = false
private var cancellables = Set<AnyCancellable>()

init(paymentInfo: PaymentInfo, deeplink: TransactionsSendDeeplink?) {
init(paymentInfo: PaymentInfo) {
self.paymentInfo = paymentInfo
self.deeplink = deeplink
super.init(nibName: nil, bundle: nil)
}

Expand All @@ -166,10 +164,8 @@ final class AddAmountViewController: DynamicThemeViewController {
updateLabelText()
showAvailableBalance()

// Deep link value
if let amount = deeplink?.amount, amount > 0 {
let tariAmount = MicroTari(amount)
addCharacter(tariAmount.formattedPrecise)
if let amount = paymentInfo.amount, amount.isGreaterThanZero {
addCharacter(amount.formattedPrecise)
}

setupOneSidedPaymentElements()
Expand All @@ -185,8 +181,9 @@ final class AddAmountViewController: DynamicThemeViewController {

private func displayAliasOrEmojiId() {
do {
guard let contact = try Tari.shared.contacts.findContact(hex: paymentInfo.address.byteVector.hex) else {
emojiIdView.setup(emojiID: try paymentInfo.address.emojis, hex: try paymentInfo.address.byteVector.hex, textCentered: true, inViewController: self)
guard let contact = try Tari.shared.contacts.findContact(hex: paymentInfo.address) else {
let tariAddress = try TariAddress(hex: paymentInfo.address)
emojiIdView.setup(emojiID: try tariAddress.emojis, hex: paymentInfo.address, textCentered: true, inViewController: self)
return
}
navigationBar.title = try contact.alias
Expand Down Expand Up @@ -455,9 +452,9 @@ final class AddAmountViewController: DynamicThemeViewController {
}

@objc private func continueButtonTapped() {
guard let amount = calculateAmount(), let feePerGram = feePerGram else { return }
let noteVC = AddNoteViewController(paymentInfo: paymentInfo, amount: amount, feePerGram: feePerGram, isOneSidedPayment: oneSidedPaymentSwitch.isOn, deeplink: deeplink)
navigationController?.pushViewController(noteVC, animated: true)
guard let paymentInfo = updatedPaymentInfo(), let feePerGram = feePerGram else { return }
let controller = AddNoteViewController(paymentInfo: paymentInfo, feePerGram: feePerGram, isOneSidedPayment: oneSidedPaymentSwitch.isOn)
navigationController?.pushViewController(controller, animated: true)
}

private func calculateAmount() -> MicroTari? {
Expand Down Expand Up @@ -492,22 +489,19 @@ final class AddAmountViewController: DynamicThemeViewController {
return amount
}

private func updatedPaymentInfo() -> PaymentInfo? {
guard let amount = calculateAmount(), let feePerGram = feePerGram else { return nil }
return PaymentInfo(address: paymentInfo.address, yatID: paymentInfo.yatID, amount: amount, feePerGram: feePerGram, note: paymentInfo.note)
}

private func updateNextStepElements(isEnabled: Bool) {
continueButton.variation = isEnabled ? .normal : .disabled
sliderBar.isEnabled = isEnabled
}

private func showTransactionProgress() {
guard let amount = calculateAmount(), let feePerGram = feePerGram else { return }
TransactionProgressPresenter.showTransactionProgress(
presenter: self,
recipientAddress: paymentInfo.address,
amount: amount,
feePerGram: feePerGram,
message: "",
isOneSidedPayment: oneSidedPaymentSwitch.isOn,
yatID: paymentInfo.yatID
)
guard let paymentInfo = updatedPaymentInfo() else { return }
TransactionProgressPresenter.showTransactionProgress(presenter: self, paymentInfo: paymentInfo, isOneSidedPayment: oneSidedPaymentSwitch.isOn)
}

@objc private func onOneSidedPaymentSwitchAction() {
Expand Down
28 changes: 9 additions & 19 deletions MobileWallet/Screens/Send/AddNote/AddNoteViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ final class AddNoteViewController: DynamicThemeViewController, UIScrollViewDeleg
private static var giphyCurrentKeywordIndex = 0

private let paymentInfo: PaymentInfo
private let amount: MicroTari
private let feePerGram: MicroTari
private let isOneSidedPayment: Bool
private let deeplink: TransactionsSendDeeplink?

private let sidePadding = Theme.shared.sizes.appSidePadding
@View private var navigationBar = NavigationBar()
Expand Down Expand Up @@ -103,12 +101,10 @@ final class AddNoteViewController: DynamicThemeViewController, UIScrollViewDeleg
}
}

init(paymentInfo: PaymentInfo, amount: MicroTari, feePerGram: MicroTari, isOneSidedPayment: Bool, deeplink: TransactionsSendDeeplink?) {
init(paymentInfo: PaymentInfo, feePerGram: MicroTari, isOneSidedPayment: Bool) {
self.paymentInfo = paymentInfo
self.amount = amount
self.feePerGram = feePerGram
self.isOneSidedPayment = isOneSidedPayment
self.deeplink = deeplink
super.init(nibName: nil, bundle: nil)
}

Expand All @@ -135,7 +131,7 @@ final class AddNoteViewController: DynamicThemeViewController, UIScrollViewDeleg

navigationController?.interactivePopGestureRecognizer?.isEnabled = false

if let note = deeplink?.note {
if let note = paymentInfo.note {
noteInput.text = note
textViewDidChangeSelection(noteInput)
}
Expand All @@ -151,13 +147,14 @@ final class AddNoteViewController: DynamicThemeViewController, UIScrollViewDeleg
var alias: String?

do {
alias = try Tari.shared.contacts.findContact(hex: try paymentInfo.address.byteVector.hex)?.alias
alias = try Tari.shared.contacts.findContact(hex: paymentInfo.address)?.alias
} catch {
}

guard let alias = alias, !alias.trimmingCharacters(in: .whitespaces).isEmpty else {
do {
emojiIdView.setup(emojiID: try paymentInfo.address.emojis, hex: try paymentInfo.address.byteVector.hex, textCentered: true, inViewController: self)
let tariAddress = try TariAddress(hex: paymentInfo.address)
emojiIdView.setup(emojiID: try tariAddress.emojis, hex: paymentInfo.address, textCentered: true, inViewController: self)
} catch {
PopUpPresenter.show(message: MessageModel(title: localized("navigation_bar.error.show_emoji.title"), message: localized("navigation_bar.error.show_emoji.description"), type: .error))
}
Expand Down Expand Up @@ -264,26 +261,19 @@ final class AddNoteViewController: DynamicThemeViewController, UIScrollViewDeleg

private func onSlideToEndAction() {
dismissKeyboard()
sendTx(recipientAddress: paymentInfo.address, amount: amount, feePerGram: feePerGram)
sendTx()
}

private func sendTx(recipientAddress: TariAddress, amount: MicroTari, feePerGram: MicroTari) {
private func sendTx() {

var message = noteText

if let attachment = attachment, let embedUrl = attachment.embedUrl {
message += " \(embedUrl)"
}

TransactionProgressPresenter.showTransactionProgress(
presenter: self,
recipientAddress: recipientAddress,
amount: amount,
feePerGram: feePerGram,
message: message,
isOneSidedPayment: isOneSidedPayment,
yatID: paymentInfo.yatID
)
let paymentInfo = PaymentInfo(address: paymentInfo.address, yatID: paymentInfo.yatID, amount: paymentInfo.amount, feePerGram: paymentInfo.amount, note: message)
TransactionProgressPresenter.showTransactionProgress(presenter: self, paymentInfo: paymentInfo, isOneSidedPayment: isOneSidedPayment)
}

override func update(theme: ColorTheme) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import Combine
final class SendingTariModel {

struct InputData {
let address: TariAddress
let address: String
let amount: MicroTari
let feePerGram: MicroTari
let message: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ enum YatTransactionViewState {
final class YatTransactionModel {

struct InputData {
let address: TariAddress
let address: String
let amount: MicroTari
let feePerGram: MicroTari
let message: String
Expand Down
2 changes: 2 additions & 0 deletions MobileWallet/TariLib/Wrappers/Utils/MicroTari.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ struct MicroTari {
return MicroTari.preciseFormatter.string(from: NSNumber(value: self.taris))!
}

var isGreaterThanZero: Bool { rawValue > 0 }

init() { self.init(0) }

init(_ rawValue: UInt64) {
Expand Down
3 changes: 1 addition & 2 deletions MobileWallet/UIElements/TabBar/MenuTabBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ final class MenuTabBarController: UITabBarController {
enum Tab: Int {
case home
case ttlStore
case sendFlow
case profile
case contactBook
case settings
}

Expand Down
Loading

0 comments on commit 1e81bcd

Please sign in to comment.