Skip to content

Commit

Permalink
Merge pull request #4527 from tangem/releases/5.20
Browse files Browse the repository at this point in the history
Sync release 5.20 into develop
  • Loading branch information
tureck1y authored Jan 22, 2025
2 parents c9df055 + 6d90cf4 commit 8bba0df
Show file tree
Hide file tree
Showing 69 changed files with 429 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@ import BigInt
import Moya
import TangemNetworkUtils

class EthereumJsonRpcProvider: HostProvider {
let url: URL
final class EthereumJsonRpcProvider: HostProvider {
private let node: NodeInfo
private let provider: NetworkProvider<EthereumTarget>

var host: String {
url.hostOrUnknown
node.url.hostOrUnknown
}

private let provider: NetworkProvider<EthereumTarget>

init(url: URL, configuration: NetworkProviderConfiguration) {
self.url = url
init(node: NodeInfo, configuration: NetworkProviderConfiguration) {
self.node = node
provider = NetworkProvider<EthereumTarget>(configuration: configuration)
}

Expand Down Expand Up @@ -63,7 +62,7 @@ class EthereumJsonRpcProvider: HostProvider {
}

private func requestPublisher<Result: Decodable>(for targetType: EthereumTarget.EthereumTargetType) -> AnyPublisher<Result, Error> {
let target = EthereumTarget(targetType: targetType, baseURL: url)
let target = EthereumTarget(targetType: targetType, node: node)

return provider.requestPublisher(target)
.filterSuccessfulStatusAndRedirectCodes()
Expand Down
23 changes: 18 additions & 5 deletions BlockchainSdk/Blockchains/Ethereum/Network/EthereumTarget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ import Moya
import TangemNetworkUtils

struct EthereumTarget: TargetType {
let targetType: EthereumTargetType
let baseURL: URL
private let targetType: EthereumTargetType
private let node: NodeInfo

var baseURL: URL {
node.url
}

var path: String {
return ""
Expand All @@ -29,9 +33,18 @@ struct EthereumTarget: TargetType {
}

var headers: [String: String]? {
[
"Content-Type": "application/json",
]
var headers = ["Content-Type": "application/json"]

if let headersKeyInfo = node.headers {
headers[headersKeyInfo.headerName] = headersKeyInfo.headerValue
}

return headers
}

init(targetType: EthereumTargetType, node: NodeInfo) {
self.targetType = targetType
self.node = node
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct BitrockExternalLinkProvider: ExternalLinkProvider {
init(isTestnet: Bool) {
baseExplorerUrl = isTestnet
? "https://testnetscan.bit-rock.io"
: "https://scan.bit-rock.io"
: "https://explorer.bit-rock.io"
}

func url(address: String, contractAddress: String?) -> URL? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct NowNodesAPIKeysInfoProvider {
let apiKey: String
func apiKeys(for blockchain: Blockchain) -> APIHeaderKeyInfo? {
switch blockchain {
case .xrp, .tron, .algorand, .aptos, .solana:
case .xrp, .tron, .algorand, .aptos, .solana, .odysseyChain:
return .init(
headerName: Constants.nowNodesApiKeyHeaderName,
headerValue: apiKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ struct NowNodesAPIResolver {
link = "https://sui.nownodes.io/\(apiKey)"
case .tezos:
link = "https://xtz.nownodes.io/\(apiKey)"
case .odysseyChain:
link = "https://odyssey.nownodes.io/ext/bc/D/rpc"
default:
return nil
}
Expand Down
8 changes: 6 additions & 2 deletions BlockchainSdk/Common/Blockchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ public indirect enum Blockchain: Equatable, Hashable {
.dash,
.kaspa,
.ravencoin,
.ducatus:
.ducatus,
.fact0rn:
return true
default:
return false
Expand All @@ -250,7 +251,8 @@ public indirect enum Blockchain: Equatable, Hashable {
.dash,
.kaspa,
.ravencoin,
.ducatus:
.ducatus,
.fact0rn:
return true
default:
return false
Expand Down Expand Up @@ -605,6 +607,8 @@ public indirect enum Blockchain: Equatable, Hashable {
"Toncoin"
case .fantom:
"Fantom"
case .odysseyChain:
"Dione"
default:
displayName
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct EstimationFeeAddressFactory {
case .bitcoin:
return "bc1qkrc5kmpq546wr2xk0errg58yw9jjq7thvhdk5k"
case .litecoin:
return "MSqjXH6toL4kHqsRo3mWaWMkhmiH9GQxLR"
return "LeAXZ4WKNy8zeybFkD6scFpBSmCPmENUEW"
case .bitcoinCash:
return "bitcoincash:qrn96yyxa93t6sqmehvls6746qafkcsuku6zmd9460"
case .dogecoin:
Expand Down
2 changes: 1 addition & 1 deletion BlockchainSdk/Common/NetworkProviderAssembly.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ struct NetworkProviderAssembly {
func makeEthereumJsonRpcProviders(with input: NetworkProviderAssemblyInput) -> [EthereumJsonRpcProvider] {
return APIResolver(blockchain: input.blockchain, config: input.blockchainSdkConfig)
.resolveProviders(apiInfos: input.apiInfo) { nodeInfo, _ in
EthereumJsonRpcProvider(url: nodeInfo.url, configuration: input.networkConfig)
EthereumJsonRpcProvider(node: nodeInfo, configuration: input.networkConfig)
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion Modules/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ var serviceModules: [PackageDescription.Target] {
]
),
.tangemTarget(
name: "TangemUIKitUtils",
name: "TangemUIUtils",
swiftSettings: [
// TODO: Andrey Fedorov - Remove after migration to Swift 6 structured concurrency (IOS-8369)
.swiftLanguageMode(.v5),
]
),
.tangemTarget(
name: "TangemUI",
swiftSettings: [
// TODO: Andrey Fedorov - Remove after migration to Swift 6 structured concurrency (IOS-8369)
.swiftLanguageMode(.v5),
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -1,67 +1,16 @@
//
// View+ReadGeometry.swift
// Tangem
// GeometryInfoReaderViewModifier.swift
// TangemUI
//
// Created by Andrey Fedorov on 14.06.2023.
// Copyright © 2023 Tangem AG. All rights reserved.
//

import SwiftUI

struct GeometryInfo: Equatable {
static var zero: Self {
return GeometryInfo(
coordinateSpace: .local,
frame: .zero,
size: .zero,
safeAreaInsets: .init()
)
}

let coordinateSpace: CoordinateSpace
let frame: CGRect
let size: CGSize
let safeAreaInsets: EdgeInsets

fileprivate init(
coordinateSpace: CoordinateSpace,
frame: CGRect,
size: CGSize,
safeAreaInsets: EdgeInsets
) {
self.coordinateSpace = coordinateSpace
self.frame = frame
self.size = size
self.safeAreaInsets = safeAreaInsets
}
}

extension GeometryInfo {
struct ThrottleInterval: ExpressibleByFloatLiteral {
// No throttling at all.
static let zero = ThrottleInterval(0.0)
/// Aggressive throttling, use for non-precision tasks.
static let aggressive = ThrottleInterval(1.0 / 30.0)
/// Standard 60 FPS (single frame duration: ~16msec).
static let standard = ThrottleInterval(1.0 / 60.0)
/// 120 FPS on ProMotion capable devices (single frame duration: ~8msec).
static let proMotion = ThrottleInterval(1.0 / 120.0)

fileprivate let value: CFTimeInterval

init(_ value: CFTimeInterval) {
self.value = value
}

init(floatLiteral value: CFTimeInterval) {
self.value = value
}
}
}

// MARK: - Convenience extensions

extension View {
public extension View {
/// Closure-based helper. Use optional `keyPath` parameter if you aren't interested
/// in the whole `GeometryInfo` but rather a single property of it.
func readGeometry<T>(
Expand Down Expand Up @@ -111,6 +60,59 @@ extension View {
}
}

// MARK: - Auxiliary types

public struct GeometryInfo: Equatable {
public static var zero: Self {
return GeometryInfo(
coordinateSpace: .local,
frame: .zero,
size: .zero,
safeAreaInsets: .init()
)
}

public let coordinateSpace: CoordinateSpace
public let frame: CGRect
public let size: CGSize
public let safeAreaInsets: EdgeInsets

fileprivate init(
coordinateSpace: CoordinateSpace,
frame: CGRect,
size: CGSize,
safeAreaInsets: EdgeInsets
) {
self.coordinateSpace = coordinateSpace
self.frame = frame
self.size = size
self.safeAreaInsets = safeAreaInsets
}
}

public extension GeometryInfo {
struct ThrottleInterval: ExpressibleByFloatLiteral {
// No throttling at all.
public static let zero = ThrottleInterval(0.0)
/// Aggressive throttling, use for non-precision tasks.
public static let aggressive = ThrottleInterval(1.0 / 30.0)
/// Standard 60 FPS (single frame duration: ~16msec).
public static let standard = ThrottleInterval(1.0 / 60.0)
/// 120 FPS on ProMotion capable devices (single frame duration: ~8msec).
public static let proMotion = ThrottleInterval(1.0 / 120.0)

fileprivate let value: CFTimeInterval

public init(_ value: CFTimeInterval) {
self.value = value
}

public init(floatLiteral value: CFTimeInterval) {
self.value = value
}
}
}

// MARK: - Private implementation

private struct GeometryInfoReaderViewModifier: ViewModifier {
Expand Down
Loading

0 comments on commit 8bba0df

Please sign in to comment.