Skip to content

Commit

Permalink
bugfixes, fix address icon
Browse files Browse the repository at this point in the history
  • Loading branch information
lynx56 committed Jan 17, 2024
1 parent 32b1142 commit 4876dc5
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ struct ProxyDepositCalculator {
return nil
}

let currentDeposit = base + BigUInt(proxyCount) * factor
let newDeposit = base + BigUInt(proxyCount + 1) * factor
let currentDeposit = proxyCount > 0 ? calculate(base: base, factor: factor, proxyCount: proxyCount) : 0
let newDeposit = calculate(base: base, factor: factor, proxyCount: proxyCount + 1)

return .init(
current: currentDeposit,
new: newDeposit
)
}

func calculate(base: BigUInt, factor: BigUInt, proxyCount: Int) -> BigUInt {
base + BigUInt(proxyCount) * factor
}
}

struct ProxyDeposit {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class StakingProxyBasePresenter: StakingSetupProxyBasePresenterProtocol {
private var fee: ExtrinsicFeeProtocol?
private var existensialDeposit: BigUInt?
private var maxProxies: Int?
private var proxy: ProxyDefinition?
private var proxy: UncertainStorage<ProxyDefinition?> = .undefined

init(
chainAsset: ChainAsset,
Expand Down Expand Up @@ -86,11 +86,11 @@ class StakingProxyBasePresenter: StakingSetupProxyBasePresenterProtocol {
dataValidatingFactory.proxyNotExists(
address: getProxyAddress(),
chain: chainAsset.chain,
proxyList: proxy,
proxyList: proxy.map { $0?.definition ?? [] }.value,
locale: selectedLocale
),
dataValidatingFactory.notReachedMaximimProxyCount(
proxy?.definition.count,
proxy.map { $0?.definition.count ?? 0 }.value,
limit: maxProxies,
chain: chainAsset.chain,
locale: selectedLocale
Expand Down Expand Up @@ -173,7 +173,7 @@ extension StakingProxyBasePresenter: StakingProxyBaseInteractorOutputProtocol {
}

func didReceive(proxy: ProxyDefinition?) {
self.proxy = proxy
self.proxy = .defined(proxy)
}

func didReceive(price: PriceData?) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Foundation
import BigInt
import SoraFoundation
import SubstrateSdk

final class StakingSetupProxyPresenter: StakingProxyBasePresenter {
weak var view: StakingSetupProxyViewProtocol? {
Expand All @@ -12,6 +13,9 @@ final class StakingSetupProxyPresenter: StakingProxyBasePresenter {
let web3NameViewModelFactory: Web3NameViewModelFactoryProtocol
private(set) var proxyAddress: StakingSetupProxyAccount? {
didSet {
guard view?.isSetup == true else {
return
}
switch proxyAddress {
case .none, .address:
view?.didReceiveWeb3NameProxy(viewModel: .loaded(value: nil))
Expand All @@ -20,10 +24,12 @@ final class StakingSetupProxyPresenter: StakingProxyBasePresenter {
view?.didReceiveWeb3NameProxy(viewModel: isLoading ? .loading :
.loaded(value: externalAccount.recipient.value??.displayTitle))
}
provideAccountFieldStateViewModel()
}
}

private var yourWallets: [MetaAccountChainResponse] = []
private(set) lazy var iconGenerator = PolkadotIconGenerator()

init(
chainAsset: ChainAsset,
Expand Down Expand Up @@ -150,6 +156,19 @@ final class StakingSetupProxyPresenter: StakingProxyBasePresenter {
override func getProxyAddress() -> AccountAddress {
proxyAddress?.address ?? ""
}

private func provideAccountFieldStateViewModel() {
if
let accountId = try? getProxyAddress().toAccountId(using: chainAsset.chain.chainFormat),
let icon = try? iconGenerator.generateFromAccountId(accountId) {
let iconViewModel = DrawableIconViewModel(icon: icon)
let viewModel = AccountFieldStateViewModel(icon: iconViewModel)
view?.didReceiveAccountState(viewModel: viewModel)
} else {
let viewModel = AccountFieldStateViewModel(icon: nil)
view?.didReceiveAccountState(viewModel: viewModel)
}
}
}

extension StakingSetupProxyPresenter: StakingSetupProxyPresenterProtocol {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ protocol StakingSetupProxyViewProtocol: StakingSetupProxyBaseViewProtocol {
func didReceiveProxyAccountInput(viewModel: InputViewModelProtocol)
func didReceiveWeb3NameProxy(viewModel: LoadableViewModelState<Web3NameReceipientView.Model>)
func didReceiveYourWallets(state: YourWalletsControl.State)
func didReceiveAccountState(viewModel: AccountFieldStateViewModel)
}

protocol StakingSetupProxyPresenterProtocol: StakingSetupProxyBasePresenterProtocol {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ extension StakingSetupProxyViewController: StakingSetupProxyViewProtocol {
func didReceiveYourWallets(state: YourWalletsControl.State) {
rootView.yourWalletsControl.apply(state: state)
}

func didReceiveAccountState(viewModel: AccountFieldStateViewModel) {
rootView.accountInputView.bind(fieldStateViewModel: viewModel)
}
}

extension StakingSetupProxyViewController: Localizable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protocol ProxyDataValidatorFactoryProtocol: BaseDataValidatingFactoryProtocol {
func proxyNotExists(
address: String,
chain: ChainModel,
proxyList: ProxyDefinition?,
proxyList: [Proxy.ProxyDefinition]?,
locale: Locale
) -> DataValidating
}
Expand Down Expand Up @@ -140,7 +140,7 @@ final class ProxyDataValidatorFactory: ProxyDataValidatorFactoryProtocol {
func proxyNotExists(
address: String,
chain: ChainModel,
proxyList: ProxyDefinition?,
proxyList: [Proxy.ProxyDefinition]?,
locale: Locale
) -> DataValidating {
ErrorConditionViolation(onError: { [weak self] in
Expand All @@ -154,10 +154,10 @@ final class ProxyDataValidatorFactory: ProxyDataValidatorFactoryProtocol {
)
}, preservesCondition: {
guard let proxyList = proxyList else {
return true
return false
}
let accountId = try? address.toAccountId(using: chain.chainFormat)
return proxyList.definition.contains(where: { $0.proxy == accountId }) == false
return proxyList.contains(where: { $0.proxy == accountId }) == false
})
}
}

0 comments on commit 4876dc5

Please sign in to comment.