Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getIsWatchAppInstalled() {
Watch.getIsWatchAppInstalled((err, isAppInstalled) => {
if (!err) {
WatchConnectivity.shared.isAppInstalled = isAppInstalled;
Watch.subscribeToWatchState((err, watchState) => {
if (!err) {
if (watchState === 'Activated') {
WatchConnectivity.shared.sendWalletsToWatch();
}
}
});
Watch.subscribeToMessages(async (err, message, reply) => {
if (!err) {
if (message.request === 'createInvoice') {
const createInvoiceRequest = await this.handleLightningInvoiceCreateRequest(
message.walletIndex,
message.amount,
message.description,
});
watch.subscribeToWatchReachability((err, watchIsReachable) => {
if (!err) {
this.setState({ watchIsReachable });
if (watchIsReachable) {
this.sendTokenToWatch();
}
}
});
watch.getWatchState((err, watchState) => {
if (!err && watchState === 'Activated') {
this.sendTokenToWatch();
}
});
watch.subscribeToWatchState((err, watchState) => {
if (!err && watchState === 'Activated') {
this.sendTokenToWatch();
}
});
};
Watch.getIsWatchAppInstalled((err, isAppInstalled) => {
if (!err) {
WatchConnectivity.shared.isAppInstalled = isAppInstalled;
Watch.subscribeToWatchState((err, watchState) => {
if (!err) {
if (watchState === 'Activated') {
WatchConnectivity.shared.sendWalletsToWatch();
}
}
});
Watch.subscribeToMessages(async (err, message, reply) => {
if (!err) {
if (message.request === 'createInvoice') {
const createInvoiceRequest = await this.handleLightningInvoiceCreateRequest(
message.walletIndex,
message.amount,
message.description,
);
reply({ invoicePaymentRequest: createInvoiceRequest });
} else if (message.message === 'sendApplicationContext') {
setUpWatchConnectivity = () => {
watch.getWatchReachability((err, watchIsReachable) => {
this.setState({ watchIsReachable });
});
watch.subscribeToWatchReachability((err, watchIsReachable) => {
if (!err) {
this.setState({ watchIsReachable });
if (watchIsReachable) {
this.sendTokenToWatch();
}
}
});
watch.getWatchState((err, watchState) => {
if (!err && watchState === 'Activated') {
this.sendTokenToWatch();
}
});
setUpWatchConnectivity = () => {
watch.getWatchReachability((err, watchIsReachable) => {
this.setState({ watchIsReachable });
});
watch.subscribeToWatchReachability((err, watchIsReachable) => {
if (!err) {
this.setState({ watchIsReachable });
if (watchIsReachable) {
this.sendTokenToWatch();
}
}
});
watch.getWatchState((err, watchState) => {
if (!err && watchState === 'Activated') {
this.sendTokenToWatch();
}
});
watch.subscribeToWatchState((err, watchState) => {
if (!err && watchState === 'Activated') {
this.sendTokenToWatch();
}
});
};
function _appWillMount({ dispatch, getState }) {
watch.subscribeToWatchReachability((error, reachable) => {
dispatch(setWatchReachable(reachable));
_updateApplicationContext(getState);
});
watch.subscribeToMessages((error, message) => {
if (error) {
logger.error('watch.subscribeToMessages error:', error);
return;
}
const {
command,
sessionID
} = message;
const currentSessionID = _getSessionId(getState());
if (!sessionID || sessionID !== currentSessionID) {
logger.warn(
`Ignoring outdated watch command: ${message.command}`
+ ` sessionID: ${sessionID} current session ID: ${currentSessionID}`);
function _appWillMount({ dispatch, getState }) {
watch.subscribeToWatchReachability((error, reachable) => {
dispatch(setWatchReachable(reachable));
_updateApplicationContext(getState);
});
watch.subscribeToMessages((error, message) => {
if (error) {
logger.error('watch.subscribeToMessages error:', error);
return;
}
const {
command,
sessionID
} = message;
const currentSessionID = _getSessionId(getState());
function _updateApplicationContext(stateful) {
const state = toState(stateful);
const { conferenceTimestamp, sessionID, watchReachable } = state['features/mobile/watchos'];
if (!watchReachable) {
return;
}
try {
watch.updateApplicationContext({
conferenceTimestamp,
conferenceURL: getCurrentConferenceUrl(state),
micMuted: _isAudioMuted(state),
recentURLs: _getRecentUrls(state),
sessionID
});
} catch (error) {
logger.error('Failed to stringify or send the context', error);
}
}