Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

Commit

Permalink
Add wallet state to log export. (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
conqeror committed Jun 9, 2021
1 parent 27bcf5f commit 875aa8c
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion mantis
Submodule mantis updated 494 files
5 changes: 4 additions & 1 deletion src/common/SupportModal.tsx
Expand Up @@ -12,6 +12,7 @@ import {wrapWithModal, ModalLocker} from './MantisModal'
import {Dialog} from './Dialog'
import {Trans} from './Trans'
import {useTranslation, useLocalizedUtilities} from '../settings-state'
import {WalletState} from './wallet-state'
import {TFunctionRenderer} from './i18n'

const CHANNELS: IPCToRendererChannelName[] = [
Expand All @@ -37,6 +38,7 @@ function createMessage(t: TFunctionRenderer, path: string) {
export const SupportDialog = (): JSX.Element => {
const {t} = useTranslation()
const {makeDismissableMessage} = useLocalizedUtilities()
const {exportState} = WalletState.useContainer()
const {setLocked, isLocked} = ModalLocker.useContainer()
const [isDone, setDone] = useState(false)

Expand Down Expand Up @@ -68,7 +70,8 @@ export const SupportDialog = (): JSX.Element => {
className="SupportModal"
leftButtonProps={{
onClick: () => {
saveDebugLogs()
const walletState = exportState()
saveDebugLogs(walletState)
setLocked(true)
},
children: t(['common', 'button', 'exportDebugLogs']),
Expand Down
4 changes: 2 additions & 2 deletions src/common/ipc-util.ts
Expand Up @@ -27,8 +27,8 @@ export const updateLanguage = (language: Language): void => {
ipcSend('update-language', language)
}

export const saveDebugLogs = (): void => {
ipcSend('save-debug-logs')
export const saveDebugLogs = (rendererStoreData: string): void => {
ipcSend('save-debug-logs', rendererStoreData)
}

export const updateNetworkName = (networkName: NetworkName): void => {
Expand Down
15 changes: 15 additions & 0 deletions src/common/wallet-state.ts
Expand Up @@ -83,6 +83,7 @@ interface CommonState {
setTncAccepted: (value: boolean) => void
syncStatus: SynchronizationStatus
error: Option<Error>
exportState(): string
}

export interface InitialState extends CommonState {
Expand Down Expand Up @@ -639,6 +640,19 @@ function useWalletState(initialState?: Partial<WalletStateParams>): WalletData {
const availableBalance = getOrElse(() => asWei(0))(availableBalanceOption)
const pendingBalance = asWei(totalBalance.minus(availableBalance))

const exportState = (): string =>
JSON.stringify({
totalBalance,
availableBalance,
pendingBalance,
transactions,
tncAccepted,
accounts,
error,
walletStatus,
syncStatus,
})

return {
walletStatus,
error,
Expand All @@ -665,6 +679,7 @@ function useWalletState(initialState?: Partial<WalletStateParams>): WalletData {
deleteContact,
tncAccepted,
setTncAccepted,
exportState,
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/log-exporter.ts
Expand Up @@ -9,6 +9,7 @@ import {CheckedDatadir, getMantisDatadirPath} from './data-dir'
export const createLogExporter = (_checkedDatadir: CheckedDatadir) => async (
config: Config,
store: MainStore,
rendererStoreData: string,
outputFilePath: string,
): Promise<void> => {
// Create and save archive
Expand All @@ -22,11 +23,13 @@ export const createLogExporter = (_checkedDatadir: CheckedDatadir) => async (
const backendLogPath = path.join(mantisDatadirPath, store.get('networkName'), 'logs')
const walletLogPath = path.join(config.walletDataDir, 'logs')
const configAndStatusText = JSON.stringify({config, status}, null, 2)
const rendererStore = JSON.stringify(JSON.parse(rendererStoreData), null, 2)

archive
.directory(backendLogPath, false)
.directory(walletLogPath, false)
.append(configAndStatusText, {name: 'wallet-config-and-status.json'})
.append(rendererStore, {name: 'renderer-store.json'})

const output = fs.createWriteStream(outputFilePath)
archive.pipe(output)
Expand Down
4 changes: 2 additions & 2 deletions src/main/main.ts
Expand Up @@ -326,7 +326,7 @@ walletInit()
})
}

ipcListenToRenderer('save-debug-logs', async (event) => {
ipcListenToRenderer('save-debug-logs', async (event, rendererStoreData: string) => {
const t = createTFunctionMain(i18n)
const options = {
title: t(['dialog', 'title', 'saveDebugLogs']),
Expand All @@ -341,7 +341,7 @@ walletInit()
}

try {
await exportLogs(config, store, outputFilePath)
await exportLogs(config, store, rendererStoreData, outputFilePath)
event.reply('save-debug-logs-success', outputFilePath)
} catch (e) {
mainLog.error(e)
Expand Down

0 comments on commit 875aa8c

Please sign in to comment.