Skip to content

Commit

Permalink
- remove force mainnet check for adding an account when its via the c…
Browse files Browse the repository at this point in the history
…ontext menu (remain in place for account scanning)

- hide "backup" warning for children who's parent is backed up
- pressing backup from a child, will backup the corresponding parent
  • Loading branch information
simonmcl committed May 29, 2024
1 parent 1a3c154 commit 155815d
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"location" : "https://github.com/kukai-wallet/kukai-core-swift",
"state" : {
"branch" : "develop",
"revision" : "d4c59332acc9d6d32ae45e5d4cbf441a0e9e1b46"
"revision" : "20c37e6e9344500c64d550a644b29c1b2185af87"
}
},
{
Expand Down
7 changes: 4 additions & 3 deletions Kukai Mobile/Modules/Account/AccountViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ class AccountViewModel: ViewModel, UITableViewDiffableDataSourceHandler {
}

let metadata = DependencyManager.shared.selectedWalletMetadata
let parentMetadata = metadata?.isChild == true ? DependencyManager.shared.walletList.parentMetadata(forChildAddress: metadata?.address ?? "") : nil
let isTestnet = DependencyManager.shared.currentNetworkType == .testnet
var snapshot = NSDiffableDataSourceSnapshot<Int, AnyHashable>()
var data: [AnyHashable] = []
Expand All @@ -224,7 +225,7 @@ class AccountViewModel: ViewModel, UITableViewDiffableDataSourceHandler {
data = handleRefreshForNewUser(startingData: data, metadata: metadata)

} else {
data = handleRefreshForRegularUser(startingData: data, metadata: metadata, selectedAddress: selectedAddress)
data = handleRefreshForRegularUser(startingData: data, metadata: metadata, parentMetadata: parentMetadata, selectedAddress: selectedAddress)
}

} else {
Expand Down Expand Up @@ -261,10 +262,10 @@ class AccountViewModel: ViewModel, UITableViewDiffableDataSourceHandler {
return (xtzBalance == .zero() && tokenCount == 0)
}

private func handleRefreshForRegularUser(startingData: [AnyHashable], metadata: WalletMetadata?, selectedAddress: String) -> [AnyHashable] {
private func handleRefreshForRegularUser(startingData: [AnyHashable], metadata: WalletMetadata?, parentMetadata: WalletMetadata?, selectedAddress: String) -> [AnyHashable] {
var data = startingData

if metadata?.backedUp == false {
if metadata?.backedUp == false && (parentMetadata == nil || parentMetadata?.backedUp != true) {
data.append(BackupCellData())
}

Expand Down
2 changes: 1 addition & 1 deletion Kukai Mobile/Modules/Home/AccountsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ class AccountsViewModel: ViewModel, UITableViewDiffableDataSourceHandler {
let addAccount = UIAction(title: "Add Account", image: UIImage(named: "AddNewAccount")) { [weak self] action in

vc.showLoadingView()
AddAccountViewModel.addAccount(forMetadata: walletMetadata, hdWalletIndex: hdWalletIndex) { [weak self] errorTitle, errorMessage in
AddAccountViewModel.addAccount(forMetadata: walletMetadata, hdWalletIndex: hdWalletIndex, forceMainnet: false) { [weak self] errorTitle, errorMessage in
vc.hideLoadingView()
if let title = errorTitle, let message = errorMessage {
vc.windowError(withTitle: title, description: message)
Expand Down
2 changes: 1 addition & 1 deletion Kukai Mobile/Modules/Home/AddAccountViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ extension AddAccountViewController: UITableViewDelegate {
tableView.selectRow(at: indexPath, animated: true, scrollPosition: .none)

self.showLoadingView()
AddAccountViewModel.addAccount(forMetadata: metadata, hdWalletIndex: indexPath.section) { [weak self] errorTitle, errorMessage in
AddAccountViewModel.addAccount(forMetadata: metadata, hdWalletIndex: indexPath.section, forceMainnet: false) { [weak self] errorTitle, errorMessage in
self?.hideLoadingView()

if let title = errorTitle, let message = errorMessage {
Expand Down
8 changes: 4 additions & 4 deletions Kukai Mobile/Modules/Home/AddAccountViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class AddAccountViewModel: ViewModel, UITableViewDiffableDataSourceHandler {
return dataSource?.itemIdentifier(for: indexPath) as? WalletMetadata
}

public static func isPreviousAccountUsed(forAddress address: String, completion: @escaping ((Bool) -> Void)) {
public static func isPreviousAccountUsed(forAddress address: String, forceMainnet: Bool, completion: @escaping ((Bool) -> Void)) {
var metadataToCheck = DependencyManager.shared.walletList.metadata(forAddress: address)
if (metadataToCheck?.children.count ?? 0) > 0, let last = metadataToCheck?.children.last {
metadataToCheck = last
Expand All @@ -100,12 +100,12 @@ class AddAccountViewModel: ViewModel, UITableViewDiffableDataSourceHandler {
return
}

WalletManagementService.isUsedAccount(address: meta.address, completion: completion)
WalletManagementService.isUsedAccount(address: meta.address, forceMainnet: forceMainnet, completion: completion)
}

public static func addAccount(forMetadata walletMetadata: WalletMetadata, hdWalletIndex: Int, completion: @escaping ((String?, String?) -> Void)) {
public static func addAccount(forMetadata walletMetadata: WalletMetadata, hdWalletIndex: Int, forceMainnet: Bool, completion: @escaping ((String?, String?) -> Void)) {

AddAccountViewModel.isPreviousAccountUsed(forAddress: walletMetadata.address, completion: { isUsed in
AddAccountViewModel.isPreviousAccountUsed(forAddress: walletMetadata.address, forceMainnet: forceMainnet, completion: { isUsed in
guard isUsed else {
completion("error-previous-account-title".localized(), "error-previous-account-empty".localized())
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,23 +297,29 @@ class VerifyRecoveryPhraseViewController: UIViewController {

private func compareIndexesAndNavigate() {
if realWordIndexes.contains(selectedIndexes) {

guard let address = (sideMenuOption_address ?? DependencyManager.shared.selectedWalletAddress) else {
return
}

// Check if we are backing up from a child wallet, if so, switch out to its parent
var metadata = DependencyManager.shared.walletList.metadata(forAddress: address)
if metadata?.isChild == true {
let parent = DependencyManager.shared.walletList.parentMetadata(forChildAddress: metadata?.address ?? "")
metadata = parent
}
metadata?.backedUp = true

guard let meta = metadata else {
return
}

let walletCache = WalletCacheService()
let _ = DependencyManager.shared.walletList.update(address: address, with: meta)
let _ = DependencyManager.shared.walletList.update(address: meta.address, with: meta) // load meta address so we pick up parent
let _ = walletCache.encryptAndWriteMetadataToDisk(DependencyManager.shared.walletList)

DependencyManager.shared.walletList = walletCache.readMetadataFromDiskAndDecrypt()
DependencyManager.shared.selectedWalletMetadata = DependencyManager.shared.walletList.metadata(forAddress: address)
DependencyManager.shared.selectedWalletMetadata = DependencyManager.shared.walletList.metadata(forAddress: address) // make sure we don't use meta address so we reload the child

self.navigate()
}
Expand Down
28 changes: 14 additions & 14 deletions Kukai Mobile/Modules/Send/Base.lproj/Send.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="22505" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="ey1-yw-mvK">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="ey1-yw-mvK">
<device id="retina4_7" orientation="portrait" appearance="dark"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22504"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22685"/>
<capability name="Named colors" minToolsVersion="9.0"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="Stack View standard spacing" minToolsVersion="9.0"/>
Expand Down Expand Up @@ -575,7 +575,7 @@
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="2" translatesAutoresizingMaskIntoConstraints="NO" id="mas-gj-c3T">
<rect key="frame" x="245.5" y="11" width="89.5" height="56"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="1000" verticalHuggingPriority="251" horizontalCompressionResistancePriority="1000" text="&lt;token&gt;" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="eNu-VS-btW">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="1000" verticalHuggingPriority="251" horizontalCompressionResistancePriority="1000" text="&lt;token&gt;" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="eNu-VS-btW">
<rect key="frame" x="0.0" y="0.0" width="89.5" height="36"/>
<fontDescription key="fontDescription" name="Figtree-Bold" family="Figtree" pointSize="30"/>
<color key="textColor" name="Txt14"/>
Expand Down Expand Up @@ -1352,11 +1352,11 @@
</connections>
</button>
<view contentMode="scaleToFill" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="cKX-GE-bkB">
<rect key="frame" x="147.5" y="0.0" width="102.5" height="28"/>
<rect key="frame" x="147.5" y="0.0" width="115.5" height="28"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
<button opaque="NO" contentMode="scaleToFill" semanticContentAttribute="forceRightToLeft" horizontalHuggingPriority="750" horizontalCompressionResistancePriority="1000" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="33O-kl-RN2" customClass="CustomisableButton" customModule="Kukai_Mobile" customModuleProvider="target">
<rect key="frame" x="254" y="0.0" width="89" height="28"/>
<rect key="frame" x="267" y="0.0" width="76" height="28"/>
<color key="backgroundColor" name="BtnSec1"/>
<constraints>
<constraint firstAttribute="height" constant="28" id="Ltq-4n-Vc3"/>
Expand Down Expand Up @@ -2517,11 +2517,11 @@
</connections>
</button>
<view contentMode="scaleToFill" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="Zdg-IE-mO6">
<rect key="frame" x="147.5" y="0.0" width="102.5" height="28"/>
<rect key="frame" x="147.5" y="0.0" width="115.5" height="28"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
<button opaque="NO" contentMode="scaleToFill" semanticContentAttribute="forceRightToLeft" horizontalHuggingPriority="750" horizontalCompressionResistancePriority="1000" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ARH-fd-Xk3" customClass="CustomisableButton" customModule="Kukai_Mobile" customModuleProvider="target">
<rect key="frame" x="254" y="0.0" width="89" height="28"/>
<rect key="frame" x="267" y="0.0" width="76" height="28"/>
<color key="backgroundColor" name="BtnSec1"/>
<constraints>
<constraint firstAttribute="height" constant="28" id="e6M-mO-nxK"/>
Expand Down Expand Up @@ -3280,11 +3280,11 @@
</connections>
</button>
<view contentMode="scaleToFill" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="Ey8-AT-W61">
<rect key="frame" x="147.5" y="0.0" width="102.5" height="28"/>
<rect key="frame" x="147.5" y="0.0" width="115.5" height="28"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
<button opaque="NO" contentMode="scaleToFill" semanticContentAttribute="forceRightToLeft" horizontalHuggingPriority="750" horizontalCompressionResistancePriority="1000" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="KLt-HO-0E1" customClass="CustomisableButton" customModule="Kukai_Mobile" customModuleProvider="target">
<rect key="frame" x="254" y="0.0" width="89" height="28"/>
<rect key="frame" x="267" y="0.0" width="76" height="28"/>
<color key="backgroundColor" name="BtnSec1"/>
<constraints>
<constraint firstAttribute="height" constant="28" id="le5-So-zaS"/>
Expand Down Expand Up @@ -3647,7 +3647,7 @@
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" semanticContentAttribute="forceRightToLeft" contentHorizontalAlignment="leading" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="6lO-29-qxr" customClass="CustomisableButton" customModule="Kukai_Mobile" customModuleProvider="target">
<rect key="frame" x="81.5" y="16" width="261.5" height="17"/>
<rect key="frame" x="81.5" y="10" width="261.5" height="29"/>
<fontDescription key="fontDescription" name="Figtree-SemiBold" family="Figtree" pointSize="14"/>
<color key="tintColor" name="BGB4"/>
<inset key="titleEdgeInsets" minX="0.0" minY="0.0" maxX="10" maxY="0.0"/>
Expand Down Expand Up @@ -4042,7 +4042,7 @@
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" semanticContentAttribute="forceRightToLeft" contentHorizontalAlignment="leading" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="jz3-Oh-twp" customClass="CustomisableButton" customModule="Kukai_Mobile" customModuleProvider="target">
<rect key="frame" x="88" y="16" width="255" height="17"/>
<rect key="frame" x="88" y="10" width="255" height="29"/>
<fontDescription key="fontDescription" name="Figtree-SemiBold" family="Figtree" pointSize="14"/>
<color key="tintColor" name="BGB4"/>
<inset key="titleEdgeInsets" minX="0.0" minY="0.0" maxX="10" maxY="0.0"/>
Expand Down Expand Up @@ -4134,11 +4134,11 @@
</connections>
</button>
<view contentMode="scaleToFill" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="Igf-71-olT">
<rect key="frame" x="145.5" y="0.0" width="104.5" height="28"/>
<rect key="frame" x="145.5" y="0.0" width="117.5" height="28"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
<button opaque="NO" contentMode="scaleToFill" semanticContentAttribute="forceRightToLeft" horizontalHuggingPriority="750" horizontalCompressionResistancePriority="1000" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="WrO-Y2-xJO" customClass="CustomisableButton" customModule="Kukai_Mobile" customModuleProvider="target">
<rect key="frame" x="254" y="0.0" width="89" height="28"/>
<rect key="frame" x="267" y="0.0" width="76" height="28"/>
<color key="backgroundColor" name="BtnSec1"/>
<constraints>
<constraint firstAttribute="height" constant="28" id="R88-3a-hNy"/>
Expand Down Expand Up @@ -4426,7 +4426,7 @@
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" semanticContentAttribute="forceRightToLeft" contentHorizontalAlignment="leading" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Tot-14-1NF" customClass="CustomisableButton" customModule="Kukai_Mobile" customModuleProvider="target">
<rect key="frame" x="81.5" y="16" width="261.5" height="17"/>
<rect key="frame" x="81.5" y="10" width="261.5" height="29"/>
<fontDescription key="fontDescription" name="Figtree-SemiBold" family="Figtree" pointSize="14"/>
<color key="tintColor" name="BGB4"/>
<inset key="titleEdgeInsets" minX="0.0" minY="0.0" maxX="10" maxY="0.0"/>
Expand Down
4 changes: 2 additions & 2 deletions Kukai Mobile/Services/WalletManagementService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ class WalletManagementService {
})
}

public static func isUsedAccount(address: String, completion: @escaping ((Bool) -> Void)) {
DependencyManager.shared.tzktClient.getAccount(forAddress: address, fromURL: DependencyManager.defaultTzktURL_mainnet) { result in
public static func isUsedAccount(address: String, forceMainnet: Bool = true, completion: @escaping ((Bool) -> Void)) {
DependencyManager.shared.tzktClient.getAccount(forAddress: address, fromURL: forceMainnet ? DependencyManager.defaultTzktURL_mainnet : DependencyManager.shared.currentTzktURL) { result in
guard let res = try? result.get() else {
completion(false)
return
Expand Down

0 comments on commit 155815d

Please sign in to comment.