Skip to content

Commit

Permalink
Merge branch 'release/0.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
RealBonus committed Jun 28, 2018
2 parents 0ced0c9 + e99ba87 commit cb805c7
Show file tree
Hide file tree
Showing 34 changed files with 623 additions and 304 deletions.
60 changes: 54 additions & 6 deletions Adamant/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ extension String.adamantLocalized {
static let chats = NSLocalizedString("Tabs.Chats", comment: "Main tab bar: Chats page")
static let settings = NSLocalizedString("Tabs.Settings", comment: "Main tab bar: Settings page")
}

struct application {
static let deviceTokenSendFailed = NSLocalizedString("Application.deviceTokenErrorFormat", comment: "Application: Failed to send deviceToken to ANS error format. %@ for error description")
}
}

extension StoreKey {
Expand All @@ -38,11 +42,16 @@ struct AdamantResources {
static let nodes: [Node] = [
Node(scheme: .https, host: "endless.adamant.im", port: nil),
Node(scheme: .https, host: "clown.adamant.im", port: nil),
Node(scheme: .https, host: "lake.adamant.im", port: nil)
Node(scheme: .https, host: "lake.adamant.im", port: nil),
Node(scheme: .http, host: "80.211.177.181", port: nil)
]

static let iosAppSupportEmail = "[email protected]"

// ANS Contact
static let ansAddress = "U10629337621822775991"
static let ansPublicKey = "188b24bd116a556ac8ba905bbbdaa16e237dfb14269f5a4f9a26be77537d977c"

private init() {}
}

Expand Down Expand Up @@ -208,6 +217,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

// MARK: - Remote notifications
extension AppDelegate {
private struct RegistrationPayload: Codable {
let token: String

#if DEBUG
let provider: String = "apns-sandbox"
#else
let provider: String = "apns"
#endif
}

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
guard let address = accountService.account?.address, let keypair = accountService.keypair else {
print("Trying to register with no user logged")
Expand All @@ -217,7 +236,7 @@ extension AppDelegate {

let token = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()

// Checking, if device token had not changed
// MARK: 1. Checking, if device token had not changed
guard let securedStore = container.resolve(SecuredStore.self) else {
fatalError("can't get secured store to get device token hash")
}
Expand All @@ -230,19 +249,48 @@ extension AppDelegate {
securedStore.set(tokenHash, for: StoreKey.application.deviceTokenHash)
}

// Storing new token in blockchain
// MARK: 2. Preparing message
guard let adamantCore = container.resolve(AdamantCore.self) else {
fatalError("Can't get AdamantCore to register device token")
}

let payload: String
do {
let data = try JSONEncoder().encode(RegistrationPayload(token: token))
payload = String(data: data, encoding: String.Encoding.utf8)!
} catch {
dialogService.showError(withMessage: "Failed to prepare ANS signal payload", error: error)
return
}

guard let encodedPayload = adamantCore.encodeMessage(payload, recipientPublicKey: AdamantResources.ansPublicKey, privateKey: keypair.privateKey) else {
dialogService.showError(withMessage: "Failed to encode ANS signal. Payload: \(payload)", error: nil)
return
}

// MARK: 3. Send signal to ANS
guard let apiService = container.resolve(ApiService.self) else {
fatalError("can't get api service to register device token")
}

apiService.store(key: "deviceToken", value: token, type: StateType.keyValue, sender: address, keypair: keypair) { [weak self] result in
apiService.sendMessage(senderId: address, recipientId: AdamantResources.ansAddress, keypair: keypair, message: encodedPayload.message, type: ChatType.signal, nonce: encodedPayload.nonce) { [unowned self] result in
switch result {
case .success:
return

case .failure(let error):
print("Failed to store device token: \(error)")
self?.notificationService?.setNotificationsMode(.disabled, completion: nil)
self.notificationService?.setNotificationsMode(.disabled, completion: nil)

switch error {
case .networkError, .notLogged:
self.dialogService.showWarning(withMessage: String.localizedStringWithFormat(String.adamantLocalized.application.deviceTokenSendFailed, error.localized))

case .accountNotFound, .serverError:
self.dialogService.showError(withMessage: String.localizedStringWithFormat(String.adamantLocalized.application.deviceTokenSendFailed, error.localized), error: error)

case .internalError(let message, _):
self.dialogService.showError(withMessage: String.localizedStringWithFormat(String.adamantLocalized.application.deviceTokenSendFailed, message), error: error)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
"template-rendering-intent" : "original"
}
}
Binary file modified Adamant/Assets/Assets.xcassets/avatar_bots.imageset/avatar_bots.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions Adamant/Assets/l18n/de.lproj/InfoPlist.strings
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
"CFBundleName" = "Adamant";

/* Privacy - Camera Usage Description */
"NSCameraUsageDescription" = "The camera needed to scan QR codes for addresses and passphrases";
"NSCameraUsageDescription" = "Die Kamera wird benötigt, um QR-Codes für Adressen und Passphrases zu scannen";

/* Privacy - Face ID Usage Description */
"NSFaceIDUsageDescription" = "Sign In into your ADAMANT with Face ID";
"NSFaceIDUsageDescription" = "In dein ADAMANT mit Face ID einloggen";

/* Privacy - Photo Library Additions Usage Description */
"NSPhotoLibraryAddUsageDescription" = "Saving generated QR codes with passphrases and addresses";
"NSPhotoLibraryAddUsageDescription" = "Generierte QR-Codes mit Passphrases und Adressen werden gespeichert";

/* Privacy - Photo Library Usage Description */
"NSPhotoLibraryUsageDescription" = "Reading QR codes with passphrases and addresses";
"NSPhotoLibraryUsageDescription" = "QR-Codes mit Passphrases und Adressen werden gelesen";

Loading

0 comments on commit cb805c7

Please sign in to comment.