Add a `.prebuilt` transaction type. For upcoming native swap support. In the future, this can also be used to refactor code that handles existing transactions that are pre-built

pull/4129/head
Hwee-Boon Yar 3 years ago
parent 4243993b23
commit 93c70189a9
  1. 2
      AlphaWallet/Activities/Types/ActivitiesFilterStrategy.swift
  2. 6
      AlphaWallet/Core/SwapToken/SwapTokenService.swift
  3. 2
      AlphaWallet/InCoordinator.swift
  4. 2
      AlphaWallet/Tokens/Coordinators/SingleChainTokenCoordinator.swift
  5. 2
      AlphaWallet/Tokens/ViewControllers/TokenViewController.swift
  6. 6
      AlphaWallet/Tokens/ViewModels/TokenViewControllerViewModel.swift
  7. 4
      AlphaWallet/Transactions/Coordinators/ReplaceTransactionCoordinator.swift
  8. 5
      AlphaWallet/Transfer/Controllers/TransactionConfigurator.swift
  9. 2
      AlphaWallet/Transfer/Coordinators/PaymentCoordinator.swift
  10. 2
      AlphaWallet/Transfer/Coordinators/SendCoordinator.swift
  11. 15
      AlphaWallet/Transfer/Types/TransactionType.swift
  12. 6
      AlphaWallet/Transfer/ViewControllers/SendViewController.swift
  13. 4
      AlphaWallet/Transfer/ViewControllers/TransactionConfirmationViewController.swift
  14. 2
      AlphaWallet/Transfer/ViewModels/ConfigureTransactionViewModel.swift
  15. 2
      AlphaWallet/Transfer/ViewModels/SendHeaderViewViewModel.swift
  16. 18
      AlphaWallet/Transfer/ViewModels/SendViewModel.swift
  17. 4
      AlphaWallet/Transfer/ViewModels/TransactionConfirmationViewModel.swift

@ -44,7 +44,7 @@ extension TransactionType {
return .contract(contract: tokenObject.contractAddress)
case .erc721Token(let tokenObject, _), .erc721ForTicketToken(let tokenObject, _), .erc1155Token(let tokenObject, _, _):
return .operationTypes(operationTypes: [], contract: tokenObject.contractAddress)
case .dapp, .claimPaidErc875MagicLink, .tokenScript:
case .dapp, .claimPaidErc875MagicLink, .tokenScript, .prebuilt:
return .none
}
}

@ -26,7 +26,7 @@ struct TokenActionsServiceKey {
protocol TokenActionsProvider {
func isSupport(token: TokenActionsServiceKey) -> Bool
func actions(token: TokenActionsServiceKey) -> [TokenInstanceAction]
}
}
protocol SwapTokenURLProviderType {
var action: String { get }
@ -42,7 +42,7 @@ protocol TokenActionsServiceType: TokenActionsProvider {
}
class TokenActionsService: TokenActionsServiceType {
private var services: [TokenActionsProvider] = []
func register(service: TokenActionsProvider) {
@ -73,7 +73,7 @@ extension TransactionType {
return TokenActionsServiceKey(tokenObject: token)
case .erc20Token(let token, _, _):
return TokenActionsServiceKey(tokenObject: token)
case .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token, .dapp, .tokenScript, .claimPaidErc875MagicLink:
case .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token, .dapp, .tokenScript, .claimPaidErc875MagicLink, .prebuilt:
return nil
}
}

@ -981,7 +981,7 @@ extension InCoordinator: TokensCoordinatorDelegate {
} else {
open(for: url)
}
case .erc875TokenOrder, .erc721ForTicketToken, .dapp, .tokenScript, .claimPaidErc875MagicLink:
case .erc875TokenOrder, .erc721ForTicketToken, .dapp, .tokenScript, .claimPaidErc875MagicLink, .prebuilt:
break
}
}

@ -319,7 +319,7 @@ extension SingleChainTokenCoordinator: TokenViewControllerDelegate {
switch transactionType {
case .erc20Token(let erc20Token, _, _):
token = erc20Token
case .dapp, .erc721Token, .erc875Token, .erc875TokenOrder, .erc721ForTicketToken, .erc1155Token, .tokenScript, .claimPaidErc875MagicLink:
case .dapp, .erc721Token, .erc875Token, .erc875TokenOrder, .erc721ForTicketToken, .erc1155Token, .tokenScript, .claimPaidErc875MagicLink, .prebuilt:
return
case .nativeCryptocurrency:
token = MultipleChainsTokensDataStore.functional.etherToken(forServer: server)

@ -238,7 +238,7 @@ class TokenViewController: UIViewController {
strongSelf.tokenInfoPageView.viewModel.currencyAmount = viewModel.currencyAmount
strongSelf.configure(viewModel: strongSelf.viewModel)
}.store(in: &cancelable)
case .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token, .dapp, .tokenScript, .claimPaidErc875MagicLink:
case .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token, .dapp, .tokenScript, .claimPaidErc875MagicLink, .prebuilt:
break
}
}

@ -19,7 +19,7 @@ struct TokenViewControllerViewModel {
return MultipleChainsTokensDataStore.functional.etherToken(forServer: session.server)
case .erc20Token(let token, _, _):
return token
case .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token, .dapp, .tokenScript, .claimPaidErc875MagicLink:
case .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token, .dapp, .tokenScript, .claimPaidErc875MagicLink, .prebuilt:
return nil
}
}
@ -98,7 +98,7 @@ struct TokenViewControllerViewModel {
return session.tokenBalanceService.ethBalanceViewModel.value
case .erc20Token(let tokenObject, _, _):
return tokenObject.valueBigInt
case .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token, .dapp, .tokenScript, .claimPaidErc875MagicLink:
case .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token, .dapp, .tokenScript, .claimPaidErc875MagicLink, .prebuilt:
return nil
}
}
@ -110,7 +110,7 @@ struct TokenViewControllerViewModel {
return session.tokenBalanceService.coinTicker(etherToken.addressAndRPCServer) != nil
case .erc20Token(let token, _, _):
return session.tokenBalanceService.coinTicker(token.addressAndRPCServer) != nil
case .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token, .dapp, .tokenScript, .claimPaidErc875MagicLink:
case .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token, .dapp, .tokenScript, .claimPaidErc875MagicLink, .prebuilt:
return false
}
}

@ -30,7 +30,7 @@ class ReplaceTransactionCoordinator: Coordinator {
switch transactionType {
case .nativeCryptocurrency:
return AlphaWallet.Address(string: transaction.to)
case .dapp, .erc20Token, .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token, .tokenScript, .claimPaidErc875MagicLink:
case .dapp, .erc20Token, .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token, .tokenScript, .claimPaidErc875MagicLink, .prebuilt:
return nil
}
}
@ -38,7 +38,7 @@ class ReplaceTransactionCoordinator: Coordinator {
switch transactionType {
case .nativeCryptocurrency:
return nil
case .dapp, .erc20Token, .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token, .tokenScript, .claimPaidErc875MagicLink:
case .dapp, .erc20Token, .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token, .tokenScript, .claimPaidErc875MagicLink, .prebuilt:
return AlphaWallet.Address(string: transaction.to)
}
}

@ -98,7 +98,7 @@ class TransactionConfigurator {
switch transaction.transactionType {
case .nativeCryptocurrency:
return transaction.recipient
case .dapp, .erc20Token, .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token, .tokenScript, .claimPaidErc875MagicLink:
case .dapp, .erc20Token, .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token, .tokenScript, .claimPaidErc875MagicLink, .prebuilt:
return transaction.contract
}
}
@ -115,6 +115,7 @@ class TransactionConfigurator {
case .erc1155Token: return 0
case .tokenScript: return transaction.value
case .claimPaidErc875MagicLink: return transaction.value
case .prebuilt: return transaction.value
}
}
@ -443,6 +444,8 @@ class TransactionConfigurator {
}
case .claimPaidErc875MagicLink:
return createConfiguration(server: server, transaction: transaction, gasLimit: transaction.gasLimit ?? GasLimitConfiguration.maxGasLimit, data: transaction.data ?? .init())
case .prebuilt:
return createConfiguration(server: server, transaction: transaction, gasLimit: transaction.gasLimit ?? GasLimitConfiguration.maxGasLimit, data: transaction.data ?? .init())
}
} catch {
return .init(transaction: transaction)

@ -96,7 +96,7 @@ class PaymentCoordinator: Coordinator {
switch transactionType {
case .erc1155Token(let tokenObject, let transferType, let tokenHolders):
startWithSendCollectiblesCoordinator(tokenObject: tokenObject, transferType: transferType, tokenHolders: tokenHolders)
case .nativeCryptocurrency, .erc20Token, .dapp, .claimPaidErc875MagicLink, .tokenScript, .erc875TokenOrder:
case .nativeCryptocurrency, .erc20Token, .dapp, .claimPaidErc875MagicLink, .tokenScript, .erc875TokenOrder, .prebuilt:
startWithSendCoordinator(transactionType: transactionType)
case .erc875Token(let tokenObject, let tokenHolders), .erc721Token(let tokenObject, let tokenHolders):
startWithSendNFTCoordinator(transactionType: transactionType, tokenObject: tokenObject, tokenHolder: tokenHolders[0])

@ -70,7 +70,7 @@ class SendCoordinator: Coordinator {
case .erc20Token(_, let destination, let amount):
controller.targetAddressTextField.value = destination?.stringValue ?? ""
controller.amountTextField.ethCost = amount ?? ""
case .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token, .dapp, .tokenScript, .claimPaidErc875MagicLink:
case .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token, .dapp, .tokenScript, .claimPaidErc875MagicLink, .prebuilt:
break
}
controller.delegate = self

@ -56,6 +56,8 @@ enum TransactionType {
case dapp(TokenObject, DAppRequester)
case claimPaidErc875MagicLink(TokenObject)
case tokenScript(TokenObject)
//TODO replace some of those above with this?
case prebuilt(RPCServer)
var contractForFungibleSend: AlphaWallet.Address? {
switch self {
@ -63,7 +65,7 @@ enum TransactionType {
return nil
case .erc20Token(let token, _, _):
return token.contractAddress
case .dapp, .tokenScript, .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token, .claimPaidErc875MagicLink:
case .dapp, .tokenScript, .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token, .claimPaidErc875MagicLink, .prebuilt:
return nil
}
}
@ -95,6 +97,9 @@ extension TransactionType {
return token.symbol
case .claimPaidErc875MagicLink(let token):
return token.symbol
case .prebuilt:
//Not applicable
return ""
}
}
@ -118,6 +123,9 @@ extension TransactionType {
return token
case .claimPaidErc875MagicLink(let token):
return token
case .prebuilt(let server):
//Not applicable
return MultipleChainsTokensDataStore.functional.etherToken(forServer: server)
}
}
@ -141,6 +149,8 @@ extension TransactionType {
return token.server
case .claimPaidErc875MagicLink(let token):
return token.server
case .prebuilt(let server):
return server
}
}
@ -162,6 +172,9 @@ extension TransactionType {
return token.contractAddress
case .dapp(let token, _), .tokenScript(let token), .claimPaidErc875MagicLink(let token):
return token.contractAddress
case .prebuilt:
//We don't care about the contract for prebuilt transactions
return Constants.nativeCryptoAddressInDatabase
}
}
}

@ -159,7 +159,7 @@ class SendViewController: UIViewController {
if let amount = amount {
amountTextField.ethCost = amount
}
case .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token, .dapp, .tokenScript, .claimPaidErc875MagicLink:
case .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token, .dapp, .tokenScript, .claimPaidErc875MagicLink, .prebuilt:
etherToFiatRateCancelable?.cancel()
amountTextField.cryptoToDollarRate = nil
}
@ -239,7 +239,7 @@ class SendViewController: UIViewController {
case .erc20Token(let token, let recipient, let amount):
let amount = amount.flatMap { EtherNumberFormatter.plain.number(from: $0, decimals: token.decimals) }
configureFor(contract: viewModel.transactionType.contract, recipient: recipient, amount: amount, shouldConfigureBalance: false)
case .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token, .dapp, .tokenScript, .claimPaidErc875MagicLink:
case .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token, .dapp, .tokenScript, .claimPaidErc875MagicLink, .prebuilt:
break
}
}
@ -325,7 +325,7 @@ class SendViewController: UIViewController {
transactionType = TransactionType(fungibleToken: tokenObject, recipient: recipient, amount: amount.flatMap { EtherNumberFormatter().string(from: $0, units: .ether) })
case .erc20Token(_, _, let amount):
transactionType = TransactionType(fungibleToken: tokenObject, recipient: recipient, amount: amount)
case .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token, .dapp, .tokenScript, .claimPaidErc875MagicLink:
case .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token, .dapp, .tokenScript, .claimPaidErc875MagicLink, .prebuilt:
transactionType = TransactionType(fungibleToken: tokenObject, recipient: recipient, amount: nil)
}
}

@ -202,7 +202,7 @@ class TransactionConfirmationViewController: UIViewController {
sendFungiblesViewModel.session.refresh(.ethBalance)
case .erc20Token(let token, _, _):
sendFungiblesViewModel.updateBalance(.erc20(token: token))
case .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token, .dapp, .tokenScript, .claimPaidErc875MagicLink:
case .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token, .dapp, .tokenScript, .claimPaidErc875MagicLink, .prebuilt:
break
}
case .sendNftTransaction(let sendNftViewModel):
@ -333,7 +333,7 @@ class TransactionConfirmationViewController: UIViewController {
let balanceBaseViewModel = sendFungiblesViewModel.session.tokenBalanceService.ethBalanceViewModel
sendFungiblesViewModel.updateBalance(.nativeCryptocurrency(balanceViewModel: balanceBaseViewModel))
case .erc20Token, .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token, .dapp, .tokenScript, .claimPaidErc875MagicLink:
case .erc20Token, .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token, .dapp, .tokenScript, .claimPaidErc875MagicLink, .prebuilt:
break
}
case .sendNftTransaction, .claimPaidErc875MagicLink:

@ -61,7 +61,7 @@ struct ConfigureTransactionViewModel {
var isDataInputHidden: Bool {
switch transactionType {
case .nativeCryptocurrency, .dapp, .tokenScript, .claimPaidErc875MagicLink:
case .nativeCryptocurrency, .dapp, .tokenScript, .claimPaidErc875MagicLink, .prebuilt:
return false
case .erc20Token, .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token:
return true

@ -241,7 +241,7 @@ struct TokenInfoPageViewModel {
} else {
return marketPriceAttributedString
}
case .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token, .dapp, .tokenScript, .claimPaidErc875MagicLink:
case .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token, .dapp, .tokenScript, .claimPaidErc875MagicLink, .prebuilt:
return nil
}
}

@ -48,7 +48,7 @@ struct SendViewModel {
return token
case .erc1155Token(let token, _, _):
return token
case .dapp, .tokenScript, .claimPaidErc875MagicLink:
case .dapp, .tokenScript, .claimPaidErc875MagicLink, .prebuilt:
return nil
}
}
@ -79,7 +79,7 @@ struct SendViewModel {
return true
}
return false
case .erc20Token, .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token, .dapp, .tokenScript, .claimPaidErc875MagicLink:
case .erc20Token, .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token, .dapp, .tokenScript, .claimPaidErc875MagicLink, .prebuilt:
return true
}
}
@ -88,7 +88,7 @@ struct SendViewModel {
switch transactionType {
case .nativeCryptocurrency, .erc20Token:
return false
case .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token, .dapp, .tokenScript, .claimPaidErc875MagicLink:
case .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token, .dapp, .tokenScript, .claimPaidErc875MagicLink, .prebuilt:
return true
}
}
@ -100,7 +100,7 @@ struct SendViewModel {
case .erc20Token(let token, _, _):
let value = EtherNumberFormatter.short.string(from: token.valueBigInt, decimals: token.decimals)
return R.string.localizable.sendAvailable("\(value) \(transactionType.symbol)")
case .dapp, .erc721ForTicketToken, .erc721Token, .erc875Token, .erc875TokenOrder, .erc1155Token, .tokenScript, .claimPaidErc875MagicLink:
case .dapp, .erc721ForTicketToken, .erc721Token, .erc875Token, .erc875TokenOrder, .erc1155Token, .tokenScript, .claimPaidErc875MagicLink, .prebuilt:
break
}
@ -114,7 +114,7 @@ struct SendViewModel {
case .erc20Token(let token, _, _):
let tokenBalance = tokensDataStore.token(forContract: token.contractAddress, server: session.server)?.valueBigInt
return tokenBalance == nil
case .dapp, .erc721ForTicketToken, .erc721Token, .erc875Token, .erc1155Token, .erc875TokenOrder, .tokenScript, .claimPaidErc875MagicLink:
case .dapp, .erc721ForTicketToken, .erc721Token, .erc875Token, .erc1155Token, .erc875TokenOrder, .tokenScript, .claimPaidErc875MagicLink, .prebuilt:
break
}
return true
@ -122,7 +122,7 @@ struct SendViewModel {
var checkIfGreaterThanZero: Bool {
switch transactionType {
case .nativeCryptocurrency, .dapp, .tokenScript, .claimPaidErc875MagicLink:
case .nativeCryptocurrency, .dapp, .tokenScript, .claimPaidErc875MagicLink, .prebuilt:
return false
case .erc20Token, .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token:
return true
@ -142,7 +142,7 @@ struct SendViewModel {
let shortValue = EtherNumberFormatter.shortPlain.string(from: token.valueBigInt, decimals: token.decimals).droppedTrailingZeros
return (fullValue.optionalDecimalValue, shortValue)
case .dapp, .erc721ForTicketToken, .erc721Token, .erc875Token, .erc1155Token, .erc875TokenOrder, .tokenScript, .claimPaidErc875MagicLink:
case .dapp, .erc721ForTicketToken, .erc721Token, .erc875Token, .erc1155Token, .erc875TokenOrder, .tokenScript, .claimPaidErc875MagicLink, .prebuilt:
return nil
}
}
@ -150,7 +150,7 @@ struct SendViewModel {
func validatedAmount(value amountString: String, checkIfGreaterThanZero: Bool = true) -> BigInt? {
let parsedValue: BigInt? = {
switch transactionType {
case .nativeCryptocurrency, .dapp, .tokenScript, .claimPaidErc875MagicLink:
case .nativeCryptocurrency, .dapp, .tokenScript, .claimPaidErc875MagicLink, .prebuilt:
return EtherNumberFormatter.full.number(from: amountString, units: .ether)
case .erc20Token(let token, _, _):
return EtherNumberFormatter.full.number(from: amountString, decimals: token.decimals)
@ -180,7 +180,7 @@ struct SendViewModel {
if let tokenBalance = tokensDataStore.token(forContract: token.contractAddress, server: session.server)?.valueBigInt, tokenBalance < value {
return nil
}
case .dapp, .erc721ForTicketToken, .erc721Token, .erc875Token, .erc1155Token, .erc875TokenOrder, .tokenScript, .claimPaidErc875MagicLink:
case .dapp, .erc721ForTicketToken, .erc721Token, .erc875Token, .erc1155Token, .erc875TokenOrder, .tokenScript, .claimPaidErc875MagicLink, .prebuilt:
break
}

@ -235,7 +235,7 @@ extension TransactionConfirmationViewModel {
} else {
return "\(amount.value) \(token.symbol)"
}
case .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token, .dapp, .tokenScript, .claimPaidErc875MagicLink:
case .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token, .dapp, .tokenScript, .claimPaidErc875MagicLink, .prebuilt:
return String()
}
}
@ -608,7 +608,7 @@ extension TransactionConfirmationViewModel {
}
return .init(title: .normal(viewModels.first ?? "-"), headerName: headerName, configuration: configuration)
case .nativeCryptocurrency, .erc20Token, .erc721Token, .claimPaidErc875MagicLink, .erc875Token, .erc875TokenOrder, .erc721ForTicketToken, .dapp, .tokenScript:
case .nativeCryptocurrency, .erc20Token, .erc721Token, .claimPaidErc875MagicLink, .erc875Token, .erc875TokenOrder, .erc721ForTicketToken, .dapp, .tokenScript, .prebuilt:
//This is really just for ERC721, but the type system
let tokenId = configurator.transaction.tokenId.flatMap({ String($0) })
let title: String

Loading…
Cancel
Save