Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private async connectInit (args: TrezorConnectArgs): Promise {
// Collect connect events that happen during init, but don't handle them
// until after init has resolved. This awkward sequence is needed because we
// need TrezorConnect to be fully operational before we're able to process
// the events.
let connectEvents = []
let connectHandler = (event: any) => {
if (event.type === 'device-connect') {
connectEvents.push(event)
}
}
TrezorConnect.on(DEVICE_EVENT, connectHandler)
// TODO: using this in electron will needs some more scaffolding:
// https://github.com/szymonlesisz/trezor-connect-electron-boilerplate/blob/master/src/electron.js
await TrezorConnect.init({
...args,
popup: POPUP,
lazyLoad: false
})
TrezorConnect.off(DEVICE_EVENT, connectHandler)
for (const connectEvent of connectEvents)
this.handleConnectTrezor(connectEvent)
TrezorConnect.on(DEVICE_EVENT, (event: any) => {
if (event.type === 'device-connect') {
this.handleConnectTrezor(event)
} else if (event.type === 'device-changed') {
this.handleChangeTrezor(event)
} else if (event.type === 'device-disconnect') {
setup() {
this._reset();
const trezorConnectAction = this.actions.ada.trezorConnect;
trezorConnectAction.cancel.listen(this._cancel);
trezorConnectAction.submitAbout.listen(this._submitAbout);
trezorConnectAction.goBacktToAbout.listen(this._goBacktToAbout);
trezorConnectAction.submitConnect.listen(this._submitConnect);
trezorConnectAction.submitSave.listen(this._submitSave);
/** Preinitialization of TrezorConnect API will result in faster first response */
try {
TrezorConnect.init({});
} catch (error) {
Logger.error(`TrezorConnectStore::setup:error: ${stringifyError(error)}`);
}
}