import React, {useState} from 'react';
import './wallet.scss';
import Dexie from 'dexie';
import {Store} from '../store';
import {logger} from '../logger';
import {DB_NAME} from '../constants';
import {track} from '../segment-analytics';
interface Props {
store: Store;
}
export const FactoryReset = (props: Props) => {
const [destroyed, setDestroyed] = useState(false);
return destroyed ? (
Success! Check your console to see your old store.
) : (
If you press this button, we will destroy your wallet.
We will dump the contents of your wallet in your console.
Contact us, and we can try to recover your funds.
);
};
const destroyStore = async (store: Store, setDestroyed) => {
track('clicked factory reset');
if (!(await Dexie.exists(DB_NAME))) {
logger.error('No store detected.');
track('did not have a store');
setDestroyed(true);
} else if (confirm('Are you sure you want to delete your store?')) {
track('approved factory reset');
logger.error({store: await (store as any).backend.dump()}, 'Wallet destroyed');
await Dexie.delete(DB_NAME);
setDestroyed(true);
track('destroyed store');
} else {
track('rejected factory reset');
}
};