Skip to content

Commit

Permalink
IOS-3440 Add precheck for backup state
Browse files Browse the repository at this point in the history
  • Loading branch information
tureck1y committed Apr 18, 2023
1 parent 2d7c6ec commit cfd2ece
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
8 changes: 6 additions & 2 deletions TangemSdk/TangemSdk/Common/Core/TangemSdkError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ public enum TangemSdkError: Error, LocalizedError, Encodable {
case backupFailedIncompatibleBatch
case backupFailedIncompatibleFirmware
case backupFailedKeysImportSettings
case backupFailedAlreadyCreated

//MARK: Settings
case filesDisabled
Expand Down Expand Up @@ -398,6 +399,7 @@ public enum TangemSdkError: Error, LocalizedError, Encodable {
case .backupFailedIncompatibleBatch: return 41231
case .backupFailedIncompatibleFirmware: return 41232
case .backupFailedKeysImportSettings: return 41233
case .backupFailedAlreadyCreated: return 41234

case .resetPinNoCardToReset: return 41300
case .resetPinWrongCard(let internalCode): return internalCode ?? 41301
Expand Down Expand Up @@ -506,8 +508,10 @@ public enum TangemSdkError: Error, LocalizedError, Encodable {
case .issuerSignatureLoadingFailed: return "issuer_signature_loading_failed".localized
case .backupCardRequired, .backupCardAlreadyAdded: return "error_backup_card_already_added".localized
case .backupFailedNotEmptyWallets: return "error_backup_not_empty_wallets".localized
case .backupFailedWrongIssuer, .backupFailedHDWalletSettings, .backupFailedNotEnoughCurves, .backupFailedNotEnoughWallets,
.backupFailedFirmware, .backupNotAllowed, .backupFailedIncompatibleBatch, .backupFailedIncompatibleFirmware, .backupFailedKeysImportSettings:
case .backupFailedWrongIssuer, .backupFailedHDWalletSettings, .backupFailedNotEnoughCurves,
.backupFailedNotEnoughWallets, .backupFailedFirmware, .backupNotAllowed,
.backupFailedIncompatibleBatch, .backupFailedIncompatibleFirmware, .backupFailedKeysImportSettings,
.backupFailedAlreadyCreated:
return "error_backup_wrong_card".localized("\(self.code)")
case .resetPinWrongCard:
return "error_reset_wrong_card".localized("\(self.code)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ final class StartBackupCardLinkingCommand: Command {
if !card.settings.isBackupAllowed {
return .backupNotAllowed
}

if let backupStatus = card.backupStatus, backupStatus.isActive {
return .backupFailedAlreadyCreated
}

if !card.wallets.isEmpty {
return .backupFailedNotEmptyWallets
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public final class StartPrimaryCardLinkingCommand: Command {
if !card.settings.isBackupAllowed {
return .backupNotAllowed
}

if let backupStatus = card.backupStatus, backupStatus.isActive {
return .backupFailedAlreadyCreated
}

if card.wallets.isEmpty {
return .backupFailedEmptyWallets
Expand Down

0 comments on commit cfd2ece

Please sign in to comment.