An advanced Ethereum/EVM mobile wallet
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
alpha-wallet-ios/Trust/Transactions/Storage/Session.swift

55 lines
1.2 KiB

// Copyright SIX DAY LLC. All rights reserved.
import Foundation
enum RefreshType {
case balance
}
class WalletSession {
let account: Account
let web3: Web3Swift
let config: Config
let chainState: ChainState
var balance: Balance? {
return balanceCoordinator.balance
}
private lazy var balanceCoordinator: BalanceCoordinator = {
return BalanceCoordinator(session: self)
}()
var balanceViewModel: Subscribable<BalanceBaseViewModel> = Subscribable(nil)
init(
account: Account,
config: Config
) {
self.account = account
self.config = config
self.web3 = Web3Swift(url: config.rpcURL)
self.chainState = ChainState(config: config)
self.web3.start()
self.balanceCoordinator.start()
self.balanceCoordinator.delegate = self
self.chainState.start()
}
func refresh(_ type: RefreshType) {
switch type {
case .balance:
balanceCoordinator.fetch()
}
}
func stop() {
chainState.stop()
}
}
extension WalletSession: BalanceCoordinatorDelegate {
func didUpdate(viewModel: BalanceViewModel) {
balanceViewModel.value = viewModel
}
}