Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SargonOS v1 integration API #184

Merged
merged 15 commits into from
Aug 12, 2024
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sargon"
version = "1.1.2"
version = "1.1.3"
edition = "2021"
build = "build.rs"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import UIKit
extension AppleHostInfoDriver: HostInfoDriver {

public func hostOs() async -> HostOs {
await .ios(version: UIDevice.current.systemVersion)
await HostOs.ios(version: UIDevice.current.systemVersion)
}

nonisolated public func hostDeviceName() async -> String {
Expand Down
17 changes: 17 additions & 0 deletions apple/Sources/Sargon/Drivers/ProfileChange/ProfileChange.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import SargonUniFFI

public typealias ProfileChangeEventPublisher = EventPublisher<Profile>

extension ProfileChangeEventPublisher: ProfileChangeDriver {
public static let shared = ProfileChangeEventPublisher()

public func handleProfileChange(changedProfile: Profile) async {
subject.send(changedProfile)
}
}

extension ProfileChangeDriver where Self == ProfileChangeEventPublisher {
public static var shared: Self {
ProfileChangeEventPublisher.shared
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ extension Drivers {
logging: .shared,
eventBus: .shared,
fileSystem: .shared,
unsafeStorage: unsafeStorage
unsafeStorage: unsafeStorage,
profileChangeDriver: .shared
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,3 @@ import SargonUniFFI
public typealias SargonOS = SargonOs

extension SargonOS: @unchecked Sendable {}

extension SargonOS {

@available(*, deprecated, message: "SHOULD migrate to use more specialized methods on SargonOS instead, e.g. `createAndSaveNewAccount` - SargonOS should be the SOLE object to perform the mutation and persisting.")
public func saveChangedProfile(_ profile: Profile) async throws {
try await deprecatedSaveFfiChangedProfile(profile: profile)
}
}
6 changes: 0 additions & 6 deletions apple/Sources/Sargon/SargonOS/SargonOSProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ extension SargonOSProtocol {

// MARK: Extensions
extension SargonOSProtocol {

@available(*, deprecated, message: "SHOULD migrate to use more specialized access methods on SargonOS instead, e.g. `accountsOnCurrentNetwork`.")
public var profile: Profile {
os.profile()
}

public var currentNetworkID: NetworkID {
os.currentNetworkId()
}
Expand Down
15 changes: 15 additions & 0 deletions apple/Sources/Sargon/Util/EventPublisher.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import AsyncExtensions

public final actor EventPublisher<Element: Sendable> {
public typealias Subject = AsyncPassthroughSubject<Element>
public typealias Stream = AsyncThrowingPassthroughSubject<Element, any Error>

let stream = Stream()
let subject = Subject()

public func eventStream() -> AsyncMulticastSequence<Subject, Stream> {
subject
.multicast(stream)
.autoconnect()

Check warning on line 13 in apple/Sources/Sargon/Util/EventPublisher.swift

View check run for this annotation

Codecov / codecov/patch

apple/Sources/Sargon/Util/EventPublisher.swift#L10-L13

Added lines #L10 - L13 were not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ extension Drivers {
logging: .shared,
eventBus: .shared,
fileSystem: .shared,
unsafeStorage: .shared
unsafeStorage: .shared,
profileChangeDriver: .shared
)
}

Expand All @@ -67,8 +68,9 @@ extension Drivers {
logging: .shared,
eventBus: .shared,
fileSystem: .shared,
unsafeStorage: .shared

unsafeStorage: .shared,
profileChangeDriver: .shared

)
}

Expand All @@ -81,7 +83,8 @@ extension Drivers {
logging: .shared,
eventBus: .shared,
fileSystem: .shared,
unsafeStorage: .shared
unsafeStorage: .shared,
profileChangeDriver: .shared
)
}

Expand All @@ -94,7 +97,8 @@ extension Drivers {
logging: .shared,
eventBus: .shared,
fileSystem: .shared,
unsafeStorage: .shared
unsafeStorage: .shared,
profileChangeDriver: .shared
)
}

Expand All @@ -107,7 +111,8 @@ extension Drivers {
logging: logging,
eventBus: .shared,
fileSystem: .shared,
unsafeStorage: .shared
unsafeStorage: .shared,
profileChangeDriver: .shared
)
}

Expand All @@ -120,7 +125,8 @@ extension Drivers {
logging: .shared,
eventBus: eventBus,
fileSystem: .shared,
unsafeStorage: .shared
unsafeStorage: .shared,
profileChangeDriver: .shared
)
}

Expand All @@ -133,7 +139,8 @@ extension Drivers {
logging: .shared,
eventBus: .shared,
fileSystem: fileSystem,
unsafeStorage: .shared
unsafeStorage: .shared,
profileChangeDriver: .shared
)
}

Expand All @@ -146,7 +153,8 @@ extension Drivers {
logging: .shared,
eventBus: .shared,
fileSystem: .shared,
unsafeStorage: unsafeStorage
unsafeStorage: unsafeStorage,
profileChangeDriver: .shared
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class InsecureStorageDriverTests: DriverTest<Insecure︕!TestOnly︕!Ephemer
func test() async throws {
let sut = SUT.init(keychainService: "test")
let data = Data.sampleAced
let key = SUT.Key.activeProfileId
let key = SUT.Key.profileSnapshot
try await sut.saveData(key: key, data: data)
let loaded = try await sut.loadData(key: key)
XCTAssertEqual(loaded, data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class NetworkingDriverTests: DriverTest<URLSession> {
let sut = SUT.shared as NetworkingDriver
let response = try await sut.executeNetworkRequest(
request: .init(
validating: "https://radixdlt.com",
method: .head
validating: "https://stokenet.radixdlt.com/",
method: .get
)
)
XCTAssertEqual(response.statusCode, 200)
Expand Down
13 changes: 7 additions & 6 deletions apple/Tests/IntegrationTests/SargonOS/TestOSTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ extension TestOS {
userDefaults: .init(
suiteName: UUID().uuidString
)!
)
),
profileChangeDriver: .shared
)
)
)
Expand Down Expand Up @@ -85,10 +86,10 @@ final class TestOSTests: OSTest {

func test_if_replace_profile_throws() async throws {
let sut = try await TestOS()
var profile = sut.profile
var profile = sut.os.profile()
profile.header.id = ProfileID() // mutate profile
do {
try await sut.os.saveChangedProfile(profile)
try await sut.os.setProfile(profile: profile)
XCTFail("We expected to throw")
} catch {
/* We expected to throw */
Expand All @@ -97,13 +98,13 @@ final class TestOSTests: OSTest {

func test_we_can_mutate_profile_in_swift_and_save_then_profile_is_updated() async throws {
let sut = try await TestOS()
var profile = sut.profile
var profile = sut.os.profile()
let creatingDevice = profile.header.creatingDevice
let newCreatingDevice = DeviceInfo.sampleOther
XCTAssertNotEqual(newCreatingDevice, creatingDevice)
profile.header.creatingDevice = newCreatingDevice // mutate profile
try await sut.os.saveChangedProfile(profile)
XCTAssertEqual(sut.profile.header.creatingDevice, newCreatingDevice) // assert change worked
try await sut.os.setProfile(profile: profile)
XCTAssertEqual(sut.os.profile().header.creatingDevice, newCreatingDevice) // assert change worked
}

func test_batch_create_many_accounts() async throws {
Expand Down
14 changes: 14 additions & 0 deletions examples/android/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.hilt)
alias(libs.plugins.ksp)
}

android {
Expand Down Expand Up @@ -38,6 +40,7 @@ android {
jvmTarget = "1.8"
}
buildFeatures {
buildConfig = true
compose = true
}
composeOptions {
Expand All @@ -56,6 +59,17 @@ dependencies {
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.material)
implementation(libs.okhttp)
implementation(libs.okhttp.logging.interceptor)
implementation(libs.hilt.android)
implementation(libs.androidx.datastore.preferences)
implementation(libs.androidx.lifecycle.runtime.compose)
implementation(libs.androidx.lifecycle.viewmodel)
implementation(libs.androidx.lifecycle.viewmodel.compose)
implementation(libs.androidx.datastore.preferences)
implementation(libs.androidx.datastore.preferences)
implementation(libs.androidx.activity)
ksp(libs.hilt.compiler)

implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.activity.compose)
Expand Down
3 changes: 2 additions & 1 deletion examples/android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:tools="http://schemas.android.com/tools">

<application
android:name=".ExampleApplication"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
Expand All @@ -17,9 +18,9 @@
android:exported="true"
android:label="@string/title_activity_main"
android:theme="@style/Theme.SargonAndroid">

<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.radixdlt.sargon.android

import android.app.Application
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class ExampleApplication: Application()
Loading
Loading