Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Passbase, add logging, refactor code, add SDK version params #10

Merged
merged 11 commits into from
Feb 22, 2023
7 changes: 1 addition & 6 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,8 @@ let package = Package(
products: [
.library(name: "Ramp", targets: ["Ramp"])
],
dependencies: [
.package(name: "Passbase",
url: "https://github.com/passbase/passbase-sp.git",
from: "2.8.0"),
],
targets: [
.target(name: "Ramp", dependencies: ["Passbase"]),
.target(name: "Ramp"),
.testTarget(name: "RampTests", dependencies: ["Ramp"])
]
)
3 changes: 1 addition & 2 deletions Ramp.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'Ramp'
spec.version = '3.0.0'
spec.version = '4.0.0'
spec.license = 'proprietary'
spec.summary = 'Ramp SDK for iOS'
spec.homepage = 'https://ramp.network/'
Expand All @@ -9,5 +9,4 @@ Pod::Spec.new do |spec|
spec.ios.deployment_target = '11.0'
spec.source_files = 'Sources/Ramp/*.swift'
spec.resource_bundles = { 'Ramp' => 'Sources/Ramp/Resources/*' }
spec.dependency 'Passbase', '~> 2.8'
end
4 changes: 4 additions & 0 deletions Sources/Ramp/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public struct Configuration: Decodable {
public var offrampAsset: String?
public var offrampWebhookV3Url: String?
public var selectedCountryCode: String?
public var sdkType: String { Constants.sdkType }
public var sdkVersion: String { Constants.sdkVersion }
public var swapAmount: String?
public var swapAsset: String?
public var userAddress: String?
Expand Down Expand Up @@ -56,6 +58,8 @@ extension Configuration {
urlComponents.appendQueryItem(name: "offrampAsset", value: offrampAsset)
urlComponents.appendQueryItem(name: "offrampWebhookV3Url", value: offrampWebhookV3Url)
urlComponents.appendQueryItem(name: "selectedCountryCode", value: selectedCountryCode)
urlComponents.appendQueryItem(name: "sdkType", value: sdkType)
urlComponents.appendQueryItem(name: "sdkVersion", value: sdkVersion)
urlComponents.appendQueryItem(name: "swapAmount", value: swapAmount)
urlComponents.appendQueryItem(name: "swapAsset", value: swapAsset)
urlComponents.appendQueryItem(name: "userAddress", value: userAddress)
Expand Down
2 changes: 2 additions & 0 deletions Sources/Ramp/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ struct Constants {
static let defaultUrl: String = "https://buy.ramp.network"
static let scriptMessageHandlerName: String = "RampInstantMobile"
static let sendCryptoVersion: Int = 1
static let sdkType: String = "IOS"
static let sdkVersion: String = "4.0.0"

static func postMessageScript(_ message: String) -> String {
return "window.postMessage(" + message + ");"
Expand Down
16 changes: 0 additions & 16 deletions Sources/Ramp/IncomingEvent.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Foundation

enum IncomingEvent {
case kycInit(KycInitPayload)
case onrampPurchaseCreated(OnrampPurchaseCreatedPayload)
case widgetClose(WidgetClosePayload)
case sendCrypto(SendCryptoPayload)
Expand All @@ -19,11 +18,6 @@ extension IncomingEvent: DictionaryDecodable {

switch type {

case EventTypes.kycInit:
guard let payload else { throw Error.missingPayload(type) }
let decoded: KycInitPayload = try decoder.decode(payload)
self = .kycInit(decoded)

case EventTypes.onrampPurchaseCreated:
guard let payload else { throw Error.missingPayload(type) }
let decoded: OnrampPurchaseCreatedPayload = try decoder.decode(payload)
Expand Down Expand Up @@ -60,7 +54,6 @@ extension IncomingEvent: DictionaryDecodable {

extension IncomingEvent {
struct EventTypes {
static let kycInit = "KYC_INIT"
static let onrampPurchaseCreated = "PURCHASE_CREATED"
static let widgetClose = "WIDGET_CLOSE"
static let sendCrypto = "SEND_CRYPTO"
Expand All @@ -81,15 +74,6 @@ extension IncomingEvent {

// MARK: - Payloads

struct KycInitPayload: Decodable {
let email: String
let countryCode: String
let verificationId: Int
let provider: String
let apiKey: String
let metaData: String?
}

struct OnrampPurchaseCreatedPayload: Decodable {
let apiUrl: URL
let purchase: OnrampPurchase
Expand Down
14 changes: 12 additions & 2 deletions Sources/Ramp/Localizable.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import Foundation

// use
// genstrings -o Sources/Ramp/Resources/en.lproj Sources/Ramp/*.swift
// to regenerate Localizable.strings

struct Localizable {
static var closeAlertTitle: String { NSLocalizedString("Do you really want to close Ramp?", comment: "Alert title for closing Ramp") }
static var closeAlertMessage: String { NSLocalizedString("You will loose all progress and will have to start over", comment: "Alert message for closing Ramp") }
static var closeAlertTitle: String {
NSLocalizedString("Do you really want to close Ramp?",
comment: "Alert title for closing Ramp")
}
static var closeAlertMessage: String {
NSLocalizedString("You will loose all progress and will have to start over",
comment: "Alert message for closing Ramp")
}
static var yes: String { NSLocalizedString("Yes", comment: "Yes") }
static var no: String { NSLocalizedString("No", comment: "No") }
}
15 changes: 15 additions & 0 deletions Sources/Ramp/Logger.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Foundation

struct Logger {
static func debug(_ message: String) {
#if DEBUG
print("[debug]", message)
#endif
}

static func error(_ error: Error) {
#if DEBUG
print("[error]", String(describing: error))
#endif
}
}
22 changes: 11 additions & 11 deletions Sources/Ramp/OnrampPurchase.swift
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import Foundation

public struct OnrampPurchase: Codable {
public let id: String
public let endTime: String
public let appliedFee: Double
public let asset: AssetInfo
public let receiverAddress: String
public let assetExchangeRate: Double
public let baseRampFee: Double
public let createdAt: String
public let cryptoAmount: String
public let endTime: String?
public let escrowAddress: String?
public let escrowDetailsHash: String?
public let fiatCurrency: String
public let fiatValue: Double
public let assetExchangeRate: Double
public let baseRampFee: Double
public let finalTxHash: String?
public let id: String
public let networkFee: Double
public let appliedFee: Double
public let paymentMethodType: String
public let finalTxHash: String?
public let createdAt: String
public let updatedAt: String
public let receiverAddress: String
public let status: String
public let escrowAddress: String?
public let escrowDetailsHash: String?
public let updatedAt: String

public struct AssetInfo: Codable {
public let address: String?
Expand Down
57 changes: 0 additions & 57 deletions Sources/Ramp/OutgoingEvent.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import Foundation

enum OutgoingEvent {
case kycStarted(KycStartedPayload)
case kycSubmitted(KycSubmittedPayload)
case kycSuccess(KycSuccessPayload)
case kycAborted(KycAbortedPayload)
case kycError(KycErrorPayload)
case backButtonPressed
case sendCryptoResult(SendCryptoResultPayload)
}
Expand All @@ -19,31 +14,6 @@ extension OutgoingEvent: MessageEventEncodable {

switch self {

case .kycStarted(let payload):
type = EventType.kycStarted
version = nil
payloadData = try encoder.encode(payload)

case .kycSubmitted(let payload):
type = EventType.kycSubmitted
version = nil
payloadData = try encoder.encode(payload)

case .kycSuccess(let payload):
type = EventType.kycSuccess
version = nil
payloadData = try encoder.encode(payload)

case .kycAborted(let payload):
type = EventType.kycAborted
version = nil
payloadData = try encoder.encode(payload)

case .kycError(let payload):
type = EventType.kycError
version = nil
payloadData = try encoder.encode(payload)

case .backButtonPressed:
type = EventType.backButtonPressed
version = nil
Expand Down Expand Up @@ -83,11 +53,6 @@ extension OutgoingEvent: MessageEventEncodable {

extension OutgoingEvent {
struct EventType {
static let kycStarted = "KYC_STARTED"
static let kycSubmitted = "KYC_SUBMITTED"
static let kycSuccess = "KYC_SUCCESS"
static let kycAborted = "KYC_ABORTED"
static let kycError = "KYC_ERROR"
static let backButtonPressed = "BACK_BUTTON_PRESSED"
static let sendCryptoResult = "SEND_CRYPTO_RESULT"
}
Expand All @@ -103,28 +68,6 @@ extension OutgoingEvent {

// MARK: - Payloads

struct KycStartedPayload: Encodable {
let verificationId: Int
}

struct KycSubmittedPayload: Encodable {
let verificationId: Int
let identityAccessKey: String
}

struct KycSuccessPayload: Encodable {
let verificationId: Int
let identityAccessKey: String
}

struct KycAbortedPayload: Encodable {
let verificationId: Int
}

struct KycErrorPayload: Encodable {
let verificationId: Int
}

public struct SendCryptoResultPayload: Encodable {
let txHash: String?

Expand Down
6 changes: 0 additions & 6 deletions Sources/Ramp/PassbaseError.swift

This file was deleted.

14 changes: 11 additions & 3 deletions Sources/Ramp/RampDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import Foundation

public protocol RampDelegate: AnyObject {
func ramp(_ rampViewController: RampViewController, didCreateOnrampPurchase purchase: OnrampPurchase, _ purchaseViewToken: String, _ apiUrl: URL)
func ramp(_ rampViewController: RampViewController, didRequestSendCrypto payload: SendCryptoPayload, responseHandler: @escaping (SendCryptoResultPayload) -> Void)
func ramp(_ rampViewController: RampViewController, didCreateOfframpSale sale: OfframpSale, _ saleViewToken: String, _ apiUrl: URL)
func ramp(_ rampViewController: RampViewController,
didCreateOnrampPurchase purchase: OnrampPurchase,
_ purchaseViewToken: String,
_ apiUrl: URL)
func ramp(_ rampViewController: RampViewController,
didRequestSendCrypto payload: SendCryptoPayload,
responseHandler: @escaping (SendCryptoResultPayload) -> Void)
func ramp(_ rampViewController: RampViewController,
didCreateOfframpSale sale: OfframpSale,
_ saleViewToken: String,
_ apiUrl: URL)
func rampDidClose(_ rampViewController: RampViewController)
}
Loading