-
Notifications
You must be signed in to change notification settings - Fork 15
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
[#1533] Flexa integration #1588
Draft
Milan-Cerovsky
wants to merge
5
commits into
main
Choose a base branch
from
1533-flexa-integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
02d8730
[#1533] Flexa integration
Milan-Cerovsky aac4b61
[#1533] Design update
Milan-Cerovsky 09b318f
Merge branch 'refs/heads/main' into 1533-flexa-integration
Milan-Cerovsky db63a71
[#1533] Code cleanup
Milan-Cerovsky c431674
[#1533] Code cleanup
Milan-Cerovsky 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 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 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 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 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 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
10 changes: 10 additions & 0 deletions
10
...roid-lib/src/main/java/co/electriccoin/zcash/preference/InstallationPreferenceProvider.kt
This file contains 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,10 @@ | ||
package co.electriccoin.zcash.preference | ||
|
||
import android.content.Context | ||
import co.electriccoin.zcash.preference.api.PreferenceProvider | ||
|
||
class InstallationPreferenceProvider(private val context: Context) : PreferenceHolder() { | ||
override suspend fun create(): PreferenceProvider { | ||
return AndroidPreferenceProvider.newStandard(context, "co.electriccoin.zcash.installation") | ||
} | ||
} |
This file contains 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 |
---|---|---|
|
@@ -135,6 +135,7 @@ dependencyResolutionManagement { | |
} | ||
} | ||
} | ||
mavenLocal() | ||
} | ||
|
||
@Suppress("MaxLineLength") | ||
|
This file contains 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 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 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 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 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 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 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
31 changes: 31 additions & 0 deletions
31
ui-lib/src/main/java/co/electriccoin/zcash/ui/common/provider/FlexaAccountIdProvider.kt
This file contains 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,31 @@ | ||
package co.electriccoin.zcash.ui.common.provider | ||
|
||
import co.electriccoin.zcash.preference.InstallationPreferenceProvider | ||
import co.electriccoin.zcash.preference.model.entry.PreferenceKey | ||
import co.electriccoin.zcash.preference.model.entry.StringPreferenceDefault | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import java.security.MessageDigest | ||
import java.util.UUID | ||
|
||
class FlexaAccountIdProvider( | ||
private val installationPreferenceProvider: InstallationPreferenceProvider | ||
) { | ||
private val preference = StringPreferenceDefault(PreferenceKey("FLEXA_ACCOUNT_ID"), "") | ||
|
||
suspend operator fun invoke(): String = | ||
withContext(Dispatchers.IO) { | ||
val existing = preference.getValue(installationPreferenceProvider()) | ||
|
||
existing.ifEmpty { | ||
val new = UUID.randomUUID().toString().toSha256() | ||
preference.putValue(installationPreferenceProvider(), new) | ||
new | ||
} | ||
} | ||
|
||
private fun String.toSha256() = | ||
MessageDigest.getInstance("SHA-256") | ||
.digest(toByteArray()) | ||
.fold("") { str, value -> str + "%02x".format(value) } | ||
} |
68 changes: 68 additions & 0 deletions
68
ui-lib/src/main/java/co/electriccoin/zcash/ui/common/repository/BalanceRepository.kt
This file contains 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,68 @@ | ||
package co.electriccoin.zcash.ui.common.repository | ||
|
||
import cash.z.ecc.sdk.ANDROID_STATE_FLOW_TIMEOUT | ||
import co.electriccoin.zcash.ui.common.compose.BalanceState | ||
import co.electriccoin.zcash.ui.common.model.WalletSnapshot | ||
import co.electriccoin.zcash.ui.common.model.hasChangePending | ||
import co.electriccoin.zcash.ui.common.model.hasValuePending | ||
import co.electriccoin.zcash.ui.common.model.spendableBalance | ||
import co.electriccoin.zcash.ui.common.model.totalBalance | ||
import co.electriccoin.zcash.ui.common.wallet.ExchangeRateState | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.SupervisorJob | ||
import kotlinx.coroutines.flow.SharingStarted | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.WhileSubscribed | ||
import kotlinx.coroutines.flow.combine | ||
import kotlinx.coroutines.flow.filterNotNull | ||
import kotlinx.coroutines.flow.stateIn | ||
|
||
interface BalanceRepository { | ||
/** | ||
* A flow of the wallet balances state used for the UI layer. It's computed from [WalletSnapshot]'s properties | ||
* and provides the result [BalanceState] UI state. | ||
*/ | ||
val state: StateFlow<BalanceState> | ||
} | ||
|
||
class BalanceRepositoryImpl( | ||
walletRepository: WalletRepository, | ||
exchangeRateRepository: ExchangeRateRepository | ||
) : BalanceRepository { | ||
private val scope = CoroutineScope(Dispatchers.IO + SupervisorJob()) | ||
|
||
override val state: StateFlow<BalanceState> = | ||
combine( | ||
walletRepository.walletSnapshot.filterNotNull(), | ||
exchangeRateRepository.state, | ||
) { snapshot, exchangeRateUsd -> | ||
when { | ||
// Show the loader only under these conditions: | ||
// - Available balance is currently zero AND total balance is non-zero | ||
// - And wallet has some ChangePending or ValuePending in progress | ||
( | ||
snapshot.spendableBalance().value == 0L && | ||
snapshot.totalBalance().value > 0L && | ||
(snapshot.hasChangePending() || snapshot.hasValuePending()) | ||
) -> { | ||
BalanceState.Loading( | ||
totalBalance = snapshot.totalBalance(), | ||
exchangeRate = exchangeRateUsd | ||
) | ||
} | ||
|
||
else -> { | ||
BalanceState.Available( | ||
totalBalance = snapshot.totalBalance(), | ||
spendableBalance = snapshot.spendableBalance(), | ||
exchangeRate = exchangeRateUsd | ||
) | ||
} | ||
} | ||
}.stateIn( | ||
scope, | ||
SharingStarted.WhileSubscribed(ANDROID_STATE_FLOW_TIMEOUT), | ||
BalanceState.None(ExchangeRateState.OptedOut) | ||
) | ||
} |
Oops, something went wrong.
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.
Why do we need this change, please?
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.
flexa is not on maven, I am instead building their sdk locally lol