User accounts
The SDK allows you to work with user accounts using CrypteriumAccountsStore class.  Every user has its own single account in the app. Use this class to store and update user account data.  
In this class, we have implemented several methods:
- 
The getSavedmethod returns the latest cached user account data.
- 
The getRemotemethod reloads data from backend into cache and returns updated data.
See more details in the description of each method.
CrypteriumAccountsStore class
The CrypteriumAccountsStore class has been implemented to store and update user account data. To manage the process, initialize a CrypteriumAccountsStore object:
let accountsStore: CrypteriumAccountsStore = CrypteriumAPI.accountsStore()
accounts: ICrypteriumAccounts = CrypteriumAPI.accountsStore()
Methods
getSaved
Use the getSaved method to get the latest cached user account data. For Android, the method calls a completion closure and puts an object of the CRPTCustomerAccountsResult type as an argument of the closure.
let account: CRPTCustomerAccounts? = accountsStore.getSaved()
accounts.getSaved(completion: (CRPTCustomerAccountsResult) -> Unit)
  
sealed class CRPTCustomerAccountsResult {
    data class success(val profile: CRPTCustomerAccounts) : CRPTCustomerAccountsResult()
    data class failure(val error: CRPTError) : CRPTCustomerAccountsResult()
}
CRPTCustomerAccountsResult (Android)
The CRPTCustomerAccountsResult object value is attached to success or failure case:
| case | variable | type | description | 
|---|---|---|---|
| success | profile | CRPTCustomerAccounts | customer accounts | 
| failure | error | CRPTError | error details | 
CRPTError (Android)
The type property of the CRPTError object may have one of the values below:
| value | error description | 
|---|---|
| AUTHORIZATION | authorization error | 
| BACKEND | backend error | 
CRPTCustomerAccounts
The CRPTCustomerAccounts object is an array of WalletModel (CRPTCustomerAccount Android) objects. The WalletModel (CRPTCustomerAccount) object is an object containing the description of each wallet: cryptocurrency, color, balance, etc.
typealias CRPTCustomerAccounts = [WalletModel]
class CRPTCustomerAccounts {
    var accounts: List<CRPTCustomerAccount>? = null
}
getRemote
The getRemote method  reloads user account data from backend into cache and returns an updated data. If an error occurs while fetching data, the cache will not get updated. The method calls a completion closure and puts an object of the CRPTCustomerAccountsResult type as an argument of the closure.
accountsStore.getRemote(completion: (CRPTCustomerAccountsResult) -> Void)
enum CRPTCustomerAccountsResult {
	case success(CRPTCustomerAccounts)
	case failure(CRPTError)
}
accounts.getRemote(completion: (CRPTCustomerAccountsResult) -> Unit)
  
sealed class CRPTCustomerAccountsResult {
    data class success(val profile: CRPTCustomerAccounts) : CRPTCustomerAccountsResult()
    data class failure(val error: CRPTError) : CRPTCustomerAccountsResult()
}
CRPTCustomerAccountsResult
The CRPTCustomerAccountsResult object value is attached to success or failure case:
| case | case type | description | 
| success | CRPTCustomerAccounts | customer accounts | 
| failure | CRPTError | error details | 
CRPTError
The type property of the CRPTError object may have one of the values below:
| value | error description | 
| AUTHORIZATION | authorization error | 
| BACKEND | backend error | 
Updated over 3 years ago
