Delegates

Delegates are triggered when there is a state change in any of the SDK Objects. Delegates are useful because they return the new data received by the logged-in user on every device. If the user is logged-in on 2 devices, delegates on both devices will be triggered.

Sample code shows how to use delegates.

class TransactionViewController: UIViewController, AbstraktDelegate {
	override func viewDidLoad() {
		super.viewDidLoad()
	
		Abstrakt.shared.delegate = self  //need to write this line in any controller that wants to use delegate methods
	}
	
	//IBOutlet
	@IBAction func btnCheckConnctionStatus(_ sender: Any) {
		print("MQTT Connection status is  \(Abstrakt.shared.getConnectionStatus())")
	}
	
	
	//MARK: - Abstrakt Delegate methods
	
	func didConnected() {
		print("MQTT is connected")
	}
	
	func didDisconnected() {
		print("MQTT is disconnected")
	}
	
	func newTransaction(transaction: EthereumTransaction) {
		print("Recieved new transaction")
	}
	
	func marketValueUpdated(newValue: MarketValue) {
		print("Updated market value \(String(describing: newValue.closePrice))")
	}
}

Monitor connectivity to abstrakt services

didConnected()                                                          // Connected to Abstrakt's Services 
didDisconnected()                                                       // Disconnected from Abstrakt's Services (user closed the app or no internet connectivity)

New Transactions and Market Data

newTransaction(transaction: EthereumTransaction)
marketValueUpdated(newValue: MarketValue)

Accounts

accountNickNameChanged(account: Account) {}                             
accountAdded(account: Account) {}
accountRemoved(accountAddress: String) {}

accountShared(account: Account) {}                   // returns an account that was shared by logged-in user or other user. 'isMyAccount' show who.
accountUnshared(account: Account) {}                 // returns an account that was unshared by logged-in user or other user. 'isMyAccount' show who. 

Connections

connectionRequestSent(connectionRequest: PendingConnectionRequest) {}   // returns pending connection request initiated by other user for the logged-in user
newConnectionRequest(connectionRequest: PendingConnectionRequest) {}    // returns pending connection request initiated by logged-in user. request could have been initiated by user on another device. 
connectionRequestAccepted(connection: UserConnection) {}                // returns 'approved' connection for a pending connection request initiated by logged-in user
connectionRequestAcceptedByMe(connection: UserConnection) {}            // returns 'approved' connection for a pending connection request initiated by other user. logged-in user accepted the request. 
connectionRequestDenied(userId: String) {}                              // returns other userId of a pending connection requested that was declined/cancelled 
connectionRemoved(userId: String) {}                                    // returns other userId of an existing connection that was removed