Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ final class ExtrinsicSubmissionDelayedCompleter {
}

private extension ExtrinsicSubmissionDelayedCompleter {
func switchToWalletIfNeeded(_ newWallet: MetaAccountModel) {
func switchToWalletIfNeeded(
_ newWallet: MetaAccountModel,
completion: @escaping () -> Void
) {
guard
let currentWallet = selectedWalletSettings.value,
currentWallet.metaId != newWallet.metaId else {
currentWallet.metaId != newWallet.metaId
else {
completion()
return
}

Expand All @@ -28,6 +33,8 @@ private extension ExtrinsicSubmissionDelayedCompleter {
if case .success = result {
self.eventCenter.notify(with: SelectedWalletSwitched())
}

completion()
}
}
}
Expand All @@ -45,16 +52,16 @@ extension ExtrinsicSubmissionDelayedCompleter: ExtrinsicSubmissionCompliting {
return false
}

MainTransitionHelper.transitToMainTabBarController(
selectingIndex: MainTabBarIndex.wallet,
closing: controller,
postProcessing: .postTransition { tabBar in
tabBar.presentDelayedOperationCreated()
},
animated: true
)

switchToWalletIfNeeded(delayedCallWallet)
switchToWalletIfNeeded(delayedCallWallet) {
MainTransitionHelper.transitToMainTabBarController(
selectingIndex: MainTabBarIndex.wallet,
closing: controller,
postProcessing: .postTransition { tabBar in
tabBar.presentDelayedOperationCreated()
},
animated: true
)
}

return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ extension DelegationResolution {
}

protocol DelegationResolutionNodeProtocol {
var metaId: MetaAccountModel.Id { get }

func pathDelegationValue() -> AccountDelegationPathValue?

func toNestedValue(
Expand All @@ -31,9 +33,14 @@ protocol DelegationResolutionNodeSourceProtocol {

extension DelegationResolution.Graph {
final class ProxyResolutionNode: DelegationResolutionNodeProtocol {
let metaId: MetaAccountModel.Id
let proxyTypes: Set<Proxy.ProxyType>

init(proxyTypes: Set<Proxy.ProxyType>) {
init(
metaId: MetaAccountModel.Id,
proxyTypes: Set<Proxy.ProxyType>
) {
self.metaId = metaId
self.proxyTypes = proxyTypes
}

Expand All @@ -49,21 +56,30 @@ extension DelegationResolution.Graph {

let availableTypes = proxyTypes.intersection(possibleTypes)

return availableTypes.isEmpty ? nil : ProxyResolutionNode(proxyTypes: availableTypes)
return availableTypes.isEmpty ? nil : ProxyResolutionNode(
metaId: metaId,
proxyTypes: availableTypes
)
}

func pathDelegationValue() -> AccountDelegationPathValue? {
guard let proxyType = proxyTypes.first else { return nil }

return DelegationResolution.PathFinder.ProxyDelegationValue(proxyType: proxyType)
return DelegationResolution.PathFinder.ProxyDelegationValue(
metaId: metaId,
proxyType: proxyType
)
}

func merging(other: DelegationResolutionNodeProtocol) -> DelegationResolutionNodeProtocol {
guard let otherProxyNode = other as? ProxyResolutionNode else {
return self
}

return ProxyResolutionNode(proxyTypes: proxyTypes.union(otherProxyNode.proxyTypes))
return ProxyResolutionNode(
metaId: other.metaId,
proxyTypes: proxyTypes.union(otherProxyNode.proxyTypes)
)
}

func delaysCallExecution() -> Bool {
Expand All @@ -76,13 +92,16 @@ extension DelegationResolution.Graph {

extension DelegationResolution.Graph {
final class MultisigResolutionNode: DelegationResolutionNodeProtocol {
let metaId: MetaAccountModel.Id
let threshold: UInt16
let signatories: [AccountId]

init(
metaId: MetaAccountModel.Id,
threshold: UInt16,
signatories: [AccountId]
) {
self.metaId = metaId
self.threshold = threshold
self.signatories = signatories
}
Expand All @@ -96,6 +115,7 @@ extension DelegationResolution.Graph {

func pathDelegationValue() -> AccountDelegationPathValue? {
DelegationResolution.PathFinder.MultisigDelegationValue(
metaId: metaId,
threshold: threshold,
signatories: signatories
)
Expand Down Expand Up @@ -128,7 +148,10 @@ extension MetaAccountModel: DelegationResolutionNodeSourceProtocol {
delegatedAccountId: proxiedChainAccount.accountId,
relationType: .proxy
)
let value = DelegationResolution.Graph.ProxyResolutionNode(proxyTypes: [proxy.type])
let value = DelegationResolution.Graph.ProxyResolutionNode(
metaId: metaId,
proxyTypes: [proxy.type]
)

return (key, value)
} else if
Expand All @@ -143,6 +166,7 @@ extension MetaAccountModel: DelegationResolutionNodeSourceProtocol {
)

let value = DelegationResolution.Graph.MultisigResolutionNode(
metaId: metaId,
threshold: UInt16(multisig.threshold),
signatories: allSignatories
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ protocol AccountDelegationPathValue {

var delegationType: DelegationResolution.ItemType { get }

var metaId: MetaAccountModel.Id { get }

func delaysCallExecution() -> Bool
}

Expand Down Expand Up @@ -203,6 +205,7 @@ extension DelegationResolution {

extension DelegationResolution.PathFinder {
struct ProxyDelegationValue: AccountDelegationPathValue {
let metaId: MetaAccountModel.Id
let proxyType: Proxy.ProxyType

var delegationType: DelegationResolution.ItemType {
Expand Down Expand Up @@ -230,6 +233,7 @@ extension DelegationResolution.PathFinder {
}

struct MultisigDelegationValue: AccountDelegationPathValue {
let metaId: MetaAccountModel.Id
let threshold: UInt16
let signatories: [AccountId]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,10 @@ extension ExtrinsicSenderResolution {
extension ExtrinsicSenderResolution.ResolvedDelegate {
func firstDelayedCallWallet() -> MetaAccountModel? {
let delayedWalletIds: [MetaAccountModel.Id] = paths.flatMap { path in
let components = path.value.components
path.value.components.compactMap { component in
guard component.delegationValue.delaysCallExecution() else { return nil }

return components.enumerated().compactMap { indexedComponent in
let index = indexedComponent.offset
let component = indexedComponent.element
if component.delegationValue.delaysCallExecution() {
return index == 0 ? delegatedAccount.metaId : components[index - 1].account.metaId
} else {
return nil
}
return component.delegationValue.metaId
}
}

Expand Down