Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/releases/5.16' into bugfix/IOS-8…
Browse files Browse the repository at this point in the history
…081_make_fix_analytics_manage_tokens
  • Loading branch information
skibinalexander committed Sep 30, 2024
2 parents 02673a0 + 8a9d266 commit 045ccb5
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 69 deletions.
82 changes: 43 additions & 39 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
GEM
remote: https://rubygems.org/
specs:
CFPropertyList (3.0.6)
CFPropertyList (3.0.7)
base64
nkf
rexml
activesupport (7.1.3)
base64
Expand All @@ -13,28 +15,28 @@ GEM
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
algoliasearch (1.27.5)
httpclient (~> 2.8, >= 2.8.3)
json (>= 1.5.1)
artifactory (3.0.15)
artifactory (3.0.17)
atomos (0.1.3)
aws-eventstream (1.3.0)
aws-partitions (1.886.0)
aws-sdk-core (3.191.0)
aws-partitions (1.981.0)
aws-sdk-core (3.209.1)
aws-eventstream (~> 1, >= 1.3.0)
aws-partitions (~> 1, >= 1.651.0)
aws-sigv4 (~> 1.8)
aws-sigv4 (~> 1.9)
jmespath (~> 1, >= 1.6.1)
aws-sdk-kms (1.77.0)
aws-sdk-core (~> 3, >= 3.191.0)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.143.0)
aws-sdk-core (~> 3, >= 3.191.0)
aws-sdk-kms (1.94.0)
aws-sdk-core (~> 3, >= 3.207.0)
aws-sigv4 (~> 1.5)
aws-sdk-s3 (1.166.0)
aws-sdk-core (~> 3, >= 3.207.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.8)
aws-sigv4 (1.8.0)
aws-sigv4 (~> 1.5)
aws-sigv4 (1.10.0)
aws-eventstream (~> 1, >= 1.0.2)
babosa (1.0.4)
base64 (0.2.0)
Expand Down Expand Up @@ -94,8 +96,8 @@ GEM
escape (0.0.4)
ethon (0.16.0)
ffi (>= 1.15.0)
excon (0.109.0)
faraday (1.10.3)
excon (0.111.0)
faraday (1.10.4)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
faraday-excon (~> 1.1)
Expand All @@ -116,22 +118,22 @@ GEM
faraday-httpclient (1.0.1)
faraday-multipart (1.0.4)
multipart-post (~> 2)
faraday-net_http (1.0.1)
faraday-net_http (1.0.2)
faraday-net_http_persistent (1.2.0)
faraday-patron (1.0.0)
faraday-rack (1.0.0)
faraday-retry (1.0.3)
faraday_middleware (1.2.0)
faraday_middleware (1.2.1)
faraday (~> 1.0)
fastimage (2.3.0)
fastlane (2.219.0)
fastimage (2.3.1)
fastlane (2.223.1)
CFPropertyList (>= 2.3, < 4.0.0)
addressable (>= 2.8, < 3.0.0)
artifactory (~> 3.0)
aws-sdk-s3 (~> 1.0)
babosa (>= 1.0.3, < 2.0.0)
bundler (>= 1.12.0, < 3.0.0)
colored
colored (~> 1.2)
commander (~> 4.6)
dotenv (>= 2.1.1, < 3.0.0)
emoji_regex (>= 0.1, < 4.0)
Expand All @@ -152,10 +154,10 @@ GEM
mini_magick (>= 4.9.4, < 5.0.0)
multipart-post (>= 2.0.0, < 3.0.0)
naturally (~> 2.2)
optparse (>= 0.1.1)
optparse (>= 0.1.1, < 1.0.0)
plist (>= 3.1.0, < 4.0.0)
rubyzip (>= 2.0.0, < 3.0.0)
security (= 0.1.3)
security (= 0.1.5)
simctl (~> 1.6.3)
terminal-notifier (>= 2.0.0, < 3.0.0)
terminal-table (~> 3)
Expand All @@ -164,7 +166,7 @@ GEM
word_wrap (~> 1.0.0)
xcodeproj (>= 1.13.0, < 2.0.0)
xcpretty (~> 0.3.0)
xcpretty-travis-formatter (>= 0.0.3)
xcpretty-travis-formatter (>= 0.0.3, < 2.0.0)
fastlane-plugin-firebase_app_distribution (0.9.0)
google-apis-firebaseappdistribution_v1 (~> 0.3.0)
google-apis-firebaseappdistribution_v1alpha (~> 0.2.0)
Expand Down Expand Up @@ -192,12 +194,12 @@ GEM
google-apis-core (>= 0.11.0, < 2.a)
google-apis-storage_v1 (0.31.0)
google-apis-core (>= 0.11.0, < 2.a)
google-cloud-core (1.6.1)
google-cloud-core (1.7.1)
google-cloud-env (>= 1.0, < 3.a)
google-cloud-errors (~> 1.0)
google-cloud-env (1.6.0)
faraday (>= 0.17.3, < 3.0)
google-cloud-errors (1.3.1)
google-cloud-errors (1.4.0)
google-cloud-storage (1.47.0)
addressable (~> 2.8)
digest-crc (~> 0.4)
Expand All @@ -213,42 +215,44 @@ GEM
os (>= 0.9, < 2.0)
signet (>= 0.16, < 2.a)
highline (2.0.3)
http-cookie (1.0.5)
http-cookie (1.0.7)
domain_name (~> 0.5)
httpclient (2.8.3)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
jmespath (1.6.2)
json (2.7.1)
jwt (2.7.1)
mini_magick (4.12.0)
json (2.7.2)
jwt (2.9.1)
base64
mini_magick (4.13.2)
mini_mime (1.1.5)
minitest (5.22.2)
molinillo (0.8.0)
multi_json (1.15.0)
multipart-post (2.4.0)
multipart-post (2.4.1)
mutex_m (0.2.0)
nanaimo (0.3.0)
nap (1.1.0)
naturally (2.2.1)
netrc (0.11.0)
optparse (0.4.0)
nkf (0.2.0)
optparse (0.5.0)
os (1.1.4)
plist (3.7.1)
public_suffix (4.0.7)
rake (13.1.0)
rake (13.2.1)
representable (3.2.0)
declarative (< 0.1.0)
trailblazer-option (>= 0.1.1, < 0.2.0)
uber (< 0.2.0)
retriable (3.1.2)
rexml (3.2.6)
rexml (3.3.7)
rouge (2.0.7)
ruby-macho (2.5.1)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
security (0.1.3)
signet (0.18.0)
security (0.1.5)
signet (0.19.0)
addressable (~> 2.8)
faraday (>= 0.17.5, < 3.a)
jwt (>= 1.5, < 3.0)
Expand All @@ -269,15 +273,15 @@ GEM
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
uber (0.1.0)
unicode-display_width (2.5.0)
unicode-display_width (2.6.0)
word_wrap (1.0.0)
xcodeproj (1.24.0)
xcodeproj (1.25.0)
CFPropertyList (>= 2.3.3, < 4.0)
atomos (~> 0.1.3)
claide (>= 1.0.2, < 2.0)
colored2 (~> 3.1)
nanaimo (~> 0.3.0)
rexml (~> 3.2.4)
rexml (>= 3.3.2, < 4.0)
xcpretty (0.3.0)
rouge (~> 2.0.7)
xcpretty-travis-formatter (1.0.1)
Expand Down
2 changes: 1 addition & 1 deletion Tangem/App/Services/Analytics/Analytics+ParameterKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extension Analytics {
enum ParameterKey: String {
case blockchain
case firmware = "Firmware"
case action
case action = "Action"
case errorDescription = "Error Description"
case errorCode = "Error Code"
case newSecOption = "new_security_option"
Expand Down
47 changes: 23 additions & 24 deletions Tangem/App/ViewModels/WalletModel/WalletModel+Balance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extension WalletModel {

var allBalance: Balance {
let cryptoBalance: Decimal? = {
switch (availableBalance.crypto, stakingManager?.state.balances?.sum()) {
switch (availableBalance.crypto, stakedBalance.crypto) {
case (.none, _): nil
// What we have to do if we have only blocked balance?
case (.some(let available), .none): available
Expand Down Expand Up @@ -61,6 +61,19 @@ extension WalletModel {
return .init(crypto: cryptoBalance, fiat: fiatBalance)
}

var stakedWithPendingBalance: Balance {
let stakingBalance = stakingManagerState.balances?.stakes().sum()
let fiatBalance: Decimal? = {
guard let stakingBalance, let currencyId = tokenItem.currencyId else {
return nil
}

return converter.convertToFiat(stakingBalance, currencyId: currencyId)
}()

return .init(crypto: stakingBalance, fiat: fiatBalance)
}

var stakedBalance: Balance {
let stakingBalance = stakingManagerState.balances?.blocked().sum()
let fiatBalance: Decimal? = {
Expand All @@ -75,7 +88,7 @@ extension WalletModel {
}

var stakedRewardsBalance: Balance {
let rewardsToClaim = stakingManagerState.rewardsToClaim
let rewardsToClaim = stakingManagerState.balances?.rewards().sum()
let fiatBalance: Decimal? = {
guard let rewardsToClaim, let currencyId = tokenItem.currencyId else {
return nil
Expand All @@ -91,14 +104,18 @@ extension WalletModel {
formatted(allBalance)
}

var stakedBalanceFormatted: BalanceFormatted {
formatted(stakedBalance)
}

var availableBalanceFormatted: BalanceFormatted {
formatted(availableBalance)
}

var stakedWithPendingBalanceFormatted: BalanceFormatted {
formatted(stakedWithPendingBalance)
}

var stakedBalanceFormatted: BalanceFormatted {
formatted(stakedBalance)
}

var stakedRewardsBalanceFormatted: BalanceFormatted {
formatted(stakedRewardsBalance)
}
Expand All @@ -110,21 +127,3 @@ extension WalletModel {
return .init(crypto: cryptoFormatted, fiat: fiatFormatted)
}
}

private extension StakingManagerState {
var balances: [StakingBalance]? {
guard case .staked(let staked) = self else {
return nil
}

return staked.balances
}

var rewardsToClaim: Decimal? {
guard case .staked(let staked) = self else {
return nil
}

return staked.balances.rewards().sum()
}
}
2 changes: 1 addition & 1 deletion Tangem/Modules/Markets/TokenList/MarketsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct MarketsView: View {
.scrollDismissesKeyboardCompat(.immediately)
}
.alert(item: $viewModel.alert, content: { $0.alert })
.background(Colors.Background.primary)
.background(Colors.Background.primary.ignoresSafeArea())

if #available(iOS 17.0, *) {
content
Expand Down
7 changes: 4 additions & 3 deletions Tangem/Modules/TokenDetails/TokenDetailsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,11 @@ private extension TokenDetailsViewModel {
private func bind() {
Publishers.CombineLatest(
walletModel.walletDidChangePublisher,
walletModel.stakingManagerStatePublisher.filter { $0 != .loading }
walletModel.stakingManagerStatePublisher
)
.filter { $1 != .loading }
.receive(on: DispatchQueue.main)
.sink { _ in } receiveValue: { [weak self] newState, _ in
.receiveValue { [weak self] newState, _ in
AppLog.shared.debug("Token details receive new wallet model state: \(newState)")
self?.updateBalance(walletModelState: newState)
}
Expand Down Expand Up @@ -306,7 +307,7 @@ private extension TokenDetailsViewModel {
}()

activeStakingViewData = ActiveStakingViewData(
balance: .balance(walletModel.stakedBalanceFormatted, action: { [weak self] in
balance: .balance(walletModel.stakedWithPendingBalanceFormatted, action: { [weak self] in
self?.openStaking()
}),
rewards: rewards
Expand Down
2 changes: 1 addition & 1 deletion TangemStaking/Models/StakingBalance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public extension Array where Element == StakingBalance {
}

/// The balance of "stakes" includes the `pending` balance from the local cache
/// DO NOT use for get the balance
/// DO NOT use it to calculate the all balance. It can affect the balance, more that there is
func stakes() -> Self {
filter { $0.balanceType != .rewards }
}
Expand Down

0 comments on commit 045ccb5

Please sign in to comment.