Skip to content

Commit

Permalink
Merge branch 'develop' into IOS-5193_refactor_scanner
Browse files Browse the repository at this point in the history
  • Loading branch information
tureck1y committed Apr 15, 2024
2 parents eb678fe + 43489ef commit d92dd69
Show file tree
Hide file tree
Showing 30 changed files with 161 additions and 79 deletions.
6 changes: 3 additions & 3 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ use_frameworks!
inhibit_all_warnings!

def tangem_sdk_pod
#pod 'TangemSdk', :git => 'https://github.com/Tangem/tangem-sdk-ios.git', :tag => 'develop-286'
pod 'TangemSdk', :path => '../tangem-sdk-ios'
pod 'TangemSdk', :git => 'https://github.com/Tangem/tangem-sdk-ios.git', :tag => 'develop-287'
#pod 'TangemSdk', :path => '../tangem-sdk-ios'
end

def blockchain_sdk_pods
# 'TangemWalletCore' dependency must be added via SPM

pod 'BlockchainSdk', :git => 'https://github.com/tangem/blockchain-sdk-swift.git', :tag => 'develop-556'
pod 'BlockchainSdk', :git => 'https://github.com/tangem/blockchain-sdk-swift.git', :tag => 'develop-560'
#pod 'BlockchainSdk', :path => '../blockchain-sdk-swift'

pod 'Solana.Swift', :git => 'https://github.com/tangem/Solana.Swift', :tag => '1.2.0-tangem5'
Expand Down
16 changes: 10 additions & 6 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ DEPENDENCIES:
- Amplitude
- BinanceChain (from `https://github.com/tangem/swiftbinancechain.git`, tag `0.0.11`)
- BitcoinCore.swift (from `https://github.com/tangem/bitcoincore.git`, tag `0.0.20`)
- BlockchainSdk (from `https://github.com/tangem/blockchain-sdk-swift.git`, tag `develop-556`)
- BlockchainSdk (from `https://github.com/tangem/blockchain-sdk-swift.git`, tag `develop-560`)
- BlockiesSwift (~> 0.1.2)
- CombineExt (~> 1.8.0)
- Firebase/Analytics
Expand All @@ -226,7 +226,7 @@ DEPENDENCIES:
- Kingfisher (~> 7.9.0)
- Moya
- Solana.Swift (from `https://github.com/tangem/Solana.Swift`, tag `1.2.0-tangem5`)
- TangemSdk (from `../tangem-sdk-ios`)
- TangemSdk (from `https://github.com/Tangem/tangem-sdk-ios.git`, tag `develop-287`)
- WalletConnectSwiftV2 (from `https://github.com/WalletConnect/WalletConnectSwiftV2`, tag `1.8.4`)

SPEC REPOS:
Expand Down Expand Up @@ -277,12 +277,13 @@ EXTERNAL SOURCES:
:tag: 0.0.20
BlockchainSdk:
:git: https://github.com/tangem/blockchain-sdk-swift.git
:tag: develop-556
:tag: develop-560
Solana.Swift:
:git: https://github.com/tangem/Solana.Swift
:tag: 1.2.0-tangem5
TangemSdk:
:path: "../tangem-sdk-ios"
:git: https://github.com/Tangem/tangem-sdk-ios.git
:tag: develop-287
WalletConnectSwiftV2:
:git: https://github.com/WalletConnect/WalletConnectSwiftV2
:tag: 1.8.4
Expand All @@ -299,10 +300,13 @@ CHECKOUT OPTIONS:
:tag: 0.0.20
BlockchainSdk:
:git: https://github.com/tangem/blockchain-sdk-swift.git
:tag: develop-556
:tag: develop-560
Solana.Swift:
:git: https://github.com/tangem/Solana.Swift
:tag: 1.2.0-tangem5
TangemSdk:
:git: https://github.com/Tangem/tangem-sdk-ios.git
:tag: develop-287
WalletConnectSwiftV2:
:git: https://github.com/WalletConnect/WalletConnectSwiftV2
:tag: 1.8.4
Expand Down Expand Up @@ -349,6 +353,6 @@ SPEC CHECKSUMS:
TweetNacl: 3abf4d1d2082b0114e7a67410e300892448951e6
WalletConnectSwiftV2: c1c2c2fbd0495860baf71515be1b943f0c5dce0c

PODFILE CHECKSUM: cc6c835fda01278f890557b454ccc917079f2fa8
PODFILE CHECKSUM: ee5d8c57b7a9691ef7c2d62484eec83355e27f07

COCOAPODS: 1.15.2
4 changes: 2 additions & 2 deletions Tangem/App/Models/Config/SupportedBlockchains.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ struct SupportedBlockchains {
/// Blockchains for test. They don't include in supported blockchains by default
private func testableBlockchains() -> Set<Blockchain> {
[
.mantle(testnet: false),
.manta(testnet: false),
]
}

Expand Down Expand Up @@ -115,12 +117,10 @@ struct SupportedBlockchains {
.aurora(testnet: false),
.base(testnet: false),
.playa3ullGames,
.manta(testnet: false),
.zkSync(testnet: false),
.moonbeam(testnet: false),
.polygonZkEVM(testnet: false),
.moonriver(testnet: false),
.mantle(testnet: false),
.flare(testnet: false),
.taraxa(testnet: false),
]
Expand Down
3 changes: 3 additions & 0 deletions Tangem/App/Services/Common/AppSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class AppSettings {
@AppStorageCompat(StorageType.userDidTapSendScreenSummary)
var userDidTapSendScreenSummary: Bool = false

@AppStorageCompat(StorageType.forcedDemoCardId)
var forcedDemoCardId: String? = nil

static let shared: AppSettings = .init()

private init() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import BlockchainSdk

class CommonExpressAllowanceProvider {
private var ethereumNetworkProvider: EthereumNetworkProvider?
private var ethereumTransactionProcessor: EthereumTransactionProcessor?
private var ethereumTransactionDataBuilder: EthereumTransactionDataBuilder?
private let logger: Logger

private var spendersAwaitingApprove = Set<String>()
Expand All @@ -27,7 +27,7 @@ class CommonExpressAllowanceProvider {
extension CommonExpressAllowanceProvider: ExpressAllowanceProvider {
func setup(wallet: WalletModel) {
ethereumNetworkProvider = wallet.ethereumNetworkProvider
ethereumTransactionProcessor = wallet.ethereumTransactionProcessor
ethereumTransactionDataBuilder = wallet.ethereumTransactionDataBuilder
}

func didSendApproveTransaction(for spender: String) {
Expand Down Expand Up @@ -80,10 +80,10 @@ extension CommonExpressAllowanceProvider: ExpressAllowanceProvider {
}

func makeApproveData(spender: String, amount: Decimal) throws -> Data {
guard let ethereumTransactionProcessor else {
guard let ethereumTransactionDataBuilder else {
throw AllowanceProviderError.ethereumTransactionProcessorNotFound
}

return ethereumTransactionProcessor.buildForApprove(spender: spender, amount: amount)
return ethereumTransactionDataBuilder.buildForApprove(spender: spender, amount: amount)
}
}
14 changes: 8 additions & 6 deletions Tangem/App/Services/QRCodeParser/QRCodeParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,19 @@ struct QRCodeParser {
case .message, .memo:
result.memo = parameterValue.removingPercentEncoding
case .address:
// Overrides destination address for token transfers (ERC-681)
guard case .token(let token) = amountType else { continue }

// Overrides destination address for token transfers (`address` parameter from ERC-681)
//
// `address` parameter is used only if the contract address, encoded in the QR,
// matches the contract address of the token from `amountType` property.
// Otherwise, the scanned string is likely malformed, and we stop the entire parsing routine
if token.contractAddress.caseInsensitiveCompare(result.destination) == .orderedSame {
result.destination = parameterValue
} else {
guard
case .token(let token) = amountType,
token.contractAddress.caseInsensitiveCompare(result.destination) == .orderedSame
else {
return nil
}

result.destination = parameterValue
case .value, .uint256:
// According to ERC-681, the value is specified in the atomic unit (i.e. wei). Converting it to decimals
if let valueInSmallestDenomination = Decimal(stringValue: parameterValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ protocol WalletConnectEthTransactionBuilder {
struct CommonWalletConnectEthTransactionBuilder {
private let zeroString = "0x0"

private func getGasPrice(for tx: WalletConnectEthTransaction, using gasLoader: EthereumGasLoader) async throws -> Int {
private func getGasPrice(for tx: WalletConnectEthTransaction, using ethereumNetworkProvider: EthereumNetworkProvider) async throws -> Int {
if let gasPrice = tx.gasPrice?.hexToInteger {
return gasPrice
}

let price = try await gasLoader.getGasPrice().async()
let price = try await ethereumNetworkProvider.getGasPrice().async()
return Int(price)
}

private func getGasLimit(for tx: WalletConnectEthTransaction, with amount: Amount, using gasLoader: EthereumGasLoader) async throws -> Int {
private func getGasLimit(for tx: WalletConnectEthTransaction, with amount: Amount, using ethereumNetworkProvider: EthereumNetworkProvider) async throws -> Int {
if let dappGasLimit = tx.gas?.hexToInteger ?? tx.gasLimit?.hexToInteger {
return dappGasLimit
}
Expand All @@ -37,7 +37,7 @@ struct CommonWalletConnectEthTransactionBuilder {
// to send value from dApp instead of creating it yourself. IOS-4865
let valueString = amount.value.isZero ? zeroString : tx.value

let gasLimitBigInt = try await gasLoader.getGasLimit(
let gasLimitBigInt = try await ethereumNetworkProvider.getGasLimit(
to: tx.to,
from: tx.from,
value: valueString,
Expand All @@ -49,7 +49,7 @@ struct CommonWalletConnectEthTransactionBuilder {

extension CommonWalletConnectEthTransactionBuilder: WalletConnectEthTransactionBuilder {
func buildTx(from wcTransaction: WalletConnectEthTransaction, for walletModel: WalletModel) async throws -> Transaction {
guard let gasLoader = walletModel.ethereumGasLoader else {
guard let ethereumNetworkProvider = walletModel.ethereumNetworkProvider else {
let error = WalletConnectV2Error.missingGasLoader
AppLog.shared.error(error)
throw error
Expand All @@ -66,8 +66,8 @@ extension CommonWalletConnectEthTransactionBuilder: WalletConnectEthTransactionB
let valueAmount = Amount(with: blockchain, type: .coin, value: value)

async let walletUpdate = walletModel.update(silent: false).async()
async let gasPrice = getGasPrice(for: wcTransaction, using: gasLoader)
async let gasLimit = getGasLimit(for: wcTransaction, with: valueAmount, using: gasLoader)
async let gasPrice = getGasPrice(for: wcTransaction, using: ethereumNetworkProvider)
async let gasLimit = getGasLimit(for: wcTransaction, with: valueAmount, using: ethereumNetworkProvider)

let feeValue = try await Decimal(gasLimit) * Decimal(gasPrice) / blockchain.decimalValue
let gasAmount = Amount(with: blockchain, value: feeValue)
Expand Down
11 changes: 10 additions & 1 deletion Tangem/App/Utilities/DemoUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import BlockchainSdk

struct DemoUtil {
func isDemoCard(cardId: String) -> Bool {
demoCardIds.contains(cardId)
if cardId == AppSettings.shared.forcedDemoCardId {
return true
}

return demoCardIds.contains(cardId)
}

func getDemoBlockchains(isTestnet: Bool) -> [String] {
Expand Down Expand Up @@ -63,6 +67,11 @@ extension DemoUtil {
"AB01000000046704",
"AB02000000051000",
"AB02000000050911",
"AC19000000000064",
"AF19000000000038",
"AB02000000000007", // NOTE ETH
"AC03000000076229", // Wallet 1
"AF04000000000118", // Wallet 2

// etc
"AC03000000091418",
Expand Down
8 changes: 2 additions & 6 deletions Tangem/App/ViewModels/WalletModel/WalletModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -631,10 +631,6 @@ extension WalletModel {
walletManager as? BitcoinTransactionFeeCalculator
}

var ethereumGasLoader: EthereumGasLoader? {
walletManager as? EthereumGasLoader
}

var ethereumTransactionSigner: EthereumTransactionSigner? {
walletManager as? EthereumTransactionSigner
}
Expand All @@ -643,8 +639,8 @@ extension WalletModel {
walletManager as? EthereumNetworkProvider
}

var ethereumTransactionProcessor: EthereumTransactionProcessor? {
walletManager as? EthereumTransactionProcessor
var ethereumTransactionDataBuilder: EthereumTransactionDataBuilder? {
walletManager as? EthereumTransactionDataBuilder
}

var signatureCountValidator: SignatureCountValidator? {
Expand Down
1 change: 1 addition & 0 deletions Tangem/Common/Storage/StorageType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ enum StorageType: String {
case userDidTapSendScreenSummary = "user_did_tap_send_screen_summary"
case pendingBackups = "pending_backups"
case pendingBackupsCurrentID = "pending_backups_current_id"
case forcedDemoCardId = "forced_demo_card_id"
}
24 changes: 24 additions & 0 deletions Tangem/Modules/EnvironmentSetup/EnvironmentSetupView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ struct EnvironmentSetupView: View {
DefaultHeaderView("Feature toggles")
}

demoCardIdControls

promotionProgramControls
}
.interContentPadding(8)
Expand All @@ -47,6 +49,28 @@ struct EnvironmentSetupView: View {
.alert(item: $viewModel.alert) { $0.alert }
}

private var demoCardIdControls: some View {
VStack(spacing: 10) {
Text("Demo card override")
.font(.headline)
.textCase(.uppercase)

TextField("Demo card ID", text: $viewModel.forcedDemoCardId)
.padding()
.border(.gray, width: 1)

Text(
"""
Note that a restart is required for the override to take effect. Only certain blockchains that have demo balances are considered to have their functionality affected **[\(DemoUtil().getDemoBlockchains(isTestnet: false).joined(separator: ", "))]**
**Warning**: when demo override is imposed on a regular card it still has all the amounts in the respective blockchain wallets and it is still possible to spend these money even though the displayed amount might be different
"""
)
.font(.footnote)
}
.padding(.horizontal)
}

private var promotionProgramControls: some View {
VStack(spacing: 30) {
Text("PROMOTION PROGRAM")
Expand Down
12 changes: 12 additions & 0 deletions Tangem/Modules/EnvironmentSetup/EnvironmentSetupViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ final class EnvironmentSetupViewModel: ObservableObject {
@Published var additionalSettingsViewModels: [DefaultRowViewModel] = []
@Published var alert: AlertBinder?

// Demo
@Published var forcedDemoCardId: String = ""

// Promotion
@Published var currentPromoCode: String = ""
@Published var finishedPromotionNames: String = ""
Expand Down Expand Up @@ -116,6 +119,15 @@ final class EnvironmentSetupViewModel: ObservableObject {
updateFinishedPromotionNames()

updateAwardedPromotionNames()

forcedDemoCardId = AppSettings.shared.forcedDemoCardId ?? ""

$forcedDemoCardId
.removeDuplicates()
.sink { newValue in
AppSettings.shared.forcedDemoCardId = newValue.nilIfEmpty
}
.store(in: &bag)
}

func copyCurrentPromoCode() {
Expand Down
7 changes: 5 additions & 2 deletions Tangem/Modules/Send/Destination/SendDestinationTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,19 @@ struct SendDestinationTextView: View {
Group {
clearIcon

if #available(iOS 16, *) {
if #available(iOS 16, *), viewModel.allowMultilineText {
TextField("", text: .constant("Two\nLines"), axis: .vertical)
.style(inputFieldFont, color: .black)
} else {
TextField("", text: .constant("One Line"))
.style(inputFieldFont, color: .black)
}
}
.opacity(0)

HStack(spacing: 12) {
Group {
if #available(iOS 16, *) {
if #available(iOS 16, *), viewModel.allowMultilineText {
TextField(viewModel.placeholder, text: $viewModel.input, axis: .vertical)
.lineLimit(5, reservesSpace: false)
} else {
Expand Down
11 changes: 11 additions & 0 deletions Tangem/Modules/Send/Destination/SendDestinationTextViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import SwiftUI
import Combine

class SendDestinationTextViewModel: ObservableObject, Identifiable {
let allowMultilineText: Bool
let name: String
let showAddressIcon: Bool
let description: String
Expand Down Expand Up @@ -40,6 +41,7 @@ class SendDestinationTextViewModel: ObservableObject, Identifiable {
didEnterDestination: @escaping (String) -> Void,
didPasteDestination: @escaping (String) -> Void
) {
allowMultilineText = style.allowMultilineText
name = style.name
showAddressIcon = style.showAddressIcon
description = style.description
Expand Down Expand Up @@ -152,6 +154,15 @@ extension SendDestinationTextViewModel {
}

private extension SendDestinationTextViewModel.Style {
var allowMultilineText: Bool {
switch self {
case .address:
return true
case .additionalField:
return false
}
}

var name: String {
switch self {
case .address:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ extension CustomBitcoinFeeService: CustomFeeService {
fieldSuffix: nil,
fractionDigits: 0,
amountAlternativePublisher: .just(output: nil),
footer: nil
footer: Localization.sendSatoshiPerByteText
) { [weak self] decimalValue in
let intValue: Int?
if let roundedValue = decimalValue?.rounded() {
Expand Down
Loading

0 comments on commit d92dd69

Please sign in to comment.