add transfer config for erc721 and add case for erc721

pull/520/head
James Sangalli 6 years ago
parent 6da0dd50b9
commit b25965afe7
  1. 12
      AlphaWallet.xcodeproj/project.pbxproj
  2. 1
      AlphaWallet/Browser/Types/DappAction.swift
  3. 1
      AlphaWallet/InCoordinator.swift
  4. 2
      AlphaWallet/Tokens/Coordinators/TokensCoordinator.swift
  5. 36
      AlphaWallet/Transfer/Controllers/TransactionConfigurator.swift
  6. 3
      AlphaWallet/Transfer/Coordinators/SendCoordinator.swift
  7. 1
      AlphaWallet/Transfer/Coordinators/TransferTicketsCoordinator.swift
  8. 11
      AlphaWallet/Transfer/Types/TransferType.swift
  9. 1
      AlphaWallet/Transfer/Types/UnconfirmedTransaction.swift
  10. 7
      AlphaWallet/Transfer/ViewControllers/SendViewController.swift
  11. 3
      AlphaWallet/Transfer/ViewModels/ConfigureTransactionViewModel.swift
  12. 6
      AlphaWallet/Transfer/ViewModels/ConfirmPaymentDetailsViewModel.swift
  13. 4
      AlphaWallet/Transfer/ViewModels/SendViewModel.swift
  14. 4
      AlphaWallet/UI/BalanceTitleView.swift
  15. 20
      AlphaWallet/Vendors/New Group/Commands/ContractERC721Transfer.swift
  16. 2
      AlphaWallet/Vendors/New Group/Commands/ContractERC875Transfer.swift

@ -438,6 +438,7 @@
73ED85A92034C42D00593BF3 /* StringFormatterTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73ED85A82034C42D00593BF3 /* StringFormatterTest.swift */; };
76F1D137B10D8309E513BBDD /* OrderSigningTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76F1DE8ADA3176D0277EDF20 /* OrderSigningTests.swift */; };
76F1D13FC8A41AD967C59947 /* ClaimOrderCoordinatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76F1DACA9404AD6740BEADBB /* ClaimOrderCoordinatorTests.swift */; };
76F1D439D545AA9B7E686DCC /* ContractERC721Transfer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76F1D6838F0069D06414009D /* ContractERC721Transfer.swift */; };
76F1D51EFA6255E0D0381E06 /* GetERC721BalanceEncode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76F1DC947821847220DE2B97 /* GetERC721BalanceEncode.swift */; };
76F1D5AF727A83205BBCF0EC /* OrderHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76F1DADFD07E2941897FD2E1 /* OrderHandler.swift */; };
76F1D74912F5D8CDA72363BD /* GetContractInteractions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76F1DF5CF4A922E6FFCB7B2A /* GetContractInteractions.swift */; };
@ -482,7 +483,7 @@
AA26C61F20412A1E00318B9B /* TicketsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA26C61D20412A1D00318B9B /* TicketsViewController.swift */; };
AA26C62320412A4100318B9B /* UIViewInspectableEnhancements.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA26C62120412A4100318B9B /* UIViewInspectableEnhancements.swift */; };
AA26C62420412A4100318B9B /* Double.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA26C62220412A4100318B9B /* Double.swift */; };
AA26C62620412C9A00318B9B /* ContractStormBirdTransfer.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA26C62520412C9A00318B9B /* ContractStormBirdTransfer.swift */; };
AA26C62620412C9A00318B9B /* ContractERC875Transfer.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA26C62520412C9A00318B9B /* ContractERC875Transfer.swift */; };
AA26C628204134C500318B9B /* TicketTableViewCellWithoutCheckbox.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA26C627204134C500318B9B /* TicketTableViewCellWithoutCheckbox.swift */; };
AA4E531820425A9500143A09 /* Date.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA4E531720425A9500143A09 /* Date.swift */; };
AA574E632054ECA400F4B3AF /* RestClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA574E622054ECA400F4B3AF /* RestClient.swift */; };
@ -979,6 +980,7 @@
76F1D419EE36261E50ABAFAE /* ClaimOrderCoordinator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ClaimOrderCoordinator.swift; sourceTree = "<group>"; };
76F1D473FF303828D93C95EB /* GetERC721BalanceCoordinator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GetERC721BalanceCoordinator.swift; sourceTree = "<group>"; };
76F1D4F77311FBF3A442E4B5 /* GetIsERC721Contract.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GetIsERC721Contract.swift; sourceTree = "<group>"; };
76F1D6838F0069D06414009D /* ContractERC721Transfer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContractERC721Transfer.swift; sourceTree = "<group>"; };
76F1D8877226D5DD086B135D /* CreateRedeemTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CreateRedeemTests.swift; sourceTree = "<group>"; };
76F1D96298E216CBFC3DD78B /* UniversalLinkHandlerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UniversalLinkHandlerTests.swift; sourceTree = "<group>"; };
76F1DACA9404AD6740BEADBB /* ClaimOrderCoordinatorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ClaimOrderCoordinatorTests.swift; sourceTree = "<group>"; };
@ -1028,7 +1030,7 @@
AA26C61D20412A1D00318B9B /* TicketsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TicketsViewController.swift; sourceTree = "<group>"; };
AA26C62120412A4100318B9B /* UIViewInspectableEnhancements.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIViewInspectableEnhancements.swift; sourceTree = "<group>"; };
AA26C62220412A4100318B9B /* Double.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Double.swift; sourceTree = "<group>"; };
AA26C62520412C9A00318B9B /* ContractStormBirdTransfer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContractStormBirdTransfer.swift; sourceTree = "<group>"; };
AA26C62520412C9A00318B9B /* ContractERC875Transfer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContractERC875Transfer.swift; sourceTree = "<group>"; };
AA26C627204134C500318B9B /* TicketTableViewCellWithoutCheckbox.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TicketTableViewCellWithoutCheckbox.swift; sourceTree = "<group>"; };
AA4E531720425A9500143A09 /* Date.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Date.swift; sourceTree = "<group>"; };
AA574E622054ECA400F4B3AF /* RestClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RestClient.swift; sourceTree = "<group>"; };
@ -1299,7 +1301,7 @@
children = (
291795001F95F5E200539A30 /* GetBalance.swift */,
2963B6BE1F9AB9A2003063C1 /* ContractERC20Transfer.swift */,
AA26C62520412C9A00318B9B /* ContractStormBirdTransfer.swift */,
AA26C62520412C9A00318B9B /* ContractERC875Transfer.swift */,
299B5E281FCA8F040051361C /* GetERC20Balance.swift */,
AA893ED02037E93000CDCED1 /* GetERC20Name.swift */,
299B5E2A1FCA9A640051361C /* ApproveERC20.swift */,
@ -1310,6 +1312,7 @@
76F1D1417613174D447DEE56 /* ClaimStormBirdOrder.swift */,
76F1DC947821847220DE2B97 /* GetERC721BalanceEncode.swift */,
76F1DC1E229431AA75EF94C3 /* GetIsERC721.swift */,
76F1D6838F0069D06414009D /* ContractERC721Transfer.swift */,
);
path = Commands;
sourceTree = "<group>";
@ -3378,7 +3381,7 @@
77B3BF3C201908ED00EEC15A /* ConfirmCoordinator.swift in Sources */,
298542F91FBE9A0100CB5081 /* CryptoAddressValidator.swift in Sources */,
291F52C11F6C8A1F00B369AB /* AccountsViewModel.swift in Sources */,
AA26C62620412C9A00318B9B /* ContractStormBirdTransfer.swift in Sources */,
AA26C62620412C9A00318B9B /* ContractERC875Transfer.swift in Sources */,
7721A6CC202EFBC5004DB16C /* AddCustomNetworkViewController.swift in Sources */,
77872D322027AA4A0032D687 /* SliderTextFieldRow.swift in Sources */,
298542E31FBA722F00CB5081 /* ContainerView.swift in Sources */,
@ -3677,6 +3680,7 @@
76F1D51EFA6255E0D0381E06 /* GetERC721BalanceEncode.swift in Sources */,
76F1D7F08263A663C3A67926 /* GetIsERC721Contract.swift in Sources */,
76F1DF0A4667F618D2BAE78C /* GetIsERC721.swift in Sources */,
76F1D439D545AA9B7E686DCC /* ContractERC721Transfer.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

@ -53,6 +53,7 @@ extension DappAction {
to: to,
data: data,
gasLimit: gasLimit,
tokenId: .none,
gasPrice: gasPrice,
nonce: nonce,
v: .none,

@ -513,6 +513,7 @@ extension InCoordinator: TokensCoordinatorDelegate {
to: address,
data: Data(bytes: payload.hexa2Bytes),
gasLimit: Constants.gasLimit,
tokenId: .none,
gasPrice: Constants.gasPriceDefaultERC875,
nonce: .none,
v: v,

@ -301,7 +301,7 @@ extension TokensCoordinator: TokensViewControllerDelegate {
case .ether:
delegate?.didPress(for: .send(type: .ether(config: session.config, destination: .none)), in: self)
case .token:
delegate?.didPress(for: .send(type: .token(token)), in: self)
delegate?.didPress(for: .send(type: .ERC20Token(token)), in: self)
case .stormBird:
delegate?.didPressERC875(for: .send(type: .ERC875Token(token)), token: token, in: self)
case .stormBirdOrder:

@ -63,12 +63,14 @@ class TransactionConfigurator {
let to: Address? = {
switch transaction.transferType {
case .ether: return transaction.to
case .token(let token):
case .ERC20Token(let token):
return Address(string: token.contract)
case .ERC875Token(let token):
return Address(string: token.contract)
case .ERC875TokenOrder(let token):
return Address(string: token.contract)
case .ERC721Token(let token):
return Address(string: token.contract)
}
}()
let request = EstimateGasRequest(
@ -111,7 +113,7 @@ class TransactionConfigurator {
data: transaction.data ?? self.configuration.data
)
completion(.success(()))
case .token:
case .ERC20Token:
session.web3.request(request: ContractERC20Transfer(amount: transaction.value, address: transaction.to!.description)) { [unowned self] result in
switch result {
case .success(let res):
@ -128,7 +130,7 @@ class TransactionConfigurator {
}
//TODO clean up
case .ERC875Token:
session.web3.request(request: ContractStormBirdTransfer(address: transaction.to!.description, indices: (transaction.indices)!)) { [unowned self] result in
session.web3.request(request: ContractERC875Transfer(address: transaction.to!.description, indices: (transaction.indices)!)) { [unowned self] result in
switch result {
case .success(let res):
let data = Data(hex: res.drop0x)
@ -159,8 +161,28 @@ class TransactionConfigurator {
completion(.failure(error))
}
}
case .ERC721Token:
session.web3.request(request: ContractERC721Transfer(address: transaction.to!.description,
tokenId: transaction.tokenId!))
{ [unowned self] result in
switch result {
case .success(let res):
let data = Data(hex: res.drop0x)
self.configuration = TransactionConfiguration(
gasPrice: self.calculatedGasPrice,
gasLimit: Constants.gasLimit,
data: data
)
completion(.success(()))
case .failure(let error):
completion(.failure(error))
}
}
}
}
}
func previewTransaction() -> PreviewTransaction {
return PreviewTransaction(
@ -180,17 +202,19 @@ class TransactionConfigurator {
let value: BigInt = {
switch transaction.transferType {
case .ether: return transaction.value
case .token: return 0
case .ERC20Token: return 0
case .ERC875Token: return 0
case .ERC875TokenOrder: return transaction.value
case .ERC721Token: return 0
}
}()
let address: Address? = {
switch transaction.transferType {
case .ether: return transaction.to
case .token(let token): return token.address
case .ERC20Token(let token): return token.address
case .ERC875Token(let token): return token.address
case .ERC875TokenOrder(let token): return token.address
case .ERC721Token(let token): return token.address
}
}()
let signTransaction = UnsignedTransaction(

@ -77,9 +77,10 @@ class SendCoordinator: Coordinator {
switch transferType {
case .ether(_, let destination):
controller.targetAddressTextField.value = destination?.description ?? ""
case .token: break
case .ERC20Token: break
case .ERC875Token: break
case .ERC875TokenOrder: break
case .ERC721Token: break
}
controller.delegate = self
return controller

@ -71,6 +71,7 @@ class TransferTicketsCoordinator: Coordinator {
to: address,
data: Data(),
gasLimit: .none,
tokenId: .none,
gasPrice: nil,
nonce: .none,
v: .none,

@ -5,9 +5,10 @@ import TrustKeystore
enum TransferType {
case ether(config: Config, destination: Address?)
case token(TokenObject)
case ERC20Token(TokenObject)
case ERC875Token(TokenObject)
case ERC875TokenOrder(TokenObject)
case ERC721Token(TokenObject)
}
extension TransferType {
@ -15,12 +16,14 @@ extension TransferType {
switch self {
case .ether:
return server.symbol
case .token(let token):
case .ERC20Token(let token):
return token.symbol
case .ERC875Token(let token):
return token.symbol
case .ERC875TokenOrder(let token):
return token.symbol
case .ERC721Token(let token):
return token.symbol
}
}
@ -28,12 +31,14 @@ extension TransferType {
switch self {
case .ether(let config, _):
return Address(string: TokensDataStore.etherToken(for: config).contract)!
case .token(let token):
case .ERC20Token(let token):
return Address(string: token.contract)!
case .ERC875Token(let token):
return Address(string: token.contract)!
case .ERC875TokenOrder(let token):
return Address(string: token.contract)!
case .ERC721Token(let token):
return Address(string: token.contract)!
}
}
}

@ -10,6 +10,7 @@ struct UnconfirmedTransaction {
let to: Address?
let data: Data?
let gasLimit: BigInt?
let tokenId: BigUInt?
let gasPrice: BigInt?
let nonce: BigInt?
// these are not the v, r, s value of a signed transaction

@ -303,12 +303,14 @@ class SendViewController: UIViewController {
switch transferType {
case .ether:
return EtherNumberFormatter.full.number(from: amountString, units: .ether)
case .token(let token):
case .ERC20Token(let token):
return EtherNumberFormatter.full.number(from: amountString, decimals: token.decimals)
case .ERC875Token(let token):
return EtherNumberFormatter.full.number(from: amountString, decimals: token.decimals)
case .ERC875TokenOrder(let token):
return EtherNumberFormatter.full.number(from: amountString, decimals: token.decimals)
case .ERC721Token(let token):
return EtherNumberFormatter.full.number(from: amountString, decimals: token.decimals)
}
}()
guard let value = parsedValue else {
@ -325,6 +327,7 @@ class SendViewController: UIViewController {
to: address,
data: data,
gasLimit: .none,
tokenId: .none,
gasPrice: gasPrice,
nonce: .none,
v: .none,
@ -459,7 +462,7 @@ class SendViewController: UIViewController {
}
}
session.refresh(.ethBalance)
case .token(let token):
case .ERC20Token(let token):
let viewModel = BalanceTokenViewModel(token: token)
let amount = viewModel.amountShort
headerViewModel.title = "\(amount) \(viewModel.symbol)"

@ -30,9 +30,10 @@ struct ConfigureTransactionViewModel {
var isDataInputHidden: Bool {
switch transferType {
case .ether: return false
case .token: return true
case .ERC20Token: return true
case .ERC875Token: return true
case .ERC875TokenOrder: return true
case .ERC721Token: return true
}
}
}

@ -99,7 +99,7 @@ struct ConfirmPaymentDetailsViewModel {
var amountAttributedString: NSAttributedString {
switch transaction.transferType {
case .token(let token):
case .ERC20Token(let token):
return amountAttributedText(
string: fullFormatter.string(from: transaction.value, decimals: token.decimals)
)
@ -115,6 +115,10 @@ struct ConfirmPaymentDetailsViewModel {
return amountAttributedText(
string: fullFormatter.string(from: transaction.value, decimals: token.decimals)
)
case .ERC721Token(let token):
return amountAttributedText(
string: fullFormatter.string(from: transaction.value, decimals: token.decimals)
)
}
}

@ -37,12 +37,14 @@ struct SendViewModel {
switch transferType {
case .ether(destination: _):
return nil
case .token(let token):
case .ERC20Token(let token):
return token
case .ERC875Token(let token):
return token
case .ERC875TokenOrder(let token):
return token
case .ERC721Token(let token):
return token
}
}

@ -102,11 +102,13 @@ extension BalanceTitleView {
guard let viewModel = viewModel else { return }
view?.viewModel = viewModel
}
case .token(let token):
case .ERC20Token(let token):
view.viewModel = BalanceTokenViewModel(token: token)
case .ERC875Token(let token):
view.viewModel = BalanceTokenViewModel(token: token)
case .ERC875TokenOrder: break
case .ERC721Token(let token):
view.viewModel = BalanceTokenViewModel(token: token)
}
session.refresh(.ethBalance)
return view

@ -0,0 +1,20 @@
//
// Created by James Sangalli on 14/7/18.
//
import Foundation
import BigInt
struct ContractERC721Transfer: Web3Request {
//function transfer(address _to, uint256 _tokenId) external; - TODO cannot transfer by bulk, should group one by one
typealias Response = String
let address: String
let tokenId: BigUInt
var type: Web3RequestType {
let abi = "{\"constant\":false,\"inputs\":[{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_tokenId\",\"type\":\"uint256\"}],\"name\":\"transfer\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"}, [\"\(address)\", \(tokenId)]"
let run = "web3.eth.abi.encodeFunctionCall(" + abi + ")"
return .script(command: run)
}
}

@ -1,6 +1,6 @@
import Foundation
struct ContractStormBirdTransfer: Web3Request {
struct ContractERC875Transfer: Web3Request {
typealias Response = String
let address: String
Loading…
Cancel
Save