Add development flag `Config.development.shouldPretendIsRealWallet` so we can force watch wallets to proceed to sign (and fail), etc

pull/3928/head
Hwee-Boon Yar 3 years ago
parent 1f92c7beef
commit a657023da6
  1. 4
      AlphaWallet/Browser/Coordinators/DappBrowserCoordinator.swift
  2. 19
      AlphaWallet/Redeem/ViewControllers/TokenCardRedemptionViewController.swift
  3. 2
      AlphaWallet/Settings/Types/Config.swift
  4. 19
      AlphaWallet/Tokens/Collectibles/ViewControllers/TokensCardCollectionViewController.swift
  5. 19
      AlphaWallet/Tokens/ViewControllers/TokenInstanceViewController.swift
  6. 19
      AlphaWallet/Tokens/ViewControllers/TokenViewController.swift
  7. 19
      AlphaWallet/Tokens/ViewControllers/TokensCardViewController.swift
  8. 19
      AlphaWallet/Tokens/Views/TokenInstanceWebView.swift
  9. 16
      AlphaWallet/Transfer/Coordinators/PaymentCoordinator.swift
  10. 5
      AlphaWallet/WalletConnect/Coordinator/WalletConnectCoordinator.swift

@ -517,6 +517,9 @@ extension DappBrowserCoordinator: BrowserViewControllerDelegate {
case .real(let account):
return performDappAction(account: account)
case .watch(let account):
if config.development.shouldPretendIsRealWallet {
return performDappAction(account: account)
} else {
switch action {
case .signTransaction, .sendTransaction, .signMessage, .signPersonalMessage, .signTypedMessage, .signTypedMessageV3, .unknown, .sendRawTransaction:
return rejectDappAction()
@ -525,6 +528,7 @@ extension DappBrowserCoordinator: BrowserViewControllerDelegate {
}
}
}
}
func didVisitURL(url: URL, title: String, inBrowserViewController viewController: BrowserViewController) {
browserNavBar?.display(url: url)

@ -114,16 +114,25 @@ class TokenCardRedemptionViewController: UIViewController, TokenVerifiableStatus
case .erc721, .erc721ForTickets:
redeemData = redeem.redeemMessage(tokenIds: viewModel.tokenHolder.tokens.map({ $0.id }))
}
switch session.account.type {
case .real(let account):
func _generateQr(account: AlphaWallet.Address) {
do {
guard let decimalSignature = try SignatureHelper.signatureAsDecimal(for: redeemData.message, account: account, analyticsCoordinator: analyticsCoordinator) else { break }
guard let decimalSignature = try SignatureHelper.signatureAsDecimal(for: redeemData.message, account: account, analyticsCoordinator: analyticsCoordinator) else { return }
let qrCodeInfo = redeemData.qrCode + decimalSignature
imageView.image = qrCodeInfo.toQRCode()
} catch {
break
//no-op
}
}
switch session.account.type {
case .real(let account):
_generateQr(account: account)
case .watch(let account):
//TODO should pass in a Config instance instead
if Config().development.shouldPretendIsRealWallet {
_generateQr(account: account)
} else {
//no-op
}
case .watch: break
}
}

@ -9,6 +9,8 @@ struct Config {
let shouldReadClipboardForWalletConnectUrl = false
///Useful to reduce network calls
let isAutoFetchingDisabled = false
///Should only be used to allow users to take paths where the current wallet is real, not watched, e.g sign buttons are enabled. Some of those actions will fail, understandably. Should not display a watch wallet as if it is a real wallet though
let shouldPretendIsRealWallet = false
}
let development = Development()

@ -151,21 +151,30 @@ class TokensCardCollectionViewController: UIViewController {
buttonsBar.configure(.combined(buttons: viewModel.actions.count))
buttonsBar.viewController = self
for (action, button) in zip(actions, buttonsBar.buttons) {
button.setTitle(action.name, for: .normal)
button.addTarget(self, action: #selector(actionButtonTapped), for: .touchUpInside)
switch session.account.type {
case .real:
func _configButton(action: TokenInstanceAction, button: BarButton) {
if let selection = action.activeExcludingSelection(selectedTokenHolder: viewModel.tokenHolders[0], tokenId: viewModel.tokenHolders[0].tokenId, forWalletAddress: session.account.address, fungibleBalance: viewModel.fungibleBalance) {
if selection.denial == nil {
button.displayButton = false
}
}
}
for (action, button) in zip(actions, buttonsBar.buttons) {
button.setTitle(action.name, for: .normal)
button.addTarget(self, action: #selector(actionButtonTapped), for: .touchUpInside)
switch session.account.type {
case .real:
_configButton(action: action, button: button)
case .watch:
//TODO pass in Config instance instead
if Config().development.shouldPretendIsRealWallet {
_configButton(action: action, button: button)
} else {
button.isEnabled = false
}
}
}
}
private func updateNavigationRightBarButtons(tokenScriptFileStatusHandler xmlHandler: XMLHandler) {
let tokenScriptStatusPromise = xmlHandler.tokenScriptStatus

@ -134,22 +134,31 @@ class TokenInstanceViewController: UIViewController, TokenVerifiableStatusViewCo
buttonsBar.configure(.combined(buttons: viewModel.actions.count))
buttonsBar.viewController = self
func _configButton(action: TokenInstanceAction, button: BarButton) {
if let selection = action.activeExcludingSelection(selectedTokenHolders: [tokenHolder], forWalletAddress: account.address) {
if selection.denial == nil {
button.displayButton = false
}
}
}
for (index, button) in buttonsBar.buttons.enumerated() {
let action = viewModel.actions[index]
button.setTitle(action.name, for: .normal)
button.addTarget(self, action: #selector(actionButtonTapped), for: .touchUpInside)
switch account.type {
case .real:
if let selection = action.activeExcludingSelection(selectedTokenHolders: [tokenHolder], forWalletAddress: account.address) {
if selection.denial == nil {
button.displayButton = false
}
}
_configButton(action: action, button: button)
case .watch:
//TODO pass in a Config instance instead
if Config().development.shouldPretendIsRealWallet {
_configButton(action: action, button: button)
} else {
button.isEnabled = false
}
}
}
}
let url = tokenHolder.values.imageUrlUrlValue ?? tokenHolder.values.thumbnailUrlUrlValue
bigImageView.setImage(url: url, placeholder: viewModel.tokenImagePlaceholder)

@ -137,21 +137,30 @@ class TokenViewController: UIViewController {
buttonsBar.configure(.combined(buttons: viewModel.actions.count))
buttonsBar.viewController = self
for (action, button) in zip(actions, buttonsBar.buttons) {
button.setTitle(action.name, for: .normal)
button.addTarget(self, action: #selector(actionButtonTapped), for: .touchUpInside)
switch session.account.type {
case .real:
func _configButton(action: TokenInstanceAction, viewModel: TokenViewControllerViewModel, button: BarButton) {
if let tokenHolder = generateTokenHolder(), let selection = action.activeExcludingSelection(selectedTokenHolders: [tokenHolder], forWalletAddress: session.account.address, fungibleBalance: viewModel.fungibleBalance) {
if selection.denial == nil {
button.displayButton = false
}
}
}
for (action, button) in zip(actions, buttonsBar.buttons) {
button.setTitle(action.name, for: .normal)
button.addTarget(self, action: #selector(actionButtonTapped), for: .touchUpInside)
switch session.account.type {
case .real:
_configButton(action: action, viewModel: viewModel, button: button)
case .watch:
//TODO pass in Config instance instead
if Config().development.shouldPretendIsRealWallet {
_configButton(action: action, viewModel: viewModel, button: button)
} else {
button.isEnabled = false
}
}
}
}
private func refreshTokenViewControllerUponAssetDefinitionChanges(forTransactionType transactionType: TransactionType) {
assetDefinitionStore.subscribeToBodyChanges { [weak self] contract in

@ -156,21 +156,30 @@ class TokensCardViewController: UIViewController {
buttonsBar.configure(.combined(buttons: viewModel.actions.count))
buttonsBar.viewController = self
for (action, button) in zip(actions, buttonsBar.buttons) {
button.setTitle(action.name, for: .normal)
button.addTarget(self, action: #selector(actionButtonTapped), for: .touchUpInside)
switch session.account.type {
case .real:
func _configButton(action: TokenInstanceAction, button: BarButton) {
if let selection = action.activeExcludingSelection(selectedTokenHolder: viewModel.tokenHolders[0], tokenId: viewModel.tokenHolders[0].tokenId, forWalletAddress: session.account.address, fungibleBalance: viewModel.fungibleBalance) {
if selection.denial == nil {
button.displayButton = false
}
}
}
for (action, button) in zip(actions, buttonsBar.buttons) {
button.setTitle(action.name, for: .normal)
button.addTarget(self, action: #selector(actionButtonTapped), for: .touchUpInside)
switch session.account.type {
case .real:
_configButton(action: action, button: button)
case .watch:
//TODO pass in a Config instance instead
if Config().development.shouldPretendIsRealWallet {
_configButton(action: action, button: button)
} else {
button.isEnabled = false
}
}
}
}
private func updateNavigationRightBarButtons(tokenScriptFileStatusHandler xmlHandler: XMLHandler) {
let tokenScriptStatusPromise = xmlHandler.tokenScriptStatus

@ -444,20 +444,29 @@ extension TokenInstanceWebView: WKScriptMessageHandler {
let token = TokensDataStore.token(forServer: server)
let action = DappAction.fromCommand(.eth(command), server: server, transactionType: .dapp(token, requester))
switch wallet.type {
case .real(let account):
func _sign(action: DappAction, command: DappCommand, account: AlphaWallet.Address) {
switch action {
case .signPersonalMessage(let hexMessage):
let msg = convertMessageToHex(msg: hexMessage)
let callbackID = command.id
signMessage(with: .personalMessage(Data(_hex: msg)), account: account, callbackID: callbackID)
case .signTransaction, .sendTransaction, .signMessage, .signTypedMessage, .unknown, .sendRawTransaction, .signTypedMessageV3, .ethCall, .walletAddEthereumChain, .walletSwitchEthereumChain:
return
}
case .watch:
break
}
}
switch wallet.type {
case .real(let account):
_sign(action: action, command: command, account: account)
case .watch(let account):
//TODO pass in Config instance instead
if Config().development.shouldPretendIsRealWallet {
_sign(action: action, command: command, account: account)
} else {
//no-op
}
}
}
}
//Block navigation. Still good to have even if we end up using XSLT?

@ -94,8 +94,7 @@ class PaymentCoordinator: Coordinator {
self.navigationController.setNavigationBarHidden(false, animated: true)
}
switch (flow, session.account.type) {
case (.send(let transactionType), .real):
func _startPaymentFlow(transactionType: PaymentFlowType) {
switch transactionType {
case .transaction(let transactionType):
switch transactionType {
@ -111,14 +110,23 @@ class PaymentCoordinator: Coordinator {
case .tokenScript(let action, let tokenObject, let tokenHolder):
startWithTokenScriptCoordinator(action: action, tokenObject: tokenObject, tokenHolder: tokenHolder)
}
}
switch (flow, session.account.type) {
case (.send(let transactionType), .real):
_startPaymentFlow(transactionType: transactionType)
case (.request, _):
let coordinator = RequestCoordinator(navigationController: navigationController, account: session.account)
coordinator.delegate = self
coordinator.start()
addCoordinator(coordinator)
case (.send, .watch):
case (.send(let transactionType), .watch):
//TODO pass in a config instance instead
if Config().development.shouldPretendIsRealWallet {
_startPaymentFlow(transactionType: transactionType)
} else {
//TODO: This case should be returning an error inCoordinator. Improve this logic into single piece.
break
}
}
}

@ -202,10 +202,15 @@ private extension WalletType {
case .real:
return .value(())
case .watch:
//TODO pass in Config instance instead
if Config().development.shouldPretendIsRealWallet {
return .value(())
} else {
return .init(error: WalletConnectCoordinator.RequestCanceledDueToWatchWalletError())
}
}
}
}
extension WalletConnectCoordinator: WalletConnectServerDelegate {
struct RequestCanceledDueToWatchWalletError: Error {

Loading…
Cancel
Save