Skip to content

Commit

Permalink
Merge branch 'feature/push-notifications-ext' into feature/push-notif…
Browse files Browse the repository at this point in the history
…ications-open-screen

# Conflicts:
#	NovaPushNotificationServiceExtension/Handlers/Transfers/TransferType.swift
#	novawallet.xcodeproj/project.pbxproj
#	novawallet/Modules/Notifications/NotificationHandlers/Payload.swift
  • Loading branch information
lynx56 committed Mar 14, 2024
2 parents 331c0c6 + d121055 commit 8c57fb0
Show file tree
Hide file tree
Showing 46 changed files with 788 additions and 816 deletions.
43 changes: 0 additions & 43 deletions NovaPushNotificationServiceExtension/CurrencyRepository.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,21 @@ class CommonHandler {
extension CommonHandler {
func balanceViewModel(
asset: AssetModel,
amount: BigUInt,
amount: String,
priceData: PriceData?,
workingQueue: OperationQueue
) -> BalanceViewModelProtocol? {
guard let currencyManager = currencyManager(operationQueue: workingQueue) else {
guard
let currencyManager = currencyManager(operationQueue: workingQueue),
let amountInPlank = BigUInt(amount) else {
return nil
}
let decimalAmount = amount.decimal(precision: asset.precision)
let decimalAmount = amountInPlank.decimal(precision: asset.precision)
let priceAssetInfoFactory = PriceAssetInfoFactory(currencyManager: currencyManager)
let factory = BalanceViewModelFactory(
let factory = PrimitiveBalanceViewModelFactory(
targetAssetInfo: asset.displayInfo,
priceAssetInfoFactory: priceAssetInfoFactory
priceAssetInfoFactory: priceAssetInfoFactory,
formatterFactory: AssetBalanceFormatterFactory()
)
return factory.balanceFromPrice(decimalAmount, priceData: priceData).value(for: locale)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,15 @@ final class NewReferendumHandler: CommonHandler, PushNotificationHandler {
completion(nil)
return
}
let title = localizedString(
LocalizationKeys.Governance.newReferendumTitle,

locale: self.locale
let title = R.string.localizable.pushNotificationNewReferendumTitle(
preferredLanguages: self.locale.rLanguages
)
let subtitle = localizedString(
LocalizationKeys.Governance.newReferendumSubtitle,

with: [chain.name, self.payload.referendumNumber],
locale: self.locale
let subtitle = R.string.localizable.pushNotificationNewReferendumSubtitle(
chain.name,
self.payload.referendumNumber,
preferredLanguages: self.locale.rLanguages
)
completion(.init(title: title, subtitle: subtitle))
case .failure:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ final class ReferendumUpdatesHandler: CommonHandler, PushNotificationHandler {
let chainId: ChainModel.Id
let payload: ReferendumStateUpdatePayload
let operationQueue: OperationQueue
let callStore = CancellableCallStore()

init(
chainId: ChainModel.Id,
Expand All @@ -29,7 +28,6 @@ final class ReferendumUpdatesHandler: CommonHandler, PushNotificationHandler {
execute(
operation: chainOperation,
inOperationQueue: operationQueue,
backingCallIn: callStore,
runningCallbackIn: callbackQueue
) { [weak self] result in
guard let self = self else {
Expand All @@ -41,66 +39,64 @@ final class ReferendumUpdatesHandler: CommonHandler, PushNotificationHandler {
completion(nil)
return
}
let content = self.content(from: chain, payload: payload)
let content = self.content(from: chain)
completion(content)
case .failure:
completion(nil)
}
}
}

private func content(
from chain: ChainModel,
payload: ReferendumStateUpdatePayload
) -> NotificationContentResult {
switch payload.to {
private func content(from chain: ChainModel) -> NotificationContentResult {
switch payload.toStatus {
case .approved:
let title = localizedString(
LocalizationKeys.Governance.referendumApprovedTitle,
locale: locale
let title = R.string.localizable.pushNotificationReferendumApprovedTitle(
preferredLanguages: locale.rLanguages
)
let subtitle = localizedString(
LocalizationKeys.Governance.referendumApprovedSubitle,
with: [chain.name, self.payload.referendumNumber],
locale: locale

let subtitle = R.string.localizable.pushNotificationReferendumApprovedSubtitle(
chain.name,
payload.referendumNumber,
preferredLanguages: locale.rLanguages
)

return .init(title: title, subtitle: subtitle)
case .rejected:
let title = localizedString(
LocalizationKeys.Governance.referendumRejectedTitle,
locale: locale
let title = R.string.localizable.pushNotificationReferendumRejectedTitle(
preferredLanguages: locale.rLanguages
)
let subtitle = localizedString(
LocalizationKeys.Governance.referendumRejectedSubitle,
with: [chain.name, self.payload.referendumNumber],
locale: locale

let subtitle = R.string.localizable.pushNotificationReferendumRejectedSubtitle(
chain.name,
payload.referendumNumber,
preferredLanguages: locale.rLanguages
)

return .init(title: title, subtitle: subtitle)
default:
let title = localizedString(
LocalizationKeys.Governance.referendumStatusUpdatedTitle,
locale: locale
let title = R.string.localizable.pushNotificationReferendumStatusUpdatedTitle(
preferredLanguages: locale.rLanguages
)

let subtitle: String

if let oldStatus = self.payload.from {
subtitle = localizedString(
LocalizationKeys.Governance.referendumStatusUpdatedSubitle,
with: [chain.name,
self.payload.referendumNumber,
oldStatus.description(for: locale),
self.payload.to.description(for: locale)],
locale: locale
if let oldStatus = payload.fromStatus {
subtitle = R.string.localizable.pushNotificationReferendumStatusUpdatedSubtitle(
chain.name,
payload.referendumNumber,
oldStatus.description(for: locale),
payload.toStatus.description(for: locale),
preferredLanguages: locale.rLanguages
)
} else {
subtitle = localizedString(
LocalizationKeys.Governance.referendumSingleStatusUpdatedSubitle,
with: [chain.name,
self.payload.referendumNumber,
self.payload.to.description(for: locale)],
locale: locale
subtitle = R.string.localizable.pushNotificationReferendumSingleStatusUpdatedSubtitle(
chain.name,
payload.referendumNumber,
payload.toStatus.description(for: locale),
preferredLanguages: locale.rLanguages
)
}

return .init(title: title, subtitle: subtitle)
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ final class StakingRewardsHandler: CommonHandler, PushNotificationHandler {
)
let walletString = walletName.flatMap { "[\($0)]" } ?? ""
let title = [
localizedString(LocalizationKeys.StakingReward.title, locale: locale),
R.string.localizable.pushNotificationStakingRewardTitle(preferredLanguages: locale.rLanguages),
walletString
].joined(with: .space)
let balance = balanceViewModel(
Expand All @@ -107,15 +107,13 @@ final class StakingRewardsHandler: CommonHandler, PushNotificationHandler {
priceData: priceData,
workingQueue: operationQueue
)

let priceString = balance?.price.map { "(\($0))" } ?? ""
let subtitle = localizedString(
LocalizationKeys.StakingReward.subtitle,
with: [
balance?.amount ?? "",
priceString,
chainAsset.chain.name
],
locale: locale
let subtitle = R.string.localizable.pushNotificationStakingRewardSubtitle(
balance?.amount ?? "",
priceString,
chainAsset.chain.name,
preferredLanguages: locale.rLanguages
)

return .init(title: title, subtitle: subtitle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,12 @@ final class NewReleaseHandler: PushNotificationHandler {
) {
dispatchInQueueWhenPossible(callbackQueue) {
let locale = self.localizationManager.selectedLocale
let title = localizedString(
LocalizationKeys.Technical.newReleaseTitle,
locale: locale
)
let subtitle = localizedString(
LocalizationKeys.Technical.newReleaseSubtitle,
with: [self.payload.version],
locale: locale
let title = R.string.localizable.pushNotificationNewReleaseTitle(preferredLanguages: locale.rLanguages)
let subtitle = R.string.localizable.pushNotificationNewReleaseSubtitle(
self.payload.version,
preferredLanguages: locale.rLanguages
)

completion(.init(title: title, subtitle: subtitle))
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import Foundation

enum TransferType {
case income
case outcome

func title(locale: Locale, walletName: String?) -> String {
let walletString = walletName.flatMap { "[\($0)]" } ?? ""
let title: String
switch self {
case .income:
title = R.string.localizable.pushNotificationReceiveTokensTitle(preferredLanguages: locale.rLanguages)
case .outcome:
title = R.string.localizable.pushNotificationSentTokensTitle(preferredLanguages: locale.rLanguages)
}

return [title, walletString].joined(with: .space)
}

func subtitle(
amount: String,
price: String?,
chainName: String,
address: AccountAddress?,
locale: Locale
) -> String {
let priceString = price.map { "(\($0))" } ?? ""
switch self {
case .income:
return R.string.localizable.pushNotificationReceiveTokensSubtitle(
amount,
priceString,
chainName,
preferredLanguages: locale.rLanguages
)
case .outcome:
if let address = address {
return R.string.localizable.pushNotificationSentTokensSubtitle(
amount,
priceString,
address,
chainName,
preferredLanguages: locale.rLanguages
)
} else {
return R.string.localizable.pushNotificationSentTokensWoAddressSubtitle(
amount,
priceString,
chainName,
preferredLanguages: locale.rLanguages
)
}
}
}

func address(from payload: NotificationTransferPayload) -> AccountAddress? {
switch self {
case .income:
return nil
case .outcome:
return payload.recipient
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import UserNotifications

extension NotificationContentResult {
func toUserNotificationContent() -> UNNotificationContent {
let content = UNMutableNotificationContent()
content.title = title
content.subtitle = ""
content.body = subtitle

return content
}
}
Loading

0 comments on commit 8c57fb0

Please sign in to comment.