-
Notifications
You must be signed in to change notification settings - Fork 262
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
Exchange Quote Picker #4534
Exchange Quote Picker #4534
Conversation
2af7400
to
dcae8ce
Compare
const feeDenominatedAmount = await fromWallet.nativeToDenomination(feeNativeAmount, request.fromWallet.currencyInfo.currencyCode) | ||
const feeFiatAmountRaw = parseFloat(convertCurrency(state, request.fromWallet.currencyInfo.currencyCode, fromWallet.fiatCurrencyCode, feeDenominatedAmount)) | ||
const feeFiatAmount = formatNumber(feeFiatAmountRaw || 0, { toFixed: 2 }) | ||
const feeCryptoAmount = div(feeNativeAmount, feeDenomination.multiplier, DECIMAL_PRECISION) |
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.
feeDenomination
is the display denom. You can't use this in convertCurrency
. The nativeToDenomination
works because (while poorly named) it returns the exchangeAmount
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.
Mainly changed it just so my earlier commit would build - where I use this method in the scene selector. Needed this to become synchronous for that commit to work.
The intention is to later clean all this up to use common utility methods.
Since I don't even use this on the scene anymore by the last cleanup commit, I'll revert
return async (dispatch, getState) => { | ||
const state = getState() | ||
const { account } = state.core | ||
dispatch({ type: 'START_SHIFT_TRANSACTION' }) | ||
|
||
const { fromDisplayAmount, quote, request, fee, fromFiat, fromTotalFiat, toDisplayAmount, toFiat } = swapInfo | ||
const { isEstimate, fromNativeAmount, toNativeAmount, networkFee, pluginId, expirationDate } = quote | ||
const { fromDisplayAmount, fee, fromFiat, fromTotalFiat, toDisplayAmount, toFiat } = getSwapInfo(state, quote) |
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.
Seems like an unnecessary refactor to pull out getSwapInfo. Updating the fiat exchange rate after the user approved the quote will possibly save different fiat info in the metadata than what the user originally saw. I would prefer the old behavior
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 entire commit was unnecessary work
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.
There were a lot of motivations.
- Work towards removing all these old guiXXX types, which are often tied into unnecessary redux and relied on a lot of duplicated handling for crypto/fiat numbers that were often inconsistent.
- At least take a step towards unifying the handling for crypto/fiat amount displays for this feature. I implemented a lot of common display/conversion handling functionality with the intention of using towards this very purpose. Going to take a bit more work to get rid of all the crypto/fiat amount display handling in favor of common utils, hence leaving a lot of this here in getSwapInfo.
- I probably could have broken up the commits better, but by the final commit at least the scenes and components can use the crypto/fiat hooks + utilities as intended by that design, and the api for the components becomes simple and makes sense for what the components are displaying. In the future we can unify crypto/fiat calcs for actions/reducers as well.
- This is crazy overly complicated, prone to making mistakes (evidenced in this PR) and missing mistakes in reviews if we keep needing these giant blocks of conversion code every time we need to deal with simple fiat and crypto amounts.
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.
If the only concern was fiat exchange rates, I'd argue that the new implementation is better.
In the old implementation, worse case scenario, the user is saving minute-old prices + the time it takes to execute. Sure, they're guaranteed to save what they see, but what they see isn't really the true price at that time.
In the new implementation, worse-case scenario for saved fiat price metadata is only the price delta in the time it takes the quote to execute.
EDIT: Actually I don't see anything in CryptoExchangeActions about saving amountFiat
metadata... It's just falling back to historical data as far as I can tell?
@@ -154,12 +152,7 @@ export const CryptoExchangeQuoteScene = (props: Props) => { | |||
walletId={request.toWallet.id} | |||
walletName={getWalletName(request.toWallet)} | |||
/> | |||
<TouchableOpacity style={styles.pluginRowPoweredByRow} onPress={handlePoweredByTap}> | |||
<EdgeText style={styles.footerText}>{lstrings.plugin_powered_by_space + ' '}</EdgeText> |
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.
footerText not used.
return ( | ||
<TouchableOpacity | ||
onPress={() => { | ||
navigation.replace('exchangeQuote', { |
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.
Instead of a full navigation.replace
, would have been simpler to make selectedQuote a useState
which you then change with a setSelectedQuote
Line 48 could be
const { initialSelectedQuote, quotes, onApprove } = route.params
Then
const [ selectedQuote, setSelectedQuote ] = useState(initialSelectedQuote)
return ( | ||
<TouchableOpacity | ||
onPress={() => { | ||
navigation.replace('exchangeQuote', { |
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.
Instead of a full navigation.replace
, would have been simpler to make selectedQuote a useState
which you then change with a setSelectedQuote
Line 48 could be
const { selectedQuote: initialSelectedQuote, quotes, onApprove } = route.params
Then
const [ selectedQuote, setSelectedQuote ] = useState(initialSelectedQuote)
const tokenId = isToQuote ? fromTokenId : toTokenId | ||
const nativeAmount = isToQuote ? fromNativeAmount : toNativeAmount | ||
|
||
const toAmount = useCryptoText({ wallet, tokenId, nativeAmount }) |
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.
Misnomer. Might be a 'from' or 'to'. Should be exchangeAmount
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.
Made it a bit more literal, exchange
already has multiple meanings in our codebase
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'll accept the update, but exchangeAmount
has a very specific meaning. I might agree that it's not the best term but we do use it consistently.
d9c1508
to
ab2bc69
Compare
Fixed unit tests on the last commit |
6eebf8d
to
4df8fd8
Compare
}) | ||
|
||
const totalFiatText = `${getSymbolFromCurrency(fromIsoFiatCurrencyCode)}${formatFiatString({ fiatAmount: add(feeFiatAmount, fromFiatAmount) })}` |
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.
revert to using no symbol
This seemed to have been implemented with the intention of being a one-stop source for all GUI display requirements of the EdgeSwapQuote. However, as implemented, this prevents fiat exchange rates from ever being updated since it only gets set once upon initial receipt of the quote. Update this to be a utility function of an EdgeSwapQuote, remove some unecessary redux.
Minor adjustments made: use of FastImage + resizeMode. Text was not updated to EdgeText due to unresolved styling differences.
- Simplify props. All this is doing is visual representation of one side of a quote. - Make use of new hooks, utility methods, and common components. - Enforce visual consistency. Also has a beneficial side effect of removing more redux dependencies.
4df8fd8
to
49ef0f1
Compare
Before final cleanup commit:
After final (WIP) cleanup commit:
CHANGELOG
Does this branch warrant an entry to the CHANGELOG?
Dependencies
noneRequirements
If you have made any visual changes to the GUI. Make sure you have: