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
12 changes: 10 additions & 2 deletions MobileWallet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,8 @@
F8472F6B2E69BBCB0094163D /* SendingTransaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8472F6A2E69BBCB0094163D /* SendingTransaction.swift */; };
F8472F6D2E744AFF0094163D /* SendingTransaction+Actions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8472F6C2E744AFA0094163D /* SendingTransaction+Actions.swift */; };
F8472F722E745A3E0094163D /* ProgressIndicator.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8472F712E745A3D0094163D /* ProgressIndicator.swift */; };
F849ACB62ED5D024005B38AF /* SwapInProgress.swift in Sources */ = {isa = PBXBuildFile; fileRef = F849ACB52ED5D01C005B38AF /* SwapInProgress.swift */; };
F849ACBA2ED5F823005B38AF /* CodableStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = F849ACB92ED5F822005B38AF /* CodableStorage.swift */; };
F88781AF2EB10B1E00207D0B /* TokenPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = F88781AE2EB10B1E00207D0B /* TokenPicker.swift */; };
F88781B12EB1EC5A00207D0B /* SwapDeposit.swift in Sources */ = {isa = PBXBuildFile; fileRef = F88781B02EB1EC5A00207D0B /* SwapDeposit.swift */; };
F88781B32EB1EE4C00207D0B /* SwapProgress.swift in Sources */ = {isa = PBXBuildFile; fileRef = F88781B22EB1EE4C00207D0B /* SwapProgress.swift */; };
Expand Down Expand Up @@ -1130,6 +1132,8 @@
F8472F6A2E69BBCB0094163D /* SendingTransaction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SendingTransaction.swift; sourceTree = "<group>"; };
F8472F6C2E744AFA0094163D /* SendingTransaction+Actions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SendingTransaction+Actions.swift"; sourceTree = "<group>"; };
F8472F712E745A3D0094163D /* ProgressIndicator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgressIndicator.swift; sourceTree = "<group>"; };
F849ACB52ED5D01C005B38AF /* SwapInProgress.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwapInProgress.swift; sourceTree = "<group>"; };
F849ACB92ED5F822005B38AF /* CodableStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodableStorage.swift; sourceTree = "<group>"; };
F88781AE2EB10B1E00207D0B /* TokenPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TokenPicker.swift; sourceTree = "<group>"; };
F88781B02EB1EC5A00207D0B /* SwapDeposit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwapDeposit.swift; sourceTree = "<group>"; };
F88781B22EB1EE4C00207D0B /* SwapProgress.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwapProgress.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1907,6 +1911,7 @@
545A9D22294F9E66008D24A6 /* User Settings */,
37B48A8224B3968F00F8A8D2 /* AppKeychainWrapper.swift */,
3A4CE32F26A18DFC00ECF460 /* UserDefaults.swift */,
F849ACB92ED5F822005B38AF /* CodableStorage.swift */,
);
path = "Persistant Data";
sourceTree = "<group>";
Expand Down Expand Up @@ -3036,6 +3041,7 @@
F82888B22EC39D730085A103 /* Models */ = {
isa = PBXGroup;
children = (
F849ACB52ED5D01C005B38AF /* SwapInProgress.swift */,
F82888B32EC39D7B0085A103 /* ExolixConfirmation.swift */,
);
path = Models;
Expand Down Expand Up @@ -3633,6 +3639,7 @@
3AE5E5682874696E00D3AF85 /* ValuePickerView.swift in Sources */,
3A0391E6290BA40E00352D73 /* BugReportingView.swift in Sources */,
546B032A2983F33600DBED8E /* OnboardingPagerView.swift in Sources */,
F849ACB62ED5D024005B38AF /* SwapInProgress.swift in Sources */,
54E007B62B8DF55600AFCD7C /* SecurityManager.swift in Sources */,
711D7FA42D511FDE0080A987 /* LogViewController.swift in Sources */,
71F2B2232D8C20E700104073 /* LoginDeeplink.swift in Sources */,
Expand Down Expand Up @@ -3744,6 +3751,7 @@
5422CBFC2B88C79200428394 /* ScreenRecordingSettingsView.swift in Sources */,
711F28EB2DA3322D00751986 /* ReceiveViewController.swift in Sources */,
711D7FA82D5503540080A987 /* StylisedButton.swift in Sources */,
F849ACBA2ED5F823005B38AF /* CodableStorage.swift in Sources */,
37547D5624601BF600EB59CC /* UIView+GlobalFrame.swift in Sources */,
54D46A952CA6909800E554C0 /* WalletTag.swift in Sources */,
BF8316FD23EF7EAA00235403 /* LAContext.swift in Sources */,
Expand Down Expand Up @@ -4125,7 +4133,7 @@
CODE_SIGN_ENTITLEMENTS = MobileWallet/Tari.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = Dev;
CURRENT_PROJECT_VERSION = 5;
DEVELOPMENT_TEAM = 8XGMD9X2H2;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -4160,7 +4168,7 @@
CODE_SIGN_ENTITLEMENTS = MobileWallet/Tari.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = Dev;
CURRENT_PROJECT_VERSION = 5;
DEVELOPMENT_TEAM = 8XGMD9X2H2;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
Expand Down
3 changes: 0 additions & 3 deletions MobileWallet/Common/APIService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@ private extension API {
if httpResponse.statusCode == 401 {
throw APIError.unauthorized
}
if let responseString = String(data: data, encoding: .utf8) {
print("API Response for \(endpoint): \(responseString)")
}
}

func refreshToken() async throws {
Expand Down
78 changes: 78 additions & 0 deletions MobileWallet/Common/Persistant Data/CodableStorage.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// CodableStorage.swift

/*
Package MobileWallet
Created by Tomas Hakel on 25.11.2025
Using Swift 6.0
Running on macOS 26.0

Copyright 2019 The Tari Project

Redistribution and use in source and binary forms, with or
without modification, are permitted provided that the
following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of
its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import SwiftUI

@propertyWrapper
public struct CodableStorage<Value: Codable>: DynamicProperty {
public init(
_ key: String,
store: UserDefaults = .standard,
defaultValue: Value
) {
self.key = key
self.store = store
self.defaultValue = defaultValue
}

private let defaultValue: Value
private let key: String
private let store: UserDefaults

public var wrappedValue: Value {
get {
Self.initialValue(for: key, in: store) ?? defaultValue
}
nonmutating set {
let data = try? JSONEncoder().encode(newValue)
store.set(data, forKey: key)
}
}
}

private extension CodableStorage {
static func initialValue(
for key: String,
in store: UserDefaults
) -> Value? {
guard let data = store.object(forKey: key) as? Data else { return nil }
return try? JSONDecoder().decode(Value.self, from: data)
}
}
16 changes: 8 additions & 8 deletions MobileWallet/Common/Persistant Data/UserDefaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import Foundation

// MARK: - Generic User Defaults

private enum UserDefaultName: String, CaseIterable {
enum UserDefaultName: String, CaseIterable {
case selectedNetworkName
case networksSettings
case walletSettings
Expand All @@ -53,13 +53,13 @@ private enum UserDefaultName: String, CaseIterable {
}

enum GroupUserDefaults {
@UserDefault(key: UserDefaultName.selectedNetworkName.rawValue, suiteName: TariSettings.groupIndentifier) static var selectedNetworkName: String?
@UserDefault(key: UserDefaultName.networksSettings.rawValue, suiteName: TariSettings.groupIndentifier) static var networksSettings: [NetworkSettings]?
@UserDefault(key: UserDefaultName.walletSettings.rawValue, suiteName: TariSettings.groupIndentifier) static var walletSettings: [WalletSettings]?
@UserDefault(key: UserDefaultName.userSettings.rawValue, suiteName: TariSettings.groupIndentifier) static var userSettings: UserSettings?
@UserDefault(key: UserDefaultName.isTrackingEnabled.rawValue, suiteName: TariSettings.groupIndentifier) static var isTrackingEnabled: Bool?
@UserDefault(key: UserDefaultName.areScreenshotsDisabled.rawValue, suiteName: TariSettings.groupIndentifier) static var areScreenshotsDisabled: Bool?
@UserDefault(key: UserDefaultName.trustedAddresses.rawValue, suiteName: TariSettings.groupIndentifier) static var trustedAddresses: Set<String>?
@UserDefault(key: UserDefaultName.selectedNetworkName, suiteName: TariSettings.groupIndentifier) static var selectedNetworkName: String?
@UserDefault(key: UserDefaultName.networksSettings, suiteName: TariSettings.groupIndentifier) static var networksSettings: [NetworkSettings]?
@UserDefault(key: UserDefaultName.walletSettings, suiteName: TariSettings.groupIndentifier) static var walletSettings: [WalletSettings]?
@UserDefault(key: UserDefaultName.userSettings, suiteName: TariSettings.groupIndentifier) static var userSettings: UserSettings?
@UserDefault(key: UserDefaultName.isTrackingEnabled, suiteName: TariSettings.groupIndentifier) static var isTrackingEnabled: Bool?
@UserDefault(key: UserDefaultName.areScreenshotsDisabled, suiteName: TariSettings.groupIndentifier) static var areScreenshotsDisabled: Bool?
@UserDefault(key: UserDefaultName.trustedAddresses, suiteName: TariSettings.groupIndentifier) static var trustedAddresses: Set<String>?
}

// MARK: - Extensions
Expand Down
6 changes: 5 additions & 1 deletion MobileWallet/Common/Property Wrappers/UserDefault.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ import Foundation
@propertyWrapper struct UserDefault<T: Codable> {
private let key: String
private let userDefaults: UserDefaults

init(key: UserDefaultName, suiteName: String? = nil) {
self.init(key.rawValue, suiteName: suiteName)
}

init(key: String, suiteName: String? = nil) {
init(_ key: String, suiteName: String? = nil) {
self.key = key
userDefaults = UserDefaults(suiteName: suiteName) ?? UserDefaults.standard
}
Expand Down
21 changes: 1 addition & 20 deletions MobileWallet/Screens/Home/Home/Scenes/Home+Actions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,28 +202,9 @@ private extension Home {
}

extension Home: SwapTransactionMonitoring {
var latestTransaction: ExolixTransactionResponse? {
get { swapTransaction }
nonmutating set { swapTransaction = newValue }
}

var isTransactionProcessed: Bool {
swapTransaction?.isProcessed == true
}

var isTransactionCancelled: Bool {
false
}

func finaliseTransaction() {
swapTransaction = nil
swapInProgressId = nil
}

func loadSwapInProgress() {
guard let swapInProgressId else { return }
Task {
await monitorTransactionStatus(transactionId: swapInProgressId)
await monitorSwapTransactions(swapTransactions)
}
}
}
40 changes: 27 additions & 13 deletions MobileWallet/Screens/Home/Home/Scenes/Home.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ import SwiftUI
import Combine

struct Home: View, ChainTipObserver {
@AppStorage("swapInProgressId") var swapInProgressId: String?
@CodableStorage("swapTransactions", defaultValue: SwapTransactionList()) var swapTransactions
@ObservedObject var network = NetworkManager.shared
@Environment(SheetRouter.self) var router
@Environment(\.scenePhase) var scenePhase
@State var activeMiners = " "
@State var totalBalance = ""
@State var availableBalance = ""
Expand All @@ -60,8 +61,8 @@ struct Home: View, ChainTipObserver {
@State var isReceivePresented = false
@State var isTransactionHistoryPresented = false
@State var isConnectionStatusPresented = false
@State var exolix = Exolix.shared

let exolix = Exolix()
let walletState: WalletState

var body: some View {
Expand All @@ -72,9 +73,7 @@ struct Home: View, ChainTipObserver {
miningStatus
VStack(spacing: 24) {
wallet
if let swapTransaction {
swapInProgress(swapTransaction)
}
swapInProgress
recentActivity
}
}
Expand Down Expand Up @@ -108,7 +107,7 @@ struct Home: View, ChainTipObserver {
}
.fullScreenCover(item: $presentedSwapProgress) { transaction in
NavigationStack {
SwapProgress(exolix: Exolix(), transaction: transaction)
SwapProgress(transaction: transaction)
}
}
.sheet(isPresented: $isConnectionStatusPresented) {
Expand All @@ -122,9 +121,18 @@ struct Home: View, ChainTipObserver {
.onReceive(Tari.mainWallet.transactions.$all) {
update(transactions: $0)
}
.onChange(of: swapInProgressId) {
.onChange(of: swapTransactions) {
loadSwapInProgress()
}
.onChange(of: scenePhase) {
Task {
if scenePhase == .active {
await exolix.monitor(transactions: Array(swapTransactions.swaps))
} else {
await exolix.stopMonitoringTransactions()
}
}
}
}
}
}
Expand Down Expand Up @@ -259,12 +267,18 @@ private extension Home {
.foregroundStyle(.primaryText)
}

func swapInProgress(_ swapTransaction: ExolixTransactionResponse) -> some View {
VStack {
sectionHeader("Swap in progress")
.frame(maxWidth: .infinity, alignment: .leading)
SwapInProgressItem(transaction: swapTransaction) {
presentedSwapProgress = swapTransaction
@ViewBuilder
var swapInProgress: some View {
let transactions = exolix.sortedTransactions
if !transactions.isEmpty {
VStack {
sectionHeader("Recent Swaps")
.frame(maxWidth: .infinity, alignment: .leading)
ForEach(transactions) { swapTransaction in
SwapInProgressItem(transaction: swapTransaction) {
presentedSwapProgress = swapTransaction
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,18 @@

protocol SwapTransactionMonitoring {
var exolix: Exolix { get }
var latestTransaction: ExolixTransactionResponse? { get nonmutating set }
var isTransactionProcessed: Bool { get }
var isTransactionCancelled: Bool { get }
func finaliseTransaction()
}

extension SwapTransactionMonitoring {
func monitorTransactionStatus(transactionId: String) async {
guard let transaction = try? await exolix.getTransaction(id: transactionId) else { return }
latestTransaction = transaction
if isTransactionProcessed {
finaliseTransaction()
} else if !isTransactionCancelled {
Task(after: 10) {
if transaction.id == latestTransaction?.id {
await monitorTransactionStatus(transactionId: transactionId)
}
}
}
func monitorSwapTransaction(id: String) async {
await exolix.monitor(transactions: [id])
}

func monitorSwapTransactions(_ transactions: SwapTransactionList) async {
await exolix.monitor(transactions: Array(transactions.swaps))
}

func latestTransaction(id: String) -> ExolixTransactionResponse? {
exolix.latestTransaction(id: id)
}
}
Loading