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] Implement missing ui + fix ui glitches #943

Merged
merged 3 commits into from
Jul 12, 2023
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ DerivedDataCache
*.ipa
*.zip
test_results/

Sources/WalletConnectModal/Secrets/secrets.json
Copy link
Contributor

@flypaper0 flypaper0 Jul 6, 2023

Choose a reason for hiding this comment

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

Where it used? Other team also need to have this file locally?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only needed if you want to run WalletConnectModal previews. If you don't have it, you will get a somewhat explanatory error to create it.

2 changes: 0 additions & 2 deletions Example/DApp/Sign/SelectChain/SelectChainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ class SelectChainViewController: UIViewController, UITableViewDataSource {
optionalNamespaces: optionalNamespaces,
sessionProperties: sessionProperties
))

let uri = try await WalletConnectModal.instance.connect(topic: nil)
}

WalletConnectModal.present(from: self)
Expand Down
5 changes: 4 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ let package = Package(
dependencies: ["WalletConnectUtils", "WalletConnectNetworking"]),
.target(
name: "WalletConnectModal",
dependencies: ["QRCode", "WalletConnectSign"]),
dependencies: ["QRCode", "WalletConnectSign"],
exclude: ["Secrets/secrets.json.sample"],
resources: [.copy("Secrets/secrets.json")]
Copy link
Contributor

Choose a reason for hiding this comment

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

Strange. You're ignoring this file by git, but it's required for WalletConnectModal SDK

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is ignored, so we don't commit actual secrets. This will pass if the file is not present, but to access the JSON with actual secrets, you need to bundle it with the target.

),
.target(
name: "WalletConnectSync",
dependencies: ["WalletConnectSigner"]),
Expand Down
13 changes: 13 additions & 0 deletions Sources/WalletConnectModal/Mocks/Listing+Mocks.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Foundation

#if DEBUG

extension Listing {
static let stubList: [Listing] = [
Listing(id: UUID().uuidString, name: "Sample Wallet", homepage: "https://example.com", order: 1, imageId: UUID().uuidString, app: Listing.App(ios: "https://example.com/download-ios", mac: "https://example.com/download-mac", safari: "https://example.com/download-safari"), mobile: Listing.Mobile(native: "sampleapp://deeplink", universal: "https://example.com/universal")),
Listing(id: UUID().uuidString, name: "Awesome Wallet", homepage: "https://example.com/awesome", order: 2, imageId: UUID().uuidString, app: Listing.App(ios: "https://example.com/download-ios", mac: "https://example.com/download-mac", safari: "https://example.com/download-safari"), mobile: Listing.Mobile(native: "awesomeapp://deeplink", universal: "https://example.com/awesome/universal")),
Listing(id: UUID().uuidString, name: "Cool Wallet", homepage: "https://example.com/cool", order: 3, imageId: UUID().uuidString, app: Listing.App(ios: "https://example.com/download-ios", mac: "https://example.com/download-mac", safari: "https://example.com/download-safari"), mobile: Listing.Mobile(native: "coolapp://deeplink", universal: "https://example.com/cool/universal"))
]
}

#endif
4 changes: 2 additions & 2 deletions Sources/WalletConnectModal/Modal/Modal+Previews.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class WebSocketFactoryMock: WebSocketFactory {
}
}

@available(iOS 14.0, *)
struct ModalContainerView_Previews: PreviewProvider {

static var previews: some View {
Expand All @@ -33,7 +32,8 @@ struct ModalContainerView_Previews: PreviewProvider {
struct Content: View {

init() {
let projectId = "9bfe94c9cbf74aaa0597094ef561f703"

let projectId = Secrets.load().projectID
Copy link
Contributor

Choose a reason for hiding this comment

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

Now we're taking Project ID from configuration. Why json file is better?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

configuration.xcconfig is not available from package, only for stuff in the ExampleApp project, or at least I haven't figured out how to read from it.

I'm not too keen on having two approaches how to share secrets/vars either. So any suggestions on how to do this better are more than welcome :D

Copy link
Contributor

Choose a reason for hiding this comment

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

you can pass projectID to w3m in a config method like in Relay

    static public func configure(
        relayHost: String = "relay.walletconnect.com",
        projectId: String,
        socketFactory: WebSocketFactory,
        socketConnectionType: SocketConnectionType = .automatic
    )

Copy link
Contributor

Choose a reason for hiding this comment

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

can't believe we missed comiting proj id xd

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this is how it will be done when actually integrating the modal SDK https://github.com/WalletConnect/WalletConnectSwiftV2/blob/9cead7d4443815687e02cd87ba888130225283fc/Sources/WalletConnectModal/WalletConnectModal.swift#L51-L57C8

but this is in the context of previews within SDK itself so I don't have any projectID injected from elsewhere.

let metadata = AppMetadata(
name: "Showcase App",
description: "Showcase description",
Expand Down
8 changes: 4 additions & 4 deletions Sources/WalletConnectModal/Modal/ModalContainerView.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import SwiftUI

struct ModalContainerView: View {

@Environment(\.presentationMode) var presentationMode

@State var showModal: Bool = false

var body: some View {

VStack(spacing: -10) {

VStack(spacing: 0) {

Color.thickOverlay
.colorScheme(.light)
.transform {
Expand All @@ -21,6 +19,7 @@ struct ModalContainerView: View {
}
#endif
}
.opacity(showModal ? 1 : 0)

if showModal {
ModalSheet(
Expand All @@ -34,6 +33,7 @@ struct ModalContainerView: View {
.animation(.spring(), value: showModal)
}
}

.edgesIgnoringSafeArea(.all)
.onChangeBackported(of: showModal, perform: { newValue in
if newValue == false {
Expand Down
26 changes: 16 additions & 10 deletions Sources/WalletConnectModal/Modal/ModalSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ public struct ModalSheet: View {
}
}
.background(
VStack(spacing: 0) {
Color.accent
.frame(height: 90)
.cornerRadius(8, corners: [[.topLeft, .topRight]])
Color.background1
ZStack {
Color.thickOverlay.colorScheme(.light)

VStack(spacing: 0) {
Color.accent
.frame(height: 90)
.cornerRadius(8, corners: [[.topLeft, .topRight]])
Color.background1
}
}
)
.toastView(toast: $viewModel.toast)
Expand Down Expand Up @@ -127,13 +131,17 @@ public struct ModalSheet: View {
.viewAll:
welcome()
case .help:
WhatIsWalletView(navigateTo: viewModel.navigateTo(_:))
WhatIsWalletView(
navigateTo: viewModel.navigateTo(_:),
navigateToExternalLink: viewModel.navigateToExternalLink(_:)
)
case .qr:
qrCode()
case .getWallet:
GetAWalletView(
wallets: Array(viewModel.wallets.prefix(6)),
onTap: viewModel.onGetWalletTap(_:)
onWalletTap: viewModel.onGetWalletTap(_:),
navigateToExternalLink: viewModel.navigateToExternalLink(_:)
)
}
}
Expand All @@ -154,9 +162,7 @@ extension ModalSheet {

private func closeButton() -> some View {
Button {
withAnimation {
viewModel.isShown.wrappedValue = false
}
viewModel.onCloseButton()
} label: {
Image(.close)
.padding(8)
Expand Down
10 changes: 10 additions & 0 deletions Sources/WalletConnectModal/Modal/ModalViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ final class ModalViewModel: ObservableObject {
destinationStack.append(destination)
}

func navigateToExternalLink(_ url: URL) {
uiApplicationWrapper.openURL(url, nil)
}

func onListingTap(_ listing: Listing) {
navigateToDeepLink(
universalLink: listing.mobile.universal ?? "",
Expand Down Expand Up @@ -161,6 +165,12 @@ final class ModalViewModel: ObservableObject {
toast = Toast(style: .info, message: "URI copied into clipboard")
}

func onCloseButton() {
withAnimation {
isShown.wrappedValue = false
}
}

@MainActor
func fetchWallets() async {
do {
Expand Down
90 changes: 70 additions & 20 deletions Sources/WalletConnectModal/Modal/Screens/GetAWalletView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,82 @@ import SwiftUI
struct GetAWalletView: View {

let wallets: [Listing]
let onTap: (Listing) -> Void
let onWalletTap: (Listing) -> Void
let navigateToExternalLink: (URL) -> Void

var body: some View {
List {
ForEach(wallets) { wallet in
Button {
onTap(wallet)
} label: {

HStack {
WalletImage(wallet: wallet)
.frame(width: 40, height: 40)

Text(wallet.name)
.font(.system(size: 16, weight: .medium))
.padding(.horizontal)

Spacer()
VStack {

List {
ForEach(wallets) { wallet in
Button {
onWalletTap(wallet)
} label: {

Image(systemName: "chevron.right")
.font(.system(.footnote).weight(.semibold))
HStack {
WalletImage(wallet: wallet)
.frame(width: 40, height: 40)

Text(wallet.name)
.font(.system(size: 16, weight: .medium))
.padding(.horizontal)

Spacer()

Image(systemName: "chevron.right")
.font(.system(.footnote).weight(.semibold))
}
}
}
}
.frame(minHeight: 400)
.listStyle(.plain)

VStack(alignment: .center, spacing: 8) {

Text("Not what you’re looking for?")
.font(
.system(size: 16)
.weight(.semibold)
)
.multilineTextAlignment(.center)
.foregroundColor(.foreground1)

Text("With hundreds of wallets out there, 
there’s something for everyone ")
.font(
.system(size: 14)
.weight(.medium)
)
.foregroundColor(.foreground2)
.fixedSize(horizontal: false, vertical: true)

Button(action: {
navigateToExternalLink(URL(string: "https://walletconnect.com/explorer?type=wallet")!)
}) {
HStack {
Text("Explore Wallets")
Image(.external_link)
}
}
.buttonStyle(W3MButtonStyle())
}
.multilineTextAlignment(.center)
.padding(.horizontal, 0)
.padding(.top, 0)
.frame(maxHeight: .infinity, alignment: .bottom)
}
.frame(height: 500)
.listStyle(.plain)
}
}

struct GetAWalletView_Previews: PreviewProvider {

static var previews: some View {

GetAWalletView(
wallets: Listing.stubList,
onWalletTap: { _ in },
navigateToExternalLink: { _ in }
)
.environment(\.projectId, Secrets.load().projectID)
}
}
13 changes: 9 additions & 4 deletions Sources/WalletConnectModal/Modal/Screens/WalletList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ struct WalletList: View {
.padding(.vertical, 3)
.frame(width: 60, height: 60)
.background(Color.background2)
.cornerRadius(8)
.cornerRadius(16)
.overlay(
RoundedRectangle(cornerRadius: 8)
RoundedRectangle(cornerRadius: 16)
.stroke(.gray.opacity(0.4), lineWidth: 1)
)

Expand All @@ -153,7 +153,7 @@ struct WalletList: View {

Spacer()
}
.frame(maxWidth: 80, maxHeight: 96)
.frame(width: 80, height: 96)
}

@ViewBuilder
Expand All @@ -162,6 +162,11 @@ struct WalletList: View {
VStack {
WalletImage(wallet: wallet)
.frame(width: 60, height: 60)
.cornerRadius(16)
.overlay(
RoundedRectangle(cornerRadius: 16)
.stroke(.gray.opacity(0.4), lineWidth: 1)
)

Text(wallet.name)
.font(.system(size: 12))
Expand Down Expand Up @@ -209,7 +214,7 @@ struct WalletList: View {
} label: {
HStack {
Text("Try Again")
Image("external_link", bundle: .module)
Image(.external_link)
}
}
.buttonStyle(W3MButtonStyle())
Expand Down
19 changes: 10 additions & 9 deletions Sources/WalletConnectModal/Modal/Screens/WhatIsWalletView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,42 @@ import SwiftUI
struct WhatIsWalletView: View {

var navigateTo: (Destination) -> Void
var navigateToExternalLink: (URL) -> Void

var body: some View {

VStack(spacing: 10) {
HelpSection(
title: "A home for your digital assets",
description: "A wallet lets you store, send and receive digital assets like cryptocurrencies and NFTs.",
assets: ["DeFi", "NFT", "ETH"]
assets: [.DeFi, .NFT, .ETH]
)
HelpSection(
title: "One login for all of web3",
description: "Log in to any app by connecting your wallet. Say goodbye to countless passwords!",
assets: ["Login", "Profile", "Lock"]
assets: [.Login, .Profile, .Lock]
)
HelpSection(
title: "Your gateway to a new web",
description: "With your wallet, you can explore and interact with DeFi, NFTs, DAOs, and much more.",
assets: ["Browser", "Noun", "DAO"]
assets: [.Browser, .Noun, .DAO]
)

HStack {
Button(action: {
navigateTo(.getWallet)
}) {
HStack {
Image("wallet", bundle: .module)
Image(.wallet)
Text("Get a Wallet")
}
}
Button(action: {

navigateToExternalLink(URL(string: "https://ethereum.org/en/wallets/")!)
}) {
HStack {
Text("Learn More")
Image("external_link", bundle: .module)
Image(.external_link)
}
}
}
Expand All @@ -51,13 +52,13 @@ struct HelpSection: View {

let title: String
let description: String
let assets: [String]
let assets: [Asset]

var body: some View {
VStack {
HStack {
ForEach(assets, id: \.self) { asset in
Image(asset, bundle: .module)
Image(asset)
}
}

Expand All @@ -81,6 +82,6 @@ struct WhatIsWalletView_Previews: PreviewProvider {

static var previews: some View {

WhatIsWalletView(navigateTo: { _ in})
WhatIsWalletView(navigateTo: { _ in}, navigateToExternalLink: { _ in })
}
}
Binary file not shown.
Loading