Skip to content

Commit

Permalink
Merge pull request #3 from reown-com/monorepo
Browse files Browse the repository at this point in the history
Monorepo
  • Loading branch information
llbartekll authored Sep 9, 2024
2 parents e5f419c + a07eec1 commit f44669a
Show file tree
Hide file tree
Showing 39 changed files with 869 additions and 226 deletions.
35 changes: 35 additions & 0 deletions Example/AppKitLab/AlertPresenter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import Foundation
import SwiftMessages
import UIKit

struct AlertPresenter {
enum MessageType {
case warning
case error
case info
case success
}

static func present(message: String, type: AlertPresenter.MessageType) {
DispatchQueue.main.async {
let view = MessageView.viewFromNib(layout: .cardView)
switch type {
case .warning:
view.configureTheme(.warning, iconStyle: .subtle)
case .error:
view.configureTheme(.error, iconStyle: .subtle)
case .info:
view.configureTheme(.info, iconStyle: .subtle)
case .success:
view.configureTheme(.success, iconStyle: .subtle)
}
view.button?.isHidden = true
view.layoutMarginAdditions = UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20)
view.configureContent(title: "", body: message)
var config = SwiftMessages.Config()
config.presentationStyle = .top
config.duration = .seconds(seconds: 1.5)
SwiftMessages.show(config: config, view: view)
}
}
}
14 changes: 14 additions & 0 deletions Example/AppKitLab/AppKitLab.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-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>com.apple.developer.associated-domains</key>
<array>
<string>applinks:lab.web3modal.com</string>
</array>
<key>com.apple.security.application-groups</key>
<array>
<string>group.com.walletconnect.web3modal</string>
</array>
</dict>
</plist>
171 changes: 171 additions & 0 deletions Example/AppKitLab/AppKitLabApp.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
import Combine
//import Sentry
import SwiftUI
import UIKit
import WalletConnectSign
import ReownAppKit

#if DEBUG
import Atlantis
#endif


class SocketConnectionManager: ObservableObject {
@Published var socketConnected: Bool = false
}

@main
class AppKitLabApp: App {
private var disposeBag = Set<AnyCancellable>()
private var socketConnectionManager = SocketConnectionManager()


@State var alertMessage: String = ""

required init() {
#if DEBUG
Atlantis.start()
#endif

let projectId = InputConfig.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: "www.web3modal.com",
icons: ["https://avatars.githubusercontent.com/u/37784886"],
redirect: try! .init(native: "w3mdapp://", universal: "https://lab.web3modal.com/web3modal_example", linkMode: true)
)

Networking.configure(
groupIdentifier: "group.com.walletconnect.web3modal",
projectId: projectId,
socketFactory: DefaultSocketFactory()
)

AppKit.configure(
projectId: projectId,
metadata: metadata,
crypto: DefaultCryptoProvider(),
authRequestParams: nil, // use .stab() for testing SIWE
customWallets: [
.init(
id: "swift-sample",
name: "Swift Sample Wallet",
homepage: "https://walletconnect.com/",
imageUrl: "https://avatars.githubusercontent.com/u/37784886?s=200&v=4",
order: 1,
mobileLink: "walletapp://",
linkMode: "https://lab.web3modal.com/wallet"
)
]
) { error in
// SentrySDK.capture(error: error)

print(error)
}

setup()

}

func setup() {
AppKit.instance.socketConnectionStatusPublisher.receive(on: DispatchQueue.main).sink { [unowned self] status in
print("Socket connection status: \(status)")
self.socketConnectionManager.socketConnected = (status == .connected)

}.store(in: &disposeBag)
AppKit.instance.logger.setLogging(level: .debug)
Sign.instance.setLogging(level: .debug)
Networking.instance.setLogging(level: .debug)
Relay.instance.setLogging(level: .debug)

AppKit.instance.authResponsePublisher.sink { (id: RPCID, result: Result<(Session?, [Cacao]), AuthError>) in
switch result {
case .success((_, _)):
AlertPresenter.present(message: "User authenticated", type: .success)
case .failure(let error):
AlertPresenter.present(message: "User authentication error: \(error)", type: .error)

}
}.store(in: &disposeBag)

AppKit.instance.SIWEAuthenticationPublisher.sink { result in
switch result {
case .success((let message, let signature)):
AlertPresenter.present(message: "User authenticated", type: .success)
case .failure(let error):
AlertPresenter.present(message: "User authentication error: \(error)", type: .error)
}
}.store(in: &disposeBag)
}

var body: some Scene {
WindowGroup { [unowned self] in
ContentView()
.environmentObject(socketConnectionManager)
.onOpenURL { url in
AppKit.instance.handleDeeplink(url)
}
.alert(
"Response",
isPresented: .init(
get: { !self.alertMessage.isEmpty },
set: { _ in self.alertMessage = "" }
)
) {
Button("Dismiss", role: .cancel) {}
} message: {
Text(alertMessage)
}
.onReceive(AppKit.instance.sessionResponsePublisher, perform: { response in
switch response.result {
case let .response(value):
self.alertMessage = "Session response: \(value.stringRepresentation)"
case let .error(error):
self.alertMessage = "Session error: \(error)"
}
})
}
}
}

extension AuthRequestParams {
static func stub(
domain: String = "lab.web3modal.com",
chains: [String] = ["eip155:1", "eip155:137"],
nonce: String = "32891756",
uri: String = "https://lab.web3modal.com",
nbf: String? = nil,
exp: String? = nil,
statement: String? = "I accept the ServiceOrg Terms of Service: https://lab.web3modal.com",
requestId: String? = nil,
resources: [String]? = nil,
methods: [String]? = ["personal_sign", "eth_sendTransaction"]
) -> AuthRequestParams {
return try! AuthRequestParams(
domain: domain,
chains: chains,
nonce: nonce,
uri: uri,
nbf: nbf,
exp: exp,
statement: statement,
requestId: requestId,
resources: resources,
methods: methods
)
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
116 changes: 116 additions & 0 deletions Example/AppKitLab/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{
"images" : [
{
"filename" : "[email protected]",
"idiom" : "iphone",
"scale" : "2x",
"size" : "20x20"
},
{
"filename" : "[email protected]",
"idiom" : "iphone",
"scale" : "3x",
"size" : "20x20"
},
{
"filename" : "[email protected]",
"idiom" : "iphone",
"scale" : "2x",
"size" : "29x29"
},
{
"filename" : "[email protected]",
"idiom" : "iphone",
"scale" : "3x",
"size" : "29x29"
},
{
"filename" : "[email protected]",
"idiom" : "iphone",
"scale" : "2x",
"size" : "40x40"
},
{
"filename" : "[email protected]",
"idiom" : "iphone",
"scale" : "3x",
"size" : "40x40"
},
{
"filename" : "[email protected]",
"idiom" : "iphone",
"scale" : "2x",
"size" : "60x60"
},
{
"filename" : "[email protected]",
"idiom" : "iphone",
"scale" : "3x",
"size" : "60x60"
},
{
"filename" : "[email protected]",
"idiom" : "ipad",
"scale" : "1x",
"size" : "20x20"
},
{
"filename" : "[email protected]",
"idiom" : "ipad",
"scale" : "2x",
"size" : "20x20"
},
{
"filename" : "[email protected]",
"idiom" : "ipad",
"scale" : "1x",
"size" : "29x29"
},
{
"filename" : "[email protected]",
"idiom" : "ipad",
"scale" : "2x",
"size" : "29x29"
},
{
"filename" : "[email protected]",
"idiom" : "ipad",
"scale" : "1x",
"size" : "40x40"
},
{
"filename" : "[email protected]",
"idiom" : "ipad",
"scale" : "2x",
"size" : "40x40"
},
{
"filename" : "[email protected]",
"idiom" : "ipad",
"scale" : "1x",
"size" : "76x76"
},
{
"filename" : "[email protected]",
"idiom" : "ipad",
"scale" : "2x",
"size" : "76x76"
},
{
"filename" : "[email protected]",
"idiom" : "ipad",
"scale" : "2x",
"size" : "83.5x83.5"
},
{
"filename" : "[email protected]",
"idiom" : "ios-marketing",
"scale" : "1x",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions Example/AppKitLab/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading

0 comments on commit f44669a

Please sign in to comment.