Merge pull request #1539 from AlphaWallet/add-spawnable-support

add support for spawnable paymaster queries
pull/1547/head
James Sangalli 5 years ago committed by GitHub
commit bdeb778855
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 33
      AlphaWallet/Market/Coordinators/UniversalLinkCoordinator.swift
  2. 1
      AlphaWallet/Settings/Types/Constants.swift

@ -88,7 +88,7 @@ class UniversalLinkCoordinator: Coordinator {
private func createHTTPParametersForCurrencyLinksToPaymentServer( private func createHTTPParametersForCurrencyLinksToPaymentServer(
signedOrder: SignedOrder, signedOrder: SignedOrder,
recipient: AlphaWallet.Address recipient: AlphaWallet.Address
) -> Parameters { ) -> (Parameters, String) {
let signature = signedOrder.signature.drop0x let signature = signedOrder.signature.drop0x
let parameters: Parameters = [ let parameters: Parameters = [
"prefix": Constants.xdaiDropPrefix, "prefix": Constants.xdaiDropPrefix,
@ -102,20 +102,23 @@ class UniversalLinkCoordinator: Coordinator {
"networkId": server.chainID.description, "networkId": server.chainID.description,
"contractAddress": signedOrder.order.contractAddress "contractAddress": signedOrder.order.contractAddress
] ]
return parameters return (parameters, Constants.currencyDropServer)
} }
private func createHTTPParametersForNormalLinksToPaymentServer( private func createHTTPParametersForNormalLinksToPaymentServer(
signedOrder: SignedOrder, signedOrder: SignedOrder,
isForTransfer: Bool isForTransfer: Bool
) -> Parameters { ) -> (Parameters, String) {
let query: String
let signature = signedOrder.signature.drop0x let signature = signedOrder.signature.drop0x
let indices = signedOrder.order.indices let indices = signedOrder.order.indices
let indicesStringEncoded = stringEncodeIndices(indices) let indicesStringEncoded = stringEncodeIndices(indices)
let tokenIdsEncoded = stringEncodeTokenIds(signedOrder.order.tokenIds)
var parameters: Parameters = [ var parameters: Parameters = [
"address": walletAddress, "address": walletAddress,
"contractAddress": signedOrder.order.contractAddress, "contractAddress": signedOrder.order.contractAddress,
"indices": indicesStringEncoded, "indices": indicesStringEncoded,
"tokenIds": tokenIdsEncoded ?? "",
"price": signedOrder.order.price.description, "price": signedOrder.order.price.description,
"expiry": signedOrder.order.expiry.description, "expiry": signedOrder.order.expiry.description,
"v": signature.substring(from: 128), "v": signature.substring(from: 128),
@ -128,7 +131,15 @@ class UniversalLinkCoordinator: Coordinator {
parameters.removeValue(forKey: "price") parameters.removeValue(forKey: "price")
} }
return parameters if signedOrder.order.spawnable {
parameters.removeValue(forKey: "indices")
query = Constants.paymentServerSpawnable
} else {
parameters.removeValue(forKey: "tokenIds")
query = Constants.paymentServer
}
return (parameters, query)
} }
@discardableResult private func handlePaidImportsImpl(signedOrder: SignedOrder) -> Bool { @discardableResult private func handlePaidImportsImpl(signedOrder: SignedOrder) -> Bool {
@ -172,23 +183,18 @@ class UniversalLinkCoordinator: Coordinator {
} }
private func getParametersAndQuery(signedOrder: SignedOrder) -> (Parameters, String)? { private func getParametersAndQuery(signedOrder: SignedOrder) -> (Parameters, String)? {
let parameters: Parameters
let query: String
switch signedOrder.order.nativeCurrencyDrop { switch signedOrder.order.nativeCurrencyDrop {
case true: case true:
parameters = createHTTPParametersForCurrencyLinksToPaymentServer( return createHTTPParametersForCurrencyLinksToPaymentServer(
signedOrder: signedOrder, signedOrder: signedOrder,
recipient: walletAddress recipient: walletAddress
) )
query = Constants.currencyDropServer
case false: case false:
parameters = createHTTPParametersForNormalLinksToPaymentServer( return createHTTPParametersForNormalLinksToPaymentServer(
signedOrder: signedOrder, signedOrder: signedOrder,
isForTransfer: true isForTransfer: true
) )
query = Constants.paymentServer
} }
return (parameters, query)
} }
func completeOrderHandling(signedOrder: SignedOrder) { func completeOrderHandling(signedOrder: SignedOrder) {
@ -431,6 +437,11 @@ class UniversalLinkCoordinator: Coordinator {
return indices.map(String.init).joined(separator: ",") return indices.map(String.init).joined(separator: ",")
} }
private func stringEncodeTokenIds(_ tokenIds: [BigUInt]?) -> String? {
guard let tokens = tokenIds else { return nil }
return tokens.map({ $0.serialize().hexString }).joined(separator: ",")
}
private func checkERC875TokensAreAvailable(indices: [UInt16], balance: [String]) -> [String] { private func checkERC875TokensAreAvailable(indices: [UInt16], balance: [String]) -> [String] {
var filteredTokens = [String]() var filteredTokens = [String]()
if balance.count < indices.count { if balance.count < indices.count {

@ -30,6 +30,7 @@ public struct Constants {
// fee master // fee master
public static let paymentServer = "https://paymaster.stormbird.sg/api/claimToken" public static let paymentServer = "https://paymaster.stormbird.sg/api/claimToken"
public static let paymentServerSpawnable = "https://paymaster.stormbird.sg/api/claimSpawnableToken"
public static let paymentServerSupportsContractEndPoint = "https://paymaster.stormbird.sg/api/checkContractIsSupportedForFreeTransfers" public static let paymentServerSupportsContractEndPoint = "https://paymaster.stormbird.sg/api/checkContractIsSupportedForFreeTransfers"
public static let paymentServerClaimedToken = "https://paymaster.stormbird.sg/api/checkIfSignatureIsUsed" public static let paymentServerClaimedToken = "https://paymaster.stormbird.sg/api/checkIfSignatureIsUsed"
public static let currencyDropServer = "https://paymaster.stormbird.sg/api/claimFreeCurrency" public static let currencyDropServer = "https://paymaster.stormbird.sg/api/claimFreeCurrency"

Loading…
Cancel
Save