Skip to content

Commit

Permalink
MOB-2042 - Added feature flags (#566)
Browse files Browse the repository at this point in the history
* Added isBuyCryptoEnabled feature flag

* Added isSendCryptoEnabled flag

* Added isMPCWalletEnabled feature flag

* Added isMPCSendCryptoEnabled feature flag

* Added isMPCMessagingEnabled feature flag

* Added isMPCWCNativeEnabled feature flag

* Added isMPCSignatureEnabled feature flag
  • Loading branch information
Oleg-Pecheneg authored May 27, 2024
1 parent 2bf7923 commit 9f820f6
Show file tree
Hide file tree
Showing 26 changed files with 194 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ final class AppContext: AppContextProtocol {

walletTransactionsService = WalletTransactionsService(networkService: NetworkService(),
cache: InMemoryWalletTransactionsCache())
mpcWalletsService = MPCWalletsService(udWalletsService: udWalletsService,
mpcWalletsService = MPCWalletsService(udWalletsService: udWalletsService,
udFeatureFlagsService: udFeatureFlagsService,
uiHandler: coreAppCoordinator)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,8 @@
C6A359332BB699FC00B1209A /* ConfirmSendTokenDataModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6A359312BB699FC00B1209A /* ConfirmSendTokenDataModel.swift */; };
C6A359352BB6BB2100B1209A /* TxHash.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6A359342BB6BB2000B1209A /* TxHash.swift */; };
C6A359362BB6BB2100B1209A /* TxHash.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6A359342BB6BB2000B1209A /* TxHash.swift */; };
C6A440092C0448530042FFCC /* UDFeatureFlagsServiceEnvironmentKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6A440082C0448530042FFCC /* UDFeatureFlagsServiceEnvironmentKey.swift */; };
C6A4400A2C0448530042FFCC /* UDFeatureFlagsServiceEnvironmentKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6A440082C0448530042FFCC /* UDFeatureFlagsServiceEnvironmentKey.swift */; };
C6A474C729D149560073415F /* LoginFlowNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6A474C629D149560073415F /* LoginFlowNavigationController.swift */; };
C6A474D029D150A40073415F /* NoParkedDomainsFoundViewPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6A474CD29D150A40073415F /* NoParkedDomainsFoundViewPresenter.swift */; };
C6A474D429D150A40073415F /* NoParkedDomainsFoundViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6A474CE29D150A40073415F /* NoParkedDomainsFoundViewController.swift */; };
Expand Down Expand Up @@ -3618,6 +3620,7 @@
C6A359292BB5586700B1209A /* NavigationTrackerViewModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationTrackerViewModifier.swift; sourceTree = "<group>"; };
C6A359312BB699FC00B1209A /* ConfirmSendTokenDataModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfirmSendTokenDataModel.swift; sourceTree = "<group>"; };
C6A359342BB6BB2000B1209A /* TxHash.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TxHash.swift; sourceTree = "<group>"; };
C6A440082C0448530042FFCC /* UDFeatureFlagsServiceEnvironmentKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UDFeatureFlagsServiceEnvironmentKey.swift; sourceTree = "<group>"; };
C6A474C629D149560073415F /* LoginFlowNavigationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginFlowNavigationController.swift; sourceTree = "<group>"; };
C6A474CD29D150A40073415F /* NoParkedDomainsFoundViewPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoParkedDomainsFoundViewPresenter.swift; sourceTree = "<group>"; };
C6A474CE29D150A40073415F /* NoParkedDomainsFoundViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoParkedDomainsFoundViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -4949,6 +4952,7 @@
C63095C72B0DA5DE00205054 /* PurchaseDomainsPreferencesStorageEnvironmentKey.swift */,
C617FD9D2B58DBCA00B93433 /* WalletsDataServiceEnvironmentKey.swift */,
C65CEB8A2B674FC700A13B34 /* UDWalletsServiceEnvironmentKey.swift */,
C6A440082C0448530042FFCC /* UDFeatureFlagsServiceEnvironmentKey.swift */,
);
path = EnvironmentKeys;
sourceTree = "<group>";
Expand Down Expand Up @@ -9752,6 +9756,7 @@
C671CD2B2BC6D5F3005DA2FB /* PreviewEcomPurchaseMPCWalletService.swift in Sources */,
C6B761DF2BB3D78F00773943 /* SerializedWalletTransaction.swift in Sources */,
C60DCEE2282D0C4000F71C13 /* ResizableRoundedWalletImageView.swift in Sources */,
C6A440092C0448530042FFCC /* UDFeatureFlagsServiceEnvironmentKey.swift in Sources */,
C61808822B19BC680032E543 /* TransactionError.swift in Sources */,
C6534A912BBFBA10008EEBB5 /* HomeExploreFollowersSectionView.swift in Sources */,
C6534AA92BBFBA10008EEBB5 /* HomeExploreSeparatorView.swift in Sources */,
Expand Down Expand Up @@ -9997,6 +10002,7 @@
C6C8F9912B218B0E00A9834D /* TextWhiteButton.swift in Sources */,
C6D646782B1ED12100D724AC /* RecordChangeType.swift in Sources */,
C6534AB02BBFBA10008EEBB5 /* HomeExploreSuggestedProfilesListView.swift in Sources */,
C6A4400A2C0448530042FFCC /* UDFeatureFlagsServiceEnvironmentKey.swift in Sources */,
C688C1802B845FE500BD233A /* ChatListUserRowView.swift in Sources */,
C6A231FD2BEB494D0037E093 /* WalletDetailsDomainItemView.swift in Sources */,
C6B761F12BB3F9D900773943 /* WalletTransactionsResponse.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ final class GeneralAppContext: AppContextProtocol {
let walletTransactionsService: WalletTransactionsServiceProtocol
let ecomPurchaseMPCWalletService: EcomPurchaseMPCWalletServiceProtocol
let mpcWalletsService: MPCWalletsServiceProtocol
let udFeatureFlagsService: UDFeatureFlagsServiceProtocol

private(set) lazy var coinRecordsService: CoinRecordsServiceProtocol = CoinRecordsService()
private(set) lazy var imageLoadingService: ImageLoadingServiceProtocol = ImageLoadingService(qrCodeService: qrCodeService,
Expand All @@ -56,7 +57,6 @@ final class GeneralAppContext: AppContextProtocol {
private(set) lazy var userDataService: UserDataServiceProtocol = UserDataService()
private(set) lazy var linkPresentationService: LinkPresentationServiceProtocol = LinkPresentationService()
private(set) lazy var domainTransferService: DomainTransferServiceProtocol = DomainTransferService()
private(set) lazy var udFeatureFlagsService: UDFeatureFlagsServiceProtocol = UDFeatureFlagsService()
private(set) lazy var hotFeatureSuggestionsService: HotFeatureSuggestionsServiceProtocol = HotFeatureSuggestionsService(fetcher: DefaultHotFeaturesSuggestionsFetcher())

init() {
Expand All @@ -65,6 +65,7 @@ final class GeneralAppContext: AppContextProtocol {
udDomainsService = UDDomainsService()
udWalletsService = UDWalletsService()
walletNFTsService = WalletNFTsService()
udFeatureFlagsService = UDFeatureFlagsService()
walletTransactionsService = WalletTransactionsService(networkService: NetworkService(),
cache: InMemoryWalletTransactionsCache())

Expand All @@ -77,7 +78,8 @@ final class GeneralAppContext: AppContextProtocol {
let coreAppCoordinator = CoreAppCoordinator(pullUpViewService: pullUpViewService)
self.coreAppCoordinator = coreAppCoordinator
walletConnectServiceV2.setUIHandler(coreAppCoordinator)
mpcWalletsService = MPCWalletsService(udWalletsService: udWalletsService,
mpcWalletsService = MPCWalletsService(udWalletsService: udWalletsService,
udFeatureFlagsService: udFeatureFlagsService,
uiHandler: coreAppCoordinator)

// Wallets data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ final class MockContext: AppContextProtocol {
private(set) lazy var walletTransactionsService: WalletTransactionsServiceProtocol = WalletTransactionsService(networkService: NetworkService(),
cache: InMemoryWalletTransactionsCache())
private(set) lazy var mpcWalletsService: MPCWalletsServiceProtocol = MPCWalletsService(udWalletsService: udWalletsService,
udFeatureFlagsService: udFeatureFlagsService,
uiHandler: coreAppCoordinator)
private(set) lazy var ecomPurchaseMPCWalletService: EcomPurchaseMPCWalletServiceProtocol = PreviewEcomPurchaseMPCWalletService()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// UDFeatureFlagsServiceEnvironmentKey.swift
// domains-manager-ios
//
// Created by Oleg Kuplin on 27.05.2024.
//

import SwiftUI

private struct UDFeatureFlagsServiceEnvironmentKey: EnvironmentKey {
static let defaultValue = appContext.udFeatureFlagsService
}

extension EnvironmentValues {
var udFeatureFlagsService: UDFeatureFlagsServiceProtocol {
get { self[UDFeatureFlagsServiceEnvironmentKey.self] }
set { self[UDFeatureFlagsServiceEnvironmentKey.self] = newValue }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ extension EnvironmentValues {
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ extension Error {
default: title = String.Constants.somethingWentWrong.localized()
message = String.Constants.pleaseTryAgain.localized()
}
} else if let mpcError = self as? MPCWalletError,
case .messageSignDisabled = mpcError {
title = String.Constants.mpcWalletSigningUnavailableErrorMessage.localizedMPCProduct()
message = String.Constants.tryAgainLater.localized()
} else {
title = String.Constants.somethingWentWrong.localized()
message = String.Constants.pleaseTryAgain.localized()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,8 @@ extension String {
static let reImportWallet = "RE_IMPORT_WALLET"
static let removeMPCWalletPullUpTitle = "REMOVE_MPC_WALLET_PULL_UP_TITLE"
static let removeMPCWalletPullUpSubtitle = "REMOVE_MPC_WALLET_PULL_UP_SUBTITLE"
static let mpcWalletMessagingUnavailableMessage = "MPC_WALLET_MESSAGING_UNAVAILABLE_MESSAGE"
static let mpcWalletSigningUnavailableErrorMessage = "MPC_WALLET_SIGNING_UNAVAILABLE_ERROR_MESSAGE"

// Send crypto first time
static let sendCryptoFirstTimePullUpTitle = "SEND_CRYPTO_FIRST_TIME_PULL_UP_TITLE"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,11 +495,14 @@ private extension DomainProfileViewPresenter {

let updatedChanges = updatedRequests.reduce([DomainProfileSectionChangeDescription](), { $0 + $1.changes })

func checkForApplePayErrorAndShowUpdateFailedPullUpFor(errors: [UpdateDomainProfileError],
requiredPullUp: ( ()async throws->())) async throws {
func checkForSpecialErrorAndShowUpdateFailedPullUpFor(errors: [UpdateDomainProfileError],
requiredPullUp: ( ()async throws->())) async throws {
let paymentsError = errors.compactMap({ $0.error as? PaymentError })
if let _ = paymentsError.first(where: { $0 == .applePayNotSupported }) {
if paymentsError.first(where: { $0 == .applePayNotSupported }) != nil {
appContext.pullUpViewService.showApplePayRequiredPullUp(in: view)
} else if let error = errors.compactMap({ $0.error as? MPCWalletError }).first(where: { $0 == .messageSignDisabled }) {
view.showAlertWith(error: error, handler: nil)
throw MPCWalletError.messageSignDisabled
} else {
try await requiredPullUp()
}
Expand Down Expand Up @@ -530,7 +533,7 @@ private extension DomainProfileViewPresenter {
await view.dismissPullUpMenu()

let numberOfFailedAttempts = dataHolder.numberOfFailedToUpdateProfileAttempts
try await checkForApplePayErrorAndShowUpdateFailedPullUpFor(errors: updateErrors, requiredPullUp: {
try await checkForSpecialErrorAndShowUpdateFailedPullUpFor(errors: updateErrors, requiredPullUp: {
if numberOfFailedAttempts >= 3 {
try await appContext.pullUpViewService.showTryUpdateDomainProfileLaterPullUp(in: view)
} else {
Expand Down Expand Up @@ -565,7 +568,7 @@ private extension DomainProfileViewPresenter {
let failedUIChanges = failedRequestsWithChanges.reduce([DomainProfileSectionChangeDescription](), { $0 + $1.changes }).map { $0.uiChange }
let failedUIChangeItems = failedUIChanges.map({ DomainProfileSectionUIChangeFailedItem(failedChangeType: $0) })

try await checkForApplePayErrorAndShowUpdateFailedPullUpFor(errors: updateErrors, requiredPullUp: {
try await checkForSpecialErrorAndShowUpdateFailedPullUpFor(errors: updateErrors, requiredPullUp: {
try await appContext.pullUpViewService.showUpdateDomainProfileSomeChangesFailedPullUp(in: view, changes: failedUIChangeItems)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import SwiftUI

struct SelectCryptoAssetToSendEmptyView: View {

@Environment(\.udFeatureFlagsService) var udFeatureFlagsService
var assetType: SendCryptoAsset.AssetType
let actionCallback: () -> Void

Expand Down Expand Up @@ -72,7 +73,7 @@ private extension SelectCryptoAssetToSendEmptyView {
@ViewBuilder
func actionButton() -> some View {
if case .tokens = assetType,
!Constants.isBuyCryptoEnabled {
!udFeatureFlagsService.valueFor(flag: .isBuyCryptoEnabled) {
EmptyView()
} else {
UDButtonView(text: actionButtonTitle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ struct HomeWalletView: View, ViewAnalyticsLogger {
// MARK: - Private methods
private extension HomeWalletView {
func walletActions() -> [WalletAction] {
[.buy, .send, .receive, .profile(enabled: viewModel.isProfileButtonEnabled)]
var actions: [WalletAction] = [.buy]
if viewModel.isSendCryptoEnabled {
actions.append(.send)
}
actions.append(contentsOf: [.receive, .profile(enabled: viewModel.isProfileButtonEnabled)])
return actions
}

func onAppear() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,21 @@ extension HomeWalletView {
private var cancellables: Set<AnyCancellable> = []
private var router: HomeTabRouter
private var lastVerifiedRecordsWalletAddress: String? = nil
var isWCSupported: Bool { selectedWallet.udWallet.type != .mpc }
var isWCSupported: Bool {
if selectedWallet.udWallet.type == .mpc {
return appContext.udFeatureFlagsService.valueFor(flag: .isMPCWCNativeEnabled)
}
return true
}
var isSendCryptoEnabled: Bool {
if appContext.udFeatureFlagsService.valueFor(flag: .isSendCryptoEnabled) == false {
return false
}
if selectedWallet.udWallet.type == .mpc {
return appContext.udFeatureFlagsService.valueFor(flag: .isMPCSendCryptoEnabled)
}
return true
}

init(selectedWallet: WalletEntity,
router: HomeTabRouter) {
Expand Down Expand Up @@ -84,7 +98,7 @@ extension HomeWalletView {
}))
}
case .buy:
if Constants.isBuyCryptoEnabled {
if appContext.udFeatureFlagsService.valueFor(flag: .isBuyCryptoEnabled) {
router.pullUp = .default(.homeWalletBuySelectionPullUp(selectionCallback: { [weak self] buyOption in
self?.router.pullUp = nil
self?.didSelectBuyOption(buyOption)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Foundation
enum MPCWalletError: String, LocalizedError {
case incorrectCode
case incorrectPassword
case messageSignDisabled

public var errorDescription: String? {
return rawValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ final class MPCWalletsService {
private var subServices = [MPCWalletProviderSubServiceProtocol]()

private let udWalletsService: UDWalletsServiceProtocol
private let udFeatureFlagsService: UDFeatureFlagsServiceProtocol
private let uiHandler: MPCWalletsUIHandler

init(udWalletsService: UDWalletsServiceProtocol,
udFeatureFlagsService: UDFeatureFlagsServiceProtocol,
uiHandler: MPCWalletsUIHandler) {
self.udWalletsService = udWalletsService
self.udFeatureFlagsService = udFeatureFlagsService
self.uiHandler = uiHandler
setup()
}
Expand Down Expand Up @@ -50,6 +53,7 @@ extension MPCWalletsService: MPCWalletsServiceProtocol {

func signMessage(_ messageString: String,
by walletMetadata: MPCWalletMetadata) async throws -> String {
guard udFeatureFlagsService.valueFor(flag: .isMPCSignatureEnabled) else { throw MPCWalletError.messageSignDisabled }
let subService = try getSubServiceFor(provider: walletMetadata.provider)

return try await subService.signMessage(messageString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private extension ReconnectMPCWalletPromptView {

@ViewBuilder
func subtitleText() -> some View {
Text(String.Constants.reImportMPCWalletPromptSubtitle.localized())
Text(String.Constants.reImportMPCWalletPromptSubtitle.localizedMPCProduct())
.textAttributes(color: .foregroundSecondary, fontSize: 16)
.multilineTextAlignment(.center)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,8 @@ extension ChatViewModel: UDFeatureFlagsListener {
setIfUserCanSendAttachments()
reloadCachedMessages()
}
default:
return
}
}
}
Expand Down
Loading

0 comments on commit 9f820f6

Please sign in to comment.