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

Version/0.42 #6057

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 42 additions & 4 deletions UnstoppableWallet/TonConnectAPI/Sources/TonConnectAPI/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,19 @@ public struct Client: APIProtocol {
switch response.status.code {
case 200:
let contentType = converter.extractContentTypeIfPresent(in: response.headerFields)
let body: Components.Responses.Response.Body
let bodyPayload: BodyUniversalData
if try contentType == nil
|| converter.isMatchingContentType(received: contentType, expectedRaw: "application/json")
{
body = try await converter.getResponseBodyAsJSON(
Components.Responses.Response.Body.jsonPayload.self,
bodyPayload = try await converter.getResponseBodyAsJSON(
JsonPayload.self,
from: responseBody,
transforming: { value in .json(value) }
)
} else {
throw converter.makeUnexpectedContentTypeError(contentType: contentType)
}
return .ok(.init(body: body))
return .ok(.init(body: .json(try bodyPayload.json)))
default:
let contentType = converter.extractContentTypeIfPresent(in: response.headerFields)
let body: Components.Responses.Response.Body
Expand All @@ -167,3 +167,41 @@ public struct Client: APIProtocol {
)
}
}

enum BodyUniversalData: Sendable, Hashable {

case json(JsonPayload)
public var json: Components.Responses.Response.Body.jsonPayload {
get throws {
switch self {
case let .json(body):
guard let message = body.message ?? body.status else {
throw ParsingError.cantParseBody
}
return .init(message: message, statusCode: body.statusCode ?? 200)
}
}
}
}

public struct JsonPayload: Codable, Hashable, Sendable {
public var message: String?
public var status: String?
public var statusCode: Int64?

public init(status: Swift.String?, message: String?, statusCode: Int64?) {
self.status = status
self.message = message
self.statusCode = statusCode
}

public enum CodingKeys: String, CodingKey {
case status
case message
case statusCode
}
}

public enum ParsingError: Error {
case cantParseBody
}
4 changes: 2 additions & 2 deletions UnstoppableWallet/UnstoppableWallet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12365,7 +12365,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.41.1;
MARKETING_VERSION = 0.42;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
OfficeMode = true;
Expand Down Expand Up @@ -12437,7 +12437,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.41.1;
MARKETING_VERSION = 0.42;
MTL_ENABLE_DEBUG_INFO = NO;
OfficeMode = false;
SDKROOT = iphoneos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class BitcoinAdapter: BitcoinBaseAdapter {
walletId: wallet.account.id,
syncMode: syncMode,
networkType: Self.networkType,
confirmationsThreshold: BitcoinBaseAdapter.confirmationsThreshold,
confirmationsThreshold: Self.confirmationsThreshold,
logger: logger
)
case let .hdExtendedKey(key):
Expand All @@ -41,7 +41,7 @@ class BitcoinAdapter: BitcoinBaseAdapter {
walletId: wallet.account.id,
syncMode: syncMode,
networkType: Self.networkType,
confirmationsThreshold: BitcoinBaseAdapter.confirmationsThreshold,
confirmationsThreshold: Self.confirmationsThreshold,
logger: logger
)
case let .btcAddress(address, _, tokenType):
Expand All @@ -55,7 +55,7 @@ class BitcoinAdapter: BitcoinBaseAdapter {
walletId: wallet.account.id,
syncMode: syncMode,
networkType: Self.networkType,
confirmationsThreshold: BitcoinBaseAdapter.confirmationsThreshold,
confirmationsThreshold: Self.confirmationsThreshold,
logger: logger
)
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import MarketKit
import RxSwift

class BitcoinBaseAdapter {
static let confirmationsThreshold = 3
static let confirmationsThreshold = 1 // Number of confirmations for coins in transaction to be available for spending
static let txStatusConfirmationsThreshold = 3 // Number of confirmations for transaction status displayed
private let abstractKit: AbstractKit

var coinRate: Decimal { 100_000_000 } // pow(10, 8)
Expand Down Expand Up @@ -86,7 +87,7 @@ class BitcoinBaseAdapter {
transactionHash: transaction.transactionHash,
transactionIndex: transaction.transactionIndex,
blockHeight: transaction.blockHeight,
confirmationsThreshold: Self.confirmationsThreshold,
confirmationsThreshold: Self.txStatusConfirmationsThreshold,
date: Date(timeIntervalSince1970: Double(transaction.timestamp)),
fee: transaction.fee.map { Decimal($0) / coinRate },
failed: transaction.status == .invalid,
Expand All @@ -105,7 +106,7 @@ class BitcoinBaseAdapter {
transactionHash: transaction.transactionHash,
transactionIndex: transaction.transactionIndex,
blockHeight: transaction.blockHeight,
confirmationsThreshold: Self.confirmationsThreshold,
confirmationsThreshold: Self.txStatusConfirmationsThreshold,
date: Date(timeIntervalSince1970: Double(transaction.timestamp)),
fee: transaction.fee.map { Decimal($0) / coinRate },
failed: transaction.status == .invalid,
Expand All @@ -126,7 +127,7 @@ class BitcoinBaseAdapter {
transactionHash: transaction.transactionHash,
transactionIndex: transaction.transactionIndex,
blockHeight: transaction.blockHeight,
confirmationsThreshold: Self.confirmationsThreshold,
confirmationsThreshold: Self.txStatusConfirmationsThreshold,
date: Date(timeIntervalSince1970: Double(transaction.timestamp)),
fee: transaction.fee.map { Decimal($0) / coinRate },
failed: transaction.status == .invalid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class BitcoinCashAdapter: BitcoinBaseAdapter {
walletId: wallet.account.id,
syncMode: syncMode,
networkType: networkType,
confirmationsThreshold: BitcoinBaseAdapter.confirmationsThreshold,
confirmationsThreshold: Self.confirmationsThreshold,
logger: logger
)
case let .hdExtendedKey(key):
Expand All @@ -41,7 +41,7 @@ class BitcoinCashAdapter: BitcoinBaseAdapter {
walletId: wallet.account.id,
syncMode: syncMode,
networkType: networkType,
confirmationsThreshold: BitcoinBaseAdapter.confirmationsThreshold,
confirmationsThreshold: Self.confirmationsThreshold,
logger: logger
)
case let .btcAddress(address, _, _):
Expand All @@ -50,7 +50,7 @@ class BitcoinCashAdapter: BitcoinBaseAdapter {
walletId: wallet.account.id,
syncMode: syncMode,
networkType: networkType,
confirmationsThreshold: BitcoinBaseAdapter.confirmationsThreshold,
confirmationsThreshold: Self.confirmationsThreshold,
logger: nil
)
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class DashAdapter: BitcoinBaseAdapter {
walletId: wallet.account.id,
syncMode: syncMode,
networkType: Self.networkType,
confirmationsThreshold: BitcoinBaseAdapter.confirmationsThreshold,
confirmationsThreshold: Self.confirmationsThreshold,
logger: logger
)
case let .hdExtendedKey(key):
Expand All @@ -35,7 +35,7 @@ class DashAdapter: BitcoinBaseAdapter {
walletId: wallet.account.id,
syncMode: syncMode,
networkType: Self.networkType,
confirmationsThreshold: BitcoinBaseAdapter.confirmationsThreshold,
confirmationsThreshold: Self.confirmationsThreshold,
logger: logger
)
case let .btcAddress(address, _, _):
Expand All @@ -44,7 +44,7 @@ class DashAdapter: BitcoinBaseAdapter {
walletId: wallet.account.id,
syncMode: syncMode,
networkType: Self.networkType,
confirmationsThreshold: BitcoinBaseAdapter.confirmationsThreshold,
confirmationsThreshold: Self.confirmationsThreshold,
logger: logger
)
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import RxSwift

class ECashAdapter: BitcoinBaseAdapter {
private static let networkType: ECashKit.Kit.NetworkType = .mainNet
private static let eCashConfirmationsThreshold = 1
override var coinRate: Decimal { 100 } // pow(10,2)

private let eCashKit: ECashKit.Kit
Expand All @@ -26,7 +25,7 @@ class ECashAdapter: BitcoinBaseAdapter {
walletId: wallet.account.id,
syncMode: syncMode,
networkType: Self.networkType,
confirmationsThreshold: Self.eCashConfirmationsThreshold,
confirmationsThreshold: Self.confirmationsThreshold,
logger: logger
)
case let .hdExtendedKey(key):
Expand All @@ -35,7 +34,7 @@ class ECashAdapter: BitcoinBaseAdapter {
walletId: wallet.account.id,
syncMode: syncMode,
networkType: Self.networkType,
confirmationsThreshold: Self.eCashConfirmationsThreshold,
confirmationsThreshold: Self.confirmationsThreshold,
logger: logger
)
case let .btcAddress(address, _, _):
Expand All @@ -44,7 +43,7 @@ class ECashAdapter: BitcoinBaseAdapter {
walletId: wallet.account.id,
syncMode: syncMode,
networkType: Self.networkType,
confirmationsThreshold: Self.eCashConfirmationsThreshold,
confirmationsThreshold: Self.confirmationsThreshold,
logger: logger
)
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class LitecoinAdapter: BitcoinBaseAdapter {
syncMode: syncMode,
hasher: hasher,
networkType: Self.networkType,
confirmationsThreshold: BitcoinBaseAdapter.confirmationsThreshold,
confirmationsThreshold: Self.confirmationsThreshold,
logger: logger
)
case let .hdExtendedKey(key):
Expand All @@ -58,7 +58,7 @@ class LitecoinAdapter: BitcoinBaseAdapter {
syncMode: syncMode,
hasher: hasher,
networkType: Self.networkType,
confirmationsThreshold: BitcoinBaseAdapter.confirmationsThreshold,
confirmationsThreshold: Self.confirmationsThreshold,
logger: logger
)
case let .btcAddress(address, _, tokenType):
Expand All @@ -73,7 +73,7 @@ class LitecoinAdapter: BitcoinBaseAdapter {
syncMode: syncMode,
hasher: hasher,
networkType: Self.networkType,
confirmationsThreshold: BitcoinBaseAdapter.confirmationsThreshold,
confirmationsThreshold: Self.confirmationsThreshold,
logger: logger
)
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class AddressUriParser {
}

// try to parse ton deeplink
if scheme == DeepLinkManager.tonDeepLinkScheme, let tonScheme = BlockchainType.ton.uriScheme {
if scheme == DeepLinkManager.deepLinkScheme, let tonScheme = BlockchainType.ton.uriScheme {
var uri = AddressUri(scheme: tonScheme)
uri.address = components.path.stripping(prefix: "/")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import RxSwift
class DeepLinkManager {
static let deepLinkScheme = "unstoppable.money"
static let tonDeepLinkScheme = "ton"
static let tonUniversalHost = "ton-connect"
static let tonDeepLinkHost = "tc"

private let newSchemeRelay = BehaviorRelay<DeepLink?>(value: nil)
}
Expand All @@ -33,6 +35,13 @@ extension DeepLinkManager {
return true
}

if ((scheme == DeepLinkManager.deepLinkScheme && (host == Self.tonDeepLinkHost || host == Self.tonUniversalHost)) ||
(scheme == "https" && host == Self.deepLinkScheme && path == "/\(Self.tonUniversalHost)")),
let parameters = try? TonConnectManager.parseParameters(queryItems: queryItems) {
newSchemeRelay.accept(.tonConnect(parameters: parameters))
return true
}

if scheme == Self.tonDeepLinkScheme {
let parser = AddressParserFactory.parser(blockchainType: .ton, tokenType: nil)
do {
Expand Down Expand Up @@ -74,6 +83,7 @@ extension DeepLinkManager {
extension DeepLinkManager {
enum DeepLink {
case walletConnect(url: String)
case tonConnect(parameters: TonConnectParameters)
case coin(uid: String)
case transfer(addressUri: AddressUri)
case referral(telegramUserId: String, referralCode: String)
Expand Down
1 change: 1 addition & 0 deletions UnstoppableWallet/UnstoppableWallet/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<false/>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>googlechrome</string>
<string>tg</string>
<string>twitter</string>
<string>cydia</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ enum MainModule {
let tonConnectHandler = TonConnectEventHandler(parentViewController: viewController)

eventHandler.append(handler: deepLinkHandler)
// eventHandler.append(handler: tonConnectHandler)
eventHandler.append(handler: tonConnectHandler)
eventHandler.append(handler: widgetCoinHandler)
eventHandler.append(handler: sendAddressHandler)
eventHandler.append(handler: telegramUserHandler)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,15 @@ class MainSettingsViewController: ThemeViewController {
self?.viewModel.onTapWalletConnect()
}
),
// StaticRow(
// cell: tonConnectCell,
// id: "ton-connect",
// height: .heightCell48,
// autoDeselect: true,
// action: { [weak self] in
// self?.onTapTonConnect()
// }
// ),
StaticRow(
cell: tonConnectCell,
id: "ton-connect",
height: .heightCell48,
autoDeselect: true,
action: { [weak self] in
self?.onTapTonConnect()
}
),
tableView.universalRow48(
id: "backup-manager",
image: .local(UIImage(named: "icloud_24")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ enum TonConnect {

struct DeviceInfo: Encodable {
let platform = "iphone"
let appName = "Tonkeeper"
let appVersion = "3.4.0"
// let appName = AppConfig.appName
// let appVersion = AppConfig.appVersion
let appName = "Unstoppable Wallet"
let appVersion = AppConfig.appVersion
let maxProtocolVersion = 2
let features = [
FeatureCompatible.legacy(Feature()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ struct TonConnectConnectView: View {

@State private var selectAccountPresented = false

init(config: TonConnectConfig) {
_viewModel = StateObject(wrappedValue: TonConnectConnectViewModel(config: config))
init(config: TonConnectConfig, returnDeepLink: String? = nil) {
_viewModel = StateObject(wrappedValue: TonConnectConnectViewModel(config: config, returnDeepLink: returnDeepLink))
}

var body: some View {
Expand Down Expand Up @@ -91,6 +91,10 @@ struct TonConnectConnectView: View {
}
.onReceive(viewModel.finishPublisher) {
presentationMode.wrappedValue.dismiss()

if let deeplink = viewModel.returnDeepLink, let url = URL(string: deeplink), UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url)
}
}
.navigationTitle("TON Connect")
.navigationBarTitleDisplayMode(.inline)
Expand Down
Loading
Loading