|
|
|
@ -3,6 +3,10 @@ |
|
|
|
|
import UIKit |
|
|
|
|
import WebKit |
|
|
|
|
|
|
|
|
|
protocol TokenCardRowViewDelegate { |
|
|
|
|
func heightChangedFor(tokenCardRowView: TokenCardRowView) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class TokenCardRowView: UIView, TokenCardRowViewProtocol { |
|
|
|
|
private let server: RPCServer |
|
|
|
|
private let assetDefinitionStore: AssetDefinitionStore |
|
|
|
@ -43,9 +47,18 @@ class TokenCardRowView: UIView, TokenCardRowViewProtocol { |
|
|
|
|
//TODO pass in keystore or wallet address instead |
|
|
|
|
let walletAddress = EtherKeystore.current!.address |
|
|
|
|
//TODO this can't sign personal message because we didn't set a delegate, but we don't need it also |
|
|
|
|
return TokenInstanceWebView(server: server, walletAddress: walletAddress, assetDefinitionStore: assetDefinitionStore) |
|
|
|
|
let webView = TokenInstanceWebView(server: server, walletAddress: walletAddress, assetDefinitionStore: assetDefinitionStore) |
|
|
|
|
webView.delegate = self |
|
|
|
|
return webView |
|
|
|
|
}() |
|
|
|
|
|
|
|
|
|
//These are necessary because non-TokenScript views have margins whereas TokenScript views doesn't |
|
|
|
|
private var constraintsWithLeadingMarginsThatDependsOnWhetherTokenScriptIsUsed: [NSLayoutConstraint] = [] |
|
|
|
|
private var constraintsWithTrailingMarginsThatDependsOnWhetherTokenScriptIsUsed: [NSLayoutConstraint] = [] |
|
|
|
|
private var constraintsWithTopMarginsThatDependsOnWhetherTokenScriptIsUsed: [NSLayoutConstraint] = [] |
|
|
|
|
private var constraintsWithBottomMarginsThatDependsOnWhetherTokenScriptIsUsed: [NSLayoutConstraint] = [] |
|
|
|
|
|
|
|
|
|
var delegate: TokenCardRowViewDelegate? |
|
|
|
|
let background = UIView() |
|
|
|
|
var checkboxImageView = UIImageView(image: R.image.ticket_bundle_unchecked()) |
|
|
|
|
var stateLabel = UILabel() |
|
|
|
@ -115,9 +128,25 @@ class TokenCardRowView: UIView, TokenCardRowViewProtocol { |
|
|
|
|
|
|
|
|
|
nativelyRenderedAttributeViews = [stateLabel, row0, row1, spaceAboveBottomRowStack, row3, detailsRowStack!] |
|
|
|
|
|
|
|
|
|
constraintsWithLeadingMarginsThatDependsOnWhetherTokenScriptIsUsed = [ |
|
|
|
|
stackView.leadingAnchor.constraint(equalTo: background.leadingAnchor), |
|
|
|
|
] |
|
|
|
|
constraintsWithTrailingMarginsThatDependsOnWhetherTokenScriptIsUsed = [ |
|
|
|
|
background.trailingAnchor.constraint(equalTo: trailingAnchor), |
|
|
|
|
stackView.trailingAnchor.constraint(equalTo: background.trailingAnchor), |
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
constraintsWithTopMarginsThatDependsOnWhetherTokenScriptIsUsed = [ |
|
|
|
|
background.topAnchor.constraint(equalTo: topAnchor), |
|
|
|
|
stackView.topAnchor.constraint(equalTo: background.topAnchor), |
|
|
|
|
] |
|
|
|
|
constraintsWithBottomMarginsThatDependsOnWhetherTokenScriptIsUsed = [ |
|
|
|
|
background.bottomAnchor.constraint(lessThanOrEqualTo: bottomAnchor), |
|
|
|
|
stackView.bottomAnchor.constraint(lessThanOrEqualTo: background.bottomAnchor), |
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
// TODO extract constant. Maybe StyleLayout.sideMargin |
|
|
|
|
let xMargin = CGFloat(7) |
|
|
|
|
let yMargin = CGFloat(5) |
|
|
|
|
checkboxRelatedConstraintsWhenShown.append(checkboxImageView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: xMargin)) |
|
|
|
|
checkboxRelatedConstraintsWhenShown.append(checkboxImageView.centerYAnchor.constraint(equalTo: centerYAnchor)) |
|
|
|
|
checkboxRelatedConstraintsWhenShown.append(background.leadingAnchor.constraint(equalTo: checkboxImageView.trailingAnchor, constant: xMargin)) |
|
|
|
@ -129,7 +158,9 @@ class TokenCardRowView: UIView, TokenCardRowViewProtocol { |
|
|
|
|
checkboxRelatedConstraintsWhenShown.append(checkboxImageView.widthAnchor.constraint(equalToConstant: 28)) |
|
|
|
|
checkboxRelatedConstraintsWhenShown.append(checkboxImageView.heightAnchor.constraint(equalToConstant: 28)) |
|
|
|
|
} |
|
|
|
|
checkboxRelatedConstraintsWhenHidden.append(background.leadingAnchor.constraint(equalTo: leadingAnchor, constant: xMargin)) |
|
|
|
|
let c1 = background.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 0) |
|
|
|
|
constraintsWithLeadingMarginsThatDependsOnWhetherTokenScriptIsUsed.append(c1) |
|
|
|
|
checkboxRelatedConstraintsWhenHidden.append(c1) |
|
|
|
|
if showCheckbox { |
|
|
|
|
NSLayoutConstraint.activate(checkboxRelatedConstraintsWhenShown) |
|
|
|
|
} else { |
|
|
|
@ -137,16 +168,12 @@ class TokenCardRowView: UIView, TokenCardRowViewProtocol { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
NSLayoutConstraint.activate([ |
|
|
|
|
stackView.leadingAnchor.constraint(equalTo: background.leadingAnchor, constant: 21), |
|
|
|
|
stackView.trailingAnchor.constraint(equalTo: background.trailingAnchor, constant: -21), |
|
|
|
|
stackView.topAnchor.constraint(equalTo: background.topAnchor, constant: 16), |
|
|
|
|
stackView.bottomAnchor.constraint(lessThanOrEqualTo: background.bottomAnchor, constant: -16), |
|
|
|
|
|
|
|
|
|
detailsRowStack!.widthAnchor.constraint(equalTo: stackView.widthAnchor), |
|
|
|
|
|
|
|
|
|
background.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -xMargin), |
|
|
|
|
background.topAnchor.constraint(equalTo: topAnchor, constant: yMargin), |
|
|
|
|
background.bottomAnchor.constraint(lessThanOrEqualTo: bottomAnchor, constant: -yMargin), |
|
|
|
|
constraintsWithLeadingMarginsThatDependsOnWhetherTokenScriptIsUsed, |
|
|
|
|
constraintsWithTrailingMarginsThatDependsOnWhetherTokenScriptIsUsed, |
|
|
|
|
constraintsWithTopMarginsThatDependsOnWhetherTokenScriptIsUsed, |
|
|
|
|
constraintsWithBottomMarginsThatDependsOnWhetherTokenScriptIsUsed, |
|
|
|
|
|
|
|
|
|
tokenScriptRendererView.widthAnchor.constraint(equalTo: stackView.widthAnchor), |
|
|
|
|
|
|
|
|
@ -259,6 +286,35 @@ class TokenCardRowView: UIView, TokenCardRowViewProtocol { |
|
|
|
|
tokenScriptRendererView.isHidden = true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for each in constraintsWithLeadingMarginsThatDependsOnWhetherTokenScriptIsUsed { |
|
|
|
|
if viewModel.hasTokenScriptHtml { |
|
|
|
|
each.constant = 0 |
|
|
|
|
} else { |
|
|
|
|
each.constant = 7 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
for each in constraintsWithTrailingMarginsThatDependsOnWhetherTokenScriptIsUsed { |
|
|
|
|
if viewModel.hasTokenScriptHtml { |
|
|
|
|
each.constant = 0 |
|
|
|
|
} else { |
|
|
|
|
each.constant = -7 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
for each in constraintsWithTopMarginsThatDependsOnWhetherTokenScriptIsUsed { |
|
|
|
|
if viewModel.hasTokenScriptHtml { |
|
|
|
|
each.constant = 0 |
|
|
|
|
} else { |
|
|
|
|
each.constant = 5 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
for each in constraintsWithBottomMarginsThatDependsOnWhetherTokenScriptIsUsed { |
|
|
|
|
if viewModel.hasTokenScriptHtml { |
|
|
|
|
each.constant = 0 |
|
|
|
|
} else { |
|
|
|
|
each.constant = -5 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
adjustmentsToHandleWhenCategoryLabelTextIsTooLong() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -273,3 +329,17 @@ extension TokenCardRowView: TokenRowView { |
|
|
|
|
configure(viewModel: TokenCardRowViewModel(tokenHolder: tokenHolder, tokenView: tokenView, assetDefinitionStore: assetDefinitionStore)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
extension TokenCardRowView: TokenInstanceWebViewDelegate { |
|
|
|
|
func navigationControllerFor(tokenInstanceWebView: TokenInstanceWebView) -> UINavigationController? { |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func shouldClose(tokenInstanceWebView: TokenInstanceWebView) { |
|
|
|
|
//no-op |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func heightChangedFor(tokenInstanceWebView: TokenInstanceWebView) { |
|
|
|
|
delegate?.heightChangedFor(tokenCardRowView: self) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|