Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import SwiftUI
import Primitives
import Localization
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The Localization import was removed from this file. While this is a good cleanup if no longer needed, please ensure that no localized strings or components that rely on Localization are still being used indirectly by ImportWalletNavigationStack or its subviews. If they are, the import should be retained, or the localization moved to the respective view models.

import PrimitivesComponents

public struct ImportWalletNavigationStack: View {
Expand Down Expand Up @@ -82,24 +81,11 @@ extension ImportWalletNavigationStack {
}
}

func onImportComplete(data: WalletImportData) {
Task {
do {
let wallet = try await model.importWallet(data: data)
navigate(to: .walletProfile(wallet: wallet))
} catch {
debugLog("Failed to import wallet: \(error)")
}
}
func onImportComplete(wallet: Wallet) {
navigate(to: .walletProfile(wallet: wallet))
}

func onSetupWalletComplete(_ wallet: Wallet) {
Task {
do {
try await model.setupWalletComplete()
} catch {
debugLog("Failed to setup wallet: \(error)")
}
}
model.onComplete?()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ final class ImportWalletSceneViewModel {
var isPresentingScanner = false
var isPresentingAlertMessage: AlertMessage?

private let onComplete: ((WalletImportData) -> Void)?
private let onComplete: ((Wallet) -> Void)?

init(
walletService: WalletService,
nameService: any NameServiceable,
type: ImportWalletType,
onComplete: ((WalletImportData) -> Void)?
onComplete: ((Wallet) -> Void)?
) {
self.walletService = walletService
self.nameService = nameService
Expand Down Expand Up @@ -175,12 +175,12 @@ extension ImportWalletSceneViewModel {
}
switch type {
case .multicoin:
importWallet(
try await importWallet(
name: recipient.name,
keystoreType: .phrase(words: words, chains: AssetConfiguration.allChains)
)
case .chain(let chain):
importWallet(
try await importWallet(
name: recipient.name,
keystoreType: .single(words: words, chain: chain)
)
Expand All @@ -189,20 +189,24 @@ extension ImportWalletSceneViewModel {
guard try validateForm(type: importType, address: recipient.address, words: [trimmedInput]) else {
return
}
importWallet(name: recipient.name, keystoreType: .privateKey(text: trimmedInput, chain: chain!))
try await importWallet(name: recipient.name, keystoreType: .privateKey(text: trimmedInput, chain: chain!))
case .address:
guard try validateForm(type: importType, address: recipient.address, words: []) else {
return
}
let chain = chain!
let address = chain.checksumAddress(recipient.address)

importWallet(name: recipient.name, keystoreType: .address(address: address, chain: chain))
try await importWallet(name: recipient.name, keystoreType: .address(address: address, chain: chain))
}
}

private func importWallet(name: String, keystoreType: KeystoreImportType) {
onComplete?(WalletImportData(name: name, keystoreType: keystoreType))
private func importWallet(name: String, keystoreType: KeystoreImportType) async throws {
let wallet = try await walletService.loadOrCreateWallet(name: name, type: keystoreType, source: .import)
walletService.acceptTerms()
try await walletService.setCurrent(wallet: wallet)
buttonState = .normal
onComplete?(wallet)
}

private func validateForm(type: WalletImportType, address: String, words: [String]) throws -> Bool {
Expand Down
15 changes: 0 additions & 15 deletions Features/Onboarding/Sources/ViewModels/ImportWalletViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ public final class ImportWalletViewModel {
public var isAcceptTermsCompleted: Bool {
walletService.isAcceptTermsCompleted
}

func dismiss() {
onComplete?()
}
}

// MARK: - Actions
Expand All @@ -46,15 +42,4 @@ extension ImportWalletViewModel {
func presentSelectImage(wallet: Wallet) {
isPresentingSelectImageWallet = wallet
}

func importWallet(data: WalletImportData) async throws -> Wallet {
let wallet = try await walletService.loadOrCreateWallet(name: data.name, type: data.keystoreType, source: .import)
walletService.acceptTerms()
try await walletService.setCurrent(wallet: wallet)
return wallet
}

func setupWalletComplete() async throws {
dismiss()
}
}
40 changes: 0 additions & 40 deletions Features/Onboarding/Tests/ImportWalletViewModelTests.swift

This file was deleted.