Skip to content

Commit

Permalink
Merge branch 'release/2.11.0' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
bigearsenal committed Jan 19, 2024
2 parents 8f20a8d + b9bad49 commit c2b278c
Show file tree
Hide file tree
Showing 47 changed files with 394 additions and 161 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public extension Moonpay {
struct MoonpayCountry: Decodable {
public let code: String
public let name: String
public let alpha3: String
public let isBuyAllowed: Bool
public let isSellAllowed: Bool
public let isNftAllowed: Bool
Expand All @@ -63,6 +64,7 @@ public extension Moonpay {
enum CodingKeys: String, CodingKey {
case code = "alpha2"
case name
case alpha3
case isBuyAllowed
case isSellAllowed
case isNftAllowed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public protocol SellDataServiceProvider {
associatedtype Transaction: ProviderTransaction
associatedtype Currency: ProviderCurrency
associatedtype Fiat: ProviderFiat
associatedtype Region: ProviderRegion

func sellTransactions(externalCustomerId: String) async throws -> [Transaction]
func detailSellTransaction(id: String) async throws -> Transaction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,6 @@ public enum SellDataServiceStatus {
case updating
case ready
case error(Error)

public var isReady: Bool {
switch self {
case .ready:
return true
default:
return false
}
}
}

public protocol ProviderCurrency: Equatable {
Expand Down Expand Up @@ -56,6 +47,14 @@ public struct SellDataServiceTransaction: Hashable {
}
}

public protocol ProviderRegion {
var alpha2: String { get }
var alpha3: String { get }
var country: String { get }
var state: String { get }
}

public enum SellDataServiceError: Error {
case unsupportedRegion(ProviderRegion)
case couldNotLoadSellData
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import Foundation
public protocol SellDataService {
associatedtype Provider: SellDataServiceProvider

/// Current region
var region: ProviderRegion? { get }

/// Availability status
var isAvailable: Bool { get }

Expand All @@ -28,8 +31,8 @@ public protocol SellDataService {
/// Check if service available
func checkAvailability() async

/// Request for pendings, rates, min amounts
func update() async
/// Request for pendings, rates, min amounts for defined region
func update(region: ProviderRegion?) async

/// Retrieve all incompleted transactions
func updateIncompletedTransactions() async throws
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public final class MoonpaySellDataService: SellDataService {

public var fiat: MoonpaySellDataServiceProvider.Fiat?

public var region: ProviderRegion?

public let userId: String

// MARK: - Initializer
Expand All @@ -55,16 +57,22 @@ public final class MoonpaySellDataService: SellDataService {
isAvailable = (try? await provider.isAvailable()) ?? false
}

public func update() async {
public func update(region: ProviderRegion?) async {
// mark as updating
status = .updating

// get currency
do {
isAvailable = try await provider.isAvailable()
if region == nil {
let regionData = try await provider.ipRegion()
self.region = regionData.0
isAvailable = regionData.isAvailable
} else {
self.region = region
}
let (currency, fiat, _) = try await(
provider.currencies().filter { $0.code.uppercased() == "SOL" }.first,
provider.fiat(),
provider.fiat(region: region),
updateIncompletedTransactions()
)
if currency == nil {
Expand All @@ -73,6 +81,12 @@ public final class MoonpaySellDataService: SellDataService {
self.currency = currency
self.fiat = fiat
status = .ready
} catch let MoonpaySellDataServiceProviderError.unsupportedRegion(region) {
currency = nil
fiat = nil
status = .error(SellDataServiceError.unsupportedRegion(region))
self.region = region
return
} catch {
debugPrint(error)
currency = nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation
import Moonpay

public enum MoonpaySellDataServiceProviderError: Error {
case unsupportedRegion
case unsupportedRegion(ProviderRegion)
}

public class MoonpaySellDataServiceProvider: SellDataServiceProvider {
Expand All @@ -11,10 +11,12 @@ public class MoonpaySellDataServiceProvider: SellDataServiceProvider {
public typealias Currency = MoonpayCurrency
public typealias Transaction = MoonpayTransaction
public typealias Fiat = MoonpayFiat
public typealias Region = Moonpay.Provider.IpAddressResponse

// MARK: - Properties

private let moonpayAPI: Moonpay.Provider
private var ipRegion: Moonpay.Provider.IpAddressResponse?

// MARK: - Initializer

Expand All @@ -25,22 +27,35 @@ public class MoonpaySellDataServiceProvider: SellDataServiceProvider {
// MARK: - Methods

func isAvailable() async throws -> Bool {
try await moonpayAPI.ipAddresses().isSellAllowed
try await ipRegion().isAvailable
}

func fiat() async throws -> Fiat {
func fiatByApha3(alpha3: String) throws -> Fiat {
if moonpayAPI.UKAlpha3Code() == alpha3 {
func ipRegion() async throws -> (Moonpay.Provider.IpAddressResponse, isAvailable: Bool) {
if let ipRegion {
return (ipRegion, ipRegion.isSellAllowed)
}
let region = try await moonpayAPI.ipAddresses()
ipRegion = region
return (region, region.isSellAllowed)
}

func fiat(region: ProviderRegion?) async throws -> Fiat {
func fiatByApha3(region: ProviderRegion) throws -> Fiat {
if moonpayAPI.UKAlpha3Code() == region.alpha3 {
return .gbp
} else if moonpayAPI.bankTransferAvailableAlpha3Codes().contains(alpha3) {
} else if moonpayAPI.bankTransferAvailableAlpha3Codes().contains(region.alpha3) {
return .eur
} else if moonpayAPI.USAlpha3Code() == alpha3 {
} else if moonpayAPI.USAlpha3Code() == region.alpha3 {
return .usd
}
throw MoonpaySellDataServiceProviderError.unsupportedRegion
throw MoonpaySellDataServiceProviderError.unsupportedRegion(region)
}
if let region {
return try fiatByApha3(region: region)
} else {
let region = try await ipRegion()
return try fiatByApha3(region: region.0)
}
let resp = try await moonpayAPI.ipAddresses()
return try fiatByApha3(alpha3: resp.alpha3)
}

func currencies() async throws -> [Currency] {
Expand Down Expand Up @@ -126,3 +141,5 @@ public extension MoonpaySellDataServiceProvider.MoonpayTransaction {
public var walletAddress: String
}
}

extension Moonpay.Provider.IpAddressResponse: ProviderRegion {}
22 changes: 0 additions & 22 deletions Packages/KeyAppKit/Sources/Wormhole/Model/SendFees.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,3 @@ public struct SendFees: Codable, Hashable, Equatable {
case bridgeFeeInToken = "bridge_fee_in_token"
}
}

public extension SendFees {
/// Total amount in fiat.
var totalInFiat: CurrencyAmount {
CurrencyAmount(usd: 0)
+ arbiter?.asCurrencyAmount
+ networkFee?.asCurrencyAmount
+ messageAccountRent?.asCurrencyAmount
+ bridgeFee?.asCurrencyAmount
}

/// Total in Crypto
var totalInCrypto: CryptoAmount? {
guard let arbiter, let networkFeeInToken, let messageAccountRentInToken, let bridgeFeeInToken else {
return nil
}
return arbiter.asCryptoAmount
+ networkFeeInToken.asCryptoAmount
+ messageAccountRentInToken.asCryptoAmount
+ bridgeFeeInToken.asCryptoAmount
}
}
4 changes: 3 additions & 1 deletion p2p_wallet/Common/Extensions/String+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ extension String {
}

static var nameServiceDomain: String {
RemoteConfig.remoteConfig().usernameDomain ?? "key"
RemoteConfig.remoteConfig().usernameDomain ?? ".key"
}

static func secretConfig(_ key: String) -> String? {
Expand Down Expand Up @@ -124,4 +124,6 @@ extension String {

return String(stringLiteral: s)
}

static let neutralFlag = "🏳️‍🌈"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,3 @@ extension UINavigationController {
topViewController
}
}

extension UINavigationController {
// True if `hidesBottomBarWhenPushed` can be set to true, otherwise false.
// Workaround for iOS 14 bug.
var canHideBottomForNextPush: Bool {
// There is a bug in iOS 14 that hides the bottom bar
// when popping multiple navigation controllers from the stack,
// and one of them has hidesBottomBarWhenPushed set to true.
// https://developer.apple.com/forums/thread/660750
viewControllers.count == 1
}
}
4 changes: 2 additions & 2 deletions p2p_wallet/Common/Models/WalletActionType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ enum WalletActionType {
case .swap:
return L10n.swap
case .cashOut:
return "Cash out"
return L10n.cashOut
}
}

Expand All @@ -33,7 +33,7 @@ enum WalletActionType {
case .swap:
return .actionSwap
case .cashOut:
return .cashOut
return .actionCashOut
}
}
}
9 changes: 5 additions & 4 deletions p2p_wallet/Common/Services/CreateName/CreateNameService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import SolanaSwift

protocol CreateNameService {
var createNameResult: AnyPublisher<Bool, Never> { get }
func create(username: String)
func create(username: String, domain: String)
}

final class CreateNameServiceImpl: CreateNameService {
Expand All @@ -22,7 +22,7 @@ final class CreateNameServiceImpl: CreateNameService {

private let createNameResultSubject = PassthroughSubject<Bool, Never>()

func create(username: String) {
func create(username: String, domain: String) {
Task {
do {
guard let account = storage.account else {
Expand All @@ -41,8 +41,9 @@ final class CreateNameServiceImpl: CreateNameService {
configs: RequestConfiguration(encoding: "base64")!
)

nameStorage.save(name: username)
nameCache.save(username, for: account.publicKey.base58EncodedString)
let name = "\(username)\(domain)"
nameStorage.save(name: name)
nameCache.save(name, for: account.publicKey.base58EncodedString)
createNameResultSubject.send(true)
} catch {
createNameResultSubject.send(false)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "Icon settings.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "Icon [email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "Icon [email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions p2p_wallet/Resources/Base.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -589,3 +589,4 @@
"Confirm selection" = "Confirm selection";
"The token %@ is out of the strict list" = "The token %@ is out of the strict list";
"Make sure the mint address %@ is correct before confirming" = "Make sure the mint address %@ is correct before confirming";
"Unfortunately, you can not cashout in %@, but you can still use other Key App features" = "Unfortunately, you can not cashout in %@, but you can still use other Key App features";
6 changes: 4 additions & 2 deletions p2p_wallet/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@
"Keep your pin safe. Hide your pin from other people." = "Keep your pin safe. Hide your pin from other people.";
"Key App" = "Key App";
"Key App cannot scan QR codes without access to your camera. Please enable access under Privacy settings." = "Key App cannot scan QR codes without access to your camera. Please enable access under Privacy settings.";
"Key App doesn’t make any profit from this swap 💚" = "Key App doesn’t make any profit from this swap 💚";
"Key App one-time transfer link" = "Key App one-time transfer link";
"Key App respects your privacy - it can't access your funds or personal details. Your information stays securely stored on your device and in the blockchain" = "Key App respects your privacy - it can't access your funds or personal details. Your information stays securely stored on your device and in the blockchain.";
"Key App’s" = "Key App’s";
Expand Down Expand Up @@ -247,7 +246,6 @@
"Multi-factor authentication" = "Multi-factor authentication";
"My Ethereum address" = "My Ethereum address";
"My Solana address" = "My Solana address";
"My crypto" = "My crypto";
"My username" = "My username";
"Name was booked" = "Name was booked";
"Network" = "Network";
Expand Down Expand Up @@ -573,3 +571,7 @@
"✌️ Great! Your new PIN is set." = "✌️ Great! Your new PIN is set.";
"😓 name is not available" = "😓 name is not available";
"😢 PIN doesn't match. Please try again" = "😢 PIN doesn't match. Please try again";
"Confirm selection" = "Confirm selection";
"The token %@ is out of the strict list" = "The token %@ is out of the strict list";
"Make sure the mint address %@ is correct before confirming" = "Make sure the mint address %@ is correct before confirming";
"Unfortunately, you can not cashout in %@, but you can still use other Key App features" = "Unfortunately, you can not cashout in %@, but you can still use other Key App features";
8 changes: 0 additions & 8 deletions p2p_wallet/Scenes/Actions/ActionsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,10 @@ import SwiftUI
import SwiftyUserDefaults

struct ActionsView: View {
@Injected private var sellDataService: any SellDataService
@Injected private var walletsRepository: SolanaAccountsService

private let actionSubject = PassthroughSubject<ActionsViewActionType, Never>()
var action: AnyPublisher<ActionsViewActionType, Never> { actionSubject.eraseToAnyPublisher() }
private let cancelSubject = PassthroughSubject<Void, Never>()
var cancel: AnyPublisher<Void, Never> { cancelSubject.eraseToAnyPublisher() }
var isSellAvailable: Bool {
available(.sellScenarioEnabled) &&
sellDataService.isAvailable &&
!walletsRepository.getWallets().isTotalAmountEmpty
}

var body: some View {
VStack(spacing: 8) {
Expand Down
2 changes: 1 addition & 1 deletion p2p_wallet/Scenes/Main/Buy/BuyView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct BuyView: View, KeyboardVisibilityReadable {
},
label: {
HStack(spacing: 10) {
Text(viewModel.flag)
Text(viewModel.region?.flag ?? .neutralFlag)
.font(uiFont: .font(of: .title1, weight: .bold))
Image(.chevronDown)
.foregroundColor(Color(.mountain))
Expand Down
Loading

0 comments on commit c2b278c

Please sign in to comment.