Skip to content

Commit

Permalink
- added en locale translation
Browse files Browse the repository at this point in the history
- dropdown css will now adjust to shorter heights (max-height: 220px)
- added option to select primary currency in settings (issue MetaMask#4510)
  • Loading branch information
Rohithzr committed Aug 28, 2018
1 parent 3854650 commit 79c6ad1
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 14 deletions.
6 changes: 6 additions & 0 deletions app/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,12 @@
"orderOneHere": {
"message": "Order a Trezor or Ledger and keep your funds in cold storage"
},
"primaryCurrency":{
"message": "Primary Currency"
},
"primaryCurrencyDescription":{
"message": "Primary Currency for Confirmation Screen"
},
"searchTokens": {
"message": "Search Tokens"
},
Expand Down
12 changes: 12 additions & 0 deletions app/scripts/controllers/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class PreferencesController {
* @property {object} store.featureFlags A key-boolean map, where keys refer to features and booleans to whether the
* user wishes to see that feature
* @property {string} store.currentLocale The preferred language locale key
* @property {string} store.primaryCurrency The preferred currency for the confirmation screen
* @property {string} store.selectedAddress A hex string that matches the currently selected address in the app
*
*/
Expand All @@ -30,6 +31,7 @@ class PreferencesController {
useBlockie: false,
featureFlags: {},
currentLocale: opts.initLangCode,
primaryCurrency: "eth",
identities: {},
lostIdentities: {},
}, opts.initState)
Expand Down Expand Up @@ -71,6 +73,16 @@ class PreferencesController {
this.store.updateState({ currentLocale: key })
}

/**
* Setter for the `primaryCurrency` property
*
* @param {string} key - preferred currency key
*
*/
setPrimaryCurrency (key) {
this.store.updateState({ primaryCurrency: key })
}

/**
* Updates identities to only include specified addresses. Removes identities
* not included in addresses array
Expand Down
15 changes: 15 additions & 0 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ module.exports = class MetamaskController extends EventEmitter {
setCurrentCurrency: this.setCurrentCurrency.bind(this),
setUseBlockie: this.setUseBlockie.bind(this),
setCurrentLocale: this.setCurrentLocale.bind(this),
setPrimaryCurrency: this.setPrimaryCurrency.bind(this),
markAccountsFound: this.markAccountsFound.bind(this),
markPasswordForgotten: this.markPasswordForgotten.bind(this),
unMarkPasswordForgotten: this.unMarkPasswordForgotten.bind(this),
Expand Down Expand Up @@ -1446,6 +1447,20 @@ module.exports = class MetamaskController extends EventEmitter {
}
}

/**
* A method for setting a user's preferred currency, affecting the confirmation screen.
* @param {string} key - Currency identifier.
* @param {Function} cb - A callback function called when complete.
*/
setPrimaryCurrency (key, cb) {
try {
this.preferencesController.setPrimaryCurrency(key)
cb(null)
} catch (err) {
cb(err)
}
}

/**
* A method for initializing storage the first time.
* @param {Object} initState - The default state to initialize with.
Expand Down
19 changes: 6 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions ui/app/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ var actions = {
updateCurrentLocale,
setLocaleMessages,
//
// primary currency
//
SET_PRIMARY_CURRENCY: 'SET_PRIMARY_CURRENCY',
setPrimaryCurrency,
// Feature Flags
setFeatureFlag,
updateFeatureFlags,
Expand Down Expand Up @@ -773,6 +777,26 @@ function setCurrentCurrency (currencyCode) {
}
}

function setPrimaryCurrency (primaryCurrency) {
return (dispatch) => {
dispatch(actions.showLoadingIndication())
log.debug(`background.setPrimaryCurrency`)
background.setPrimaryCurrency(primaryCurrency, (err, data) => {
dispatch(actions.hideLoadingIndication())
if (err) {
log.error(err.stack)
return dispatch(actions.displayWarning(err.message))
}
dispatch({
type: actions.SET_PRIMARY_CURRENCY,
value: {
primaryCurrency: primaryCurrency
}
})
})
}
}

function signMsg (msgData) {
log.debug('action - signMsg')
return (dispatch, getState) => {
Expand Down
1 change: 1 addition & 0 deletions ui/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ function mapStateToProps (state) {
lostAccounts,
frequentRpcList: state.metamask.frequentRpcList || [],
currentCurrency: state.metamask.currentCurrency,
primaryCurrency: state.metamask.primaryCurrency,
isMouseUser: state.appState.isMouseUser,
betaUI: state.metamask.featureFlags.betaUI,
isRevealingSeedWords: state.metamask.isRevealingSeedWords,
Expand Down
1 change: 1 addition & 0 deletions ui/app/components/pages/settings/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ Info.propTypes = {
tab: PropTypes.string,
metamask: PropTypes.object,
setCurrentCurrency: PropTypes.func,
setPrimaryCurrency: PropTypes.func,
setRpcTarget: PropTypes.func,
displayWarning: PropTypes.func,
revealSeedConfirmation: PropTypes.func,
Expand Down
27 changes: 27 additions & 0 deletions ui/app/components/pages/settings/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,30 @@ class Settings extends Component {
])
}

renderPrimaryCurrency () {
const { metamask: { primaryCurrency }, setPrimaryCurrency } = this.props
const primaryCurrencyOptions = [
{displayValue: "ETH", key: "eth", value: "eth"},
{displayValue: "Converted Fiat", key: "converted", value: "converted"}
]
return h('div.settings__content-row', [
h('div.settings__content-item', [
h('span', this.context.t('primaryCurrency')),
h('span.settings__content-description', this.context.t('primaryCurrencyDescription')),
]),
h('div.settings__content-item', [
h('div.settings__content-item-col', [
h(SimpleDropdown, {
placeholder: 'Select Primary Currency',
options: primaryCurrencyOptions,
selectedOption: primaryCurrency || "eth",
onSelect: newPrimaryCurrency => setPrimaryCurrency(newPrimaryCurrency)
}),
]),
]),
])
}

renderCurrentConversion () {
const { metamask: { currentCurrency, conversionDate }, setCurrentCurrency } = this.props

Expand Down Expand Up @@ -299,6 +323,7 @@ class Settings extends Component {
h('div.settings__content', [
warning && h('div.settings__error', warning),
this.renderCurrentConversion(),
this.renderPrimaryCurrency(),
this.renderCurrentLocale(),
// this.renderCurrentProvider(),
this.renderNewRpcUrl(),
Expand All @@ -316,6 +341,7 @@ Settings.propTypes = {
metamask: PropTypes.object,
setUseBlockie: PropTypes.func,
setCurrentCurrency: PropTypes.func,
setPrimaryCurrency: PropTypes.func,
setRpcTarget: PropTypes.func,
displayWarning: PropTypes.func,
revealSeedConfirmation: PropTypes.func,
Expand All @@ -340,6 +366,7 @@ const mapStateToProps = state => {

const mapDispatchToProps = dispatch => {
return {
setPrimaryCurrency: primaryCurrency => dispatch(actions.setPrimaryCurrency(primaryCurrency)),
setCurrentCurrency: currency => dispatch(actions.setCurrentCurrency(currency)),
setRpcTarget: newRpc => dispatch(actions.setRpcTarget(newRpc)),
displayWarning: warning => dispatch(actions.displayWarning(warning)),
Expand Down
2 changes: 1 addition & 1 deletion ui/app/css/itcss/components/simple-dropdown.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
.simple-dropdown__options {
z-index: 1050;
position: absolute;
height: 220px;
max-height: 220px;
width: 100%;
border: 1px solid #d2d8dd;
border-radius: 4px;
Expand Down
6 changes: 6 additions & 0 deletions ui/app/reducers/metamask.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function reduceMetamask (state, action) {
nextUnreadNotice: undefined,
frequentRpcList: [],
addressBook: [],
primaryCurrency: "eth",
selectedTokenAddress: null,
contractExchangeRates: {},
tokenExchangeRates: {},
Expand Down Expand Up @@ -179,6 +180,11 @@ function reduceMetamask (state, action) {
conversionDate: action.value.conversionDate,
})

case actions.SET_PRIMARY_CURRENCY:
return extend(metamaskState, {
primaryCurrency: action.value.primaryCurrency
})

case actions.UPDATE_TOKENS:
return extend(metamaskState, {
tokens: action.newTokens,
Expand Down

0 comments on commit 79c6ad1

Please sign in to comment.