-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sargon: Add method to read Mnemonic, UniFFI exported, Improve iOS exa…
…mple app
- Loading branch information
Showing
26 changed files
with
779 additions
and
199 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
apple/Sources/Sargon/Extensions/Methods/AppearanceID+Wrap+Functions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
extension AppearanceID: CaseIterable { | ||
public static var allCases: [Self] { | ||
appearanceIdsAll() | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
apple/Sources/Sargon/Extensions/Methods/BagOfBytes+Wrap+Functions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
extension BagOfBytes { | ||
public init(data: Data) { | ||
self = newBagOfBytesFrom(bytes: data) | ||
} | ||
} |
File renamed without changes.
5 changes: 5 additions & 0 deletions
5
apple/Sources/Sargon/Extensions/Methods/DisplayName+Wrap+Functions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
extension DisplayName { | ||
public init(validating name: String) throws { | ||
self = try newDisplayName(name: name) | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
apple/Sources/Sargon/Extensions/Methods/Mnemonic+Wrap+Functions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
extension Mnemonic { | ||
public var phrase: String { | ||
mnemonicPhrase(from: self) | ||
} | ||
} |
File renamed without changes.
12 changes: 9 additions & 3 deletions
12
apple/Sources/Sargon/Extensions/Swiftified/AppearanceID+Swiftified.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
public typealias AppearanceID = AppearanceId | ||
|
||
extension AppearanceID: Sendable {} | ||
extension AppearanceID: CaseIterable { | ||
public static var allCases: [Self] { | ||
appearanceIdsAll() | ||
extension AppearanceID: Identifiable { | ||
public typealias ID = UInt8 | ||
public var id: ID { | ||
value | ||
} | ||
} | ||
extension AppearanceID: CustomStringConvertible { | ||
public var description: String { | ||
value.description | ||
} | ||
} |
3 changes: 0 additions & 3 deletions
3
apple/Sources/Sargon/Extensions/Swiftified/BagOfBytes+Random.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 0 additions & 5 deletions
5
apple/Sources/Sargon/Extensions/Swiftified/DisplayName+Swiftified.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
apple/Sources/Sargon/Extensions/Swiftified/Mnemonic+Swiftified.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
extension Mnemonic: Sendable {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
examples/iOS/Sources/Planbok/Features/Flows/CreateAccount/CreateAccountFlowFeature.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
@Reducer | ||
public struct CreateAccountFlowFeature { | ||
|
||
@Reducer(state: .equatable) | ||
public enum Path { | ||
case selectGradient(SelectGradientFeature) | ||
} | ||
|
||
@ObservableState | ||
public struct State: Equatable { | ||
public let walletHolder: WalletHolder | ||
public var path = StackState<Path.State>() | ||
public var nameAccount: NameNewAccountFeature.State | ||
|
||
public init(walletHolder: WalletHolder) { | ||
self.walletHolder = walletHolder | ||
self.nameAccount = NameNewAccountFeature.State(walletHolder: walletHolder) | ||
} | ||
|
||
public init(wallet: Wallet) { | ||
self.init(walletHolder: .init(wallet: wallet)) | ||
} | ||
} | ||
|
||
public enum Action { | ||
public enum DelegateAction { | ||
case createdAccount | ||
} | ||
case path(StackAction<Path.State, Path.Action>) | ||
case nameAccount(NameNewAccountFeature.Action) | ||
case delegate(DelegateAction) | ||
} | ||
|
||
public struct View: SwiftUI.View { | ||
@Bindable var store: StoreOf<CreateAccountFlowFeature> | ||
public init(store: StoreOf<CreateAccountFlowFeature>) { | ||
self.store = store | ||
} | ||
public var body: some SwiftUI.View { | ||
NavigationStack(path: $store.scope(state: \.path, action: \.path)) { | ||
NameNewAccountFeature.View( | ||
store: store.scope(state: \.nameAccount, action: \.nameAccount) | ||
) | ||
} destination: { store in | ||
switch store.state { | ||
case .selectGradient: | ||
if let store = store.scope(state: \.selectGradient, action: \.selectGradient) { | ||
SelectGradientFeature.View(store: store) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
public init() {} | ||
|
||
public var body: some ReducerOf<Self> { | ||
Scope(state: \.nameAccount, action: \.nameAccount) { | ||
NameNewAccountFeature() | ||
} | ||
|
||
Reduce { state, action in | ||
switch action { | ||
|
||
case let .nameAccount(.delegate(.named(name))): | ||
state.path.append(.selectGradient(.init(name: name))) | ||
return .none | ||
|
||
case .path(let pathAction): | ||
switch pathAction { | ||
|
||
case let .element( | ||
id: _, | ||
action: .selectGradient(.delegate(.selected(appearanceID, displayName))) | ||
): | ||
do { | ||
let wallet = state.walletHolder.wallet | ||
var account = try wallet.createNewAccount( | ||
networkId: .mainnet, | ||
name: displayName | ||
) | ||
account.appearanceId = appearanceID | ||
|
||
try wallet.addAccount(account: account) | ||
|
||
return .send(.delegate(.createdAccount)) | ||
|
||
} catch { | ||
fatalError("TODO error handling: \(error)") | ||
} | ||
|
||
case .element(id: _, action: _): | ||
return .none | ||
case .popFrom(id: _): | ||
return .none | ||
case .push(id: _, state: _): | ||
return .none | ||
} | ||
return .none | ||
|
||
case .nameAccount(.view): | ||
return .none | ||
|
||
case .delegate: | ||
return .none | ||
} | ||
} | ||
.forEach(\.path, action: \.path) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.