Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Conversation

@willpiers
Copy link
Contributor

Closes #486


ipcMain.on('get-locale', event => {
event.sender.send('locale', { response: { locale } });
});
Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor

@tanx tanx left a 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",
Copy link
Contributor

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


ipcMain.on('get-locale', event => {
event.sender.send('locale', { response: { locale } });
});
Copy link
Contributor

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
)
) {
Copy link
Contributor

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.

let response = await this._sendIpc('get-locale', 'locale');
return response.locale;
}

Copy link
Contributor

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.

observe(store, 'lndReady', () => {
observe(store, 'lndReady', async () => {
const locale = await grpc.getLocale();
setting.setFiatByLocale({ locale });
Copy link
Contributor

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;
Copy link
Contributor

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 });
}
Copy link
Contributor

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).

Copy link
Contributor Author

@willpiers willpiers Aug 6, 2018

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');
});
});

Copy link
Contributor

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.

*/
sendLocaleRequest() {
return this._sendIpc('get-locale', 'locale');
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

options here:

  1. make _sendIpc public so it can be called from actions/setting
  2. replicate logic of _sendIpc in actions/setting, and pass ipcRenderer into that file
  3. 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 });
}
Copy link
Contributor Author

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

@tanx
Copy link
Contributor

tanx commented Aug 7, 2018

Closing in favor of #501

@tanx tanx closed this Aug 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants