-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1027 from novasamatech/develop
7.10.0 Push Notifications
- Loading branch information
Showing
257 changed files
with
12,988 additions
and
870 deletions.
There are no files selected for viewing
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
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
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
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
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
3 changes: 3 additions & 0 deletions
3
NovaPushNotificationServiceExtension/Config/notification-ext.debug.xcconfig
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,3 @@ | ||
#include "../../Pods/Target Support Files/Pods-NovaPushNotificationServiceExtension/Pods-NovaPushNotificationServiceExtension.debug.xcconfig" | ||
|
||
OTHER_SWIFT_FLAGS = $(inherited) "-DF_DEV" |
3 changes: 3 additions & 0 deletions
3
NovaPushNotificationServiceExtension/Config/notification-ext.dev.xcconfig
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,3 @@ | ||
#include "../../Pods/Target Support Files/Pods-NovaPushNotificationServiceExtension/Pods-NovaPushNotificationServiceExtension.dev.xcconfig" | ||
|
||
OTHER_SWIFT_FLAGS = $(inherited) "-DF_DEV" |
3 changes: 3 additions & 0 deletions
3
NovaPushNotificationServiceExtension/Config/notification-ext.release.xcconfig
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,3 @@ | ||
#include "../../Pods/Target Support Files/Pods-NovaPushNotificationServiceExtension/Pods-NovaPushNotificationServiceExtension.release.xcconfig" | ||
|
||
OTHER_SWIFT_FLAGS = $(inherited) "-DF_RELEASE" |
142 changes: 142 additions & 0 deletions
142
NovaPushNotificationServiceExtension/Handlers/CommonHandler.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,142 @@ | ||
import RobinHood | ||
import SoraFoundation | ||
import SoraKeystore | ||
import BigInt | ||
|
||
class CommonHandler { | ||
let userStorageFacade: StorageFacadeProtocol | ||
let substrateStorageFacade: StorageFacadeProtocol | ||
var locale: Locale { | ||
LocalizationManager.shared.selectedLocale | ||
} | ||
|
||
lazy var settingsRepository: AnyDataProviderRepository<Web3Alert.LocalSettings> = createSettingsRepository() | ||
lazy var chainsRepository: AnyDataProviderRepository<ChainModel> = createChainsRepository() | ||
let settingsManager: SettingsManagerProtocol | ||
|
||
init( | ||
userStorageFacade: StorageFacadeProtocol = UserDataStorageFacade.shared, | ||
substrateStorageFacade: StorageFacadeProtocol = SubstrateDataStorageFacade.shared, | ||
settingsManager: SettingsManagerProtocol = SharedSettingsManager() ?? SettingsManager.shared | ||
) { | ||
self.userStorageFacade = userStorageFacade | ||
self.substrateStorageFacade = substrateStorageFacade | ||
self.settingsManager = settingsManager | ||
} | ||
|
||
func createSettingsRepository() -> AnyDataProviderRepository<Web3Alert.LocalSettings> { | ||
let pushSettings = NSPredicate( | ||
format: "%K == %@", | ||
#keyPath(CDUserSingleValue.identifier), | ||
Web3Alert.LocalSettings.getIdentifier() | ||
) | ||
|
||
let repository: CoreDataRepository<Web3Alert.LocalSettings, CDUserSingleValue> = | ||
userStorageFacade.createRepository( | ||
filter: pushSettings, | ||
sortDescriptors: [], | ||
mapper: AnyCoreDataMapper(Web3AlertSettingsMapper()) | ||
) | ||
|
||
return AnyDataProviderRepository(repository) | ||
} | ||
|
||
func createChainsRepository() -> AnyDataProviderRepository<ChainModel> { | ||
let mapper = ChainModelMapper() | ||
let repository = substrateStorageFacade.createRepository( | ||
filter: nil, | ||
sortDescriptors: [], | ||
mapper: AnyCoreDataMapper(mapper) | ||
) | ||
|
||
return AnyDataProviderRepository(repository) | ||
} | ||
|
||
func search(chainId: ChainModel.Id, in chains: [ChainModel]) -> ChainModel? { | ||
chains.first(where: { chain in | ||
let remoteChainId = Web3Alert.createRemoteChainId(from: chain.chainId) | ||
return remoteChainId == chainId | ||
}) | ||
} | ||
} | ||
|
||
extension CommonHandler { | ||
func balanceViewModel( | ||
asset: AssetModel, | ||
amount: String, | ||
priceData: PriceData?, | ||
workingQueue: OperationQueue | ||
) -> BalanceViewModelProtocol? { | ||
guard | ||
let currencyManager = currencyManager(operationQueue: workingQueue), | ||
let amountInPlank = BigUInt(amount) else { | ||
return nil | ||
} | ||
let decimalAmount = amountInPlank.decimal(precision: asset.precision) | ||
let priceAssetInfoFactory = PriceAssetInfoFactory(currencyManager: currencyManager) | ||
let factory = PrimitiveBalanceViewModelFactory( | ||
targetAssetInfo: asset.displayInfo, | ||
priceAssetInfoFactory: priceAssetInfoFactory, | ||
formatterFactory: AssetBalanceFormatterFactory() | ||
) | ||
return factory.balanceFromPrice(decimalAmount, priceData: priceData).value(for: locale) | ||
} | ||
|
||
func priceRepository(for priceId: String, currencyId: Int) -> CoreDataRepository<PriceData, CDPrice> { | ||
let mapper = PriceDataMapper() | ||
let identifier = PriceData.createIdentifier(for: priceId, currencyId: currencyId) | ||
let filter = NSPredicate(format: "%K == %@", #keyPath(CDPrice.identifier), identifier) | ||
|
||
let repository: CoreDataRepository<PriceData, CDPrice> = substrateStorageFacade.createRepository( | ||
filter: filter, | ||
sortDescriptors: [], | ||
mapper: AnyCoreDataMapper(mapper) | ||
) | ||
|
||
return repository | ||
} | ||
|
||
func currencyManager(operationQueue: OperationQueue) -> CurrencyManagerProtocol? { | ||
try? CurrencyManager( | ||
currencyRepository: CurrencyRepository(), | ||
settingsManager: SharedSettingsManager() ?? SettingsManager.shared, | ||
queue: operationQueue | ||
) | ||
} | ||
|
||
func targetWalletName( | ||
for address: AccountAddress?, | ||
chainId: ChainModel.Id, | ||
wallets: [Web3Alert.LocalWallet], | ||
metaAccounts: [MetaAccountModel] | ||
) -> String? { | ||
guard let address = address, wallets.count > 1 else { | ||
return nil | ||
} | ||
|
||
guard let targetWallet = wallets.first(where: { | ||
if let specificAddress = $0.model.chainSpecific[chainId] { | ||
return specificAddress == address | ||
} else { | ||
return $0.model.baseSubstrate == address || | ||
$0.model.baseEthereum == address | ||
} | ||
}) else { | ||
return nil | ||
} | ||
|
||
return metaAccounts.first(where: { $0.metaId == targetWallet.metaId })?.name | ||
} | ||
|
||
func walletsRepository() -> AnyDataProviderRepository<MetaAccountModel> { | ||
let mapper = MetaAccountMapper() | ||
|
||
let repository = userStorageFacade.createRepository( | ||
filter: nil, | ||
sortDescriptors: [], | ||
mapper: AnyCoreDataMapper(mapper) | ||
) | ||
|
||
return AnyDataProviderRepository(repository) | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
NovaPushNotificationServiceExtension/Handlers/Extensions/LocalizationManagerExtensions.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,10 @@ | ||
import SoraFoundation | ||
|
||
extension LocalizationManager { | ||
func refreshLocale() { | ||
if let settingsKey = settingsKey, | ||
let localization = settings?.string(for: settingsKey) { | ||
selectedLocalization = localization | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
NovaPushNotificationServiceExtension/Handlers/Extensions/ReferendumStatusExtensions.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,24 @@ | ||
import Foundation | ||
|
||
extension ReferendumStateUpdatePayload.Status { | ||
func description(for locale: Locale?) -> String { | ||
switch self { | ||
case .created: | ||
return R.string.localizable.pushNotificationReferendumCreated(preferredLanguages: locale?.rLanguages) | ||
case .deciding: | ||
return R.string.localizable.pushNotificationReferendumDeciding(preferredLanguages: locale?.rLanguages) | ||
case .confirming: | ||
return R.string.localizable.pushNotificationReferendumConfirming(preferredLanguages: locale?.rLanguages) | ||
case .approved: | ||
return R.string.localizable.pushNotificationReferendumApproved(preferredLanguages: locale?.rLanguages) | ||
case .rejected: | ||
return R.string.localizable.pushNotificationReferendumRejected(preferredLanguages: locale?.rLanguages) | ||
case .cancelled: | ||
return R.string.localizable.pushNotificationReferendumCancelled(preferredLanguages: locale?.rLanguages) | ||
case .timedOut: | ||
return R.string.localizable.pushNotificationReferendumTimedOut(preferredLanguages: locale?.rLanguages) | ||
case .killed: | ||
return R.string.localizable.pushNotificationReferendumKilled(preferredLanguages: locale?.rLanguages) | ||
} | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
NovaPushNotificationServiceExtension/Handlers/Extensions/TransferTypeExtensions.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,61 @@ | ||
import Foundation | ||
|
||
extension PushNotification.TransferType { | ||
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.pushNotificationSentTokensNoAddressSubtitle( | ||
amount, | ||
priceString, | ||
chainName, | ||
preferredLanguages: locale.rLanguages | ||
) | ||
} | ||
} | ||
} | ||
|
||
func address(from payload: NotificationTransferPayload) -> AccountAddress? { | ||
switch self { | ||
case .income: | ||
return nil | ||
case .outcome: | ||
return payload.recipient | ||
} | ||
} | ||
} |
Oops, something went wrong.