-
Notifications
You must be signed in to change notification settings - Fork 168
Detect locale updated #501
Changes from all commits
88cec1b
917a5ac
322dbca
82a01da
0ec08be
1843d07
a30842b
7da38fb
88d83a7
3f23b7f
23131f4
400f430
d3d0b7f
c22704d
af54ab1
a186294
5aab506
66c361c
104b9c2
7297222
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ import { AsyncStorage, Clipboard } from 'react-native'; | |
| import { nap } from '../helper'; | ||
| import store from '../store'; | ||
| import AppStorage from './app-storage'; | ||
| import IpcAction from './ipc'; | ||
| import GrpcAction from './grpc'; | ||
| import NavAction from './nav'; | ||
| import WalletAction from './wallet'; | ||
|
|
@@ -21,18 +22,17 @@ import PaymentAction from './payment'; | |
| import InvoiceAction from './invoice'; | ||
| import SettingAction from './setting'; | ||
|
|
||
| const ipcRenderer = window.ipcRenderer; // exposed to sandbox via preload.js | ||
|
|
||
| // | ||
| // Inject dependencies | ||
| // | ||
|
|
||
| store.init(); // initialize computed values | ||
|
|
||
| export const ipc = new IpcAction(window.ipcRenderer); | ||
| export const db = new AppStorage(store, AsyncStorage); | ||
| export const log = new LogAction(store, ipcRenderer); | ||
| export const log = new LogAction(store, ipc); | ||
| export const nav = new NavAction(store); | ||
| export const grpc = new GrpcAction(store, ipcRenderer); | ||
| export const grpc = new GrpcAction(store, ipc); | ||
| export const notify = new NotificationAction(store, nav); | ||
| export const wallet = new WalletAction(store, grpc, db, nav, notify); | ||
| export const info = new InfoAction(store, grpc, nav, notify); | ||
|
|
@@ -47,9 +47,9 @@ export const invoice = new InvoiceAction( | |
| Clipboard | ||
| ); | ||
| export const payment = new PaymentAction(store, grpc, transaction, nav, notify); | ||
| export const setting = new SettingAction(store, wallet, db); | ||
| export const setting = new SettingAction(store, wallet, db, ipc); | ||
|
|
||
| payment.listenForUrl(ipcRenderer); // enable incoming url handler | ||
| payment.listenForUrl(ipc); // enable incoming url handler | ||
|
|
||
| // | ||
| // Init actions | ||
|
|
@@ -71,6 +71,14 @@ observe(store, 'unlockerReady', async () => { | |
| await wallet.init(); | ||
| }); | ||
|
|
||
| /** | ||
| * Triggered the first time the app was started e.g. to set the | ||
| * local fiat currency only once. | ||
| */ | ||
| observe(store, 'firstStart', async () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems like we could get rid of this logic by following the pattern of or alternately, simplify
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought about that too...
Problem is we can't use the settings action inside wallet init, because setting already depends on wallet i.e. it's injected to fetch the exchange rate.
Not super happy about that either because we can't really unit test this routine. Trying to keep all testable logic in actions. |
||
| await setting.detectLocalCurrency(); | ||
| }); | ||
|
|
||
| /** | ||
| * Triggered after the user's password has unlocked the wallet. | ||
| */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /** | ||
| * @fileOverview a low level action to wrap electron's IPC renderer api. | ||
| */ | ||
|
|
||
| class IpcAction { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is nice 👌 learned a lot about electron reading this code! |
||
| constructor(ipcRenderer) { | ||
| this._ipcRenderer = ipcRenderer; | ||
| } | ||
|
|
||
| /** | ||
| * A wrapper around electron's ipcRenderer send api that can be | ||
| * reused wherever IPC to the main process is necessary. | ||
| * @param {string} event The event name the main process listens to | ||
| * @param {string} listen (optional) The response event name this process listens to | ||
| * @param {*} payload The data sent over IPC | ||
| * @return {Promise<Object>} | ||
| */ | ||
| send(event, listen, payload) { | ||
| return new Promise((resolve, reject) => { | ||
| this._ipcRenderer.send(event, payload); | ||
| if (!listen) return resolve(); | ||
| this._ipcRenderer.once(listen, (e, arg) => { | ||
| if (arg.err) { | ||
| reject(arg.err); | ||
| } else { | ||
| resolve(arg.response); | ||
| } | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * A wrapper around electron's ipcRenderer listen api that can be | ||
| * reused wherever listening to IPC from the main process is necessary. | ||
| * @param {string} event The event name this process listens to | ||
| * @param {Function} callback The event handler for incoming data | ||
| * @return {undefined} | ||
| */ | ||
| listen(event, callback) { | ||
| this._ipcRenderer.on(event, callback); | ||
| } | ||
| } | ||
|
|
||
| export default IpcAction; | ||
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.
is this a security measure?
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.
Yes. See #75