This repository was archived by the owner on Mar 26, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathConfirmRecipientViewModel.swift
More file actions
98 lines (88 loc) · 3.03 KB
/
ConfirmRecipientViewModel.swift
File metadata and controls
98 lines (88 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright (c). Gem Wallet. All rights reserved.
import Components
import Localization
import Primitives
import PrimitivesComponents
import Style
struct ConfirmRecipientViewModel {
private let model: TransferDataViewModel
private let addressName: AddressName?
private let addressLink: BlockExplorerLink
init(model: TransferDataViewModel, addressName: AddressName?, addressLink: BlockExplorerLink) {
self.model = model
self.addressName = addressName
self.addressLink = addressLink
}
}
// MARK: - ItemModelProvidable
extension ConfirmRecipientViewModel: ItemModelProvidable {
var itemModel: ConfirmTransferItemModel {
guard showRecipient else { return .empty }
return .recipient(
AddressListItemViewModel(
title: recipientTitle,
account: SimpleAccount(
name: addressName?.name ?? model.recipient.name,
chain: model.chain,
address: model.recipient.address,
assetImage: addressNameImage,
addressType: addressName?.type
),
mode: .nameOrAddress,
addressLink: addressLink
)
)
}
}
// MARK: - Private
extension ConfirmRecipientViewModel {
private var addressNameImage: AssetImage? {
switch addressName?.type {
case .contact: .image(Images.System.person)
case .internalWallet: .image(Images.System.wallet)
case .address, .contract, .validator, .none: nil
}
}
private var recipientTitle: String {
switch model.type {
case .swap: Localized.Common.provider
case .stake(_, let stakeType):
switch stakeType {
case .stake, .unstake, .redelegate, .rewards, .withdraw: Localized.Stake.validator
case .freeze, .unfreeze: Localized.Stake.resource
}
case .generic:
switch model.type.outputAction {
case .sign: Localized.Asset.contract
case .send: Localized.Transfer.Recipient.title
}
case .earn: Localized.Common.provider
case .transfer, .deposit, .withdrawal, .transferNft, .tokenApprove, .account, .perpetual: Localized.Transfer.Recipient.title
}
}
private var showRecipient: Bool {
guard !model.recipient.address.isEmpty else { return false }
return switch model.type {
case .stake(_, let stakeType):
switch stakeType {
case .stake, .unstake, .redelegate, .withdraw: true
case .rewards: false
case .freeze, .unfreeze: true
}
case .account,
.swap,
.perpetual: false
case .earn: true
case .generic:
switch model.type.outputAction {
case .sign: false
case .send: true
}
case .transfer,
.transferNft,
.deposit,
.withdrawal,
.tokenApprove: true
}
}
}