Skip to content

Commit

Permalink
Merge pull request #7 from ProtonProtocol/develop
Browse files Browse the repository at this point in the history
Fixed exchange rate timeout bug, update to latest Kotlin plugin
  • Loading branch information
Joey Harward authored Sep 10, 2020
2 parents 7cdcd50 + 5a3102b commit 62a78f4
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 47 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Then add the following dependency to your module's build.gradle
```gradle
dependencies {
...
implementation "com.metallicus:protonsdk:0.5.4"
implementation "com.metallicus:protonsdk:0.5.5"
}
```

Expand Down
18 changes: 9 additions & 9 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
const val kotlinVersion = "1.3.72"
const val kotlinVersion = "1.4.10"
const val orchidVersion = "0.21.1"

object ProtonSdk {
const val versionCode = 16
const val versionName = "0.5.4"
const val versionCode = 17
const val versionName = "0.5.5"
}

object BuildPlugins {
Expand Down Expand Up @@ -60,13 +60,13 @@ object Android {

object Libraries {
private object Versions {
const val ktx = "1.5.0-alpha01"
const val ktx = "1.5.0-alpha02"
const val lifecycleLiveData = "2.3.0-alpha05"
const val room = "2.2.5"
const val workManager = "2.3.4"
const val okhttp3 = "4.8.0"
const val workManager = "2.4.0"
const val okhttp3 = "4.8.1"
const val retrofit = "2.9.0"
const val dagger = "2.28.1"
const val dagger = "2.28.3"
const val daggerAssistedInject = "0.5.2"
const val coroutines = "1.3.4"
const val timber = "4.7.1"
Expand Down Expand Up @@ -107,8 +107,8 @@ object Libraries {
object TestLibraries {
private object Versions {
const val junit = "4.13"
const val testExt = "1.1.1"
const val espresso = "3.2.0"
const val testExt = "1.1.2"
const val espresso = "3.3.0"
}
const val junit = "junit:junit:${Versions.junit}"
const val testExt = "androidx.test.ext:junit:${Versions.testExt}"
Expand Down
78 changes: 52 additions & 26 deletions protonsdk/src/main/java/com/metallicus/protonsdk/Proton.kt
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,11 @@ class Proton private constructor(context: Context) {
val chainProvider = getChainProviderAsync()
emit(Resource.success(chainProvider))
} catch (e: ProtonException) {
emit(Resource.error(e))
val error: Resource<ChainProvider> = Resource.error(e)
emit(error)
} catch (e: Exception) {
emit(Resource.error(e.localizedMessage.orEmpty()))
val error: Resource<ChainProvider> = Resource.error(e.localizedMessage.orEmpty())
emit(error)
}
}

Expand All @@ -127,9 +129,11 @@ class Proton private constructor(context: Context) {
val tokenContracts = getTokenContractsAsync()
emit(Resource.success(tokenContracts))
} catch (e: ProtonException) {
emit(Resource.error(e))
val error: Resource<List<TokenContract>> = Resource.error(e)
emit(error)
} catch (e: Exception) {
emit(Resource.error(e.localizedMessage.orEmpty()))
val error: Resource<List<TokenContract>> = Resource.error(e.localizedMessage.orEmpty())
emit(error)
}
}

Expand Down Expand Up @@ -165,9 +169,11 @@ class Proton private constructor(context: Context) {

emit(Resource.success(accountModule.accountAvailable(chainProvider.chainUrl, accountName)))
} catch (e: ProtonException) {
emit(Resource.error(e))
val error: Resource<Boolean> = Resource.error(e)
emit(error)
} catch (e: Exception) {
emit(Resource.error(e.localizedMessage.orEmpty()))
val error: Resource<Boolean> = Resource.error(e.localizedMessage.orEmpty())
emit(error)
}
}

Expand Down Expand Up @@ -203,9 +209,11 @@ class Proton private constructor(context: Context) {
val accounts = findAccounts(publicKeyStr)
emit(accounts)
} catch (e: ProtonException) {
emit(Resource.error(e))
val error: Resource<List<Account>> = Resource.error(e)
emit(error)
} catch (e: Exception) {
emit(Resource.error(e.localizedMessage.orEmpty()))
val error: Resource<List<Account>> = Resource.error(e.localizedMessage.orEmpty())
emit(error)
}
}

Expand All @@ -224,9 +232,11 @@ class Proton private constructor(context: Context) {
val chainProvider = getChainProviderAsync()
emit(accountModule.setActiveAccount(chainProvider.chainId, chainProvider.chainUrl, activeAccount))
} catch (e: ProtonException) {
emit(Resource.error(e))
val error: Resource<ChainAccount> = Resource.error(e)
emit(error)
} catch (e: Exception) {
emit(Resource.error(e.localizedMessage.orEmpty()))
val error: Resource<ChainAccount> = Resource.error(e.localizedMessage.orEmpty())
emit(error)
}
}

Expand All @@ -253,9 +263,11 @@ class Proton private constructor(context: Context) {
val activeAccount = getActiveAccountAsync()
emit(Resource.success(activeAccount))
} catch (e: ProtonException) {
emit(Resource.error(e))
val error: Resource<ChainAccount> = Resource.error(e)
emit(error)
} catch (e: Exception) {
emit(Resource.error(e.localizedMessage.orEmpty()))
val error: Resource<ChainAccount> = Resource.error(e.localizedMessage.orEmpty())
emit(error)
}
}

Expand All @@ -269,9 +281,11 @@ class Proton private constructor(context: Context) {
activeAccount.chainProvider.chainUrl,
activeAccount.account.accountName))
} catch (e: ProtonException) {
emit(Resource.error(e))
val error: Resource<ChainAccount> = Resource.error(e)
emit(error)
} catch (e: Exception) {
emit(Resource.error(e.localizedMessage.orEmpty()))
val error: Resource<ChainAccount> = Resource.error(e.localizedMessage.orEmpty())
emit(error)
}
}

Expand Down Expand Up @@ -300,9 +314,11 @@ class Proton private constructor(context: Context) {

emit(tokenBalances)
} catch (e: ProtonException) {
emit(Resource.error(e))
val error: Resource<List<TokenCurrencyBalance>> = Resource.error(e)
emit(error)
} catch (e: Exception) {
emit(Resource.error(e.localizedMessage.orEmpty()))
val error: Resource<List<TokenCurrencyBalance>> = Resource.error(e.localizedMessage.orEmpty())
emit(error)
}
}

Expand All @@ -322,9 +338,11 @@ class Proton private constructor(context: Context) {

emit(tokenBalance)
} catch (e: ProtonException) {
emit(Resource.error(e))
val error: Resource<TokenCurrencyBalance> = Resource.error(e)
emit(error)
} catch (e: Exception) {
emit(Resource.error(e.localizedMessage.orEmpty()))
val error: Resource<TokenCurrencyBalance> = Resource.error(e.localizedMessage.orEmpty())
emit(error)
}
}

Expand All @@ -344,9 +362,11 @@ class Proton private constructor(context: Context) {

emit(actions)
} catch (e: ProtonException) {
emit(Resource.error(e))
val error: Resource<List<Action>> = Resource.error(e)
emit(error)
} catch (e: Exception) {
emit(Resource.error(e.localizedMessage.orEmpty()))
val error: Resource<List<Action>> = Resource.error(e.localizedMessage.orEmpty())
emit(error)
}
}

Expand All @@ -358,9 +378,11 @@ class Proton private constructor(context: Context) {

emit(accountModule.updateAccountName(activeAccount, pin, name))
} catch (e: ProtonException) {
emit(Resource.error(e))
val error: Resource<ChainAccount> = Resource.error(e)
emit(error)
} catch (e: Exception) {
emit(Resource.error(e.localizedMessage.orEmpty()))
val error: Resource<ChainAccount> = Resource.error(e.localizedMessage.orEmpty())
emit(error)
}
}

Expand All @@ -372,9 +394,11 @@ class Proton private constructor(context: Context) {

emit(accountModule.updateAccountAvatar(activeAccount, pin, byteArray))
} catch (e: ProtonException) {
emit(Resource.error(e))
val error: Resource<ChainAccount> = Resource.error(e)
emit(error)
} catch (e: Exception) {
emit(Resource.error(e.localizedMessage.orEmpty()))
val error: Resource<ChainAccount> = Resource.error(e.localizedMessage.orEmpty())
emit(error)
}
}

Expand All @@ -395,9 +419,11 @@ class Proton private constructor(context: Context) {
amount,
memo))
} catch (e: ProtonException) {
emit(Resource.error(e))
val error: Resource<JsonObject> = Resource.error(e)
emit(error)
} catch (e: Exception) {
emit(Resource.error(e.localizedMessage.orEmpty()))
val error: Resource<JsonObject> = Resource.error(e.localizedMessage.orEmpty())
emit(error)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,22 @@ class TokenContractsModule {
}

suspend fun updateExchangeRates(exchangeRatesUrl: String, tokenContractsMap: Map<String, String>) {
val exchangeRatesResponse = tokenContractRepository.fetchExchangeRates(exchangeRatesUrl)
if (exchangeRatesResponse.isSuccessful) {
val exchangeRatesJsonArray = exchangeRatesResponse.body()
exchangeRatesJsonArray?.forEach {
val exchangeRate = it.asJsonObject
val contract = exchangeRate.get("contract").asString
val symbol = exchangeRate.get("symbol").asString
val rates = exchangeRate.get("rates").asJsonObject
try {
val exchangeRatesResponse = tokenContractRepository.fetchExchangeRates(exchangeRatesUrl)
if (exchangeRatesResponse.isSuccessful) {
val exchangeRatesJsonArray = exchangeRatesResponse.body()
exchangeRatesJsonArray?.forEach {
val exchangeRate = it.asJsonObject
val contract = exchangeRate.get("contract").asString
val symbol = exchangeRate.get("symbol").asString
val rates = exchangeRate.get("rates").asJsonObject

try {
val tokenContractId = tokenContractsMap.getValue("$contract:$symbol")
tokenContractRepository.updateRates(tokenContractId, rates.toString())
} catch (e: Exception) {
Timber.d(e.localizedMessage)
}
}
} catch (e: Exception) {
Timber.d(e.localizedMessage)
}
}
}

0 comments on commit 62a78f4

Please sign in to comment.