Merge pull request #3407 from vladyslav-iosdev/#3403

Indicate which chain for each WalletConnect session more prominently by showing an icon for the chain for each session #3403
pull/3414/head
Hwee-Boon Yar 3 years ago committed by GitHub
commit df502ec871
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      AlphaWallet/Assets.xcassets/Network/Contents.json
  2. 12
      AlphaWallet/Assets.xcassets/Network/icons-network-arbitrum.imageset/Contents.json
  3. BIN
      AlphaWallet/Assets.xcassets/Network/icons-network-arbitrum.imageset/icons-network-arbitrum.pdf
  4. 12
      AlphaWallet/Assets.xcassets/Network/icons-network-artis.imageset/Contents.json
  5. BIN
      AlphaWallet/Assets.xcassets/Network/icons-network-artis.imageset/icons-network-artis.pdf
  6. 12
      AlphaWallet/Assets.xcassets/Network/icons-network-avalanche.imageset/Contents.json
  7. BIN
      AlphaWallet/Assets.xcassets/Network/icons-network-avalanche.imageset/icons-network-avalanche.pdf
  8. 12
      AlphaWallet/Assets.xcassets/Network/icons-network-bsc.imageset/Contents.json
  9. BIN
      AlphaWallet/Assets.xcassets/Network/icons-network-bsc.imageset/icons-network-bsc.pdf
  10. 12
      AlphaWallet/Assets.xcassets/Network/icons-network-callisto.imageset/Contents.json
  11. BIN
      AlphaWallet/Assets.xcassets/Network/icons-network-callisto.imageset/icons-network-callisto.pdf
  12. 12
      AlphaWallet/Assets.xcassets/Network/icons-network-etc.imageset/Contents.json
  13. BIN
      AlphaWallet/Assets.xcassets/Network/icons-network-etc.imageset/icons-network-etc.pdf
  14. 12
      AlphaWallet/Assets.xcassets/Network/icons-network-eth.imageset/Contents.json
  15. BIN
      AlphaWallet/Assets.xcassets/Network/icons-network-eth.imageset/icons-network-eth.pdf
  16. 12
      AlphaWallet/Assets.xcassets/Network/icons-network-fantom.imageset/Contents.json
  17. BIN
      AlphaWallet/Assets.xcassets/Network/icons-network-fantom.imageset/icons-network-fantom.pdf
  18. 12
      AlphaWallet/Assets.xcassets/Network/icons-network-heco.imageset/Contents.json
  19. BIN
      AlphaWallet/Assets.xcassets/Network/icons-network-heco.imageset/icons-network-heco.pdf
  20. 12
      AlphaWallet/Assets.xcassets/Network/icons-network-optimism.imageset/Contents.json
  21. BIN
      AlphaWallet/Assets.xcassets/Network/icons-network-optimism.imageset/icons-network-optimism.pdf
  22. 12
      AlphaWallet/Assets.xcassets/Network/icons-network-palm.imageset/Contents.json
  23. BIN
      AlphaWallet/Assets.xcassets/Network/icons-network-palm.imageset/icons-network-palm.pdf
  24. 12
      AlphaWallet/Assets.xcassets/Network/icons-network-poa.imageset/Contents.json
  25. BIN
      AlphaWallet/Assets.xcassets/Network/icons-network-poa.imageset/icons-network-poa.pdf
  26. 12
      AlphaWallet/Assets.xcassets/Network/icons-network-polygon.imageset/Contents.json
  27. BIN
      AlphaWallet/Assets.xcassets/Network/icons-network-polygon.imageset/icons-network-polygon.pdf
  28. 12
      AlphaWallet/Assets.xcassets/Network/icons-network-xdai.imageset/Contents.json
  29. BIN
      AlphaWallet/Assets.xcassets/Network/icons-network-xdai.imageset/icons-network-xdai.pdf
  30. 21
      AlphaWallet/UI/TokenImageView.swift
  31. 73
      AlphaWallet/UI/TokenObject+UI.swift
  32. 11
      AlphaWallet/WalletConnect/View/WalletConnectSessionCell.swift
  33. 6
      AlphaWallet/WalletConnect/ViewModel/WalletConnectSessionCellViewModel.swift

@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}

@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "icons-network-arbitrum.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "icons-network-artis.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "icons-network-avalanche.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "icons-network-bsc.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "icons-network-callisto.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "icons-network-etc.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "icons-network-eth.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "icons-network-fantom.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "icons-network-heco.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "icons-network-optimism.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "icons-network-palm.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "icons-network-poa.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "icons-network-polygon.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "icons-network-xdai.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

@ -2,6 +2,27 @@
import UIKit import UIKit
class ImageView: UIImageView {
private var subscriptionKey: Subscribable<Image>.SubscribableKey?
var subscribable: Subscribable<Image>? {
didSet {
if let previousSubscribable = oldValue, let subscriptionKey = subscriptionKey {
previousSubscribable.unsubscribe(subscriptionKey)
}
if let subscribable = subscribable {
image = nil
subscriptionKey = subscribable.subscribe { [weak self] image in
self?.image = image
}
} else {
subscriptionKey = nil
image = nil
}
}
}
}
class TokenImageView: UIView { class TokenImageView: UIView {
private var subscriptionKey: Subscribable<TokenImage>.SubscribableKey? private var subscriptionKey: Subscribable<TokenImage>.SubscribableKey?
private let symbolLabel: UILabel = { private let symbolLabel: UILabel = {

@ -4,6 +4,7 @@ import UIKit
import PromiseKit import PromiseKit
typealias TokenImage = (image: UIImage, symbol: String, isFinal: Bool) typealias TokenImage = (image: UIImage, symbol: String, isFinal: Bool)
typealias Image = UIImage
private func programmaticallyGeneratedIconImage(for contractAddress: AlphaWallet.Address, server: RPCServer) -> UIImage { private func programmaticallyGeneratedIconImage(for contractAddress: AlphaWallet.Address, server: RPCServer) -> UIImage {
let backgroundColor = symbolBackgroundColor(for: contractAddress, server: server) let backgroundColor = symbolBackgroundColor(for: contractAddress, server: server)
@ -26,6 +27,78 @@ private func symbolBackgroundColor(for contractAddress: AlphaWallet.Address, ser
} }
} }
extension RPCServer {
var walletConnectIconImage: Subscribable<Image> {
return RPCServerImageFetcher.instance.image(server: self)
}
fileprivate var _walletConnectIconImage: UIImage? {
switch self {
case .main:
return R.image.iconsNetworkEth()
case .xDai:
return R.image.iconsNetworkXdai()
case .poa:
return R.image.iconsNetworkPoa()
case .classic:
return nil
case .callisto:
return R.image.iconsNetworkCallisto()
case .artis_sigma1:
return nil
case .binance_smart_chain:
return R.image.iconsNetworkBsc()
case .kovan, .ropsten, .rinkeby, .sokol, .goerli, .artis_tau1, .binance_smart_chain_testnet, .cronosTestnet, .custom:
return nil
case .heco, .heco_testnet:
return R.image.iconsNetworkHeco()
case .fantom, .fantom_testnet:
return R.image.iconsNetworkFantom()
case .avalanche, .avalanche_testnet:
return R.image.iconsNetworkAvalanche()
case .polygon:
return R.image.iconsNetworkPolygon()
case .mumbai_testnet:
return nil
case .optimistic:
return R.image.iconsNetworkOptimism()
case .optimisticKovan:
return nil
case .arbitrum:
return R.image.iconsNetworkArbitrum()
case .palm, .palmTestnet:
return R.image.iconsTokensPalm()
}
}
}
class RPCServerImageFetcher {
static var instance = RPCServerImageFetcher()
private static var subscribables: ThreadSafeDictionary<Int, Subscribable<Image>> = .init()
private static func programmaticallyGenerateIcon(for server: RPCServer) -> Image {
return UIView.tokenSymbolBackgroundImage(backgroundColor: server.blockChainNameColor)
}
func image(server: RPCServer) -> Subscribable<Image> {
if let sub = Self.subscribables[server.chainID] {
return sub
} else {
let sub = Subscribable<Image>(nil)
Self.subscribables[server.chainID] = sub
if let value = server._walletConnectIconImage {
sub.value = value
} else {
sub.value = Self.programmaticallyGenerateIcon(for: server)
}
return sub
}
}
}
extension TokenObject { extension TokenObject {
fileprivate static let numberOfCharactersOfSymbolToShowInIcon = 4 fileprivate static let numberOfCharactersOfSymbolToShowInIcon = 4

@ -2,7 +2,7 @@
import UIKit import UIKit
class RoundedImageView: UIImageView { class RoundedImageView: ImageView {
init(size: CGSize) { init(size: CGSize) {
super.init(frame: .zero) super.init(frame: .zero)
@ -34,6 +34,11 @@ class WalletConnectSessionCell: UITableViewCell {
return imageView return imageView
}() }()
private let serverIconImageView: RoundedImageView = {
let imageView = RoundedImageView(size: .init(width: 16, height: 16))
return imageView
}()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier) super.init(style: style, reuseIdentifier: reuseIdentifier)
@ -49,8 +54,11 @@ class WalletConnectSessionCell: UITableViewCell {
].asStackView(axis: .horizontal, alignment: .center) ].asStackView(axis: .horizontal, alignment: .center)
stackView.translatesAutoresizingMaskIntoConstraints = false stackView.translatesAutoresizingMaskIntoConstraints = false
contentView.addSubview(stackView) contentView.addSubview(stackView)
contentView.addSubview(serverIconImageView)
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([
serverIconImageView.centerXAnchor.constraint(equalTo: iconImageView.leadingAnchor, constant: 8),
serverIconImageView.centerYAnchor.constraint(equalTo: iconImageView.bottomAnchor, constant: -8),
//NOTE: using edge insets to avoid braking constraints //NOTE: using edge insets to avoid braking constraints
stackView.anchorsConstraint(to: contentView, edgeInsets: .init(top: 20, left: StyleLayout.sideMargin, bottom: 20, right: StyleLayout.sideMargin)) stackView.anchorsConstraint(to: contentView, edgeInsets: .init(top: 20, left: StyleLayout.sideMargin, bottom: 20, right: StyleLayout.sideMargin))
]) ])
@ -66,5 +74,6 @@ class WalletConnectSessionCell: UITableViewCell {
nameLabel.attributedText = viewModel.sessionNameAttributedString nameLabel.attributedText = viewModel.sessionNameAttributedString
urlLabel.attributedText = viewModel.sessionURLAttributedString urlLabel.attributedText = viewModel.sessionURLAttributedString
iconImageView.setImage(url: viewModel.sessionIconURL, placeholder: R.image.walletConnectIcon()) iconImageView.setImage(url: viewModel.sessionIconURL, placeholder: R.image.walletConnectIcon())
serverIconImageView.subscribable = viewModel.serverIconImage
} }
} }

@ -8,7 +8,11 @@ struct WalletConnectSessionCellViewModel {
var backgroundColor: UIColor { var backgroundColor: UIColor {
Colors.appBackground Colors.appBackground
} }
var serverIconImage: Subscribable<Image> {
server.walletConnectIconImage
}
var sessionNameAttributedString: NSAttributedString { var sessionNameAttributedString: NSAttributedString {
return .init(string: "\(session.dAppInfo.peerMeta.name) (\(server.name))", attributes: [ return .init(string: "\(session.dAppInfo.peerMeta.name) (\(server.name))", attributes: [

Loading…
Cancel
Save