Skip to content

Commit

Permalink
WCM using api.web3modal.com
Browse files Browse the repository at this point in the history
  • Loading branch information
radeknovis committed Dec 19, 2023
1 parent 9e677be commit 55205e9
Show file tree
Hide file tree
Showing 21 changed files with 425 additions and 294 deletions.
11 changes: 11 additions & 0 deletions Example/DApp/Modules/Sign/SignPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import UIKit
import Combine

import Web3Modal
import WalletConnectModal
import WalletConnectSign

final class SignPresenter: ObservableObject {
Expand Down Expand Up @@ -52,6 +53,16 @@ final class SignPresenter: ObservableObject {
Web3Modal.present(from: nil)
}

func connectWalletWithWCM() {
Task {
WalletConnectModal.set(sessionParams: .init(
requiredNamespaces: Proposal.requiredNamespaces,
optionalNamespaces: Proposal.optionalNamespaces
))
}
WalletConnectModal.present(from: nil)
}

@MainActor
func connectWalletWithSign() {
Task {
Expand Down
59 changes: 36 additions & 23 deletions Example/DApp/Modules/Sign/SignView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,42 @@ struct SignView: View {

Spacer()

Button {
presenter.connectWalletWithW3M()
} label: {
Text("Connect with Web3Modal")
.font(.system(size: 16, weight: .semibold))
.foregroundColor(.white)
.padding(.horizontal, 16)
.padding(.vertical, 10)
.background(Color(red: 95/255, green: 159/255, blue: 248/255))
.cornerRadius(16)
}
.padding(.top, 20)

Button {
presenter.connectWalletWithSign()
} label: {
Text("Connect with Sign API")
.font(.system(size: 16, weight: .semibold))
.foregroundColor(.white)
.padding(.horizontal, 16)
.padding(.vertical, 10)
.background(Color(red: 95/255, green: 159/255, blue: 248/255))
.cornerRadius(16)
VStack(spacing: 10) {
Button {
presenter.connectWalletWithW3M()
} label: {
Text("Connect with Web3Modal")
.font(.system(size: 16, weight: .semibold))
.foregroundColor(.white)
.padding(.horizontal, 16)
.padding(.vertical, 10)
.background(Color(red: 95/255, green: 159/255, blue: 248/255))
.cornerRadius(16)
}

Button {
presenter.connectWalletWithSign()
} label: {
Text("Connect with Sign API")
.font(.system(size: 16, weight: .semibold))
.foregroundColor(.white)
.padding(.horizontal, 16)
.padding(.vertical, 10)
.background(Color(red: 95/255, green: 159/255, blue: 248/255))
.cornerRadius(16)
}

Button {
presenter.connectWalletWithWCM()
} label: {
Text("Connect with WalletConnectModal")
.font(.system(size: 16, weight: .semibold))
.foregroundColor(.white)
.padding(.horizontal, 16)
.padding(.vertical, 10)
.background(Color(red: 95/255, green: 159/255, blue: 248/255))
.cornerRadius(16)
}
}
.padding(.top, 10)
}
Expand Down
6 changes: 6 additions & 0 deletions Example/DApp/SceneDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import UIKit

import Web3Modal
import WalletConnectModal
import Auth
import WalletConnectRelay
import WalletConnectNetworking
Expand Down Expand Up @@ -31,6 +32,11 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
metadata: metadata
)

WalletConnectModal.configure(
projectId: InputConfig.projectId,
metadata: metadata
)

setupWindow(scene: scene)
}

Expand Down
9 changes: 8 additions & 1 deletion Example/ExampleApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@
CF25F2892A432476009C7E49 /* WalletConnectModal in Frameworks */ = {isa = PBXBuildFile; productRef = CF25F2882A432476009C7E49 /* WalletConnectModal */; };
CF6704DF29E59DDC003326A4 /* XCUIElementQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = CF6704DE29E59DDC003326A4 /* XCUIElementQuery.swift */; };
CF6704E129E5A014003326A4 /* XCTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = CF6704E029E5A014003326A4 /* XCTestCase.swift */; };
CFDB50722B2869AA00A0CBC2 /* WalletConnectModal in Frameworks */ = {isa = PBXBuildFile; productRef = CFDB50712B2869AA00A0CBC2 /* WalletConnectModal */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -724,6 +725,7 @@
84943C7B2A9BA206007EBAC2 /* Mixpanel in Frameworks */,
A573C53929EC365000E3CBFD /* HDWalletKit in Frameworks */,
A5BB7FA328B6A50400707FC6 /* WalletConnectAuth in Frameworks */,
CFDB50722B2869AA00A0CBC2 /* WalletConnectModal in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -2011,6 +2013,7 @@
84943C7A2A9BA206007EBAC2 /* Mixpanel */,
C5BE01DE2AF692D80064FC88 /* WalletConnectRouter */,
C579FEB52AFA86CD008855EB /* Web3Modal */,
CFDB50712B2869AA00A0CBC2 /* WalletConnectModal */,
);
productName = DApp;
productReference = 84CE641C27981DED00142511 /* DApp.app */;
Expand Down Expand Up @@ -3393,7 +3396,7 @@
repositoryURL = "https://github.com/WalletConnect/web3modal-swift";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 1.0.9;
minimumVersion = 1.0.15;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down Expand Up @@ -3602,6 +3605,10 @@
isa = XCSwiftPackageProductDependency;
productName = WalletConnectModal;
};
CFDB50712B2869AA00A0CBC2 /* WalletConnectModal */ = {
isa = XCSwiftPackageProductDependency;
productName = WalletConnectModal;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = 764E1D3426F8D3FC00A1FB15 /* Project object */;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@
"repositoryURL": "https://github.com/WalletConnect/web3modal-swift",
"state": {
"branch": null,
"revision": "3295d69d1b12df29a5040578d107f56986b1b399",
"version": "1.0.13"
"revision": "017e5645be65d23725f74d7482151cce75c68504",
"version": "1.0.15"
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion Sources/WalletConnectModal/Extensions/View+Backport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extension View {

@ViewBuilder
func onTapGestureBackported(count: Int = 1, perform action: @escaping () -> Void) -> some View {
self
self.onTapGesture(count: count, perform: action)
}

#elseif os(tvOS)
Expand Down
70 changes: 23 additions & 47 deletions Sources/WalletConnectModal/Mocks/Listing+Mocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,40 @@ import Foundation

#if DEBUG

extension Listing {
static let stubList: [Listing] = [
Listing(
extension Wallet {
static let stubList: [Wallet] = [
Wallet(
id: UUID().uuidString,
name: "Sample Wallet",
homepage: "https://example.com",
homepage: "https://example.com/cool",
imageId: "0528ee7e-16d1-4089-21e3-bbfb41933100",
order: 1,
imageId: UUID().uuidString,
app: Listing.App(
ios: "https://example.com/download-ios",
browser: "https://example.com/download-safari"
),
mobile: .init(
native: "sampleapp://deeplink",
universal: "https://example.com/universal"
),
desktop: .init(
native: nil,
universal: "https://example.com/universal"
)
mobileLink: "https://sample.com/foo/universal",
desktopLink: "sampleapp://deeplink",
webappLink: "https://sample.com/foo/webapp",
appStore: ""
),
Listing(
Wallet(
id: UUID().uuidString,
name: "Awesome Wallet",
homepage: "https://example.com/awesome",
name: "Cool Wallet",
homepage: "https://example.com/cool",
imageId: "5195e9db-94d8-4579-6f11-ef553be95100",
order: 2,
imageId: UUID().uuidString,
app: Listing.App(
ios: "https://example.com/download-ios",
browser: "https://example.com/download-safari"
),
mobile: .init(
native: "awesomeapp://deeplink",
universal: "https://example.com/awesome/universal"
),
desktop: .init(
native: nil,
universal: "https://example.com/awesome/universal"
)
mobileLink: "awsomeapp://",
desktopLink: "awsomeapp://deeplink",
webappLink: "https://awesome.com/foo/webapp",
appStore: ""
),
Listing(
Wallet(
id: UUID().uuidString,
name: "Cool Wallet",
homepage: "https://example.com/cool",
imageId: "3913df81-63c2-4413-d60b-8ff83cbed500",
order: 3,
imageId: UUID().uuidString,
app: Listing.App(
ios: "https://example.com/download-ios",
browser: "https://example.com/download-safari"
),
mobile: .init(
native: "coolapp://deeplink",
universal: "https://example.com/cool/universal"
),
desktop: .init(
native: nil,
universal: "https://example.com/cool/universal"
)
mobileLink: "https://cool.com/foo/universal",
desktopLink: "coolapp://deeplink",
webappLink: "https://cool.com/foo/webapp",
appStore: ""
)
]
}
Expand Down
27 changes: 15 additions & 12 deletions Sources/WalletConnectModal/Modal/ModalInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,35 @@ import Combine
import Foundation

protocol ModalSheetInteractor {
func getListings() async throws -> [Listing]
func getWallets(page: Int, entries: Int) async throws -> (Int, [Wallet])
func createPairingAndConnect() async throws -> WalletConnectURI?

var sessionSettlePublisher: AnyPublisher<Session, Never> { get }
var sessionRejectionPublisher: AnyPublisher<(Session.Proposal, Reason), Never> { get }
}

final class DefaultModalSheetInteractor: ModalSheetInteractor {

lazy var sessionSettlePublisher: AnyPublisher<Session, Never> = WalletConnectModal.instance.sessionSettlePublisher
lazy var sessionRejectionPublisher: AnyPublisher<(Session.Proposal, Reason), Never> = WalletConnectModal.instance.sessionRejectionPublisher

func getListings() async throws -> [Listing] {

let httpClient = HTTPNetworkClient(host: "explorer-api.walletconnect.com")
func getWallets(page: Int, entries: Int) async throws -> (Int, [Wallet]) {
let httpClient = HTTPNetworkClient(host: "api.web3modal.org")
let response = try await httpClient.request(
ListingsResponse.self,
at: ExplorerAPI.getListings(
projectId: WalletConnectModal.config.projectId,
metadata: WalletConnectModal.config.metadata,
recommendedIds: WalletConnectModal.config.recommendedWalletIds,
excludedIds: WalletConnectModal.config.excludedWalletIds
GetWalletsResponse.self,
at: Web3ModalAPI.getWallets(
params: Web3ModalAPI.GetWalletsParams(
page: page,
entries: entries,
search: nil,
projectId: WalletConnectModal.config.projectId,
metadata: WalletConnectModal.config.metadata,
recommendedIds: WalletConnectModal.config.recommendedWalletIds,
excludedIds: WalletConnectModal.config.excludedWalletIds
)
)
)

return response.listings.values.compactMap { $0 }
return (response.count, response.data.compactMap { $0 })
}

func createPairingAndConnect() async throws -> WalletConnectURI? {
Expand Down
6 changes: 2 additions & 4 deletions Sources/WalletConnectModal/Modal/ModalSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,12 @@ public struct ModalSheet: View {
@ViewBuilder
private func welcome() -> some View {
WalletList(
wallets: .init(get: {
viewModel.filteredWallets
}, set: { _ in }),
destination: .init(get: {
viewModel.destination
}, set: { _ in }),
viewModel: viewModel,
navigateTo: viewModel.navigateTo(_:),
onListingTap: { viewModel.onListingTap($0) }
onWalletTap: { viewModel.onWalletTap($0) }
)
}

Expand Down
Loading

0 comments on commit 55205e9

Please sign in to comment.