Skip to content

Commit

Permalink
Merge pull request #29 from WalletConnect/feat/network-detail
Browse files Browse the repository at this point in the history
Network detail screen
  • Loading branch information
radeknovis authored Nov 14, 2023
2 parents 83ffcd9 + 346a843 commit 5ba59f8
Show file tree
Hide file tree
Showing 53 changed files with 930 additions and 572 deletions.
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/WalletConnect/WalletConnectSwiftV2",
"state" : {
"branch" : "remove-wcm",
"revision" : "0085250fd993f40a638f8d3e300f4af8cbf9e7a8"
"revision" : "4aa4c8229077c133730e361d0d7a17f9e56bdffd",
"version" : "1.9.6"
}
}
],
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let package = Package(
dependencies: [
.package(
url: "https://github.com/WalletConnect/WalletConnectSwiftV2",
from: "1.9.2"
from: "1.9.8"
),
.package(
url: "https://github.com/WalletConnect/QRCode",
Expand Down
4 changes: 2 additions & 2 deletions Sample/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = Example/Example.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 7;
CURRENT_PROJECT_VERSION = 9;
DEVELOPMENT_ASSET_PATHS = "\"Example/Preview Content\"";
DEVELOPMENT_TEAM = W5R8AG9K22;
ENABLE_HARDENED_RUNTIME = YES;
Expand Down Expand Up @@ -364,7 +364,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = Example/Example.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 7;
CURRENT_PROJECT_VERSION = 9;
DEVELOPMENT_ASSET_PATHS = "\"Example/Preview Content\"";
DEVELOPMENT_TEAM = W5R8AG9K22;
ENABLE_HARDENED_RUNTIME = YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/WalletConnect/WalletConnectSwiftV2",
"state" : {
"revision" : "c3c84f221ef945edb766125bc07f03c7694fc516",
"version" : "1.9.2"
"revision" : "addf9a3688ef5e5d9d148ecbb30ca0fd3132b908",
"version" : "1.9.8"
}
}
],
Expand Down
6 changes: 6 additions & 0 deletions Sample/Example/ComponentLibraryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ struct ComponentLibraryView: View {
Group {
#if DEBUG
List {
NavigationLink(destination: AccountButtonPreviewView()) {
Text("AccountButton")
}
NavigationLink(destination: NetworkButtonPreviewView()) {
Text("NetworkButton")
}
NavigationLink(destination: W3MButtonStylePreviewView()) {
Text("W3MButton")
}
Expand Down
4 changes: 2 additions & 2 deletions Sample/Example/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ struct ContentView: View {
VStack {
Spacer()

Web3Button()
Web3ModalButton()

NetworkButton()
Web3ModalNetworkButton()

Spacer()

Expand Down
4 changes: 2 additions & 2 deletions Sample/Example/ExampleApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ struct ExampleApp: App {
name: "Web3Modal Swift Dapp",
description: "Web3Modal DApp sample",
url: "wallet.connect",
icons: ["https://avatars.githubusercontent.com/u/37784886"]
icons: ["https://avatars.githubusercontent.com/u/37784886"],
redirect: .init(native: "", universal: "")
)

let projectId = Secrets.load().projectID
Expand All @@ -30,7 +31,6 @@ struct ExampleApp: App {

Web3Modal.configure(
projectId: projectId,
chainId: Blockchain("eip155:1")!,
metadata: metadata
)
}
Expand Down
76 changes: 48 additions & 28 deletions Sources/Web3Modal/Components/AccountButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct AccountButtonStyle: ButtonStyle {
}

var selectedChain: Chain {
return store.selectedChain ?? ChainsPresets.ethChains.first!
return store.selectedChain ?? ChainPresets.ethChains.first!
}

func makeBody(configuration: Configuration) -> some View {
Expand Down Expand Up @@ -158,11 +158,11 @@ public struct AccountButton: View {
Button(action: {
Web3Modal.present()
}, label: {})
.buttonStyle(AccountButtonStyle(store: store))
.onAppear {
fetchIdentity()
fetchBalance()
}
.buttonStyle(AccountButtonStyle(store: store))
.onAppear {
fetchIdentity()
fetchBalance()
}
}

func fetchIdentity() {
Expand All @@ -186,45 +186,65 @@ public struct AccountButton: View {
}
}

struct AccountButton_Preview: PreviewProvider {
#if DEBUG

public struct AccountButtonPreviewView: View {
public init() {}

static let store = { (balance: Double?) -> Store in
let store = Store()
store.balance = balance
store.session = .stub

Web3Modal.configure(
projectId: "",
metadata: .init(
name: "",
description: "",
url: "",
icons: [],
redirect: .init(native: "", universal: "")
)
)

return store
}

static var previews: some View {
public var body: some View {
VStack {
AccountButton(store: AccountButton_Preview.store(1.23))
AccountButton(store: AccountButtonPreviewView.store(1.23))

AccountButton(store: AccountButton_Preview.store(nil))
AccountButton(store: AccountButtonPreviewView.store(nil))

AccountButton(store: AccountButton_Preview.store(1.23))
AccountButton(store: AccountButtonPreviewView.store(1.23))
.disabled(true)

AccountButton(store: AccountButton_Preview.store(nil))
AccountButton(store: AccountButtonPreviewView.store(nil))
.disabled(true)

Button(action: {}, label: {
// Text("Foo")
})
.buttonStyle(
AccountButtonStyle(
store: AccountButton_Preview.store(1.23),
isPressedOverride: true
Button(action: {}, label: {})
.buttonStyle(
AccountButtonStyle(
store: AccountButtonPreviewView.store(1.23),
isPressedOverride: true
)
)
)

Button(action: {}, label: {
// Text("Foo")
})
.buttonStyle(
AccountButtonStyle(
store: AccountButton_Preview.store(nil),
isPressedOverride: true
Button(action: {}, label: {})
.buttonStyle(
AccountButtonStyle(
store: AccountButtonPreviewView.store(nil),
isPressedOverride: true
)
)
)
}
}
}

struct AccountButton_Preview: PreviewProvider {
static var previews: some View {
AccountButtonPreviewView()
}
}

#endif
8 changes: 7 additions & 1 deletion Sources/Web3Modal/Components/ConnectButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ public struct ConnectButton: View {
Web3Modal.present()
} label: {
if store.connecting {
CircleProgressView(color: .white, lineWidth: 2, isAnimating: .constant(true))
DrawingProgressView(
shape: .circle,
color: .white,
lineWidth: 2,
duration: 1,
isAnimating: .constant(true)
)
.frame(width: 20, height: 20)
} else {
Text("Connect wallet")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import SwiftUI

public struct Web3Button: View {

public struct Web3ModalButton: View {
@ObservedObject var store: Store

public init() {
Expand All @@ -24,7 +23,6 @@ public struct Web3Button: View {
}

struct Web3Button_Preview: PreviewProvider {

static let store = { () -> Store in
let store = Store()
store.balance = 1.23
Expand All @@ -34,9 +32,9 @@ struct Web3Button_Preview: PreviewProvider {

static var previews: some View {
VStack {
Web3Button(store: Web3Button_Preview.store)
Web3ModalButton(store: Web3Button_Preview.store)

Web3Button(store: Web3Button_Preview.store)
Web3ModalButton(store: Web3Button_Preview.store)
.disabled(true)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SwiftUI
import Web3ModalUI

public struct NetworkButton: View {
public struct Web3ModalNetworkButton: View {
@ObservedObject var store: Store

public init() {
Expand All @@ -14,7 +14,6 @@ public struct NetworkButton: View {

public var body: some View {
if let selectedChain = store.selectedChain {

let storedImage = store.chainImages[selectedChain.imageId]
let chainImage = Image(
uiImage: storedImage ?? UIImage()
Expand Down Expand Up @@ -45,7 +44,11 @@ public struct NetworkButton: View {
}
}

struct NetworkButton_Preview: PreviewProvider {
#if DEBUG

public struct NetworkButtonPreviewView: View {
public init() {}

static let store = { (chain: Chain?) -> Store in
let store = Store()
store.balance = 1.23
Expand All @@ -54,21 +57,27 @@ struct NetworkButton_Preview: PreviewProvider {
return store
}

static var previews: some View {
public var body: some View {
VStack {
NetworkButton(store: NetworkButton_Preview.store(nil))

ConnectButton()
Web3ModalNetworkButton(store: NetworkButtonPreviewView.store(nil))

NetworkButton(store: NetworkButton_Preview.store(ChainsPresets.ethChains[0]))
Web3ModalNetworkButton(store: NetworkButtonPreviewView.store(ChainPresets.ethChains[0]))

NetworkButton(store: NetworkButton_Preview.store(ChainsPresets.ethChains[1]))
Web3ModalNetworkButton(store: NetworkButtonPreviewView.store(ChainPresets.ethChains[1]))

NetworkButton(store: NetworkButton_Preview.store(ChainsPresets.ethChains[0]))
Web3ModalNetworkButton(store: NetworkButtonPreviewView.store(ChainPresets.ethChains[0]))
.disabled(true)

NetworkButton(store: NetworkButton_Preview.store(nil))
Web3ModalNetworkButton(store: NetworkButtonPreviewView.store(nil))
.disabled(true)
}
}
}

struct NetworkButton_Preview: PreviewProvider {
static var previews: some View {
NetworkButtonPreviewView()
}
}

#endif
3 changes: 2 additions & 1 deletion Sources/Web3Modal/Core/W3MAPIInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ final class W3MAPIInteractor: ObservableObject {
}

self.isLoading = false
self.objectWillChange.send()
}
}

Expand Down Expand Up @@ -174,7 +175,7 @@ final class W3MAPIInteractor: ObservableObject {
func prefetchChainImages() async throws {
var chainImages: [String: UIImage] = [:]

try await ChainsPresets.ethChains.concurrentMap { chain in
try await ChainPresets.ethChains.concurrentMap { chain in

let url = URL(string: "https://api.web3modal.com/public/getAssetImage/\(chain.imageId)")!
var request = URLRequest(url: url)
Expand Down
Loading

0 comments on commit 5ba59f8

Please sign in to comment.