blockchainethereumblockchain-walleterc20erc721walletxdaidappdecentralizederc1155erc875iosswifttokens
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.8 KiB
44 lines
1.8 KiB
//
|
|
// LocalNotificationService.swift
|
|
// AlphaWallet
|
|
//
|
|
// Created by Vladyslav Shepitko on 25.03.2022.
|
|
//
|
|
|
|
import Foundation
|
|
import UserNotifications
|
|
|
|
protocol ScheduledNotificationService: AnyObject {
|
|
func schedule(notification: LocalNotification)
|
|
}
|
|
|
|
class LocalNotificationService: ScheduledNotificationService {
|
|
|
|
func schedule(notification: LocalNotification) {
|
|
switch notification {
|
|
case .receiveEther(let transaction, let amount, let server):
|
|
notifyUserEtherReceived(for: transaction, amount: amount, server: server)
|
|
}
|
|
}
|
|
|
|
private func notifyUserEtherReceived(for transactionId: String, amount: String, server: RPCServer) {
|
|
let notificationCenter = UNUserNotificationCenter.current()
|
|
let content = UNMutableNotificationContent()
|
|
//TODO support other mainnets too
|
|
switch server {
|
|
case .main, .xDai:
|
|
content.body = R.string.localizable.transactionsReceivedEther(amount, server.symbol)
|
|
case .kovan, .ropsten, .rinkeby, .poa, .sokol, .classic, .callisto, .goerli, .artis_sigma1, .artis_tau1, .binance_smart_chain, .binance_smart_chain_testnet, .custom, .heco, .heco_testnet, .fantom, .fantom_testnet, .avalanche, .avalanche_testnet, .polygon, .mumbai_testnet, .optimistic, .optimisticKovan, .cronosTestnet, .arbitrum, .arbitrumRinkeby, .palm, .palmTestnet, .klaytnCypress, .klaytnBaobabTestnet:
|
|
content.body = R.string.localizable.transactionsReceivedEther("\(amount) (\(server.name))", server.symbol)
|
|
}
|
|
|
|
content.sound = .default
|
|
let identifier = Constants.etherReceivedNotificationIdentifier
|
|
let request = UNNotificationRequest(identifier: "\(identifier):\(transactionId)", content: content, trigger: nil)
|
|
|
|
DispatchQueue.main.async {
|
|
notificationCenter.add(request)
|
|
}
|
|
}
|
|
}
|
|
|
|
|