vultisig / vultisig-ios

Vultisig iOS App
Apache License 2.0
8 stars 5 forks source link

SendCryptoViewModel - Full refactory #827

Open enriquesouza opened 1 week ago

enriquesouza commented 1 week ago

@johnnyluo @flypaper0 I would like to propose a full re-factory of this view model and create a service, with protocols and polymorphism so that we can eliminate those switches and if, else. We can use generics, and some factories to make the calculations.

import SwiftUI
import BigInt

protocol SendChainService {
    func setMaxValues(tx: SendTransaction, percentage: Double)
    func loadGasInfoForSending(tx: SendTransaction) async
    func getPriceRate(tx: SendTransaction) async -> Decimal
    func convertFiatToCoin(newValue: String, tx: SendTransaction) async
    func convertToFiat(newValue: String, tx: SendTransaction, setMaxValue: Bool) async
    func validateAddress(tx: SendTransaction, address: String) -> Bool
    func validateForm(tx: SendTransaction) async -> Bool
}

Some abstract classes:

So some commons classes can be reused and we can override whatever is particular.

Then we will have a way more organized view model.

johnnyluo commented 1 week ago

Have a discussion with @flypaper0 , I personally don't like polymorphism much

enriquesouza commented 1 week ago

Yup. Let's try to keep this in the loop for the next meeting.