Skip to content

Commit

Permalink
[ETH-942] Terms&Conditions for referral program
Browse files Browse the repository at this point in the history
  • Loading branch information
Elizaveta Semenova committed Feb 9, 2024
1 parent 6e68416 commit 1d916c4
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
},
{
Expand Down
1 change: 1 addition & 0 deletions p2p_wallet/Resources/Base.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -609,3 +609,4 @@
"KeyApp swap fee" = "KeyApp swap fee";
"Referral reward" = "Referral reward";
"Open SOLScan" = "Open SOLScan";
"Terms & Conditions" = "Terms & Conditions";
1 change: 1 addition & 0 deletions p2p_wallet/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -597,3 +597,4 @@
"KeyApp swap fee" = "KeyApp swap fee";
"Referral reward" = "Referral reward";
"Open SOLScan" = "Open SOLScan";
"Terms & Conditions" = "Terms & Conditions";
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ enum ReferralBridgeMethod: String {
case nativeLog
case signMessage
case getUserPublicKey
case openTermsUrl
}

enum ReferralBridgeError: String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import WebKit

protocol ReferralBridge {
var sharePublisher: AnyPublisher<String, Never> { get }
var openTermsUrl: AnyPublisher<URL, Never> { get }
}

final class ReferralJSBridge: NSObject, ReferralBridge {
var sharePublisher: AnyPublisher<String, Never> { shareSubject.eraseToAnyPublisher() }
var openTermsUrl: AnyPublisher<URL, Never> { openTermsUrlSubject.eraseToAnyPublisher() }

// MARK: - Dependencies

Expand All @@ -21,6 +23,7 @@ final class ReferralJSBridge: NSObject, ReferralBridge {
// MARK: - Properties

private let shareSubject = PassthroughSubject<String, Never>()
private let openTermsUrlSubject = PassthroughSubject<URL, Never>()
private var subscriptions: [AnyCancellable] = []
private weak var webView: WKWebView?

Expand Down Expand Up @@ -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)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ final class ReferralProgramCoordinator: Coordinator<Void> {
}
.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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ final class ReferralProgramViewModel: BaseViewModel, ObservableObject {
let webView: WKWebView

let openShare = PassthroughSubject<String, Never>()
let openTerms = PassthroughSubject<URL, Never>()

override init() {
let wkWebView = ReferralProgramViewModel.buildWebView()
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Combine
import SwiftUI
import UIKit

final class TermsAndConditionsCoordinator: Coordinator<Void> {
private let navigationController: UINavigationController
private let result = PassthroughSubject<Void, Never>()
private let url: URL

init(navigationController: UINavigationController, url: URL) {
self.navigationController = navigationController
self.url = url
}

override func start() -> AnyPublisher<Void, Never> {
let view = TermsAndConditionsView(url: url)
let vc = UIHostingController(rootView: view)
navigationController.pushViewController(vc, animated: true)
return result.eraseToAnyPublisher()
}
}
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 1d916c4

Please sign in to comment.