-
Notifications
You must be signed in to change notification settings - Fork 10
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
Conversation
da09c4d
to
bba3088
Compare
...d-sdk/src/main/kotlin/it/trade/android/sdk/model/TradeItCryptoTradeOrderDetailsParcelable.kt
Show resolved
Hide resolved
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.
I added some comments.
if (linkedBrokers.isEmpty()) { | ||
showAlert("getCryptoQuoteFirstCryptoBrokerAccount", "No linked broker!"); | ||
} else { | ||
TradeItLinkedBrokerAccountParcelable cryptoAccount = null; |
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.
maybe better to extract these to a getCrytoAccunt
function instead?
showAlert("previewTradeFirstLinkedBroker", "No linked broker!") | ||
} else { | ||
var cryptoAccount: TradeItLinkedBrokerAccountParcelable? = null | ||
for (linkedBroker in linkedBrokers) { |
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.
finding the crypto account and be simplified to as below:
val cryptoAccount = linkedBrokers.mapNotNull { linkedBroker -> linkedBroker.accounts.find{
it.getOrderCapabilityForInstrument(Instrument.CRYPTO) != null
}}.firstOrNull()
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.
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) { |
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.
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 |
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.
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()) { |
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.
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
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.
done
intent.putExtra(PREVIEW_ORDER_PARAMETER, cryptoOrderParcelable); | ||
startActivity(intent); | ||
} else { | ||
showAlert("previewTradeFirstLinkedBroker", "No crypto account!"); |
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.
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> { |
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 does this need to be a companion object? Why can't it just be a private instance method?
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.
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!") |
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.
See my comment on the Java version about using guard-style statements to avoid large/nested blocks.
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.
done
private fun getFirstCryptoAccount( | ||
linkedBrokers: List<TradeItLinkedBrokerParcelable> | ||
): TradeItLinkedBrokerAccountParcelable? { | ||
return linkedBrokers.mapNotNull { linkedBroker -> |
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.
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)
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.
This doesn't compile. We need to return a TradeItLinkedBrokerAccountParcelable
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.
you'll need to use map
or mapNonNull
instead of find
or first
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.
Ah sorry, I am reviewing this from my laptop and I don't have intellij.
No description provided.