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

Adds toggle for primary currency #5421

Merged
merged 15 commits into from
Oct 16, 2018
Merged

Conversation

alextsg
Copy link
Contributor

@alextsg alextsg commented Oct 4, 2018

Fixes #4510
Fixes #5477

Screenshots

@bdresser
Copy link
Contributor

bdresser commented Oct 8, 2018

looks awesome @alextsg!

@cjeria @danfinlay on the confirm screen, are you cool with the diamond? or would you prefer ETH. Shoulda asked earlier, my b

screen shot 2018-10-07 at 5 22 01 pm

@cjeria
Copy link
Contributor

cjeria commented Oct 8, 2018

Conceptually, I like the idea of using a diamond to represent the ETH symbol, however, what I keep on getting caught up with is the fact that it's not exactly the Ethereum symbol - it's generic diamond alt code.

I know some folks in the community have proposed using Ξ to represent Eth. https://www.reddit.com/r/ethereum/comments/6ldlgi/making_%CE%BE_ether_symbol_more_known/

I think if we decide to go with an ETH symbol, we should use the actual version of the logo in SVG format to reuse in different contexts.

Here's a link to an svg version of the eth symbol
https://www.dropbox.com/s/5vkgagjof5vlam1/eth.svg?dl=0

image

@alextsg
Copy link
Contributor Author

alextsg commented Oct 8, 2018

That makes sense, and I'm open to either one. Should we also make the representation, whether it be the ETH logo or Ξ, be consistent across the whole app? This would include the transactions list, wallet view, etc.

Copy link
Contributor

@whymarrh whymarrh left a comment

Choose a reason for hiding this comment

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

I'm not sure introducing a preferences property to the PreferencesController state is the best option here—something about preferencesController.store.getState().preferences seems redundant to me. Shouldn't the entire state of the PreferencesController keep be considered the "preferences"?

Also the generic setPreference method taking a string argument is a bit lax. I could live with it if we introduced constants for each of the available preferences (e.g. setPreference(PreferencesController.USE_ETH_AS_PRIMARY, value)) but I think we're better off having a method to set each of the preferences directly. With this implementation we can easily mistype preference names e.g. setPreference('useETHAsPriamryCurrency', value).

@alextsg
Copy link
Contributor Author

alextsg commented Oct 9, 2018

@whymarrh From changes in the PR, preferences would be a property on state.metamask, which is desired because we want to move away from polluting state.metamask with preferences properties. I agree that at first glance preferencesController.store.getState().preferences looks redundant. However, the issue isn't really that the preferences object is being introduced, but that we'll need to refactor the preferences controller to use preferences as its state, because as things are now, properties in the preferences controller state get copied over to state.metamask as top level properties. My goal for this PR was to introduce the preferences object in state.metamask, then refactor and migrate other existing preference props over in a future PR.

I agree with the second point - I was following what we were doing with modals and feature flags. Creating specific methods for each preference will probably work better.

@whymarrh
Copy link
Contributor

whymarrh commented Oct 9, 2018

Ah, yes—I had forgotten that we flatten the state. 😔

@bdresser
Copy link
Contributor

Should we also make the representation, whether it be the ETH logo or Ξ, be consistent across the whole app? This would include the transactions list, wallet view, etc.

Yeah, I guess. For now let's use the ethereum diamond here and we can get to the rest shortly. Filed here: #5477

@kumavis
Copy link
Member

kumavis commented Oct 10, 2018

Is this just about Eth vs Fiat or does this also affect displaying token values vs fiat values?

what happens when we're missing fiat values (e.g. ether price api is down)?

@kumavis
Copy link
Member

kumavis commented Oct 10, 2018

@whymarrh @alextsg Can we fix the state flattening issue by starting to use the non-flattened state in the UI?

@alextsg
Copy link
Contributor Author

alextsg commented Oct 10, 2018

@kumavis This is about ETH vs Fiat. For tokens this would affect whether an ETH or Fiat value is displayed as the conversion underneath.

By missing Fiat values/price API being down are you referring to the conversionRate in state.metamask? I'm not really sure how that's currently handled in the app, but I think we generally assume that conversionRate is populated properly, and this PR doesn't change that. But since we've been prioritizing Fiat over ETH and this PR would allow users to swap that, I assume missing Fiat values would be less of an issue?

prophit987
prophit987 previously approved these changes Oct 15, 2018
Copy link
Contributor

@danjm danjm left a comment

Choose a reason for hiding this comment

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

Nice work! I left a few minor comments.

import PropTypes from 'prop-types'
import TokenInput from '../token-input'

export default class UserPreferencedCurrencyInput extends PureComponent {
Copy link
Contributor

Choose a reason for hiding this comment

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

UserPreferencedCurrencyInput -> UserPreferencedTokenInput

const { decimalValue } = this.state

return (
<UnitInput
Copy link
Contributor

Choose a reason for hiding this comment

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

Extracting the UnitInput component was a great idea 👍

import UserPreferencedCurrencyDisplay from '../user-preferenced-currency-display.component'
import CurrencyDisplay from '../../currency-display'

describe('UserPreferencedCurrencyInput Component', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

UserPreferencedCurrencyInput -> UserPreferencedCurrencyDisplay

@@ -0,0 +1,13 @@
import { connect } from 'react-redux'
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if either user-preferenced-currency-input.container.js or currency-input.container.js can be eliminated?

They both only get a small amount of data from state, and the currency-input.container.js is only ever imported in the user-preferenced-currency-input.component.js.

It seems like CurrencyInput could be an unconnected component that just receives its props from its parent. I think this would make it easier to understand the relation between the UserPreferencedCurrencyInput and the CurrencyInput. Also could make CurrencyInput more flexible for future use.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The way I look at this is that UserPreferencedCurrencyInput builds on top of CurrencyInput, which builds on top of UnitInput, the unconnected component. Everything that UserPreferencedCurrencyInput and CurrencyInput does can be done with UnitInput itself, but they're just added layers of convenience and do require being connected to the redux store. It's a much easier API to use for the developer when the component requires just a few props to use and reduces duplication of managing these props.

@alextsg alextsg force-pushed the currency-selector branch 2 times, most recently from 09f7f17 to 91879c4 Compare October 16, 2018 06:25
@whymarrh
Copy link
Contributor

@alextsg wanna add "fixes #5477" to the PR description given 91879c4

whymarrh
whymarrh previously approved these changes Oct 16, 2018
Copy link
Contributor

@whymarrh whymarrh left a comment

Choose a reason for hiding this comment

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

I did a quick QA pass and this LGTM 👍

@alextsg alextsg merged commit badebe0 into MetaMask:develop Oct 16, 2018
@alextsg alextsg deleted the currency-selector branch October 16, 2018 23:03
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.

7 participants