Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instapay logs export #887

Merged
merged 5 commits into from Jul 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 48 additions & 1 deletion app/components/Views/Settings/AdvancedSettings/index.js
Expand Up @@ -3,6 +3,7 @@ import React, { PureComponent } from 'react';
import { ActivityIndicator, SafeAreaView, StyleSheet, Switch, Text, Platform, View } from 'react-native';
import { connect } from 'react-redux';
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
import PaymentChannelsClient from '../../../../core/PaymentChannelsClient';
import ActionModal from '../../../UI/ActionModal';
import Engine from '../../../../core/Engine';
import StyledButton from '../../../UI/StyledButton';
Expand Down Expand Up @@ -110,6 +111,10 @@ class AdvancedSettings extends PureComponent {
* Indicates whether hex data should be shown in transaction editor
*/
showHexData: PropTypes.bool,
/**
* Indicates whether InstaPay is ON or OFF
*/
paymentChannelsEnabled: PropTypes.bool,
/**
* Called to toggle show hex data
*/
Expand Down Expand Up @@ -224,13 +229,41 @@ class AdvancedSettings extends PureComponent {
}
};

downloadInstapayStateLogs = async () => {
const appName = DeviceInfo.getApplicationName();
const appVersion = DeviceInfo.getVersion();
const buildNumber = DeviceInfo.getBuildNumber();
const path = RNFS.DocumentDirectoryPath + `/instapay-logs-v${appVersion}-(${buildNumber}).json`;

try {
const dump = PaymentChannelsClient.dump();
dump.connext = !!dump.connext;
delete dump.ethprovider;
const data = JSON.stringify(dump);

let url = `data:text/plain;base64,${new Buffer(data).toString('base64')}`;
// // Android accepts attachements as BASE64
if (Platform.OS === 'ios') {
await RNFS.writeFile(path, data, 'utf8');
url = path;
}
await Share.open({
subject: `${appName} Instapay logs - v${appVersion} (${buildNumber})`,
title: `${appName} Instapay logs - v${appVersion} (${buildNumber})`,
url
});
} catch (err) {
Logger.error('Instapay log error', err);
}
};

setIpfsGateway = ipfsGateway => {
const { PreferencesController } = Engine.context;
PreferencesController.setIpfsGateway(ipfsGateway);
};

render = () => {
const { showHexData, ipfsGateway } = this.props;
const { showHexData, ipfsGateway, paymentChannelsEnabled } = this.props;
const { resetModalVisible, onlineIpfsGateways } = this.state;
return (
<SafeAreaView style={baseStyles.flexGrow}>
Expand Down Expand Up @@ -319,6 +352,19 @@ class AdvancedSettings extends PureComponent {
{strings('app_settings.state_logs_button')}
</StyledButton>
</View>
{paymentChannelsEnabled && (
<View style={styles.setting}>
<Text style={styles.title}>{strings('app_settings.instapay_state_logs')}</Text>
<Text style={styles.desc}>{strings('app_settings.instapay_state_logs_desc')}</Text>
<StyledButton
type="info"
onPress={this.downloadInstapayStateLogs}
containerStyle={styles.syncConfirm}
>
{strings('app_settings.instapay_state_logs_button')}
</StyledButton>
</View>
)}
</View>
</KeyboardAwareScrollView>
{Platform.OS === 'android' && <AndroidBackHandler navigation={this.props.navigation} />}
Expand All @@ -330,6 +376,7 @@ class AdvancedSettings extends PureComponent {
const mapStateToProps = state => ({
ipfsGateway: state.engine.backgroundState.PreferencesController.ipfsGateway,
showHexData: state.settings.showHexData,
paymentChannelsEnabled: state.settings.paymentChannelsEnabled,
fullState: state
});

Expand Down
7 changes: 6 additions & 1 deletion app/core/PaymentChannelsClient.js
Expand Up @@ -566,7 +566,12 @@ const instance = {
* Event emitter instance that allows to subscribe
* to the events emitted by the instance
*/
hub
hub,
/**
* returns the entire state of the client
* only used for debugging purposes
*/
dump: () => (client && client.state) || {}
};

const reloadClient = () => {
Expand Down
3 changes: 3 additions & 0 deletions locales/en.json
Expand Up @@ -266,16 +266,19 @@
"search_engine": "Search Engine",
"new_RPC_URL": "New RPC Network",
"state_logs": "State Logs",
"instapay_state_logs": "InstaPay Logs",
"auto_lock": "Auto-lock",
"auto_lock_desc": "Choose the amount of time before the application automatically locks.",
"state_logs_desc": "This will help MetaMask debug any issue you might encounter. Please send it via email to mobile@metamask.io",
"instapay_state_logs_desc": "This will help MetaMask debug issues with InstaPay. Please send it via email to mobile@metamask.io",
"autolock_immediately": "Immediately",
"autolock_never": "Never",
"autolock_after": "After {{time}} seconds",
"autolock_after_minutes": "After {{time}} minutes",
"reveal_seed_words": "Reveal Seed Words",
"reset_account": "Reset Account",
"state_logs_button": "DOWNLOAD STATE LOGS",
"instapay_state_logs_button": "GET INSTAPAY LOGS",
"reveal_seed_words_button": "REVEAL SEED WORDS",
"reset_account_button": "RESET ACCOUNT",
"reset_account_confirm_button": "RESET",
Expand Down
4 changes: 4 additions & 0 deletions locales/es.json
Expand Up @@ -261,9 +261,11 @@
"ipfs_gateway_down": "IPFS gateway actual está desconectado",
"ipfs_gateway_desc": "Elige tu IPFS gateway preferida.",
"state_logs": "Logs de Estado",
"instapay_state_logs": "Logs de Instapay",
"reveal_seed_words": "Revelar Palabras de Semilla",
"reset_account": "Reiniciar Cuenta",
"state_logs_button": "DESCARGAR LOGS DE ESTADO",
"instapay_state_logs_button": "OBTENER LOGS DE INSTAPAY",
"reveal_seed_words_button": "REVELAR PALABRAS DE SEMILLA",
"reset_account_button": "REINICIAR CUENTA",
"reset_account_confirm_button": "REINICIAR",
Expand All @@ -276,6 +278,8 @@
"search_engine": "Motor de Búsqueda",
"auto_lock": "Bloqueo automático",
"auto_lock_desc": "Elige la cantidad de tiempo para que la aplicación se bloquee automáticamente.",
"state_logs_desc": "Esto nos ayudará a investigar cualquier problema con la app. Envíalo a mobile@metamask.io",
"instapay_state_logs_desc": "Esto nos ayudará a investigar problemas con InstaPay. Envíalo a mobile@metamask.io",
"autolock_immediately": "Inmediatamente",
"autolock_never": "Nunca",
"autolock_after": "Luego de {{time}} segundos",
Expand Down