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

feat: reset data menu #560

Merged
merged 6 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,15 @@ function createWindow () {
{ label: 'Copy', accelerator: 'CmdOrCtrl+C', selector: 'copy:' },
{ label: 'Paste', accelerator: 'CmdOrCtrl+V', selector: 'paste:' },
{ label: 'Select All', accelerator: 'CmdOrCtrl+A', selector: 'selectAll:' }
]}
]},
];

if (debugMode) {
template.push({
label: 'Debug',
submenu: [
{ label: `Open DevTools`, accelerator: 'CmdOrCtrl+B', click: function() { mainWindow.webContents.openDevTools(); }}
{ label: `Open DevTools`, accelerator: 'CmdOrCtrl+B', click: function() { mainWindow.webContents.openDevTools(); }},
{ label: 'Reset all data', click: function() { mainWindow.webContents.send('app:reset_all_data'); }},
]
});
};
Expand Down Expand Up @@ -167,6 +168,11 @@ function createWindow () {
}
});

ipcMain.on('app:reset_all_data_success', () => {
console.log('Data reset success. Closing window...');
mainWindow.close();
});

addLedgerListeners(mainWindow);
}

Expand Down
15 changes: 14 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import React, { useEffect, useState } from 'react';
import React, { useEffect, useState, useContext } from 'react';
import { Redirect, Route, Switch, useHistory, useRouteMatch } from 'react-router-dom';
import Wallet from './screens/Wallet';
import SendTokens from './screens/SendTokens';
Expand Down Expand Up @@ -38,6 +38,7 @@
import storageUtils from './utils/storage';
import { useDispatch, useSelector } from 'react-redux';
import RequestErrorModal from './components/RequestError';
import { GlobalModalContext, MODAL_TYPES } from './components/GlobalModal';
import createRequestInstance from './api/axiosInstance';
import hathorLib from '@hathor/wallet-lib';
import { IPC_RENDERER } from './constants';
Expand Down Expand Up @@ -67,6 +68,7 @@
});
const dispatch = useDispatch();
const history = useHistory();
const context = useContext(GlobalModalContext);

Check warning on line 71 in src/App.js

View check run for this annotation

Codecov / codecov/patch

src/App.js#L71

Added line #L71 was not covered by tests

// Monitors when Ledger device loses connection or the app is closed
useEffect(() => {
Expand Down Expand Up @@ -98,6 +100,17 @@

// If there is an `Inter Process Communication` channel available, initialize Ledger logic
if (IPC_RENDERER) {
// Event called when the user wants to reset all data
IPC_RENDERER.on('app:reset_all_data', async () => {
context.showModal(MODAL_TYPES.CONFIRM_RESET, {

Check warning on line 105 in src/App.js

View check run for this annotation

Codecov / codecov/patch

src/App.js#L104-L105

Added lines #L104 - L105 were not covered by tests
success: () => {
localStorage.clear();
IPC_RENDERER.send('app:reset_all_data_success');

Check warning on line 108 in src/App.js

View check run for this annotation

Codecov / codecov/patch

src/App.js#L107-L108

Added lines #L107 - L108 were not covered by tests
},
});

});

// Registers the event handlers for the ledger

// Event called when user quits hathor app
Expand Down
3 changes: 3 additions & 0 deletions src/components/GlobalModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import ModalLedgerResetTokenSignatures from './ModalLedgerResetTokenSignatures';
import ModalResetAllData from './ModalResetAllData';
import ModalLedgerSignToken from './ModalLedgerSignToken';
import ModalConfirmTestnet from './ModalConfirmTestnet';
import ModalConfirmReset from './ModalConfirmReset';
import ModalSendTx from './ModalSendTx';
import ModalUnregisteredTokenInfo from './ModalUnregisteredTokenInfo';
import ModalPin from "./ModalPin";
Expand All @@ -43,6 +44,7 @@ export const MODAL_TYPES = {
'RESET_ALL_DATA': 'RESET_ALL_DATA',
'LEDGER_SIGN_TOKEN': 'LEDGER_SIGN_TOKEN',
'CONFIRM_TESTNET': 'CONFIRM_TESTNET',
'CONFIRM_RESET': 'CONFIRM_RESET',
'SEND_TX': 'SEND_TX',
'UNREGISTERED_TOKEN_INFO': 'UNREGISTERED_TOKEN_INFO',
'PIN': 'PIN',
Expand All @@ -63,6 +65,7 @@ export const MODAL_COMPONENTS = {
[MODAL_TYPES.RESET_ALL_DATA]: ModalResetAllData,
[MODAL_TYPES.LEDGER_SIGN_TOKEN]: ModalLedgerSignToken,
[MODAL_TYPES.CONFIRM_TESTNET]: ModalConfirmTestnet,
[MODAL_TYPES.CONFIRM_RESET]: ModalConfirmReset,
[MODAL_TYPES.SEND_TX]: ModalSendTx,
[MODAL_TYPES.UNREGISTERED_TOKEN_INFO]: ModalUnregisteredTokenInfo,
[MODAL_TYPES.PIN]: ModalPin,
Expand Down
63 changes: 63 additions & 0 deletions src/components/ModalConfirmReset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React, { useEffect, useState, useCallback } from 'react';
import { t } from 'ttag';
import $ from 'jquery';

export default function ModalConfirmResetAllData({ onClose, success }) {
const [confirmText, setConfirmText] = useState('');
const [confirmError, setConfirmError] = useState('');

Check warning on line 7 in src/components/ModalConfirmReset.js

View check run for this annotation

Codecov / codecov/patch

src/components/ModalConfirmReset.js#L6-L7

Added lines #L6 - L7 were not covered by tests

useEffect(() => {
$('#modalConfirmResetAllData').modal('show');
$('#modalConfirmResetAllData').on('hidden.bs.modal', onClose);

Check warning on line 11 in src/components/ModalConfirmReset.js

View check run for this annotation

Codecov / codecov/patch

src/components/ModalConfirmReset.js#L9-L11

Added lines #L9 - L11 were not covered by tests

return () => {
$('#modalConfirmResetAllData').modal('hide');
$('#modalConfirmResetAllData').off();

Check warning on line 15 in src/components/ModalConfirmReset.js

View check run for this annotation

Codecov / codecov/patch

src/components/ModalConfirmReset.js#L13-L15

Added lines #L13 - L15 were not covered by tests
};
}, []);

const confirmResetData = useCallback(() => {

Check warning on line 19 in src/components/ModalConfirmReset.js

View check run for this annotation

Codecov / codecov/patch

src/components/ModalConfirmReset.js#L19

Added line #L19 was not covered by tests
if (confirmText.toLowerCase() !== 'i want to reset all wallet data') {
setConfirmError(t`Invalid value.`);
return;

Check warning on line 22 in src/components/ModalConfirmReset.js

View check run for this annotation

Codecov / codecov/patch

src/components/ModalConfirmReset.js#L21-L22

Added lines #L21 - L22 were not covered by tests
}

success();

Check warning on line 25 in src/components/ModalConfirmReset.js

View check run for this annotation

Codecov / codecov/patch

src/components/ModalConfirmReset.js#L25

Added line #L25 was not covered by tests
}, [confirmText, setConfirmError]);

return (

Check warning on line 28 in src/components/ModalConfirmReset.js

View check run for this annotation

Codecov / codecov/patch

src/components/ModalConfirmReset.js#L28

Added line #L28 was not covered by tests
<div className="modal fade" id="modalConfirmResetAllData" tabIndex="-1" role="dialog" aria-labelledby="alertModal" aria-hidden="true" data-backdrop="static" data-keyboard="false">
<div className="modal-dialog" role="document">
<div className="modal-content">
<div className="modal-header">
<h5 className="modal-title">
{ t`Confirm reset all data` }
</h5>
</div>
<div className="modal-body">
<div>
<p>{t`Do you want to reset all of your wallet data? Only continue if you know what you are doing.`}</p>
pedroferreira1 marked this conversation as resolved.
Show resolved Hide resolved
<p>{t`This action cannot be undone. All your data will be lost.`}</p>
pedroferreira1 marked this conversation as resolved.
Show resolved Hide resolved
<p>{t`Your wallet uniqueId will be reset.`} uniqueId: {localStorage.getItem('app:uniqueId')}</p>
<p>{t`If you want to reset all data, please type 'I want to reset all wallet data' in the box below and click on 'Reset all data' button.`}</p>
<div className="mt-2 d-flex flex-row align-items-center">
<input type="text" className="form-control col-4" defaultValue={confirmText} onChange={(e) => setConfirmText(e.target.value)} />

Check warning on line 44 in src/components/ModalConfirmReset.js

View check run for this annotation

Codecov / codecov/patch

src/components/ModalConfirmReset.js#L44

Added line #L44 was not covered by tests
<span className="text-danger ml-2">
{confirmError}
</span>
</div>
</div>
</div>
<div className="modal-footer">
<button onClick={confirmResetData} type="button" className="btn btn-secondary">
{t`Reset all data`}
</button>
<button onClick={onClose} type="button" className="btn btn-hathor">
{ t`Cancel` }
</button>
</div>
</div>
</div>
</div>
);
}
Loading