Skip to content

Commit

Permalink
- add delegation to list of handled WC2 conformation screens
Browse files Browse the repository at this point in the history
- add the same header UI to stake confirm to allow display of WC2 dApp info (name, image etc)
  • Loading branch information
simonmcl committed Feb 14, 2024
1 parent 82fd35b commit 1ea9c7d
Show file tree
Hide file tree
Showing 7 changed files with 591 additions and 412 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"location" : "https://github.com/kukai-wallet/kukai-core-swift",
"state" : {
"branch" : "develop",
"revision" : "50642c483fcc185a2bf55f3fc2334154f703b79d"
"revision" : "137b92329aa18883efd2c73a0002f61ea9e4ee53"
}
},
{
Expand Down
13 changes: 11 additions & 2 deletions Kukai Mobile/Modules/Home/Base.lproj/Home.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
<segue destination="70q-lL-8WM" kind="presentation" identifier="app-update-required" modalPresentationStyle="overFullScreen" modalTransitionStyle="crossDissolve" id="2kJ-tl-bHi"/>
<segue destination="wXr-c8-sbt" kind="show" identifier="side-menu-show-onramp" id="yB4-OA-Mg2"/>
<segue destination="5kq-lD-FPQ" kind="custom" identifier="wallet-connect-generic" customClass="BottomSheetCustomSegue" customModule="Kukai_Mobile" customModuleProvider="target" id="bWZ-eJ-9bp"/>
<segue destination="SuN-lc-s6p" kind="custom" identifier="wallet-connect-delegate" customClass="BottomSheetCustomSegue" customModule="Kukai_Mobile" customModuleProvider="target" id="xUf-Hg-Wxw"/>
</connections>
</tabBarController>
<placeholder placeholderIdentifier="IBFirstResponder" id="C8m-X9-tpS" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
Expand Down Expand Up @@ -550,7 +551,7 @@
<viewControllerPlaceholder storyboardName="Send" referencedIdentifier="confirm-batch" id="2yu-Z9-dT9" sceneMemberID="viewController"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="QBe-QO-cvT" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-115" y="-2504"/>
<point key="canvasLocation" x="-132" y="-2527"/>
</scene>
<!--Discover-->
<scene sceneID="iYF-dS-aIN">
Expand Down Expand Up @@ -1372,7 +1373,15 @@
<viewControllerPlaceholder storyboardName="Send" referencedIdentifier="confirm-generic" id="5kq-lD-FPQ" sceneMemberID="viewController"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="QY1-LC-Yeq" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-115" y="-2458"/>
<point key="canvasLocation" x="-124" y="-2472"/>
</scene>
<!--confirm-stake-->
<scene sceneID="f6P-Cx-nlY">
<objects>
<viewControllerPlaceholder storyboardName="Stake" referencedIdentifier="confirm-stake" id="SuN-lc-s6p" sceneMemberID="viewController"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="d1g-SF-82o" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-132" y="-2498"/>
</scene>
</scenes>
<designables>
Expand Down
3 changes: 3 additions & 0 deletions Kukai Mobile/Modules/Home/HomeTabBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,9 @@ extension HomeTabBarController: WalletConnectServiceDelegate {
case .batch:
self.performSegue(withIdentifier: "wallet-connect-batch", sender: nil)

case .delegate:
self.performSegue(withIdentifier: "wallet-connect-delegate", sender: nil)

case .generic:
self.performSegue(withIdentifier: "wallet-connect-generic", sender: nil)
}
Expand Down
468 changes: 234 additions & 234 deletions Kukai Mobile/Modules/Send/Base.lproj/Send.storyboard

Large diffs are not rendered by default.

87 changes: 68 additions & 19 deletions Kukai Mobile/Modules/Stake/ConfirmStakeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@

import UIKit
import KukaiCoreSwift
import WalletConnectSign
import os.log

class ConfirmStakeViewController: UIViewController, SlideButtonDelegate, EditFeesViewControllerDelegate {
class ConfirmStakeViewController: SendAbstractConfirmViewController, SlideButtonDelegate, EditFeesViewControllerDelegate {

// Connected app
@IBOutlet weak var connectedAppLabel: UILabel!
@IBOutlet weak var connectedAppIcon: UIImageView!
@IBOutlet weak var connectedAppNameLabel: UILabel!
@IBOutlet weak var connectedAppMetadataStackView: UIStackView!

@IBOutlet weak var containerView: UIView!
@IBOutlet weak var confirmBakerAddView: UIView!
Expand All @@ -33,7 +40,6 @@ class ConfirmStakeViewController: UIViewController, SlideButtonDelegate, EditFee
@IBOutlet weak var testnetWarningView: UIView!

private var currentDelegateData: TransactionService.DelegateData = TransactionService.DelegateData()
private var selectedMetadata: WalletMetadata? = nil

var dimBackground: Bool = false

Expand All @@ -46,12 +52,38 @@ class ConfirmStakeViewController: UIViewController, SlideButtonDelegate, EditFee
}

self.currentDelegateData = TransactionService.shared.delegateData
self.selectedMetadata = DependencyManager.shared.selectedWalletMetadata

guard let baker = self.currentDelegateData.chosenBaker else {
return
}

// Handle wallet connect data
if let currentTopic = TransactionService.shared.walletConnectOperationData.request?.topic,
let session = Sign.instance.getSessions().first(where: { $0.topic == currentTopic }) {

guard let account = WalletConnectService.accountFromRequest(TransactionService.shared.walletConnectOperationData.request),
let walletMetadataForRequestedAccount = DependencyManager.shared.walletList.metadata(forAddress: account) else {
self.windowError(withTitle: "error".localized(), description: "error-no-account".localized())
self.handleRejection()
return
}

self.isWalletConnectOp = true
self.selectedMetadata = walletMetadataForRequestedAccount
self.connectedAppNameLabel.text = session.peer.name

if let iconString = session.peer.icons.first, let iconUrl = URL(string: iconString) {
let smallIconURL = MediaProxyService.url(fromUri: iconUrl, ofFormat: MediaProxyService.Format.icon.rawFormat())
connectedAppURL = smallIconURL
}

} else {
self.isWalletConnectOp = false
self.selectedMetadata = DependencyManager.shared.selectedWalletMetadata

connectedAppMetadataStackView.isHidden = true
connectedAppLabel.isHidden = true
}


// Baker info config
if self.currentDelegateData.isAdd == true {
Expand Down Expand Up @@ -112,6 +144,12 @@ class ConfirmStakeViewController: UIViewController, SlideButtonDelegate, EditFee
return
}

if let connectedAppURL = connectedAppURL {
MediaProxyService.load(url: connectedAppURL, to: self.connectedAppIcon, withCacheType: .temporary, fallback: UIImage.unknownToken())
} else {
self.connectedAppIcon.image = UIImage.unknownToken()
}

if self.currentDelegateData.isAdd == true {
MediaProxyService.load(url: URL(string: baker.logo ?? ""), to: bakerAddIcon, withCacheType: .temporary, fallback: UIImage.unknownToken())

Expand All @@ -126,15 +164,27 @@ class ConfirmStakeViewController: UIViewController, SlideButtonDelegate, EditFee
}

private func selectedOperationsAndFees() -> [KukaiCoreSwift.Operation] {
return TransactionService.shared.currentOperationsAndFeesData.selectedOperationsAndFees()
if isWalletConnectOp {
return TransactionService.shared.currentRemoteOperationsAndFeesData.selectedOperationsAndFees()

} else {
return TransactionService.shared.currentOperationsAndFeesData.selectedOperationsAndFees()
}
}

func didCompleteSlide() {
self.showLoadingModal(invisible: true)

self.showLoadingModal(invisible: true) { [weak self] in
self?.performAuth()
}
}

override func authSuccessful() {
guard let walletAddress = selectedMetadata?.address, let wallet = WalletCacheService().fetchWallet(forAddress: walletAddress) else {
self.windowError(withTitle: "error".localized(), description: "error-no-wallet-short".localized())
self.slideButton.resetSlider()
self.hideLoadingModal { [weak self] in
self?.windowError(withTitle: "error".localized(), description: "error-no-wallet-short".localized())
self?.slideButton.resetSlider()
}

return
}

Expand All @@ -145,9 +195,9 @@ class ConfirmStakeViewController: UIViewController, SlideButtonDelegate, EditFee
switch sendResult {
case .success(let opHash):
Logger.app.info("Sent: \(opHash)")

self?.didSend = true
self?.addPendingTransaction(opHash: opHash)
self?.dismissAndReturn()
self?.handleApproval(opHash: opHash)

case .failure(let sendError):
self?.windowError(withTitle: "error".localized(), description: sendError.description)
Expand All @@ -157,6 +207,12 @@ class ConfirmStakeViewController: UIViewController, SlideButtonDelegate, EditFee
}
}

override func authFailure() {
self.hideLoadingModal { [weak self] in
self?.slideButton.resetSlider()
}
}

func updateFees(isFirstCall: Bool = false) {
let feesAndData = TransactionService.shared.currentOperationsAndFeesData
let fee = (feesAndData.fee + feesAndData.maxStorageCost)
Expand All @@ -166,14 +222,7 @@ class ConfirmStakeViewController: UIViewController, SlideButtonDelegate, EditFee
}

@IBAction func closeTapped(_ sender: Any) {
self.dismissBottomSheet()
}

func dismissAndReturn() {
TransactionService.shared.resetAllState()

self.dismiss(animated: true, completion: nil)
(self.presentingViewController as? UINavigationController)?.popToHome()
handleRejection(collapseOnly: true)
}

func addPendingTransaction(opHash: String) {
Expand Down
Loading

0 comments on commit 1ea9c7d

Please sign in to comment.