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

Main #80

Closed
wants to merge 6 commits into from
Closed

Main #80

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
13 changes: 2 additions & 11 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,13 @@
"version": "1.1.6"
}
},
{
"package": "CoinbaseWalletSDK",
"repositoryURL": "https://github.com/MobileWalletProtocol/wallet-mobile-sdk",
"state": {
"branch": null,
"revision": "84b3d3f25a2e3b140ec12bb0d22c35b58f817d44",
"version": "1.0.0"
}
},
{
"package": "Yttrium",
"repositoryURL": "https://github.com/reown-com/yttrium",
"state": {
"branch": null,
"revision": "79fdd0d3be2d00e371b8f23998a4aa7b1c14e847",
"version": "0.4.7"
"revision": "533e9bacce2c7a45b1f9b3705726d03f2a37be4e",
"version": "0.4.8"
}
}
]
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let yttriumDebug = false
var dependencies: [Package.Dependency] = [
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.3.0"),
.package(url: "https://github.com/WalletConnect/QRCode", from: "14.3.1"),
.package(name: "CoinbaseWalletSDK", url: "https://github.com/MobileWalletProtocol/wallet-mobile-sdk", .upToNextMinor(from: "1.0.0")),
// .package(name: "CoinbaseWalletSDK", url: "https://github.com/MobileWalletProtocol/wallet-mobile-sdk", .upToNextMinor(from: "1.0.0")),
// .package(url: "https://github.com/pointfreeco/swift-snapshot-testing", .upToNextMinor(from: "1.10.0")),
]

Expand Down Expand Up @@ -166,7 +166,7 @@ let package = Package(
"WalletConnectSign",
"ReownAppKitUI",
"ReownAppKitBackport",
"CoinbaseWalletSDK"
// "CoinbaseWalletSDK"
],
path: "Sources/ReownAppKit",
resources: [
Expand Down
156 changes: 75 additions & 81 deletions Sources/ReownAppKit/Core/AppKit.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import CoinbaseWalletSDK
//import CoinbaseWalletSDK
import Foundation
import SwiftUI

Expand Down Expand Up @@ -38,12 +38,6 @@ public class AppKit {
store.session = session
store.connectedWith = .wc
store.account = .init(from: session)
} else if config.coinbaseEnabled,
CoinbaseWalletSDK.shared.isConnected() {

let storedAccount = AccountStorage.read()
store.connectedWith = .cb
store.account = storedAccount
} else {
AccountStorage.clear()
}
Expand Down Expand Up @@ -122,11 +116,11 @@ public class AppKit {

store.customWallets = customWallets

configureCoinbaseIfNeeded(
store: store,
metadata: metadata,
w3mApiInteractor: w3mApiInteractor
)
// configureCoinbaseIfNeeded(
// store: store,
// metadata: metadata,
// w3mApiInteractor: w3mApiInteractor
// )

AppKit.viewModel = Web3ModalViewModel(
router: router,
Expand All @@ -149,75 +143,75 @@ public class AppKit {
AppKit.config.sessionParams = sessionParams
}

private static func configureCoinbaseIfNeeded(
store: Store,
metadata: AppMetadata,
w3mApiInteractor: W3MAPIInteractor
) {
guard AppKit.config.coinbaseEnabled else { return }

if let redirectLink = metadata.redirect?.universal ?? metadata.redirect?.native {
CoinbaseWalletSDK.configure(callback: URL(string: redirectLink)!)
} else {
CoinbaseWalletSDK.configure(
callback: URL(string: "w3mdapp://")!
)
}

var wallet: Wallet = .init(
id: "fd20dc426fb37566d803205b19bbc1d4096b248ac04548e3cfb6b3a38bd033aa",
name: "Coinbase",
homepage: "https://www.coinbase.com/wallet/",
imageId: "a5ebc364-8f91-4200-fcc6-be81310a0000",
order: 4,
mobileLink: nil,
linkMode: nil,
desktopLink: nil,
webappLink: nil,
appStore: "https://apps.apple.com/us/app/coinbase-wallet-nfts-crypto/id1278383455",
alternativeConnectionMethod: {
CoinbaseWalletSDK.shared.initiateHandshake { result, account in
switch result {
case .success:
guard
let account = account,
let blockchain = Blockchain(
namespace: account.chain == "eth" ? "eip155" : "",
reference: String(account.networkId)
)
else { return }

store.connectedWith = .cb
store.account = .init(
address: account.address,
chain: blockchain
)

withAnimation {
store.isModalShown = false
}
AppKit.viewModel.router.setRoute(Router.AccountSubpage.profile)

let matchingChain = ChainPresets.ethChains.first(where: {
$0.chainNamespace == blockchain.namespace && $0.chainReference == blockchain.reference
})

store.selectedChain = matchingChain
case .failure(let error):
store.toast = .init(style: .error, message: error.localizedDescription)
}
}
}
)

wallet.isInstalled = CoinbaseWalletSDK.isCoinbaseWalletInstalled()

store.customWallets.append(wallet)

Task { [wallet] in
try? await w3mApiInteractor.fetchWalletImages(for: [wallet])
}
}
// private static func configureCoinbaseIfNeeded(
// store: Store,
// metadata: AppMetadata,
// w3mApiInteractor: W3MAPIInteractor
// ) {
// guard AppKit.config.coinbaseEnabled else { return }
//
// if let redirectLink = metadata.redirect?.universal ?? metadata.redirect?.native {
// CoinbaseWalletSDK.configure(callback: URL(string: redirectLink)!)
// } else {
// CoinbaseWalletSDK.configure(
// callback: URL(string: "w3mdapp://")!
// )
// }
//
// var wallet: Wallet = .init(
// id: "fd20dc426fb37566d803205b19bbc1d4096b248ac04548e3cfb6b3a38bd033aa",
// name: "Coinbase",
// homepage: "https://www.coinbase.com/wallet/",
// imageId: "a5ebc364-8f91-4200-fcc6-be81310a0000",
// order: 4,
// mobileLink: nil,
// linkMode: nil,
// desktopLink: nil,
// webappLink: nil,
// appStore: "https://apps.apple.com/us/app/coinbase-wallet-nfts-crypto/id1278383455",
// alternativeConnectionMethod: {
// CoinbaseWalletSDK.shared.initiateHandshake { result, account in
// switch result {
// case .success:
// guard
// let account = account,
// let blockchain = Blockchain(
// namespace: account.chain == "eth" ? "eip155" : "",
// reference: String(account.networkId)
// )
// else { return }
//
// store.connectedWith = .cb
// store.account = .init(
// address: account.address,
// chain: blockchain
// )
//
// withAnimation {
// store.isModalShown = false
// }
// AppKit.viewModel.router.setRoute(Router.AccountSubpage.profile)
//
// let matchingChain = ChainPresets.ethChains.first(where: {
// $0.chainNamespace == blockchain.namespace && $0.chainReference == blockchain.reference
// })
//
// store.selectedChain = matchingChain
// case .failure(let error):
// store.toast = .init(style: .error, message: error.localizedDescription)
// }
// }
// }
// )
//
// wallet.isInstalled = CoinbaseWalletSDK.isCoinbaseWalletInstalled()
//
// store.customWallets.append(wallet)
//
// Task { [wallet] in
// try? await w3mApiInteractor.fetchWalletImages(for: [wallet])
// }
// }

}

Expand Down
109 changes: 55 additions & 54 deletions Sources/ReownAppKit/Core/AppKitClient.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import class CoinbaseWalletSDK.CoinbaseWalletSDK
import struct CoinbaseWalletSDK.Action
import struct CoinbaseWalletSDK.ActionError
//import class CoinbaseWalletSDK.CoinbaseWalletSDK
//import struct CoinbaseWalletSDK.Action
//import struct CoinbaseWalletSDK.ActionError
import Combine
import Foundation
import UIKit
Expand Down Expand Up @@ -175,44 +175,44 @@ public class AppKitClient {
)
)
}
case .cb:

guard let jsonRpc = request.toCbAction() else { return }

// Execute on main as Coinbase SDK is not dispatching on main when calling UIApplication.openUrl()
DispatchQueue.main.async {
CoinbaseWalletSDK.shared.makeRequest(
.init(
actions: [
Action(jsonRpc: jsonRpc)
]
)
) { result in
let response: W3MResponse
switch result {
case let .success(payload):

switch payload.content.first {
case let .success(JSONString):
response = .init(result: .response(AnyCodable(JSONString)))
case let .failure(error):
response = .init(result: .error(.init(code: error.code, message: error.message)))
case .none:
response = .init(result: .error(.init(code: -1, message: "Empty response")))
}
case let .failure(error):
AppKit.config.onError(error)

if let cbError = error as? ActionError {
response = .init(result: .error(.init(code: cbError.code, message: cbError.message)))
} else {
response = .init(result: .error(.init(code: -1, message: error.localizedDescription)))
}
}

self.coinbaseResponseSubject.send(response)
}
}
// case .cb:
//
// guard let jsonRpc = request.toCbAction() else { return }
//
// // Execute on main as Coinbase SDK is not dispatching on main when calling UIApplication.openUrl()
// DispatchQueue.main.async {
// CoinbaseWalletSDK.shared.makeRequest(
// .init(
// actions: [
// Action(jsonRpc: jsonRpc)
// ]
// )
// ) { result in
// let response: W3MResponse
// switch result {
// case let .success(payload):
//
// switch payload.content.first {
// case let .success(JSONString):
// response = .init(result: .response(AnyCodable(JSONString)))
// case let .failure(error):
// response = .init(result: .error(.init(code: error.code, message: error.message)))
// case .none:
// response = .init(result: .error(.init(code: -1, message: "Empty response")))
// }
// case let .failure(error):
// AppKit.config.onError(error)
//
// if let cbError = error as? ActionError {
// response = .init(result: .error(.init(code: cbError.code, message: cbError.message)))
// } else {
// response = .init(result: .error(.init(code: -1, message: error.localizedDescription)))
// }
// }
//
// self.coinbaseResponseSubject.send(response)
// }
// }
case .none:
break
}
Expand Down Expand Up @@ -247,13 +247,13 @@ public class AppKitClient {
analyticsService.track(.DISCONNECT_ERROR)
throw error
}
case .cb:
if case let .failure(error) = CoinbaseWalletSDK.shared.resetSession() {
analyticsService.track(.DISCONNECT_ERROR)
throw error
} else {
analyticsService.track(.DISCONNECT_SUCCESS)
}
// case .cb:
// if case let .failure(error) = CoinbaseWalletSDK.shared.resetSession() {
// analyticsService.track(.DISCONNECT_ERROR)
// throw error
// } else {
// analyticsService.track(.DISCONNECT_SUCCESS)
// }
case .none:
break
}
Expand Down Expand Up @@ -330,12 +330,13 @@ public class AppKitClient {
return false
}
}
do {
return try CoinbaseWalletSDK.shared.handleResponse(url)
} catch {
store.toast = .init(style: .error, message: error.localizedDescription)
return false
}
return false
// do {
// return try CoinbaseWalletSDK.shared.handleResponse(url)
// } catch {
// store.toast = .init(style: .error, message: error.localizedDescription)
// return false
// }
}

private func setUpConnectionEvents() {
Expand Down
Loading