diff --git a/Gem/Views/MainTabView.swift b/Gem/Views/MainTabView.swift index 145c6db5a..b28d97fee 100644 --- a/Gem/Views/MainTabView.swift +++ b/Gem/Views/MainTabView.swift @@ -184,14 +184,19 @@ extension MainTabView { private func onReceiveNotification(notification: PushNotification) async { do { switch notification { - case .transaction(let walletIndex, let assetId): - //select wallet + case let .transaction(walletIndex, assetId, transaction): if walletIndex != model.wallet.index.asInt { walletService.setCurrent(for: walletIndex) } let asset = try await assetsService.getOrFetchAsset(for: assetId) - navigationState.wallet.append(Scenes.Asset(asset: asset)) + try transactionsService.addTransaction(walletId: model.walletId, transaction: transaction) + let transaction = try transactionsService.getTransaction(walletId: model.walletId, transactionId: transaction.id) + + var path = NavigationPath() + path.append(Scenes.Asset(asset: asset)) + path.append(transaction) + navigationState.wallet = path case .priceAlert(let assetId): let asset = try await assetsService.getOrFetchAsset(for: assetId) navigationState.wallet.append(Scenes.Price(asset: asset)) diff --git a/Packages/FeatureServices/TransactionsService/TransactionsService.swift b/Packages/FeatureServices/TransactionsService/TransactionsService.swift index 833c39ad3..a2dff98fb 100644 --- a/Packages/FeatureServices/TransactionsService/TransactionsService.swift +++ b/Packages/FeatureServices/TransactionsService/TransactionsService.swift @@ -70,10 +70,18 @@ public final class TransactionsService: Sendable { try await prefetchAssets(walletId: wallet.walletId, transactions: response.transactions) try transactionStore.addTransactions(walletId: wallet.id, transactions: response.transactions) try addressStore.addAddressNames(response.addressNames) - + store.setTransactionsForAssetTimestamp(assetId: assetId.identifier, value: newTimestamp) } + + public func addTransaction(walletId: WalletId, transaction: Transaction) throws { + try transactionStore.addTransactions(walletId: walletId.id, transactions: [transaction]) + } + public func getTransaction(walletId: WalletId, transactionId: String) throws -> TransactionExtended { + try transactionStore.getTransaction(walletId: walletId.id, transactionId: transactionId) + } + private func prefetchAssets(walletId: WalletId, transactions: [Transaction]) async throws { let assetIds = transactions.map { $0.assetIds }.flatMap { $0 } if assetIds.isEmpty { diff --git a/Packages/GemAPI/Sources/GemAPI.swift b/Packages/GemAPI/Sources/GemAPI.swift index 356602016..3ed86e6f8 100644 --- a/Packages/GemAPI/Sources/GemAPI.swift +++ b/Packages/GemAPI/Sources/GemAPI.swift @@ -28,7 +28,7 @@ public enum GemAPI: TargetType { case deletePriceAlerts(deviceId: String, priceAlerts: [PriceAlert]) case getTransactions(deviceId: String, options: TransactionsFetchOption) - + case getAsset(AssetId) case getAssets([AssetId]) case getSearchAssets(query: String, chains: [Chain], tags: [AssetTag]) diff --git a/Packages/GemAPI/Sources/GemAPIService.swift b/Packages/GemAPI/Sources/GemAPIService.swift index 2d4bb1b6f..3a5170611 100644 --- a/Packages/GemAPI/Sources/GemAPIService.swift +++ b/Packages/GemAPI/Sources/GemAPIService.swift @@ -176,7 +176,7 @@ extension GemAPIService: GemAPITransactionService { .request(.getTransactions(deviceId: deviceId, options: options)) .map(as: TransactionsResponse.self) } - + public func getTransactionsAll(deviceId: String, walletIndex: Int, fromTimestamp: Int) async throws -> TransactionsResponse { let options = TransactionsFetchOption(wallet_index: walletIndex.asInt32, asset_id: .none, from_timestamp: fromTimestamp.asUInt32) return try await provider diff --git a/Packages/Primitives/Sources/PushNotification+Primitives.swift b/Packages/Primitives/Sources/PushNotification+Primitives.swift index acb158967..9049768fe 100644 --- a/Packages/Primitives/Sources/PushNotification+Primitives.swift +++ b/Packages/Primitives/Sources/PushNotification+Primitives.swift @@ -3,7 +3,7 @@ import Foundation public enum PushNotification: Equatable, Sendable { - case transaction(walletIndex: Int, AssetId) + case transaction(walletIndex: Int, AssetId, transaction: Transaction) case asset(AssetId) case priceAlert(AssetId) case buyAsset(AssetId) @@ -22,12 +22,12 @@ public enum PushNotification: Equatable, Sendable { } let data = try JSONSerialization.data(withJSONObject: dataDict, options: []) - let decoder = JSONDecoder() + let decoder = JSONDateDecoder.standard switch type { case .transaction: let transaction = try decoder.decode(PushNotificationTransaction.self, from: data) let assetId = try AssetId(id: transaction.assetId) - self = .transaction(walletIndex: transaction.walletIndex.asInt, assetId) + self = .transaction(walletIndex: transaction.walletIndex.asInt, assetId, transaction: transaction.transaction) case .asset: let asset = try decoder.decode(PushNotificationAsset.self, from: data) self = .asset(try AssetId(id: asset.assetId)) diff --git a/Packages/Store/Sources/Stores/TransactionStore.swift b/Packages/Store/Sources/Stores/TransactionStore.swift index c3e35d998..289d4edae 100644 --- a/Packages/Store/Sources/Stores/TransactionStore.swift +++ b/Packages/Store/Sources/Stores/TransactionStore.swift @@ -62,6 +62,12 @@ public struct TransactionStore: Sendable { .fetchAll(db) } } + + public func getTransaction(walletId: String, transactionId: String) throws -> TransactionExtended { + try db.read { db in + try TransactionRequest(walletId: walletId, transactionId: transactionId).fetch(db) + } + } public func addTransactions(walletId: String, transactions: [Transaction]) throws { if transactions.isEmpty {