-
Notifications
You must be signed in to change notification settings - Fork 2
feat(#195): adopt koin annotation for dependency injection #117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
JosephSanjaya
wants to merge
1
commit into
gruntsoftware:develop
from
JosephSanjaya:js/feat/#195-koin-annotations
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
app/src/main/java/com/brainwallet/data/repository/FirebaseRemoteConfigRepository.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.brainwallet.data.repository | ||
|
||
import com.brainwallet.BuildConfig | ||
import com.brainwallet.R | ||
import com.brainwallet.data.source.RemoteConfigSource | ||
import com.google.firebase.remoteconfig.ConfigUpdate | ||
import com.google.firebase.remoteconfig.ConfigUpdateListener | ||
import com.google.firebase.remoteconfig.FirebaseRemoteConfig | ||
import com.google.firebase.remoteconfig.FirebaseRemoteConfigException | ||
import com.google.firebase.remoteconfig.remoteConfigSettings | ||
import org.koin.core.annotation.Single | ||
import timber.log.Timber | ||
|
||
@Single(binds = [RemoteConfigSource::class]) | ||
class FirebaseRemoteConfigRepository( | ||
private val remoteConfig: FirebaseRemoteConfig | ||
) : RemoteConfigSource { | ||
|
||
init { | ||
val configSettings = remoteConfigSettings { | ||
minimumFetchIntervalInSeconds = if (BuildConfig.DEBUG) { | ||
0 // fetch every time in debug mode | ||
} else { | ||
60 * 180 // fetch every 3 hours in production mode | ||
} | ||
} | ||
remoteConfig.setConfigSettingsAsync(configSettings) | ||
remoteConfig.setDefaultsAsync(R.xml.remote_config_defaults) | ||
} | ||
|
||
override fun initialize() { | ||
remoteConfig.fetchAndActivate() | ||
.addOnSuccessListener { Timber.d("timber: RemoteConfig Success fetchAndActivate") } | ||
.addOnFailureListener { | ||
Timber.d( | ||
it, | ||
"timber: RemoteConfig Failure fetchAndActivate" | ||
) | ||
} | ||
remoteConfig.addOnConfigUpdateListener(object : ConfigUpdateListener { | ||
override fun onUpdate(configUpdate: ConfigUpdate) { | ||
Timber.d("timber: [RemoteConfig] onUpdate ${configUpdate.updatedKeys}") | ||
} | ||
|
||
override fun onError(error: FirebaseRemoteConfigException) { | ||
Timber.d("timber: [RemoteConfig] onError ${error.code} | ${error.message}") | ||
} | ||
|
||
}) | ||
} | ||
|
||
override fun getString(key: String): String { | ||
return remoteConfig.getString(key) | ||
} | ||
|
||
override fun getNumber(key: String): Double { | ||
return remoteConfig.getDouble(key) | ||
} | ||
|
||
override fun getBoolean(key: String): Boolean { | ||
return remoteConfig.getBoolean(key) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
app/src/main/java/com/brainwallet/data/repository/LtcRepositoryImpl.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package com.brainwallet.data.repository | ||
|
||
import android.content.Context | ||
import android.content.SharedPreferences | ||
import androidx.core.net.toUri | ||
import com.brainwallet.BuildConfig | ||
import com.brainwallet.data.model.CurrencyEntity | ||
import com.brainwallet.data.model.Fee | ||
import com.brainwallet.data.model.MoonpayCurrencyLimit | ||
import com.brainwallet.data.repository.LtcRepository.Companion.PREF_KEY_BUY_LIMITS_PREFIX | ||
import com.brainwallet.data.repository.LtcRepository.Companion.PREF_KEY_BUY_LIMITS_PREFIX_CACHED_AT | ||
import com.brainwallet.data.source.RemoteApiSource | ||
import com.brainwallet.data.source.fetchWithCache | ||
import com.brainwallet.data.source.response.GetMoonpayBuyQuoteResponse | ||
import com.brainwallet.tools.manager.BRSharedPrefs | ||
import com.brainwallet.tools.manager.FeeManager | ||
import com.brainwallet.tools.sqlite.CurrencyDataSource | ||
import com.brainwallet.tools.util.Utils | ||
import org.koin.core.annotation.Single | ||
|
||
@Single(binds = [LtcRepository::class]) | ||
class LtcRepositoryImpl( | ||
private val context: Context, | ||
private val remoteApiSource: RemoteApiSource, | ||
private val currencyDataSource: CurrencyDataSource, | ||
private val sharedPreferences: SharedPreferences, | ||
) : LtcRepository { | ||
|
||
//todo: make it offline first here later, currently just using CurrencyDataSource.getAllCurrencies | ||
override suspend fun fetchRates(): List<CurrencyEntity> { | ||
return runCatching { | ||
val rates = remoteApiSource.getRates() | ||
|
||
//legacy logic | ||
FeeManager.updateFeePerKb(context) | ||
val selectedISO = BRSharedPrefs.getIsoSymbol(context) | ||
rates.forEachIndexed { index, currencyEntity -> | ||
if (currencyEntity.code.equals(selectedISO, ignoreCase = true)) { | ||
BRSharedPrefs.putIso(context, currencyEntity.code) | ||
BRSharedPrefs.putCurrencyListPosition(context, index - 1) | ||
} | ||
} | ||
|
||
//save to local | ||
currencyDataSource.putCurrencies(rates) | ||
return rates | ||
}.getOrElse { currencyDataSource.getAllCurrencies(true) } | ||
|
||
} | ||
|
||
/** | ||
* for now we just using [Fee.Default] | ||
* will move to [RemoteApiSource.getFeePerKb] after fix the calculation when we do send | ||
* | ||
* maybe need updaete core if we need to use dynamic fee? | ||
*/ | ||
override suspend fun fetchFeePerKb(): Fee = Fee.Default //using static fee | ||
|
||
override suspend fun fetchLimits(baseCurrencyCode: String): MoonpayCurrencyLimit { | ||
return sharedPreferences.fetchWithCache( | ||
key = "${PREF_KEY_BUY_LIMITS_PREFIX}${baseCurrencyCode.lowercase()}", | ||
cachedAtKey = "${PREF_KEY_BUY_LIMITS_PREFIX_CACHED_AT}${baseCurrencyCode.lowercase()}", | ||
cacheTimeMs = 5 * 60 * 1000, //5 minutes | ||
fetchData = { | ||
remoteApiSource.getMoonpayCurrencyLimit(baseCurrencyCode) | ||
} | ||
) | ||
} | ||
|
||
override suspend fun fetchBuyQuote(params: Map<String, String>): GetMoonpayBuyQuoteResponse = | ||
remoteApiSource.getBuyQuote(params) | ||
|
||
override suspend fun fetchMoonpaySignedUrl(params: Map<String, String>): String { | ||
val externalTransactionID = Utils.getEncryptedAgentString(context) | ||
val finalParams = params + mapOf( | ||
"defaultCurrencyCode" to "ltc", | ||
"externalTransactionId" to externalTransactionID, | ||
"currencyCode" to "ltc", | ||
"themeId" to "main-v1.0.0", | ||
) | ||
return remoteApiSource.getMoonpaySignedUrl(finalParams) | ||
.signedUrl.toUri() | ||
.buildUpon() | ||
.apply { | ||
if (BuildConfig.DEBUG) { | ||
authority("buy-sandbox.moonpay.com")//replace base url from buy.moonpay.com | ||
} | ||
} | ||
.build() | ||
.toString() | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this to close? https://github.com/gruntsoftware/internal/issues/155 @JosephSanjaya
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes im already done for the remote config, but currently there's no key that use the source yet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on it to fix