Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dapp mixpanel #1371

Merged
merged 2 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions Example/DApp/Common/InputConfig.swift

This file was deleted.

2 changes: 2 additions & 0 deletions Example/DApp/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>MIXPANEL_TOKEN</key>
<string>$(MIXPANEL_TOKEN)</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
Expand Down
5 changes: 5 additions & 0 deletions Example/DApp/Modules/Configuration/ConfigPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ final class ConfigPresenter: ObservableObject, SceneViewModel {

private let router: ConfigRouter

var clientId: String {
guard let clientId = try? Networking.interactor.getClientId() else { return .empty }
return clientId
}

init(
router: ConfigRouter
) {
Expand Down
81 changes: 69 additions & 12 deletions Example/DApp/Modules/Configuration/ConfigView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import SwiftUI

struct ConfigView: View {
@EnvironmentObject var presenter: ConfigPresenter
@State private var copyAlert: Bool = false
@State private var cacheCleanAlert: Bool = false

var body: some View {
NavigationStack {
Expand All @@ -10,22 +12,71 @@ struct ConfigView: View {
.ignoresSafeArea()

ScrollView {
VStack {
Button {
VStack(spacing: 12) {
// Clean Cache Button
Button(action: {
presenter.cleanLinkModeSupportedWalletsCache()
} label: {
HStack {
Spacer()
Text("Clean Link Mode Supported Wallets Cache")
.font(.system(size: 16, weight: .semibold))
.foregroundColor(.white)
.padding(.vertical, 25)
Spacer()
cacheCleanAlert = true
}) {
VStack(alignment: .leading, spacing: 4) {
HStack(spacing: 6) {
Text("Clean Cache")
.multilineTextAlignment(.leading)
.foregroundColor(.white)
.font(.system(size: 16, weight: .semibold))

Image(systemName: "trash")
.foregroundColor(.white)

Spacer()
}
.padding(.horizontal, 12)
.padding(.top, 16)

Text("Clean link mode supported wallets cache")
.multilineTextAlignment(.leading)
.foregroundColor(.white.opacity(0.7))
.font(.system(size: 14))
.padding(.horizontal, 12)
.padding(.bottom, 16)
}
.background(Color(red: 95/255, green: 159/255, blue: 248/255))
.cornerRadius(16)
.background(Color(red: 95/255, green: 159/255, blue: 248/255).opacity(0.2).cornerRadius(12))
}
.frame(maxWidth: .infinity)
.padding(.horizontal, 12)
.padding(.top, 10)

// Client ID Row
Button(action: {
UIPasteboard.general.string = presenter.clientId
copyAlert = true
}) {
VStack(alignment: .leading, spacing: 4) {
HStack(spacing: 6) {
Text("Client ID")
.multilineTextAlignment(.leading)
.foregroundColor(.white)
.font(.system(size: 16, weight: .semibold))

Image(systemName: "doc.on.doc")
.foregroundColor(.white)

Spacer()
}
.padding(.horizontal, 12)
.padding(.top, 16)

Text(presenter.clientId)
.multilineTextAlignment(.leading)
.foregroundColor(.white.opacity(0.7))
.font(.system(size: 14))
.padding(.horizontal, 12)
.padding(.bottom, 16)
}
.background(Color(red: 95/255, green: 159/255, blue: 248/255).opacity(0.2).cornerRadius(12))
}
.frame(maxWidth: .infinity)
.padding(.horizontal, 12)
}
.padding(12)
}
Expand All @@ -43,6 +94,12 @@ struct ConfigView: View {
for: .navigationBar
)
}
.alert("Cache cleaned successfully", isPresented: $cacheCleanAlert) {
Button("OK", role: .cancel) { }
}
.alert("Client ID copied to clipboard", isPresented: $copyAlert) {
Button("OK", role: .cancel) { }
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion Example/DApp/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
projectId: InputConfig.projectId,
socketFactory: DefaultSocketFactory()
)
Sign.configure(crypto: DefaultCryptoProvider())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is was this removed?


let metadata = AppMetadata(
name: "Swift Dapp",
Expand All @@ -58,6 +57,10 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
)
]
)

if let clientId = try? Networking.interactor.getClientId() {
ProfilingService.instance.setUpProfiling(account: "swift_dapp_\(clientId)", clientId: clientId)
}

Web3Modal.instance.authResponsePublisher.sink { (id, result) in
switch result {
Expand Down
18 changes: 8 additions & 10 deletions Example/ExampleApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
846E35A42C0065B600E63DF4 /* ConfigPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 846E35A32C0065B600E63DF4 /* ConfigPresenter.swift */; };
846E35A62C0065C100E63DF4 /* ConfigView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 846E35A52C0065C100E63DF4 /* ConfigView.swift */; };
846E35A82C006C5600E63DF4 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 846E35A72C006C5600E63DF4 /* Constants.swift */; };
84733CD32C1C2A4B001B2850 /* AlertPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84AEC2502B4D42C100E27A5B /* AlertPresenter.swift */; };
84733CD42C1C2C24001B2850 /* ProfilingService.swift in Sources */ = {isa = PBXBuildFile; fileRef = A50B6A372B06697B00162B01 /* ProfilingService.swift */; };
84733CD52C1C2CEB001B2850 /* InputConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = C56EE25D293F56D6004840D1 /* InputConfig.swift */; };
847BD1D62989492500076C90 /* MainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847BD1D12989492500076C90 /* MainViewController.swift */; };
847BD1D82989492500076C90 /* MainModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847BD1D32989492500076C90 /* MainModule.swift */; };
847BD1D92989492500076C90 /* MainPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847BD1D42989492500076C90 /* MainPresenter.swift */; };
Expand All @@ -36,7 +39,6 @@
847BD1E8298A806800076C90 /* NotificationsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847BD1E3298A806800076C90 /* NotificationsView.swift */; };
847BD1EB298A87AB00076C90 /* SubscriptionsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847BD1EA298A87AB00076C90 /* SubscriptionsViewModel.swift */; };
847F08012A25DBFF00B2A5A4 /* XPlatformW3WTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847F08002A25DBFF00B2A5A4 /* XPlatformW3WTests.swift */; };
8486EDD12B4F2DC1008E53C3 /* AlertPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8486EDD02B4F2DC1008E53C3 /* AlertPresenter.swift */; };
8486EDD32B4F2EA6008E53C3 /* SwiftMessages in Frameworks */ = {isa = PBXBuildFile; productRef = 8486EDD22B4F2EA6008E53C3 /* SwiftMessages */; };
8487A9442A836C2A0003D5AF /* Sentry in Frameworks */ = {isa = PBXBuildFile; productRef = 8487A9432A836C2A0003D5AF /* Sentry */; };
8487A9462A836C3F0003D5AF /* Sentry in Frameworks */ = {isa = PBXBuildFile; productRef = 8487A9452A836C3F0003D5AF /* Sentry */; };
Expand Down Expand Up @@ -87,7 +89,6 @@
A518A98829683FB60035247E /* Web3InboxModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = A518A98529683FB60035247E /* Web3InboxModule.swift */; };
A518A98929683FB60035247E /* Web3InboxRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = A518A98629683FB60035247E /* Web3InboxRouter.swift */; };
A518B31428E33A6500A2CE93 /* InputConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = A518B31328E33A6500A2CE93 /* InputConfig.swift */; };
A51AC0D928E436A3001BACF9 /* InputConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = A51AC0D828E436A3001BACF9 /* InputConfig.swift */; };
A51AC0DF28E4379F001BACF9 /* InputConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = A51AC0DE28E4379F001BACF9 /* InputConfig.swift */; };
A5417BBE299BFC3E00B469F3 /* ImportAccount.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5417BBD299BFC3E00B469F3 /* ImportAccount.swift */; };
A541959E2934BFEF0035AD19 /* CacaoSignerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A541959A2934BFEF0035AD19 /* CacaoSignerTests.swift */; };
Expand Down Expand Up @@ -419,7 +420,6 @@
847BD1E3298A806800076C90 /* NotificationsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationsView.swift; sourceTree = "<group>"; };
847BD1EA298A87AB00076C90 /* SubscriptionsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubscriptionsViewModel.swift; sourceTree = "<group>"; };
847F08002A25DBFF00B2A5A4 /* XPlatformW3WTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XPlatformW3WTests.swift; sourceTree = "<group>"; };
8486EDD02B4F2DC1008E53C3 /* AlertPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertPresenter.swift; sourceTree = "<group>"; };
8487A92E2A7BD2F30003D5AF /* XPlatformProtocolTests.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; name = XPlatformProtocolTests.xctestplan; path = ../XPlatformProtocolTests.xctestplan; sourceTree = "<group>"; };
8487A9472A83AD680003D5AF /* LoggingService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoggingService.swift; sourceTree = "<group>"; };
849A4F18298281E300E61ACE /* WalletAppRelease.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = WalletAppRelease.entitlements; sourceTree = "<group>"; };
Expand Down Expand Up @@ -470,7 +470,6 @@
A518A98529683FB60035247E /* Web3InboxModule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Web3InboxModule.swift; sourceTree = "<group>"; };
A518A98629683FB60035247E /* Web3InboxRouter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Web3InboxRouter.swift; sourceTree = "<group>"; };
A518B31328E33A6500A2CE93 /* InputConfig.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InputConfig.swift; sourceTree = "<group>"; };
A51AC0D828E436A3001BACF9 /* InputConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputConfig.swift; sourceTree = "<group>"; };
A51AC0DE28E4379F001BACF9 /* InputConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputConfig.swift; sourceTree = "<group>"; };
A5417BBD299BFC3E00B469F3 /* ImportAccount.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImportAccount.swift; sourceTree = "<group>"; };
A541959A2934BFEF0035AD19 /* CacaoSignerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CacaoSignerTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1380,6 +1379,8 @@
84CB43D429B9FC88004DDA31 /* Tests */,
A5629AEF2877F73000094373 /* DefaultSocketFactory.swift */,
A59CF4F5292F83D50031A42F /* DefaultSignerFactory.swift */,
A50B6A372B06697B00162B01 /* ProfilingService.swift */,
84AEC2502B4D42C100E27A5B /* AlertPresenter.swift */,
A5A0843B29D2F60A000B9B17 /* DefaultCryptoProvider.swift */,
A51606F72A2F47BD00CACB92 /* DefaultBIP44Provider.swift */,
A5417BBD299BFC3E00B469F3 /* ImportAccount.swift */,
Expand All @@ -1392,10 +1393,8 @@
A5BB7FAB28B6AA7100707FC6 /* Common */ = {
isa = PBXGroup;
children = (
A51AC0D828E436A3001BACF9 /* InputConfig.swift */,
A5BB7FAC28B6AA7D00707FC6 /* QRCodeGenerator.swift */,
84D093EA2B4EA6CB005B1925 /* ActivityIndicatorManager.swift */,
8486EDD02B4F2DC1008E53C3 /* AlertPresenter.swift */,
);
path = Common;
sourceTree = "<group>";
Expand Down Expand Up @@ -1630,7 +1629,6 @@
C56EE262293F56D6004840D1 /* Extensions */,
C56EE263293F56D6004840D1 /* VIPER */,
84AEC24E2B4D1EE400E27A5B /* ActivityIndicatorManager.swift */,
84AEC2502B4D42C100E27A5B /* AlertPresenter.swift */,
);
path = Common;
sourceTree = "<group>";
Expand Down Expand Up @@ -1688,7 +1686,6 @@
C56EE280293F5757004840D1 /* Application.swift */,
C56EE27F293F5757004840D1 /* AppDelegate.swift */,
C56EE281293F5757004840D1 /* SceneDelegate.swift */,
A50B6A372B06697B00162B01 /* ProfilingService.swift */,
84DB38F22983CDAE00BFEE37 /* PushRegisterer.swift */,
A51811972A52E21A00A52B15 /* ConfigurationService.swift */,
8487A9472A83AD680003D5AF /* LoggingService.swift */,
Expand Down Expand Up @@ -2249,6 +2246,9 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
84733CD52C1C2CEB001B2850 /* InputConfig.swift in Sources */,
84733CD42C1C2C24001B2850 /* ProfilingService.swift in Sources */,
84733CD32C1C2A4B001B2850 /* AlertPresenter.swift in Sources */,
C5BE021C2AF79B9A0064FC88 /* SessionAccountRouter.swift in Sources */,
C5B4C4C42AF11C8B00B4274A /* SignView.swift in Sources */,
C5BE02042AF7764F0064FC88 /* UIViewController.swift in Sources */,
Expand All @@ -2262,7 +2262,6 @@
846E359F2C00654F00E63DF4 /* ConfigModule.swift in Sources */,
C5BE01E52AF697470064FC88 /* Color.swift in Sources */,
A5BB7FAD28B6AA7D00707FC6 /* QRCodeGenerator.swift in Sources */,
A51AC0D928E436A3001BACF9 /* InputConfig.swift in Sources */,
C5BE01E22AF693080064FC88 /* Application.swift in Sources */,
C5BE021B2AF79B9A0064FC88 /* SessionAccountPresenter.swift in Sources */,
A5A8E47E293A1CFE00FEB97D /* DefaultSignerFactory.swift in Sources */,
Expand All @@ -2273,7 +2272,6 @@
C5BE02012AF774CB0064FC88 /* NewPairingModule.swift in Sources */,
C5BE02002AF774CB0064FC88 /* NewPairingRouter.swift in Sources */,
C5BE01F82AF6CB270064FC88 /* SignInteractor.swift in Sources */,
8486EDD12B4F2DC1008E53C3 /* AlertPresenter.swift in Sources */,
C5BE01D12AF661D70064FC88 /* NewPairingView.swift in Sources */,
846E35A42C0065B600E63DF4 /* ConfigPresenter.swift in Sources */,
84CE642127981DED00142511 /* SceneDelegate.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation
import Mixpanel
import WalletConnectNetworking
import Combine
import Web3Wallet
import WalletConnectSign
import WalletConnectNotify

final class ProfilingService {
Expand Down Expand Up @@ -33,10 +33,7 @@ final class ProfilingService {
mixpanel.people.set(properties: ["$name": account, "account": account])

handleLogs(from: Networking.instance.logsPublisher)
handleLogs(from: Notify.instance.logsPublisher)
handleLogs(from: Push.instance.logsPublisher)
handleLogs(from: Web3Wallet.instance.logsPublisher)

Comment on lines -36 to -39
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we removing all these?

handleLogs(from: Sign.instance.logsPublisher)
}

private func handleLogs(from publisher: AnyPublisher<Log, Never>) {
Expand Down
35 changes: 0 additions & 35 deletions Example/WalletApp/Common/AlertPresenter.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,18 @@ final class LinkEnvelopesDispatcher {
}

func dispatchEnvelope(_ envelope: String) throws {
logger.debug("will dispatch an envelope: \(envelope)")
guard let envelopeURL = URL(string: envelope),
let components = URLComponents(url: envelopeURL, resolvingAgainstBaseURL: true) else {
throw Errors.invalidURL
}

guard let wcEnvelope = components.queryItems?.first(where: { $0.name == "wc_ev" })?.value else {
logger.error(Errors.envelopeNotFound.localizedDescription)
throw Errors.envelopeNotFound
}
guard let topic = components.queryItems?.first(where: { $0.name == "topic" })?.value else {
logger.error(Errors.topicNotFound.localizedDescription)
throw Errors.topicNotFound
}
manageEnvelope(topic, wcEnvelope)
Expand Down Expand Up @@ -159,19 +162,21 @@ final class LinkEnvelopesDispatcher {

private func handleRequest(topic: String, request: RPCRequest) {
do {
logger.debug("handling link mode request")
try rpcHistory.set(request, forTopic: topic, emmitedBy: .remote, transportType: .linkMode)
requestPublisherSubject.send((topic, request))
} catch {
logger.debug(error)
logger.debug("Handling link mode request failed: \(error)")
}
}

private func handleResponse(topic: String, response: RPCResponse) {
do {
logger.debug("handling link mode response")
let record = try rpcHistory.resolve(response)
responsePublisherSubject.send((topic, record.request, response))
} catch {
logger.debug("Handle json rpc response error: \(error)")
logger.debug("Handling link mode response failed: \(error)")
}
}
}
Loading