Skip to content

Commit

Permalink
Merge pull request #943 from WalletConnect/feature/wcm-cleanup
Browse files Browse the repository at this point in the history
[WCM] Implement missing ui + fix ui glitches
  • Loading branch information
radeknovis authored Jul 12, 2023
2 parents 8775e5f + 65ae0ba commit f025099
Show file tree
Hide file tree
Showing 17 changed files with 168 additions and 65 deletions.
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
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")]
),
.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
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

0 comments on commit f025099

Please sign in to comment.