-
Notifications
You must be signed in to change notification settings - Fork 529
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
POC: Configure two Web Wallet applications (Root Document & Main Proc…
…ess) to coexist.
- Loading branch information
1 parent
a708ee6
commit f22a528
Showing
102 changed files
with
4,215 additions
and
1,606 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
main-process/packages/blockchain-wallet-v4-frontend/src/IPC/Middleware.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import * as router from 'connected-react-router' | ||
import * as R from 'ramda' | ||
|
||
import * as coreTypes from 'blockchain-wallet-v4/src/redux/actionTypes' | ||
import * as types from '../data/actionTypes' | ||
|
||
const alreadyForwarded = ({ meta }) => meta && meta.forwarded | ||
|
||
const dispatchToBoth = ({ rootDocumentDispatch, next }, action) => { | ||
if (!alreadyForwarded(action)) { | ||
rootDocumentDispatch(action) | ||
} | ||
|
||
next(action) | ||
} | ||
|
||
const dispatchToRootDocument = ({ rootDocumentDispatch }, action) => { | ||
rootDocumentDispatch(action) | ||
} | ||
|
||
const tag = action => ({ | ||
...action, | ||
meta: { ...action.meta, forwarded: true } | ||
}) | ||
|
||
const handlers = { | ||
// This requires the GUID. | ||
[coreTypes.data.misc.FETCH_LOGS]: dispatchToRootDocument, | ||
|
||
// This requires the GUID. | ||
[coreTypes.settings.FETCH_SETTINGS]: dispatchToRootDocument, | ||
|
||
// Tell the Root Document to merge our wrapper with its own. | ||
[coreTypes.wallet.MERGE_WRAPPER]: dispatchToRootDocument, | ||
|
||
// Inform the root document about routing changes so that it can switch which | ||
// application is displayed. | ||
[router.LOCATION_CHANGE]: dispatchToBoth, | ||
|
||
// Tell the root document to reload itself when we do. | ||
[types.auth.LOGOUT]: dispatchToBoth, | ||
|
||
// This requires the GUID. | ||
[types.modules.settings.UPDATE_LANGUAGE]: dispatchToRootDocument | ||
} | ||
|
||
export default ({ actionsChannel, rootDocumentDispatch }) => store => { | ||
// Now that we have access to the store, dispatch stored actions from the Root | ||
// Document to it. | ||
actionsChannel.forEach(store.dispatch) | ||
|
||
return next => action => { | ||
const { type } = action | ||
|
||
const context = { | ||
rootDocumentDispatch: R.pipe( | ||
tag, | ||
rootDocumentDispatch | ||
), | ||
next, | ||
store | ||
} | ||
|
||
if (type in handlers) { | ||
return handlers[type](context, action) | ||
} else { | ||
return next(action) | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
main-process/packages/blockchain-wallet-v4-frontend/src/IPC/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import Channel from '@nodeguy/channel' | ||
|
||
import { serializer } from 'blockchain-wallet-v4/src/types' | ||
import Middleware from './Middleware' | ||
import { RealmConnectionModule } from '../../../web-microkernel/src' | ||
|
||
const { RealmConnection, sanitizeFunction } = RealmConnectionModule({ | ||
ErrorEvent, | ||
EventTarget, | ||
getRandomValues: typedArray => window.crypto.getRandomValues(typedArray) | ||
}) | ||
|
||
export default async ({ input, output, outputOrigin }) => { | ||
// We need to export a function for dispatching actions from the Root | ||
// Document before the store is created so use a channel to save them until | ||
// the store is ready. | ||
const actionsChannel = Channel() | ||
|
||
const connection = await RealmConnection({ | ||
exports: { dispatch: actionsChannel.push }, | ||
input, | ||
output, | ||
outputOrigin, | ||
reviver: serializer.reviver | ||
}) | ||
|
||
return { | ||
connection, | ||
|
||
middleware: Middleware({ | ||
actionsChannel, | ||
rootDocumentDispatch: connection.imports.dispatch | ||
}), | ||
|
||
sanitizeFunction | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.