Skip to content
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

Gd/sdk supports crypto/160078379 #104

Merged
merged 22 commits into from
Sep 14, 2018

Conversation

guillaumedebavelaere
Copy link
Contributor

No description provided.

@guillaumedebavelaere guillaumedebavelaere force-pushed the gd/sdk_supports_crypto/160078379 branch from da09c4d to bba3088 Compare September 7, 2018 09:15
@guillaumedebavelaere guillaumedebavelaere changed the title [WIP] Gd/sdk supports crypto/160078379 Gd/sdk supports crypto/160078379 Sep 7, 2018
Copy link
Contributor

@gigiyy gigiyy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some comments.

if (linkedBrokers.isEmpty()) {
showAlert("getCryptoQuoteFirstCryptoBrokerAccount", "No linked broker!");
} else {
TradeItLinkedBrokerAccountParcelable cryptoAccount = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe better to extract these to a getCrytoAccunt function instead?

showAlert("previewTradeFirstLinkedBroker", "No linked broker!")
} else {
var cryptoAccount: TradeItLinkedBrokerAccountParcelable? = null
for (linkedBroker in linkedBrokers) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

finding the crypto account and be simplified to as below:

val cryptoAccount = linkedBrokers.mapNotNull { linkedBroker -> linkedBroker.accounts.find{
      it.getOrderCapabilityForInstrument(Instrument.CRYPTO) != null
}}.firstOrNull()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe no need to transform it to use functional calls, however, maybe it's better to extracted to a functional call too, like in java example app.

}

fun getQuantitySymbol(): String? {
when (orderQuantityType) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when is expression in kotlin, you can return the when result direclty:

return when(xxx){
    aaa -> bbb
    ccc -> ddd
    else null
}

symbol: String,
var action: TradeItOrderAction = TradeItOrderAction.BUY
) : Parcelable {
var symbol: String = symbol
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be private? It seems like it's only used so that the constructor can take a raw string. Or should we have some kind of SymbolPair object so that our expectation from consumers of this library is explicit? That way there is no guessing what format of crypto pair we accept from the UI.

private void previewCryptoTradeFirstCryptoBrokerAccount() {
final MainActivity mainActivity = this;
List<TradeItLinkedBrokerParcelable> linkedBrokers = linkedBrokerManager.getLinkedBrokers();
if (linkedBrokers.isEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a guard-style statement so that the corresponding else block isn't so large. Something like:

if (linkedBrokers.isEmpty()) {
    showAlert("previewTradeFirstLinkedBroker", "No linked broker!");
    return;
}

// Then you don't need the else clause

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

intent.putExtra(PREVIEW_ORDER_PARAMETER, cryptoOrderParcelable);
startActivity(intent);
} else {
showAlert("previewTradeFirstLinkedBroker", "No crypto account!");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this into a guard-style if statement like above so that you don't need the giant if/else block.

if (cryptoAccount == null) {
    showAlert("previewTradeFirstLinkedBroker", "No crypto account!");
    return;
}

// Do other stuff here

}

companion object {
private fun mapWarnings(warnings: List<Warning>?): List<TradeItWarningParcelable> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this need to be a companion object? Why can't it just be a private instance method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a static method for non crypto order, so I took the same code

val mainActivity = this
val linkedBrokers = linkedBrokerManager.linkedBrokers
if (linkedBrokers.isEmpty()) {
showAlert("previewTradeFirstLinkedBroker", "No linked broker!")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment on the Java version about using guard-style statements to avoid large/nested blocks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

private fun getFirstCryptoAccount(
linkedBrokers: List<TradeItLinkedBrokerParcelable>
): TradeItLinkedBrokerAccountParcelable? {
return linkedBrokers.mapNotNull { linkedBroker ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be simplified further so that it doesn't continue iterating once you have found the first crypto account:

val cryptoAccount = linkedBrokers.firstOrNull { linkedBroker ->
    linkedBroker.accounts.firstOrNull { account ->
        it.getOrderCapabilityForInstrument(Instrument.CRYPTO) != null
    } != null
}

(You can use firstOrNull or find as they both do the same thing if you pass a predicate)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't compile. We need to return a TradeItLinkedBrokerAccountParcelable

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you'll need to use map or mapNonNull instead of find or first

Copy link
Contributor

@mitochondrion mitochondrion Sep 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry, I am reviewing this from my laptop and I don't have intellij.

@mitochondrion mitochondrion merged commit f1ce9ce into develop Sep 14, 2018
@mitochondrion mitochondrion deleted the gd/sdk_supports_crypto/160078379 branch September 14, 2018 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants