Skip to content

Commit

Permalink
Merge pull request #1365 from LukasKorba/1358-build-Request-ZEC-flow
Browse files Browse the repository at this point in the history
[#1358] build Request ZEC flow
  • Loading branch information
LukasKorba authored Oct 3, 2024
2 parents 686d482 + 510b4c0 commit b9af5a0
Show file tree
Hide file tree
Showing 54 changed files with 1,547 additions and 287 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1600"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DeeplinkWarning"
BuildableName = "DeeplinkWarning"
BlueprintName = "DeeplinkWarning"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DeeplinkWarning"
BuildableName = "DeeplinkWarning"
BlueprintName = "DeeplinkWarning"
ReferencedContainer = "container:">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
25 changes: 22 additions & 3 deletions modules/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ let package = Package(
.library(name: "DatabaseFiles", targets: ["DatabaseFiles"]),
.library(name: "Date", targets: ["Date"]),
.library(name: "Deeplink", targets: ["Deeplink"]),
.library(name: "DeeplinkWarning", targets: ["DeeplinkWarning"]),
.library(name: "DeleteWallet", targets: ["DeleteWallet"]),
.library(name: "DerivationTool", targets: ["DerivationTool"]),
.library(name: "DiskSpaceChecker", targets: ["DiskSpaceChecker"]),
Expand Down Expand Up @@ -88,9 +89,11 @@ let package = Package(
.package(url: "https://github.com/pointfreeco/swift-case-paths", from: "1.5.4"),
.package(url: "https://github.com/pointfreeco/swift-url-routing", from: "0.6.2"),
.package(url: "https://github.com/zcash-hackworks/MnemonicSwift", from: "2.2.4"),
.package(url: "https://github.com/Electric-Coin-Company/zcash-swift-wallet-sdk", from: "2.2.3"),
// .package(url: "https://github.com/Electric-Coin-Company/zcash-swift-wallet-sdk", from: "2.2.3"),
.package(url: "https://github.com/Electric-Coin-Company/zcash-swift-wallet-sdk", branch: "fix/note_commitment_tree_conflict"),
.package(url: "https://github.com/firebase/firebase-ios-sdk", from: "10.27.0"),
.package(url: "https://github.com/flexa/flexa-ios.git", from: "1.0.2")
.package(url: "https://github.com/flexa/flexa-ios.git", from: "1.0.3"),
.package(url: "https://github.com/pacu/zcash-swift-payment-uri", from: "0.1.0-beta.9")
],
targets: [
.target(
Expand Down Expand Up @@ -252,6 +255,15 @@ let package = Package(
],
path: "Sources/Dependencies/Deeplink"
),
.target(
name: "DeeplinkWarning",
dependencies: [
"Generated",
"UIComponents",
.product(name: "ComposableArchitecture", package: "swift-composable-architecture")
],
path: "Sources/Features/DeeplinkWarning"
),
.target(
name: "DeleteWallet",
dependencies: [
Expand Down Expand Up @@ -520,7 +532,8 @@ let package = Package(
"Utils",
"ZcashSDKEnvironment",
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
.product(name: "ZcashLightClientKit", package: "zcash-swift-wallet-sdk")
.product(name: "ZcashLightClientKit", package: "zcash-swift-wallet-sdk"),
.product(name: "ZcashPaymentURI", package: "zcash-swift-payment-uri")
],
path: "Sources/Features/RequestZec"
),
Expand Down Expand Up @@ -551,6 +564,7 @@ let package = Package(
"CrashReporter",
"DatabaseFiles",
"Deeplink",
"DeeplinkWarning",
"DerivationTool",
"DiskSpaceChecker",
"ExchangeRate",
Expand All @@ -571,6 +585,7 @@ let package = Package(
"ServerSetup",
"Tabs",
"UIComponents",
"URIParser",
"UserDefaults",
"UserPreferencesStorage",
"Utils",
Expand Down Expand Up @@ -605,6 +620,7 @@ let package = Package(
"UIComponents",
"Utils",
"ZcashSDKEnvironment",
.product(name: "ZcashPaymentURI", package: "zcash-swift-payment-uri"),
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
.product(name: "ZcashLightClientKit", package: "zcash-swift-wallet-sdk")
],
Expand Down Expand Up @@ -760,6 +776,7 @@ let package = Package(
.target(
name: "Tabs",
dependencies: [
"AddressBook",
"AddressDetails",
"BalanceBreakdown",
"CurrencyConversionSetup",
Expand Down Expand Up @@ -813,6 +830,8 @@ let package = Package(
name: "URIParser",
dependencies: [
"DerivationTool",
"Models",
.product(name: "ZcashPaymentURI", package: "zcash-swift-payment-uri"),
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
.product(name: "ZcashLightClientKit", package: "zcash-swift-wallet-sdk")
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,19 @@ extension AddressBookClient: DependencyKey {
}

// contacts haven't been loaded from the remote storage yet, do it
do {
let data = try await remoteStorage.loadAddressBookContacts()

let storedContacts = try AddressBookClient.decryptData(data)
latestKnownContacts.value = storedContacts

return storedContacts
} catch RemoteStorageClient.RemoteStorageError.fileDoesntExist {
return []
} catch {
throw error
}
// do {
// let data = try await remoteStorage.loadAddressBookContacts()
//
// let storedContacts = try AddressBookClient.decryptData(data)
// latestKnownContacts.value = storedContacts
//
// return storedContacts
// } catch RemoteStorageClient.RemoteStorageError.fileDoesntExist {
// return []
// } catch {
// throw error
// }
return []
},
storeContact: {
var contacts = latestKnownContacts.value ?? []
Expand All @@ -63,7 +64,8 @@ extension AddressBookClient: DependencyKey {
contacts.append($0)

// push encrypted data to the remote storage
try await remoteStorage.storeAddressBookContacts(AddressBookClient.encryptContacts(contacts))
//try await remoteStorage.storeAddressBookContacts(AddressBookClient.encryptContacts(contacts))
// TODO: FIXME

// update the latest known contacts
latestKnownContacts.value = contacts
Expand All @@ -81,7 +83,7 @@ extension AddressBookClient: DependencyKey {
contacts.remove($0)

// push encrypted data to the remote storage
try await remoteStorage.storeAddressBookContacts(AddressBookClient.encryptContacts(contacts))
//try await remoteStorage.storeAddressBookContacts(AddressBookClient.encryptContacts(contacts))

// update the latest known contacts
latestKnownContacts.value = contacts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ extension DependencyValues {
public struct NumberFormatterClient {
public var string: (NSDecimalNumber) -> String?
public var number: (String) -> NSNumber?
public var convertUSToLocale: (String) -> String?
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,17 @@ extension NumberFormatterClient: DependencyKey {

public static func live(numberFormatter: NumberFormatter = NumberFormatter.zcashNumberFormatter) -> Self {
Self(
string: { numberFormatter.string(from: $0) },
number: { numberFormatter.number(from: $0) }
string: {
numberFormatter.string(from: $0)
},
number: {
numberFormatter.number(from: $0)
},
convertUSToLocale: {
let number = NumberFormatter.zcashUSNumberFormatter.number(from: $0)
let decimalNumber = NSDecimalNumber(decimal: number?.decimalValue ?? 0)
return numberFormatter.string(from: decimalNumber)
}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import XCTestDynamicOverlay
extension NumberFormatterClient: TestDependencyKey {
public static let testValue = Self(
string: unimplemented("\(Self.self).string", placeholder: nil),
number: unimplemented("\(Self.self).number", placeholder: nil)
number: unimplemented("\(Self.self).number", placeholder: nil),
convertUSToLocale: XCTUnimplemented("\(Self.self).number", placeholder: nil)
)
}

extension NumberFormatterClient {
public static let noOp = Self(
string: { _ in nil },
number: { _ in nil }
number: { _ in nil },
convertUSToLocale: { _ in nil }
)
}
18 changes: 18 additions & 0 deletions modules/Sources/Dependencies/URIParser/RequestPaymentParser.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// RequestPaymentParser.swift
//
//
// Created by Lukáš Korba on 24.05.2024.
//

import Foundation
import Models
import ZcashPaymentURI

public struct RequestPaymentParser {
public enum URIParserError: Error { }

public func checkRP(_ dataStr: String) -> ParserResult? {
try? ZIP321.request(from: dataStr)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import Foundation
import ComposableArchitecture
import ZcashLightClientKit
import Models
import ZcashPaymentURI

extension DependencyValues {
public var uriParser: URIParserClient {
Expand All @@ -19,5 +21,6 @@ extension DependencyValues {
@DependencyClient
public struct URIParserClient {
public var isValidURI: (String, NetworkType) -> Bool = { _, _ in false }
public var checkRP: (String) -> ParserResult? = { _ in nil }
}

3 changes: 3 additions & 0 deletions modules/Sources/Dependencies/URIParser/URIParserLive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ extension URIParserClient: DependencyKey {
public static let liveValue = Self(
isValidURI: { uri, network in
URIParser().isValidURI(uri, network: network)
},
checkRP: { data in
RequestPaymentParser().checkRP(data)
}
)
}
3 changes: 2 additions & 1 deletion modules/Sources/Dependencies/URIParser/URIParserTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import XCTestDynamicOverlay

extension URIParserClient: TestDependencyKey {
public static let testValue = Self(
isValidURI: unimplemented("\(Self.self).isValidURI", placeholder: false)
isValidURI: XCTUnimplemented("\(Self.self).isValidURI", placeholder: false),
checkRP: XCTUnimplemented("\(Self.self).checkRP", placeholder: nil)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public struct AddressBookContactView: View {
ZashiButton(L10n.General.save) {
store.send(.saveButtonTapped)
}
//.disabled(store.isSaveButtonDisabled) // TODO: FIXME
.disabled(store.isSaveButtonDisabled)
.padding(.bottom, isInEditMode ? 0 : 24)

if isInEditMode {
Expand Down
8 changes: 4 additions & 4 deletions modules/Sources/Features/AddressBook/AddressBookStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,11 @@ public struct AddressBook {
return .send(.updateDestination(.add))

case .saveButtonTapped:
let name = state.name.isEmpty ? "testName" : state.name
let address = state.address.isEmpty ? "testAddress" : state.address
return .run { send in
// let name = state.name.isEmpty ? "testName" : state.name
// let address = state.address.isEmpty ? "testAddress" : state.address
return .run { [state] send in
do {
let contacts = try await addressBook.storeContact(ABRecord(address: address, name: name))
let contacts = try await addressBook.storeContact(ABRecord(address: state.address, name: state.name))
await send(.fetchedABRecords(contacts))
await send(.contactStoreSuccess)
} catch {
Expand Down
2 changes: 1 addition & 1 deletion modules/Sources/Features/AddressBook/AddressBookView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public struct AddressBookView: View {
ContactView(
iconText: record.name.initials,
title: record.name,
desc: record.id
desc: record.id.trailingZip316
) {
store.send(.editId(record.id))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public struct AddressDetails {
state.isAddressExpanded = false
state.isQRCodeAppreanceFlipped = false
return .none

case .onDisappear:
return .cancel(id: state.cancelId)

Expand All @@ -77,7 +77,7 @@ public struct AddressDetails {
}
state.isQRCodeAppreanceFlipped.toggle()
return .send(.generateQRCode(true))

case let .rememberQR(image):
state.storedQR = image
return .none
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public struct AddressDetailsView: View {
Text(store.address.data)
.zFont(size: 14, style: Design.Text.tertiary)
.lineLimit(store.isAddressExpanded ? nil : 2)
.truncationMode(.middle)
.padding(.top, 8)
.onTapGesture {
store.send(.addressTapped)
Expand Down Expand Up @@ -126,7 +127,11 @@ extension AddressDetailsView {
color: .black
) {
UIShareDialogView(activityItems: [
ShareableImage(image: UIImage(cgImage: cgImg)), "Hi, scan this QR code to send me a ZEC payment!"
ShareableImage(
image: UIImage(cgImage: cgImg),
title: "My Zashi ZEC Address",
reason: "Hi, scan this QR code to send me a ZEC payment!"
), "Hi, scan this QR code to send me a ZEC payment!"
]) {
store.send(.shareFinished)
}
Expand Down
Loading

0 comments on commit b9af5a0

Please sign in to comment.