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(
signedOrder: SignedOrder,
recipient: AlphaWallet.Address
) -> Parameters {
) -> (Parameters, String) {
let signature = signedOrder.signature.drop0x
let parameters: Parameters = [
"prefix": Constants.xdaiDropPrefix,
@ -102,20 +102,23 @@ class UniversalLinkCoordinator: Coordinator {
"networkId": server.chainID.description,
"contractAddress": signedOrder.order.contractAddress
]
return parameters
return (parameters, Constants.currencyDropServer)
}
private func createHTTPParametersForNormalLinksToPaymentServer(
signedOrder: SignedOrder,
isForTransfer: Bool
) -> Parameters {
) -> (Parameters, String) {
let query: String
let signature = signedOrder.signature.drop0x
let indices = signedOrder.order.indices
let indicesStringEncoded = stringEncodeIndices(indices)
let tokenIdsEncoded = stringEncodeTokenIds(signedOrder.order.tokenIds)
var parameters: Parameters = [
"address": walletAddress,
"contractAddress": signedOrder.order.contractAddress,
"indices": indicesStringEncoded,
"tokenIds": tokenIdsEncoded ?? "",
"price": signedOrder.order.price.description,
"expiry": signedOrder.order.expiry.description,
"v": signature.substring(from: 128),
@ -128,7 +131,15 @@ class UniversalLinkCoordinator: Coordinator {
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 {
@ -172,23 +183,18 @@ class UniversalLinkCoordinator: Coordinator {
}
private func getParametersAndQuery(signedOrder: SignedOrder) -> (Parameters, String)? {
let parameters: Parameters
let query: String
switch signedOrder.order.nativeCurrencyDrop {
case true:
parameters = createHTTPParametersForCurrencyLinksToPaymentServer(
return createHTTPParametersForCurrencyLinksToPaymentServer(
signedOrder: signedOrder,
recipient: walletAddress
)
query = Constants.currencyDropServer
case false:
parameters = createHTTPParametersForNormalLinksToPaymentServer(
return createHTTPParametersForNormalLinksToPaymentServer(
signedOrder: signedOrder,
isForTransfer: true
)
query = Constants.paymentServer
}
return (parameters, query)
}
func completeOrderHandling(signedOrder: SignedOrder) {
@ -431,6 +437,11 @@ class UniversalLinkCoordinator: Coordinator {
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] {
var filteredTokens = [String]()
if balance.count < indices.count {

@ -30,6 +30,7 @@ public struct Constants {
// fee master
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 paymentServerClaimedToken = "https://paymaster.stormbird.sg/api/checkIfSignatureIsUsed"
public static let currencyDropServer = "https://paymaster.stormbird.sg/api/claimFreeCurrency"

Loading…
Cancel
Save