From 1d916c47a3dcdec1d1183d83437059a2585aacd8 Mon Sep 17 00:00:00 2001 From: Elizaveta Semenova Date: Fri, 9 Feb 2024 17:18:59 +0300 Subject: [PATCH] [ETH-942] Terms&Conditions for referral program --- .../xcshareddata/swiftpm/Package.resolved | 4 ++-- .../Resources/Base.lproj/Localizable.strings | 1 + .../Resources/en.lproj/Localizable.strings | 1 + .../Details/Bridge/BridgeModels.swift | 1 + .../Details/Bridge/ReferralBridge.js | 3 +++ .../Details/Bridge/ReferralJSBridge.swift | 10 +++++++++ .../Details/ReferralProgramCoordinator.swift | 8 +++++++ .../Details/ReferralProgramViewModel.swift | 7 ++++++ .../TermsAndConditionsCoordinator.swift | 21 ++++++++++++++++++ .../TermsAndConditionsView.swift | 22 +++++++++++++++++++ 10 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 p2p_wallet/Scenes/Main/ReferralProgram/Details/TermsAndConditions/TermsAndConditionsCoordinator.swift create mode 100644 p2p_wallet/Scenes/Main/ReferralProgram/Details/TermsAndConditions/TermsAndConditionsView.swift diff --git a/p2p_wallet.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/p2p_wallet.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index f33fb6855..0b06043ec 100644 --- a/p2p_wallet.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/p2p_wallet.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -230,8 +230,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/marmelroy/PhoneNumberKit.git", "state" : { - "revision" : "d2886b0735a47e47fb227504666756efb2e2ac26", - "version" : "3.7.6" + "revision" : "7268078304df2f4e07ac864b5ba27ae4c1e6f4a6", + "version" : "3.7.7" } }, { diff --git a/p2p_wallet/Resources/Base.lproj/Localizable.strings b/p2p_wallet/Resources/Base.lproj/Localizable.strings index 37fe73d5c..7a6830ff9 100644 --- a/p2p_wallet/Resources/Base.lproj/Localizable.strings +++ b/p2p_wallet/Resources/Base.lproj/Localizable.strings @@ -609,3 +609,4 @@ "KeyApp swap fee" = "KeyApp swap fee"; "Referral reward" = "Referral reward"; "Open SOLScan" = "Open SOLScan"; +"Terms & Conditions" = "Terms & Conditions"; diff --git a/p2p_wallet/Resources/en.lproj/Localizable.strings b/p2p_wallet/Resources/en.lproj/Localizable.strings index fd51845ee..9a8ea0953 100644 --- a/p2p_wallet/Resources/en.lproj/Localizable.strings +++ b/p2p_wallet/Resources/en.lproj/Localizable.strings @@ -597,3 +597,4 @@ "KeyApp swap fee" = "KeyApp swap fee"; "Referral reward" = "Referral reward"; "Open SOLScan" = "Open SOLScan"; +"Terms & Conditions" = "Terms & Conditions"; diff --git a/p2p_wallet/Scenes/Main/ReferralProgram/Details/Bridge/BridgeModels.swift b/p2p_wallet/Scenes/Main/ReferralProgram/Details/Bridge/BridgeModels.swift index 1a1745538..f88820b65 100644 --- a/p2p_wallet/Scenes/Main/ReferralProgram/Details/Bridge/BridgeModels.swift +++ b/p2p_wallet/Scenes/Main/ReferralProgram/Details/Bridge/BridgeModels.swift @@ -3,6 +3,7 @@ enum ReferralBridgeMethod: String { case nativeLog case signMessage case getUserPublicKey + case openTermsUrl } enum ReferralBridgeError: String { diff --git a/p2p_wallet/Scenes/Main/ReferralProgram/Details/Bridge/ReferralBridge.js b/p2p_wallet/Scenes/Main/ReferralProgram/Details/Bridge/ReferralBridge.js index 3b64088da..dd7bdee14 100644 --- a/p2p_wallet/Scenes/Main/ReferralProgram/Details/Bridge/ReferralBridge.js +++ b/p2p_wallet/Scenes/Main/ReferralProgram/Details/Bridge/ReferralBridge.js @@ -31,5 +31,8 @@ window.ReferralBridge = { signMessageAsync: async function(message) { const result = await handleRequest({ method: "signMessage", message: message }); return result + }, + openTermsUrl: function(link) { + handleRequest({ method: "openTermsUrl", link: link }); } } diff --git a/p2p_wallet/Scenes/Main/ReferralProgram/Details/Bridge/ReferralJSBridge.swift b/p2p_wallet/Scenes/Main/ReferralProgram/Details/Bridge/ReferralJSBridge.swift index a5077674b..8c2fcbf92 100644 --- a/p2p_wallet/Scenes/Main/ReferralProgram/Details/Bridge/ReferralJSBridge.swift +++ b/p2p_wallet/Scenes/Main/ReferralProgram/Details/Bridge/ReferralJSBridge.swift @@ -8,10 +8,12 @@ import WebKit protocol ReferralBridge { var sharePublisher: AnyPublisher { get } + var openTermsUrl: AnyPublisher { get } } final class ReferralJSBridge: NSObject, ReferralBridge { var sharePublisher: AnyPublisher { shareSubject.eraseToAnyPublisher() } + var openTermsUrl: AnyPublisher { openTermsUrlSubject.eraseToAnyPublisher() } // MARK: - Dependencies @@ -21,6 +23,7 @@ final class ReferralJSBridge: NSObject, ReferralBridge { // MARK: - Properties private let shareSubject = PassthroughSubject() + private let openTermsUrlSubject = PassthroughSubject() private var subscriptions: [AnyCancellable] = [] private weak var webView: WKWebView? @@ -133,6 +136,13 @@ extension ReferralJSBridge: WKScriptMessageHandlerWithReply { case .getUserPublicKey: handler(user.account.publicKey.base58EncodedString, nil) + case .openTermsUrl: + if let link = dict["link"] as? String, let url = URL(string: link) { + openTermsUrlSubject.send(url) + handler(link, nil) + } else { + handler(nil, .emptyLink) + } } } } diff --git a/p2p_wallet/Scenes/Main/ReferralProgram/Details/ReferralProgramCoordinator.swift b/p2p_wallet/Scenes/Main/ReferralProgram/Details/ReferralProgramCoordinator.swift index 3625e3bed..34e6a0390 100644 --- a/p2p_wallet/Scenes/Main/ReferralProgram/Details/ReferralProgramCoordinator.swift +++ b/p2p_wallet/Scenes/Main/ReferralProgram/Details/ReferralProgramCoordinator.swift @@ -27,6 +27,14 @@ final class ReferralProgramCoordinator: Coordinator { } .store(in: &subscriptions) + viewModel.openTerms + .sink { [weak self] url in + guard let self else { return } + coordinate(to: TermsAndConditionsCoordinator(navigationController: self.navigationController, url: url)) + .sink(receiveValue: {}).store(in: &self.subscriptions) + } + .store(in: &subscriptions) + return result.eraseToAnyPublisher() } } diff --git a/p2p_wallet/Scenes/Main/ReferralProgram/Details/ReferralProgramViewModel.swift b/p2p_wallet/Scenes/Main/ReferralProgram/Details/ReferralProgramViewModel.swift index 9d8f6d9c0..22644c4d0 100644 --- a/p2p_wallet/Scenes/Main/ReferralProgram/Details/ReferralProgramViewModel.swift +++ b/p2p_wallet/Scenes/Main/ReferralProgram/Details/ReferralProgramViewModel.swift @@ -12,6 +12,7 @@ final class ReferralProgramViewModel: BaseViewModel, ObservableObject { let webView: WKWebView let openShare = PassthroughSubject() + let openTerms = PassthroughSubject() override init() { let wkWebView = ReferralProgramViewModel.buildWebView() @@ -27,6 +28,12 @@ final class ReferralProgramViewModel: BaseViewModel, ObservableObject { self?.openShare.send(value) }) .store(in: &subscriptions) + + bridge.openTermsUrl + .sink(receiveValue: { [weak self] value in + self?.openTerms.send(value) + }) + .store(in: &subscriptions) } private static func buildWebView() -> WKWebView { diff --git a/p2p_wallet/Scenes/Main/ReferralProgram/Details/TermsAndConditions/TermsAndConditionsCoordinator.swift b/p2p_wallet/Scenes/Main/ReferralProgram/Details/TermsAndConditions/TermsAndConditionsCoordinator.swift new file mode 100644 index 000000000..da0da3423 --- /dev/null +++ b/p2p_wallet/Scenes/Main/ReferralProgram/Details/TermsAndConditions/TermsAndConditionsCoordinator.swift @@ -0,0 +1,21 @@ +import Combine +import SwiftUI +import UIKit + +final class TermsAndConditionsCoordinator: Coordinator { + private let navigationController: UINavigationController + private let result = PassthroughSubject() + private let url: URL + + init(navigationController: UINavigationController, url: URL) { + self.navigationController = navigationController + self.url = url + } + + override func start() -> AnyPublisher { + let view = TermsAndConditionsView(url: url) + let vc = UIHostingController(rootView: view) + navigationController.pushViewController(vc, animated: true) + return result.eraseToAnyPublisher() + } +} diff --git a/p2p_wallet/Scenes/Main/ReferralProgram/Details/TermsAndConditions/TermsAndConditionsView.swift b/p2p_wallet/Scenes/Main/ReferralProgram/Details/TermsAndConditions/TermsAndConditionsView.swift new file mode 100644 index 000000000..8087e60db --- /dev/null +++ b/p2p_wallet/Scenes/Main/ReferralProgram/Details/TermsAndConditions/TermsAndConditionsView.swift @@ -0,0 +1,22 @@ +import Foundation +import SwiftUI +import WebKit + +struct TermsAndConditionsView: View { + private let url: URL + init(url: URL) { + self.url = url + } + + var body: some View { + ColoredBackground( + { + ReferralWebView(webView: WKWebView(), link: url) + .ignoresSafeArea(edges: .bottom) + }, + color: Color(uiColor: UIColor(resource: .f2F5Fa)) + ) + .navigationTitle(L10n.termsConditions) + .navigationBarTitleDisplayMode(.inline) + } +}