Skip to content

Commit

Permalink
Merge branch 'feature/bug_fixes' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmcl committed Jan 22, 2024
2 parents 22fe8c3 + 91d05ad commit d7a8758
Show file tree
Hide file tree
Showing 19 changed files with 168 additions and 88 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" : "55c19abeb503e4e69c7a811d85e77d8199e74b9d"
"revision" : "6a7d1f937117de5d88b9a936e74c64084a56be2b"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@

import UIKit
import KukaiCoreSwift
import CloudKit

public enum AddressType: String, CaseIterable {
case tezosAddress = "Tezos Address"
case tezosDomain = "Tezos Domain"
case gmail = "Google"
case reddit = "Reddit"
case twitter = "Twitter"
case email = "Email"
}

public protocol AddressTypeDelegate: AnyObject {
Expand All @@ -30,7 +32,7 @@ class AddressTypeViewController: UIViewController, UITableViewDelegate, UITableV
public var selectedIndex: IndexPath = IndexPath(row: 0, section: 0)

public var headerText: String = "Recipient Address"
public var supportedAddressTypes: [AddressType] = [.tezosAddress, .tezosDomain, .gmail]
public var supportedAddressTypes: [AddressType] = [.tezosAddress, .tezosDomain, .gmail, .reddit, .twitter, .email]

override func viewDidLoad() {
super.viewDidLoad()
Expand Down Expand Up @@ -72,6 +74,9 @@ class AddressTypeViewController: UIViewController, UITableViewDelegate, UITableV

case .twitter:
tempMetadata = WalletMetadata(address: "", hdWalletGroupName: nil, walletNickname: nil, socialUsername: nil, socialType: .twitter, type: .social, children: [], isChild: false, isWatchOnly: false, bas58EncodedPublicKey: "", backedUp: false)

case .email:
tempMetadata = WalletMetadata(address: "", hdWalletGroupName: nil, walletNickname: nil, socialUsername: nil, socialType: .email, type: .social, children: [], isChild: false, isWatchOnly: false, bas58EncodedPublicKey: "", backedUp: false)
}

return TransactionService.walletMedia(forWalletMetadata: tempMetadata, ofSize: .size_22).image
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class EnterAddressComponent: UIView {
private let addressTypeVC = UIStoryboard(name: "SendAddressType", bundle: nil).instantiateInitialViewController() as? AddressTypeViewController
private var addressTypeHeader = "Recipient Address"
private let nibName = "EnterAddressComponent"
private let cloudKitService = CloudKitService()

private var currentSelectedType: AddressType = .tezosAddress

Expand Down Expand Up @@ -127,7 +128,7 @@ public class EnterAddressComponent: UIView {
completion(Result.success(string))

case .tezosDomain:
DependencyManager.shared.tezosDomainsClient.getAddressFor(domain: string, completion: { result in
DependencyManager.shared.tezosDomainsClient.getAddressFor(domain: string.lowercased(), completion: { result in
switch result {
case .success(let response):
if let add = response.data?.domain.address {
Expand All @@ -150,10 +151,31 @@ public class EnterAddressComponent: UIView {

case .twitter:
handleTorus(verifier: .twitter, string: string, completion: completion)

case .email:
handleTorus(verifier: .email, string: string, completion: completion)
}
}

private func handleTorus(verifier: TorusAuthProvider, string: String, completion: @escaping ((Result<String, KukaiError>) -> Void)) {

// Check to see if we need to fetch torus verfier config
if DependencyManager.shared.torusVerifiers.keys.count == 0 {
cloudKitService.fetchConfigItems { [weak self] error in
if let e = error {
completion(Result.failure(KukaiError.unknown(withString: String.localized(String.localized("error-no-cloudkit-config"), withArguments: e.localizedDescription))))

} else {
DependencyManager.shared.torusVerifiers = self?.cloudKitService.extractTorusConfig() ?? [:]
self?.performTorusLookup(verifier: verifier, string: string, completion: completion)
}
}
} else {
performTorusLookup(verifier: verifier, string: string, completion: completion)
}
}

private func performTorusLookup(verifier: TorusAuthProvider, string: String, completion: @escaping ((Result<String, KukaiError>) -> Void)) {
guard DependencyManager.shared.torusVerifiers[verifier] != nil else {
let error = KukaiError.unknown(withString: "No \(verifier.rawValue) verifier details found")
completion(Result.failure(error))
Expand All @@ -167,8 +189,6 @@ public class EnterAddressComponent: UIView {





// MARK: - UI functions

public func showError(message: String) {
Expand Down Expand Up @@ -248,6 +268,9 @@ extension EnterAddressComponent: ValidatorTextFieldDelegate {

case .twitter:
return "Invalid Twitter username"

case .email:
return "Invalid email address"
}
}

Expand Down Expand Up @@ -302,6 +325,12 @@ extension EnterAddressComponent: AddressTypeDelegate {
addressTypeButton.setTitle("Twitter", for: .normal)
textField.placeholder = "@ Enter Twitter Handle"
textField.validator = NoWhiteSpaceStringValidator()

case .email:
sendToIcon.image = AddressTypeViewController.imageFor(addressType: type)
addressTypeButton.setTitle("Email", for: .normal)
textField.placeholder = "Enter email address"
textField.validator = NoWhiteSpaceStringValidator()
}

if !textField.revalidateTextfield() {
Expand Down
1 change: 0 additions & 1 deletion Kukai Mobile/Controls/ScanViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ class ScanViewController: UIViewController, AVCaptureMetadataOutputObjectsDelega
self.textfield.text = ""

} else {
captureSession.stopRunning()
found(code: stringToCheck)
}
}
Expand Down
1 change: 1 addition & 0 deletions Kukai Mobile/Localization/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"error-wc2-errorcode"="Unable to respond to Wallet Connect: %@ - %@";
"error-no-cloudkit-config"="Unable to fetch config settings: %@";
"error-cant-cache"="Unable to cache";
"error-wallet-already-exists"="This wallet address already exists. It can't be added again";
"error-cant-create-wallet"="Unable to create wallet";
"error-missing-verifier"="Unsupported, due to missing verifier";
"error-new-wallet-details"="Unable to create wallet from details supplied. Please check and try again";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ class CollectiblesDetailsViewModel: ViewModel, UICollectionViewDiffableDataSourc
if mediaType == nil && !isCached {

// Check to see if we have a cached thumbnail. If so load that (using its dimensions for the correct layout), then load real image later
let cacheURL = MediaProxyService.url(fromUri: nft?.thumbnailURI, ofFormat: MediaProxyService.Format.small.rawFormat())
let cacheURL = MediaProxyService.url(fromUri: nft?.thumbnailURI, ofFormat: MediaProxyService.Format.medium.rawFormat())
MediaProxyService.sizeForImageIfCached(url: cacheURL) { size in
let finalSize = (size ?? CGSize(width: 300, height: 300))
let mediaContent = MediaContent(isImage: true, isThumbnail: true, mediaURL: cacheURL, mediaURL2: nil, width: finalSize.width, height: finalSize.height)
Expand Down Expand Up @@ -393,7 +393,7 @@ class CollectiblesDetailsViewModel: ViewModel, UICollectionViewDiffableDataSourc

// Fallback
else {
let mediaContent = MediaContent(isImage: true, isThumbnail: true, mediaURL: MediaProxyService.url(fromUri: nft?.thumbnailURI, ofFormat: MediaProxyService.Format.small.rawFormat()), mediaURL2: nil, width: 300, height: 300)
let mediaContent = MediaContent(isImage: true, isThumbnail: true, mediaURL: MediaProxyService.url(fromUri: nft?.thumbnailURI, ofFormat: MediaProxyService.Format.medium.rawFormat()), mediaURL2: nil, width: 300, height: 300)
completion((mediaContent: mediaContent, needsToDownloadFullImage: false, needsMediaTypeVerification: true))
}
}
Expand Down Expand Up @@ -431,7 +431,7 @@ class CollectiblesDetailsViewModel: ViewModel, UICollectionViewDiffableDataSourc
MediaProxyService.sizeForImageIfCached(url: cacheURL) { size in
let finalSize = (size ?? CGSize(width: 300, height: 300))
if mediaType == .imageOnly {
let url = loadingThumbnailFirst ? MediaProxyService.url(fromUri: nft?.thumbnailURI ?? nft?.artifactURI, ofFormat: MediaProxyService.Format.small.rawFormat()) : MediaProxyService.url(fromUri: nft?.displayURI ?? nft?.artifactURI, ofFormat: MediaProxyService.Format.large.rawFormat())
let url = loadingThumbnailFirst ? MediaProxyService.url(fromUri: nft?.thumbnailURI ?? nft?.artifactURI, ofFormat: MediaProxyService.Format.medium.rawFormat()) : MediaProxyService.url(fromUri: nft?.displayURI ?? nft?.artifactURI, ofFormat: MediaProxyService.Format.large.rawFormat())
let mediaContent = MediaContent(isImage: true, isThumbnail: loadingThumbnailFirst, mediaURL: url, mediaURL2: nil, width: finalSize.width, height: finalSize.height)
completion((mediaContent: mediaContent, needsToDownloadFullImage: loadingThumbnailFirst, needsMediaTypeVerification: false))

Expand All @@ -452,7 +452,7 @@ class CollectiblesDetailsViewModel: ViewModel, UICollectionViewDiffableDataSourc
return
}

currentSnapshot.insertItems([newMediaContent], beforeItem: quantityContent)
currentSnapshot.insertItems([newMediaContent], beforeItem: oldMediaContent)
currentSnapshot.deleteItems([oldMediaContent])

DispatchQueue.main.async { [weak self] in
Expand Down
13 changes: 6 additions & 7 deletions Kukai Mobile/Modules/Home/AccountsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,14 @@ class AccountsViewModel: ViewModel, UITableViewDiffableDataSourceHandler {
return
}

WalletManagementService.cacheNew(wallet: newChild, forChildOfIndex: hdWalletIndex, markSelected: false) { [weak self] success in
guard success else {
WalletManagementService.cacheNew(wallet: newChild, forChildOfIndex: hdWalletIndex, markSelected: false) { [weak self] errorString in
if let eString = errorString {
vc.hideLoadingView()
vc.windowError(withTitle: "error".localized(), description: eString)
} else {
self?.refresh(animate: true)
vc.hideLoadingView()
vc.windowError(withTitle: "error".localized(), description: "error-cant-cache".localized())
return
}

self?.refresh(animate: true)
vc.hideLoadingView()
}
})
}
Expand Down
4 changes: 3 additions & 1 deletion Kukai Mobile/Modules/Home/HomeTabBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,9 @@ extension HomeTabBarController: WalletConnectServiceDelegate {
DispatchQueue.main.asyncAfter(wallDeadline: .now() + 3) { [weak self] in
WalletConnectService.shared.isConnected { [weak self] connected in
if connected {
self?.connectionStatusChanged(status: .connected)
DispatchQueue.main.async {
self?.connectionStatusChanged(status: .connected)
}
}
}
}
Expand Down
14 changes: 12 additions & 2 deletions Kukai Mobile/Modules/Onboarding/CreateWalletViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,21 @@ class CreateWalletViewController: UIViewController {
if let wallet = HDWallet(withMnemonicLength: .twentyFour, passphrase: "") {
let walletCache = WalletCacheService()

if walletCache.cache(wallet: wallet, childOfIndex: nil, backedUp: false) {
do {
try walletCache.cache(wallet: wallet, childOfIndex: nil, backedUp: false)
DependencyManager.shared.walletList = walletCache.readMetadataFromDiskAndDecrypt()
DependencyManager.shared.selectedWalletMetadata = DependencyManager.shared.walletList.metadata(forAddress: wallet.address)
self.navigate()
} else {

} catch let error as WalletCacheError {

if error == WalletCacheError.walletAlreadyExists {
self.windowError(withTitle: "error".localized(), description: "error-wallet-already-exists".localized())
} else {
self.windowError(withTitle: "error".localized(), description: "error-cant-cache".localized())
}

} catch {
self.windowError(withTitle: "error".localized(), description: "error-cant-cache".localized())
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,12 @@ class CreateWithSocialViewController: UIViewController {
case .success(let wallet):
self.updateLoadingModalStatusLabel(message: "Wallet created, checking for tezos domain registrations")

WalletManagementService.cacheNew(wallet: wallet, forChildOfIndex: nil, markSelected: true) { [weak self] success in
if success {
self?.navigate()

} else {
WalletManagementService.cacheNew(wallet: wallet, forChildOfIndex: nil, markSelected: true) { [weak self] errorString in
if let eString = errorString {
self?.hideLoadingView()
self?.windowError(withTitle: "error".localized(), description: "error-cant-cache".localized())
self?.windowError(withTitle: "error".localized(), description: eString)
} else {
self?.navigate()
}
}

Expand Down
24 changes: 13 additions & 11 deletions Kukai Mobile/Modules/Onboarding/ImportWalletViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,35 +174,37 @@ class ImportWalletViewController: UIViewController {

if wallet is HDWallet, let hd = wallet as? HDWallet {
Task {
if await WalletManagementService.cacheWalletAndScanForAccounts(wallet: hd, progress: { [weak self] found in
let errorString = await WalletManagementService.cacheWalletAndScanForAccounts(wallet: hd, progress: { [weak self] found in
if found == 1 {
self?.accountScanningVc?.showAllText()
}

self?.accountScanningVc?.updateFound(found)

}) {
})

if let eString = errorString {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in
self?.hideLoadingView()
self?.windowError(withTitle: "error".localized(), description: eString)
}
} else {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in
self?.removeScanningVc()
self?.navigate()
}

} else {
self.removeScanningVc()
self.windowError(withTitle: "error".localized(), description: "error-cant-cache".localized())
}
}

} else {
accountScanningVc?.hideAllText()
WalletManagementService.cacheNew(wallet: wallet, forChildOfIndex: nil, markSelected: true) { [weak self] success in
if success {
WalletManagementService.cacheNew(wallet: wallet, forChildOfIndex: nil, markSelected: true) { [weak self] errorString in
if let eString = errorString {
self?.removeScanningVc()
self?.navigate()

self?.windowError(withTitle: "error".localized(), description: eString)
} else {
self?.removeScanningVc()
self?.windowError(withTitle: "error".localized(), description: "error-cant-cache".localized())
self?.navigate()
}
}
}
Expand Down
22 changes: 13 additions & 9 deletions Kukai Mobile/Modules/Send/SendAbstractConfirmViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,33 @@ class SendAbstractConfirmViewController: UIViewController {
}
}

func dismissAndReturn() {
func dismissAndReturn(collapseOnly: Bool) {
if !isWalletConnectOp {
TransactionService.shared.resetAllState()
}

self.dismiss(animated: true)
(self.presentingViewController as? UINavigationController)?.popToHome()

if collapseOnly == false {
(self.presentingViewController as? UINavigationController)?.popToHome()
}
}



// MARK: - WC2 functions

func handleRejection(andDismiss: Bool = true) {
func handleRejection(andDismiss: Bool = true, collapseOnly: Bool = false) {
if !isWalletConnectOp {
if andDismiss { self.dismissAndReturn() }
if andDismiss { self.dismissAndReturn(collapseOnly: collapseOnly) }
return
}

WalletConnectService.rejectCurrentRequest(completion: { [weak self] success, error in
self?.hideLoadingModal(completion: { [weak self] in
if success {
if andDismiss { self?.dismissAndReturn() }
self?.didSend = true
if andDismiss { self?.dismissAndReturn(collapseOnly: collapseOnly) }

} else {
var message = ""
Expand All @@ -69,22 +73,22 @@ class SendAbstractConfirmViewController: UIViewController {

Logger.app.error("WC Rejction error: \(error)")
self?.windowError(withTitle: "error".localized(), description: message)
self?.dismissAndReturn()
self?.dismissAndReturn(collapseOnly: collapseOnly)
}
})
})
}

func handleApproval(opHash: String) {
if !isWalletConnectOp {
self.dismissAndReturn()
self.dismissAndReturn(collapseOnly: false)
return
}

WalletConnectService.approveCurrentRequest(signature: nil, opHash: opHash, completion: { [weak self] success, error in
self?.hideLoadingModal(completion: { [weak self] in
if success {
self?.dismissAndReturn()
self?.dismissAndReturn(collapseOnly: false)

} else {
var message = "error-wc2-unrecoverable".localized()
Expand All @@ -99,7 +103,7 @@ class SendAbstractConfirmViewController: UIViewController {

Logger.app.error("WC Approve error: \(error)")
self?.windowError(withTitle: "error".localized(), description: message)
self?.dismissAndReturn()
self?.dismissAndReturn(collapseOnly: true)
}
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class SendCollectibleConfirmViewController: SendAbstractConfirmViewController, S
}

@IBAction func closeTapped(_ sender: Any) {
handleRejection()
handleRejection(collapseOnly: true)
}

private func selectedOperationsAndFees() -> [KukaiCoreSwift.Operation] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ class SendContractConfirmViewController: SendAbstractConfirmViewController, Slid
}

@IBAction func closeTapped(_ sender: Any) {
handleRejection()
handleRejection(collapseOnly: true)
}

func addPendingTransaction(opHash: String) {
Expand Down
Loading

0 comments on commit d7a8758

Please sign in to comment.