-
Notifications
You must be signed in to change notification settings - Fork 168
Detect locale #490
Detect locale #490
Conversation
e874aec to
a6dc6ea
Compare
public/grpc-client.js
Outdated
|
|
||
| ipcMain.on('get-locale', event => { | ||
| event.sender.send('locale', { response: { locale } }); | ||
| }); |
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.
wasn't sure if these lines should be here or in electron.js - feedback wanted
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.
Yeah better in electron.js as the local isn't really used for grpc.
tanx
left a comment
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.
@willpiers thanks so much for your PR! I've added some comments. Let me know if those make sense to you :)
| "electron-log": "^2.2.14", | ||
| "electron-updater": "^2.21.10", | ||
| "grpc": "^1.10.0", | ||
| "locale-currency": "0.0.2", |
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.
Please generate the package-lock.json with a compatible npm@5.6.0 and rebase/squash the big diff. thanks
public/grpc-client.js
Outdated
|
|
||
| ipcMain.on('get-locale', event => { | ||
| event.sender.send('locale', { response: { locale } }); | ||
| }); |
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.
Yeah better in electron.js as the local isn't really used for grpc.
| !/^(lnd)|(unlock)|(log)|(get-locale)|(locale)|(open-url)[a-zA-Z_-]{0,20}$/.test( | ||
| event | ||
| ) | ||
| ) { |
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.
Probably easier to just prefix with lnd_ for future ipc calls. I was planning to do the same and refactor other IPCs as well to tidy things up.
src/action/grpc.js
Outdated
| let response = await this._sendIpc('get-locale', 'locale'); | ||
| return response.locale; | ||
| } | ||
|
|
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.
Probably better to handle this in the settings action as locale has little to do with grpc.
src/action/index.js
Outdated
| observe(store, 'lndReady', () => { | ||
| observe(store, 'lndReady', async () => { | ||
| const locale = await grpc.getLocale(); | ||
| setting.setFiatByLocale({ locale }); |
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 shouldn't be necessary if the settings action listens to the ipc event internally.
| throw new Error(`Invalid fiat currency: ${fiat}`); | ||
| } | ||
| this._store.settings.fiat = fiat; | ||
| this._store.settings.fiat = FIATS[fiat] ? fiat : DEFAULT_FIAT; |
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 would suggest keeping the check like it was and ...
| setFiatByLocale({ locale }) { | ||
| const fiat = LocaleCurrency.getCurrency(locale).toLowerCase(); | ||
| this.setFiatCurrency({ fiat }); | ||
| } |
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 (!FIATS[fiat]) falling back to usd if the app does not support the currency yet. This will allow us to detect Euro and Pounds for now and add more currency support in the future (which requires a design change in the settings).
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.
the ternary expression on line 21 does just that - if fiat is any of the supported fiats, it will be used. otherwise USD
| expect(store2.settings.fiat, 'to be', 'usd'); | ||
| }); | ||
| }); | ||
|
|
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.
No need to add an integration test since we don't spin up electron here anyway. Unit tests should suffice for this feature.
a6dc6ea to
724aa4c
Compare
724aa4c to
967527a
Compare
| */ | ||
| sendLocaleRequest() { | ||
| return this._sendIpc('get-locale', 'locale'); | ||
| } |
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.
options here:
- make
_sendIpcpublic so it can be called fromactions/setting - replicate logic of
_sendIpcinactions/setting, and passipcRendererinto that file - leave this code here, which seems out of place
I would prefer 1 or 3, just for aesthetics and simplicity
| let response = await this._grpc.sendLocaleRequest(); | ||
| const fiat = LocaleCurrency.getCurrency(response.locale).toLowerCase(); | ||
| this.setFiatCurrency({ fiat }); | ||
| } |
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 add an annotation to this function
|
Closing in favor of #501 |
Closes #486