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

[WCM] Using api.web3modal.com #1262

Merged
merged 5 commits into from
Jan 29, 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
9 changes: 9 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,14 @@ final class SignPresenter: ObservableObject {
Web3Modal.present(from: nil)
}

func connectWalletWithWCM() {
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
7 changes: 7 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 @@ -42,6 +43,12 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
)
]
)

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


Sign.instance.logsPublisher.sink { log in
switch log {
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 @@ -341,6 +341,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 @@ -712,6 +713,7 @@
84943C7B2A9BA206007EBAC2 /* Mixpanel in Frameworks */,
A573C53929EC365000E3CBFD /* HDWalletKit in Frameworks */,
A5BB7FA328B6A50400707FC6 /* WalletConnectAuth in Frameworks */,
CFDB50722B2869AA00A0CBC2 /* WalletConnectModal in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -1961,6 +1963,7 @@
84943C7A2A9BA206007EBAC2 /* Mixpanel */,
C5BE01DE2AF692D80064FC88 /* WalletConnectRouter */,
C579FEB52AFA86CD008855EB /* Web3Modal */,
CFDB50712B2869AA00A0CBC2 /* WalletConnectModal */,
8486EDD22B4F2EA6008E53C3 /* SwiftMessages */,
);
productName = DApp;
Expand Down Expand Up @@ -3348,7 +3351,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 @@ -3567,6 +3570,10 @@
isa = XCSwiftPackageProductDependency;
productName = WalletConnectModal;
};
CFDB50712B2869AA00A0CBC2 /* WalletConnectModal */ = {
isa = XCSwiftPackageProductDependency;
productName = WalletConnectModal;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = 764E1D3426F8D3FC00A1FB15 /* Project object */;
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
Loading