Skip to content

Commit

Permalink
Add onError callback and log to sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
radeknovis committed Jan 4, 2024
1 parent 7bd44e9 commit 0fb0fae
Show file tree
Hide file tree
Showing 14 changed files with 201 additions and 46 deletions.
1 change: 1 addition & 0 deletions Sample/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.sentryclirc
40 changes: 40 additions & 0 deletions Sample/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
23F6FD03919B41DE98CAFCD3 /* Sentry in Frameworks */ = {isa = PBXBuildFile; productRef = BD206AA550964C49AE94A3CA /* Sentry */; };
CF0BCCE52AB0886400A2866C /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CF0BCCE42AB0886400A2866C /* ContentView.swift */; };
CF25F3A22B40C7070030B3DC /* Web3Modal in Frameworks */ = {isa = PBXBuildFile; productRef = CF25F3A12B40C7070030B3DC /* Web3Modal */; };
CF25F3A42B40C7070030B3DC /* Web3ModalUI in Frameworks */ = {isa = PBXBuildFile; productRef = CF25F3A32B40C7070030B3DC /* Web3ModalUI */; };
Expand All @@ -26,6 +27,7 @@
/* Begin PBXFileReference section */
CF0BCCE42AB0886400A2866C /* ContentView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
CF533D032ADD411A00B3441C /* web3modal-swift */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = "web3modal-swift"; path = ..; sourceTree = "<group>"; };
CF74C5C62B323048007B0926 /* swift-web3modal-Package.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = "swift-web3modal-Package.xctestplan"; sourceTree = "<group>"; };
CFA99B912AD0549F00EB5331 /* WCSocketFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WCSocketFactory.swift; sourceTree = "<group>"; };
CFA99B942AD054A600EB5331 /* secrets.sample.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = secrets.sample.json; sourceTree = "<group>"; };
CFA99B952AD054A600EB5331 /* Secrets.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Secrets.swift; sourceTree = "<group>"; };
Expand All @@ -49,6 +51,7 @@
CF25F3A42B40C7070030B3DC /* Web3ModalUI in Frameworks */,
CF3B9AD22ACDBA3A00984D53 /* Web3ModalUI in Frameworks */,
CF25F3A22B40C7070030B3DC /* Web3Modal in Frameworks */,
23F6FD03919B41DE98CAFCD3 /* Sentry in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -68,6 +71,7 @@
CFD7206B2A9CC60600636CAF = {
isa = PBXGroup;
children = (
CF74C5C62B323048007B0926 /* swift-web3modal-Package.xctestplan */,
CF533D032ADD411A00B3441C /* web3modal-swift */,
CFD720762A9CC60600636CAF /* Example */,
CFD720752A9CC60600636CAF /* Products */,
Expand Down Expand Up @@ -124,6 +128,7 @@
CFD720702A9CC60600636CAF /* Sources */,
CFD720712A9CC60600636CAF /* Frameworks */,
CFD720722A9CC60600636CAF /* Resources */,
E330D833155D4B53B676C733 /* Upload Debug Symbols to Sentry */,
);
buildRules = (
);
Expand All @@ -134,6 +139,7 @@
CF3B9ACF2ACDBA3A00984D53 /* Web3Modal */,
CF3B9AD12ACDBA3A00984D53 /* Web3ModalUI */,
CFD6A70E2ADE8DE2002B402C /* Atlantis */,
BD206AA550964C49AE94A3CA /* Sentry */,
CF25F3A12B40C7070030B3DC /* Web3Modal */,
CF25F3A32B40C7070030B3DC /* Web3ModalUI */,
);
Expand Down Expand Up @@ -168,6 +174,7 @@
packageReferences = (
CFD6A70D2ADE8DE2002B402C /* XCRemoteSwiftPackageReference "atlantis" */,
CF25F3A02B40C7070030B3DC /* XCLocalSwiftPackageReference ".." */,
F4A0329B6CFF49E682D3DFE7 /* XCRemoteSwiftPackageReference "sentry-cocoa" */,
);
productRefGroup = CFD720752A9CC60600636CAF /* Products */;
projectDirPath = "";
Expand All @@ -192,6 +199,24 @@
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
E330D833155D4B53B676C733 /* Upload Debug Symbols to Sentry */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${DWARF_DSYM_FOLDER_PATH}/${DWARF_DSYM_FILE_NAME}/Contents/Resources/DWARF/${TARGET_NAME}",
);
name = "Upload Debug Symbols to Sentry";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "# This script is responsable to upload debug symbols and source context for Sentry.\nif which sentry-cli >/dev/null; then\nexport SENTRY_ORG=walletconnect\nexport SENTRY_PROJECT=web3modal-sample\nERROR=$(sentry-cli debug-files upload --include-sources \"$DWARF_DSYM_FOLDER_PATH\" 2>&1 >/dev/null)\nif [ ! $? -eq 0 ]; then\necho \"warning: sentry-cli - $ERROR\"\nfi\nelse\necho \"warning: sentry-cli not installed, download from https://github.com/getsentry/sentry-cli/releases\"\nfi\n";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
CFD720702A9CC60600636CAF /* Sources */ = {
isa = PBXSourcesBuildPhase;
Expand Down Expand Up @@ -332,6 +357,7 @@
CODE_SIGN_ENTITLEMENTS = Example/Example.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 12;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_ASSET_PATHS = "\"Example/Preview Content\"";
DEVELOPMENT_TEAM = W5R8AG9K22;
ENABLE_HARDENED_RUNTIME = YES;
Expand Down Expand Up @@ -375,6 +401,7 @@
CODE_SIGN_ENTITLEMENTS = Example/Example.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 12;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_ASSET_PATHS = "\"Example/Preview Content\"";
DEVELOPMENT_TEAM = W5R8AG9K22;
ENABLE_HARDENED_RUNTIME = YES;
Expand Down Expand Up @@ -449,6 +476,14 @@
minimumVersion = 1.22.0;
};
};
F4A0329B6CFF49E682D3DFE7 /* XCRemoteSwiftPackageReference "sentry-cocoa" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/getsentry/sentry-cocoa/";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 8.0.0;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
Expand All @@ -460,6 +495,11 @@
isa = XCSwiftPackageProductDependency;
productName = Web3ModalUI;
};
BD206AA550964C49AE94A3CA /* Sentry */ = {
isa = XCSwiftPackageProductDependency;
package = F4A0329B6CFF49E682D3DFE7 /* XCRemoteSwiftPackageReference "sentry-cocoa" */;
productName = Sentry;
};
CF3B9ACF2ACDBA3A00984D53 /* Web3Modal */ = {
isa = XCSwiftPackageProductDependency;
productName = Web3Modal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
"version" : "14.3.1"
}
},
{
"identity" : "sentry-cocoa",
"kind" : "remoteSourceControl",
"location" : "https://github.com/getsentry/sentry-cocoa/",
"state" : {
"revision" : "74cf23b2946c92550fb1185612077151497e648e",
"version" : "8.17.1"
}
},
{
"identity" : "swift-qrcode-generator",
"kind" : "remoteSourceControl",
Expand Down
26 changes: 20 additions & 6 deletions Sample/Example/ExampleApp.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Sentry
import SwiftUI
import Web3Modal

import WalletConnectSign
import Web3Modal

#if DEBUG
import Atlantis
Expand All @@ -9,21 +11,31 @@ import Atlantis
@main
struct ExampleApp: App {
init() {

#if DEBUG
Atlantis.start()
#endif

let projectId = Secrets.load().projectID

// We're tracking Crash Reports / Issues from the Demo App to keep improving the SDK
SentrySDK.start { options in
options.dsn = "https://[email protected]/4506394479099904"
options.debug = false
options.enableTracing = true
}

SentrySDK.configureScope { scope in
scope.setContext(value: ["projectId": projectId], key: "Project")
}

let metadata = AppMetadata(
name: "Web3Modal Swift Dapp",
description: "Web3Modal DApp sample",
url: "wallet.connect",
icons: ["https://avatars.githubusercontent.com/u/37784886"],
redirect: .init(native: "w3mdapp://", universal: nil)
)

let projectId = Secrets.load().projectID


Networking.configure(
projectId: projectId,
socketFactory: WalletConnectSocketClientFactory()
Expand All @@ -32,7 +44,9 @@ struct ExampleApp: App {
Web3Modal.configure(
projectId: projectId,
metadata: metadata
)
) { error in
SentrySDK.capture(error: error)
}
}

var body: some Scene {
Expand Down
44 changes: 44 additions & 0 deletions Sample/swift-web3modal-Package.xctestplan
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"configurations" : [
{
"id" : "829C9690-2201-4591-80FD-185F8D8FD18F",
"name" : "Test Scheme Action",
"options" : {

}
}
],
"defaultOptions" : {
"codeCoverage" : {
"targets" : [
{
"containerPath" : "container:",
"identifier" : "Web3Modal",
"name" : "Web3Modal"
},
{
"containerPath" : "container:",
"identifier" : "Web3ModalUI",
"name" : "Web3ModalUI"
}
]
}
},
"testTargets" : [
{
"target" : {
"containerPath" : "container:",
"identifier" : "Web3ModalTests",
"name" : "Web3ModalTests"
}
},
{
"target" : {
"containerPath" : "container:",
"identifier" : "Web3ModalUITests",
"name" : "Web3ModalUITests"
}
}
],
"version" : 1
}
2 changes: 2 additions & 0 deletions Sources/Web3Modal/Components/AccountButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ public struct AccountButton: View {
try await blockchainApiInteractor.getIdentity()
} catch {
store.toast = .init(style: .error, message: "Network error")
Web3Modal.config.onError(error)
}
}
}
Expand All @@ -187,6 +188,7 @@ public struct AccountButton: View {
try await blockchainApiInteractor.getBalance()
} catch {
store.toast = .init(style: .error, message: "Network error")
Web3Modal.config.onError(error)
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions Sources/Web3Modal/Core/SignInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ class SignInteractor: ObservableObject {

do {
try await Web3Modal.instance.disconnect(topic: store.session?.topic ?? "")
try await Web3Modal.instance.cleanup()
try await createPairingAndConnect()
} catch {
DispatchQueue.main.async {
self.store.toast = .init(style: .error, message: "Failed to disconnect.")
Web3Modal.config.onError(error)
}
}
try await Web3Modal.instance.cleanup()
try await createPairingAndConnect()
}
}
11 changes: 5 additions & 6 deletions Sources/Web3Modal/Core/Web3Modal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class Web3Modal {
let includeWebWallets: Bool
let recommendedWalletIds: [String]
let excludedWalletIds: [String]
public let onError: (Error) -> Void
}

private(set) static var config: Config!
Expand All @@ -72,23 +73,21 @@ public class Web3Modal {
sessionParams: SessionParams = .default,
recommendedWalletIds: [String] = [],
excludedWalletIds: [String] = [],
includeWebWallets: Bool = true
includeWebWallets: Bool = true,
onError: @escaping (Error) -> Void = { _ in }
) {
Pair.configure(metadata: metadata)



Web3Modal.config = Web3Modal.Config(
projectId: projectId,
metadata: metadata,
sessionParams: sessionParams,
includeWebWallets: includeWebWallets,
recommendedWalletIds: recommendedWalletIds,
excludedWalletIds: excludedWalletIds
excludedWalletIds: excludedWalletIds,
onError: onError
)



let store = Store.shared
let router = Router()
let w3mApiInteractor = W3MAPIInteractor(store: store)
Expand Down
Loading

0 comments on commit 0fb0fae

Please sign in to comment.