Skip to content

Commit

Permalink
Add keys for cloud containers
Browse files Browse the repository at this point in the history
- make timestamps in contacts as Double
  • Loading branch information
ant013 committed Jun 6, 2023
1 parent 5303411 commit 2e91018
Show file tree
Hide file tree
Showing 18 changed files with 77 additions and 34 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/deploy_appstore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,5 @@ jobs:
XCCONFIG_PROD_TWITTER_BEARER_TOKEN: ${{ secrets.XCCONFIG_PROD_TWITTER_BEARER_TOKEN }}
XCCONFIG_PROD_HS_PROVIDER_API_KEY: ${{ secrets.XCCONFIG_PROD_HS_PROVIDER_API_KEY }}
XCCONFIG_PROD_WALLET_CONNECT_V2_PROJECT_KEY: ${{ secrets.XCCONFIG_PROD_WALLET_CONNECT_V2_PROJECT_KEY }}
XCCONFIG_PROD_SHARED_CLOUD_CONTAINER_ID: ${{ secrets.XCCONFIG_PROD_SHARED_CLOUD_CONTAINER_ID }}
XCCONFIG_PROD_PRIVATE_CLOUD_CONTAINER_ID: ${{ secrets.XCCONFIG_PROD_PRIVATE_CLOUD_CONTAINER_ID }}
2 changes: 2 additions & 0 deletions .github/workflows/deploy_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,5 @@ jobs:
XCCONFIG_DEV_TWITTER_BEARER_TOKEN: ${{ secrets.XCCONFIG_DEV_TWITTER_BEARER_TOKEN }}
XCCONFIG_DEV_HS_PROVIDER_API_KEY: ${{ secrets.XCCONFIG_DEV_HS_PROVIDER_API_KEY }}
XCCONFIG_DEV_WALLET_CONNECT_V2_PROJECT_KEY: ${{ secrets.XCCONFIG_DEV_WALLET_CONNECT_V2_PROJECT_KEY }}
XCCONFIG_DEV_SHARED_CLOUD_CONTAINER_ID: ${{ secrets.XCCONFIG_DEV_SHARED_CLOUD_CONTAINER_ID }}
XCCONFIG_DEV_PRIVATE_CLOUD_CONTAINER_ID: ${{ secrets.XCCONFIG_DEV_PRIVATE_CLOUD_CONTAINER_ID }}
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ market_api_url = https:/$()/api-dev.blocksdecoded.com
hs_provider_api_key =
wallet_connect_v2_project_key =
default_words =
shared_cloud_container_id =
private_cloud_container_id =
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ twitter_bearer_token =
market_api_url = https:/$()/api.blocksdecoded.com
hs_provider_api_key =
wallet_connect_v2_project_key =
shared_cloud_container_id =
private_cloud_container_id =
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<key>com.apple.developer.icloud-container-identifiers</key>
<array>
<string>iCloud.io.horizontalsystems.bank-wallet</string>
<string>iCloud.io.horizontalsystems.bank-wallet.shared</string>
</array>
<key>com.apple.developer.icloud-services</key>
<array>
Expand All @@ -19,6 +20,7 @@
<key>com.apple.developer.ubiquity-container-identifiers</key>
<array>
<string>iCloud.io.horizontalsystems.bank-wallet</string>
<string>iCloud.io.horizontalsystems.bank-wallet.shared</string>
</array>
<key>com.apple.developer.ubiquity-kvstore-identifier</key>
<string>$(TeamIdentifierPrefix)$(CFBundleIdentifier)</string>
Expand Down
4 changes: 2 additions & 2 deletions UnstoppableWallet/UnstoppableWallet/Core/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class App {
accountRestoreWarningManager = AccountRestoreWarningManager(accountManager: accountManager, localStorage: StorageKit.LocalStorage.default)
accountFactory = AccountFactory(accountManager: accountManager)

cloudAccountBackupManager = CloudAccountBackupManager(ubiquityContainerIdentifier: CloudAccountBackupManager.iCloudSharedContainer, logger: logger)
cloudAccountBackupManager = CloudAccountBackupManager(ubiquityContainerIdentifier: appConfigProvider.sharedCloudContainer, logger: logger)
backupManager = BackupManager(accountManager: accountManager)

kitCleaner = KitCleaner(accountManager: accountManager)
Expand Down Expand Up @@ -298,7 +298,7 @@ class App {
balanceHiddenManager = BalanceHiddenManager(localStorage: StorageKit.LocalStorage.default)
balanceConversionManager = BalanceConversionManager(marketKit: marketKit, localStorage: StorageKit.LocalStorage.default)

contactManager = ContactBookManager(localStorage: localStorage, helper: ContactBookHelper(), logger: logger)
contactManager = ContactBookManager(localStorage: localStorage, ubiquityContainerIdentifier: appConfigProvider.privateCloudContainer, helper: ContactBookHelper(), logger: logger)

subscriptionManager = SubscriptionManager(localStorage: StorageKit.LocalStorage.default)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import HsExtensions
class CloudAccountBackupManager {
static private let batchingInterval: TimeInterval = 1
static private let fileExtension = ".json"
static let iCloudSharedContainer = "iCloud.io.horizontalsystems.bank-wallet.shared.dev"

private let ubiquityContainerIdentifier: String
private let ubiquityContainerIdentifier: String?
private let fileStorage: FileStorage
private let logger: Logger?

Expand All @@ -25,7 +24,7 @@ class CloudAccountBackupManager {
@PostPublished private(set) var items = [String: WalletBackup]()
@PostPublished private(set) var state = State.loading

init(ubiquityContainerIdentifier: String, logger: Logger?) {
init(ubiquityContainerIdentifier: String?, logger: Logger?) {
self.ubiquityContainerIdentifier = ubiquityContainerIdentifier

fileStorage = FileStorage(logger: logger)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ class AppConfigProvider {
Bundle.main.object(forInfoDictionaryKey: "DefaultPassphrase") as? String ?? ""
}

var sharedCloudContainer: String? {
Bundle.main.object(forInfoDictionaryKey: "SharedCloudContainerId") as? String
}

var privateCloudContainer: String? {
Bundle.main.object(forInfoDictionaryKey: "PrivateCloudContainerId") as? String
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class ContactBookManager {
static let localUrl = try? FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
private let scheduler = SerialDispatchQueueScheduler(qos: .userInitiated, internalSerialQueueName: "io.horizontalsystems.unstoppable.contact_manager")

private let ubiquityContainerIdentifier: String?

private let disposeBag = DisposeBag()
private var monitorDisposeBag = DisposeBag()

Expand Down Expand Up @@ -53,19 +55,26 @@ class ContactBookManager {
private let fileStorage = FileDataStorage()

let localUrl: URL
var iCloudUrl: URL? { FileManager.default.url(forUbiquityContainerIdentifier: nil)?.appendingPathComponent("Documents") }
var iCloudUrl: URL? {
FileManager
.default
.url(forUbiquityContainerIdentifier: ubiquityContainerIdentifier)?
.appendingPathComponent("Documents")
}

private var needsToSyncRemote = false {
didSet {
logger?.debug("=C-MANAGER: set needsToRemoteUpdate \(needsToSyncRemote)))")
}
}

init?(localStorage: LocalStorage, helper: ContactBookHelper, logger: Logger? = nil) {
init?(localStorage: LocalStorage, ubiquityContainerIdentifier: String?, helper: ContactBookHelper, logger: Logger? = nil) {
guard let localUrl = ContactBookManager.localUrl else {
return nil
}

self.ubiquityContainerIdentifier = ubiquityContainerIdentifier

logger?.debug("=C-MANAGER> INIT")
self.localStorage = localStorage
self.helper = helper
Expand Down Expand Up @@ -131,7 +140,6 @@ class ContactBookManager {
localError.code == 260 {

sync(localData: Data())

return
}

Expand Down
28 changes: 16 additions & 12 deletions UnstoppableWallet/UnstoppableWallet/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,22 @@
<array>
<string>UIInterfaceOrientationPortrait</string>
</array>
<key>NSUbiquitousContainers</key>
<dict>
<key>iCloud.io.horizontalsystems.bank-wallet.shared.dev</key>
<dict>
<key>NSUbiquitousContainerIsDocumentScopePublic</key>
<true/>
<key>NSUbiquitousContainerName</key>
<string>$(PRODUCT_NAME)</string>
<key>NSUbiquitousContainerSupportedFolderLevels</key>
<string>Any</string>
</dict>
</dict>
<key>NSUbiquitousContainers</key>
<dict>
<key>${shared_cloud_container_id}</key>
<dict>
<key>NSUbiquitousContainerIsDocumentScopePublic</key>
<true/>
<key>NSUbiquitousContainerName</key>
<string>$(PRODUCT_NAME)</string>
<key>NSUbiquitousContainerSupportedFolderLevels</key>
<string>Any</string>
</dict>
</dict>
<key>SharedCloudContainerId</key>
<string>${shared_cloud_container_id}</string>
<key>PrivateCloudContainerId</key>
<string>${private_cloud_container_id}</string>
<key>WallectConnectV2ProjectKey</key>
<string>${wallet_connect_v2_project_key}</string>
</dict>
Expand Down
8 changes: 4 additions & 4 deletions UnstoppableWallet/UnstoppableWallet/Models/Contact.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ extension Array where Element == ContactAddress {

class Contact: ImmutableMappable, Hashable, Equatable {
let uid: String
let modifiedAt: Int
let modifiedAt: TimeInterval
let name: String
let addresses: [ContactAddress]

init(uid: String, modifiedAt: Int, name: String, addresses: [ContactAddress]) {
init(uid: String, modifiedAt: TimeInterval, name: String, addresses: [ContactAddress]) {
self.uid = uid
self.modifiedAt = modifiedAt
self.name = name
Expand Down Expand Up @@ -83,9 +83,9 @@ class Contact: ImmutableMappable, Hashable, Equatable {

class DeletedContact: ImmutableMappable, Hashable, Equatable {
let uid: String
let deletedAt: Int
let deletedAt: TimeInterval

init(uid: String, deletedAt: Int) {
init(uid: String, deletedAt: TimeInterval) {
self.uid = uid
self.deletedAt = deletedAt
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ extension ContactBookContactService {
}

let uid = oldContact?.uid ?? UUID().uuidString
let contact = Contact(uid: uid, modifiedAt: Int(Date().timeIntervalSince1970), name: contactName, addresses: addresses)
let contact = Contact(uid: uid, modifiedAt: Date().timeIntervalSince1970, name: contactName, addresses: addresses)

try contactManager.update(contact: contact)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ extension ContactBookHelper {
let removed = contacts.remove(at: index)

var deleted = book.deleted
deleted.append(DeletedContact(uid: removed.uid, deletedAt: Int(Date().timeIntervalSince1970)))
deleted.append(DeletedContact(uid: removed.uid, deletedAt: Date().timeIntervalSince1970))

return ContactBook(version: book.version, contacts: contacts, deletedContacts: deleted)
}
Expand Down Expand Up @@ -150,7 +150,7 @@ extension ContactBookHelper {
version: (lastVersion ?? 0) + 1,
contacts: contacts
.map { Contact(uid: $0.uid,
modifiedAt: Int(Date().timeIntervalSince1970),
modifiedAt: Date().timeIntervalSince1970,
name: $0.name,
addresses: $0.addresses)
},
Expand All @@ -163,7 +163,7 @@ extension ContactBookHelper {

private struct EqualContactData: Equatable, Hashable {
let uid: String
let timestamp: Int
let timestamp: TimeInterval

static func ==(lhs: EqualContactData, rhs: EqualContactData) -> Bool {
lhs.uid == rhs.uid && lhs.timestamp == rhs.timestamp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ class ManageAccountViewModel {
private func keyActions(account: Account, isCloudBackedUp: Bool) -> [KeyActionSection] {
var backupActions = [KeyAction]()

let footerText: String = !(account.backedUp || isCloudBackedUp) ?
"manage_account.backup.no_backup_yet_description".localized :
"manage_account.backup.has_backup_description".localized
var footerText: String = ""

if account.canBeBackedUp {
backupActions.append(.manualBackup(account.backedUp))
footerText = !(account.backedUp || isCloudBackedUp) ?
"manage_account.backup.no_backup_yet_description".localized :
"manage_account.backup.has_backup_description".localized
}

if !account.watchAccount {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class RestoreTypeViewController: ThemeViewController {
override func viewDidLoad() {
super.viewDidLoad()

title = "recovery_phrase.title".localized
title = "restore.title".localized

navigationItem.largeTitleDisplayMode = .never
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "button.cancel".localized, style: .plain, target: self, action: #selector(didTapCancel))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ extension MainSettingsService {
}

var isCloudAvailableError: Bool {
(contactBookManager?.remoteSync ?? false) && (contactBookManager?.iCloudError != nil)
guard let contactBookManager else {
return false
}
return contactBookManager.remoteSync && contactBookManager.iCloudError != nil
}

var iCloudAvailableErrorObservable: Observable<Bool> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ Go to Settings - > Unstoppable and allow access to the camera.";
"backup.cloud.title" = "Backup to iCloud";
"backup.cloud.description" = "iCloud storage is a third-party cloud storage service provided by Apple. It's important to know that your data will be stored on Apple's servers, not on your personal devices. This means that you are entrusting your data and handing over the security of your information to a third-party service.";

"backup.cloud.terms.item.1" = "I understand that loosing access to my iCloud, will result in loosing access to the backup of a respective wallet.";
"backup.cloud.terms.item.1" = "I understand that losing access to my iCloud, will result in loosing access to the backup of a respective wallet.";

"backup.cloud.name.title" = "Backup Name";
"backup.cloud.name.description" = "Enter name for the backup file.";
Expand Down
10 changes: 10 additions & 0 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ XCCONFIG_DEV_TWITTER_BEARER_TOKEN = ENV["XCCONFIG_DEV_TWITTER_BEARER_TOKEN"]
XCCONFIG_DEV_HS_PROVIDER_API_KEY = ENV["XCCONFIG_DEV_HS_PROVIDER_API_KEY"]
XCCONFIG_DEV_WALLET_CONNECT_V2_PROJECT_KEY = ENV["XCCONFIG_DEV_WALLET_CONNECT_V2_PROJECT_KEY"]

XCCONFIG_DEV_SHARED_CLOUD_CONTAINER_ID = ENV["XCCONFIG_DEV_SHARED_CLOUD_CONTAINER_ID"]
XCCONFIG_DEV_PRIVATE_CLOUD_CONTAINER_ID = ENV["XCCONFIG_DEV_PRIVATE_CLOUD_CONTAINER_ID"]

XCCONFIG_PROD_INFURA_PROJECT_ID = ENV["XCCONFIG_PROD_INFURA_PROJECT_ID"]
XCCONFIG_PROD_INFURA_PROJECT_SECRET = ENV["XCCONFIG_PROD_INFURA_PROJECT_SECRET"]
XCCONFIG_PROD_ETHERSCAN_API_KEY = ENV["XCCONFIG_PROD_ETHERSCAN_API_KEY"]
Expand All @@ -43,6 +46,9 @@ XCCONFIG_PROD_TWITTER_BEARER_TOKEN = ENV["XCCONFIG_PROD_TWITTER_BEARER_TOKEN"]
XCCONFIG_PROD_HS_PROVIDER_API_KEY = ENV["XCCONFIG_PROD_HS_PROVIDER_API_KEY"]
XCCONFIG_PROD_WALLET_CONNECT_V2_PROJECT_KEY = ENV["XCCONFIG_PROD_WALLET_CONNECT_V2_PROJECT_KEY"]

XCCONFIG_PROD_SHARED_CLOUD_CONTAINER_ID = ENV["XCCONFIG_PROD_SHARED_CLOUD_CONTAINER_ID"]
XCCONFIG_PROD_PRIVATE_CLOUD_CONTAINER_ID = ENV["XCCONFIG_PROD_PRIVATE_CLOUD_CONTAINER_ID"]

def delete_temp_keychain(name)
delete_keychain(
name: name
Expand Down Expand Up @@ -114,6 +120,8 @@ def apply_dev_xcconfig
update_dev_xcconfig('twitter_bearer_token', XCCONFIG_DEV_TWITTER_BEARER_TOKEN)
update_dev_xcconfig('hs_provider_api_key', XCCONFIG_DEV_HS_PROVIDER_API_KEY)
update_dev_xcconfig('wallet_connect_v2_project_key', XCCONFIG_DEV_WALLET_CONNECT_V2_PROJECT_KEY)
update_dev_xcconfig('shared_cloud_container_id', XCCONFIG_DEV_SHARED_CLOUD_CONTAINER_ID)
update_dev_xcconfig('private_cloud_container_id', XCCONFIG_DEV_PRIVATE_CLOUD_CONTAINER_ID)
end

def apply_prod_xcconfig
Expand All @@ -131,6 +139,8 @@ def apply_prod_xcconfig
update_prod_xcconfig('twitter_bearer_token', XCCONFIG_PROD_TWITTER_BEARER_TOKEN)
update_prod_xcconfig('hs_provider_api_key', XCCONFIG_PROD_HS_PROVIDER_API_KEY)
update_prod_xcconfig('wallet_connect_v2_project_key', XCCONFIG_PROD_WALLET_CONNECT_V2_PROJECT_KEY)
update_prod_xcconfig('shared_cloud_container_id', XCCONFIG_PROD_SHARED_CLOUD_CONTAINER_ID)
update_prod_xcconfig('private_cloud_container_id', XCCONFIG_PROD_PRIVATE_CLOUD_CONTAINER_ID)
end

def force_update_devices(type, username)
Expand Down

0 comments on commit 2e91018

Please sign in to comment.