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
4 changes: 4 additions & 0 deletions Features/Onboarding/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ let package = Package(
name: "OnboardingTest",
dependencies: [
"Onboarding",
.product(name: "PrimitivesTestKit", package: "Primitives"),
.product(name: "WalletServiceTestKit", package: "FeatureServices"),
.product(name: "KeystoreTestKit", package: "Keystore"),
.product(name: "NameServiceTestKit", package: "ChainServices"),
.product(name: "StoreTestKit", package: "Store"),
],
path: "Tests"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ extension CreateWalletModel {
source: .create
)
walletService.acceptTerms()
WalletPreferences(walletId: wallet.walletId).completeInitialSynchronization()
return wallet
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Primitives
import WalletService
import AvatarService
import PrimitivesComponents
import Preferences
import enum Keystore.KeystoreImportType

@Observable
Expand Down Expand Up @@ -51,7 +50,6 @@ extension ImportWalletViewModel {
func importWallet(data: WalletImportData) async throws -> Wallet {
let wallet = try await walletService.loadOrCreateWallet(name: data.name, type: data.keystoreType, source: .import)
walletService.acceptTerms()
WalletPreferences(walletId: wallet.walletId).completeInitialSynchronization()
try await walletService.setCurrent(wallet: wallet)
return wallet
}
Expand Down
32 changes: 32 additions & 0 deletions Features/Onboarding/Tests/CreateWalletModelTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c). Gem Wallet. All rights reserved.

import Foundation
import Testing
import Preferences
import Keystore
import KeystoreTestKit
import StoreTestKit
import WalletServiceTestKit

@testable import Onboarding

@MainActor
struct CreateWalletModelTests {

@Test
func createWalletSetsAddressStatus() async throws {
let model = CreateWalletModel(
walletService: .mock(keystore: KeystoreMock()),
avatarService: .init(store: .mock()),
onComplete: nil
)

let wallet = try await model.createWallet(words: LocalKeystore.words)
let preferences = WalletPreferences(walletId: wallet.walletId)

#expect(preferences.completeInitialAddressStatus)
#expect(preferences.completeInitialLoadAssets)

preferences.clear()
}
}
40 changes: 40 additions & 0 deletions Features/Onboarding/Tests/ImportWalletViewModelTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c). Gem Wallet. All rights reserved.

import Foundation
import Testing
import Primitives
import Preferences
import Keystore
import KeystoreTestKit
import PrimitivesTestKit
import NameServiceTestKit
import StoreTestKit
import WalletServiceTestKit

@testable import Onboarding

@MainActor
struct ImportWalletViewModelTests {

@Test
func importWalletDoesNotSetAddressStatus() async throws {
let keystore = KeystoreMock()
let preferences = WalletPreferences(walletId: Wallet.mock().walletId)
preferences.clear()

let model = ImportWalletViewModel(
walletService: .mock(keystore: keystore),
avatarService: .init(store: .mock()),
nameService: .mock(),
onComplete: nil
)

_ = try await model.importWallet(data: WalletImportData(
name: "Test",
keystoreType: .phrase(words: LocalKeystore.words, chains: [.tron])
))

#expect(preferences.completeInitialAddressStatus == false)
#expect(preferences.completeInitialLoadAssets == false)
}
}
5 changes: 4 additions & 1 deletion Features/WalletTab/Tests/WalletSceneViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ import PreferencesTestKit
struct WalletSceneViewModelTests {
@Test
func isLoading() {
let preferences = WalletPreferences(walletId: Wallet.mock().walletId)
preferences.clear()

let model = WalletSceneViewModel.mock()
#expect(model.isLoadingAssets == false)

model.shouldStartLoadingAssets()
#expect(model.isLoadingAssets)

Expand Down
4 changes: 0 additions & 4 deletions Packages/Preferences/Sources/WalletPreferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ public final class WalletPreferences: @unchecked Sendable {
get { defaults.bool(forKey: Keys.completeInitialAddressStatus) }
}

public var isCompleteInitialSynchronization: Bool {
completeInitialAddressStatus && completeInitialLoadAssets
}

public func completeInitialSynchronization() {
completeInitialAddressStatus = true
completeInitialLoadAssets = true
Expand Down
Loading