Add snackbar for invalid mnemonic error
This commit is contained in:
parent
01289678d4
commit
c25bf11822
@ -1,4 +1,4 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
|
|
||||||
import { Dialog, DialogActions, DialogContent, DialogTitle, TextField, Grid, Button, Typography } from "@mui/material";
|
import { Dialog, DialogActions, DialogContent, DialogTitle, TextField, Grid, Button, Typography } from "@mui/material";
|
||||||
|
|
||||||
@ -29,6 +29,10 @@ const ImportWalletDialog = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setWords(Array(12).fill(''));
|
||||||
|
},[visible]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={visible} onClose={hideDialog}>
|
<Dialog open={visible} onClose={hideDialog}>
|
||||||
<DialogTitle>Import your wallet from your mnemonic</DialogTitle>
|
<DialogTitle>Import your wallet from your mnemonic</DialogTitle>
|
||||||
|
@ -5,6 +5,7 @@ import { Button, Text } from 'react-native-paper';
|
|||||||
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
|
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
|
||||||
import { useNavigation } from '@react-navigation/native';
|
import { useNavigation } from '@react-navigation/native';
|
||||||
import { getSdkError } from '@walletconnect/utils';
|
import { getSdkError } from '@walletconnect/utils';
|
||||||
|
import { Portal, Snackbar } from '@mui/material';
|
||||||
|
|
||||||
import { createWallet, resetWallet, retrieveAccounts } from '../utils/accounts';
|
import { createWallet, resetWallet, retrieveAccounts } from '../utils/accounts';
|
||||||
import { MnemonicDialog } from '../components/MnemonicDialog';
|
import { MnemonicDialog } from '../components/MnemonicDialog';
|
||||||
@ -59,6 +60,8 @@ const HomeScreen = () => {
|
|||||||
const [importWalletDialog, setImportWalletDialog] = useState<boolean>(false);
|
const [importWalletDialog, setImportWalletDialog] = useState<boolean>(false);
|
||||||
const [mnemonicDialog, setMnemonicDialog] = useState<boolean>(false);
|
const [mnemonicDialog, setMnemonicDialog] = useState<boolean>(false);
|
||||||
const [resetWalletDialog, setResetWalletDialog] = useState<boolean>(false);
|
const [resetWalletDialog, setResetWalletDialog] = useState<boolean>(false);
|
||||||
|
const [toastVisible, setToastVisible] = useState(false);
|
||||||
|
const [invalidMnemonicError, setInvalidMnemonicError] = useState('');
|
||||||
const [isAccountsFetched, setIsAccountsFetched] = useState<boolean>(true);
|
const [isAccountsFetched, setIsAccountsFetched] = useState<boolean>(true);
|
||||||
const [phrase, setPhrase] = useState('');
|
const [phrase, setPhrase] = useState('');
|
||||||
|
|
||||||
@ -92,12 +95,17 @@ const HomeScreen = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const importWalletHandler = async (recoveryPhrase: string) => {
|
const importWalletHandler = async (recoveryPhrase: string) => {
|
||||||
const mnemonic = await createWallet(networksData, recoveryPhrase);
|
try{
|
||||||
if (mnemonic) {
|
const mnemonic = await createWallet(networksData, recoveryPhrase);
|
||||||
fetchAccounts();
|
if (mnemonic) {
|
||||||
setPhrase(mnemonic);
|
fetchAccounts();
|
||||||
setSelectedNetwork(networksData[0]);
|
setPhrase(mnemonic);
|
||||||
setImportWalletDialog(false);
|
setSelectedNetwork(networksData[0]);
|
||||||
|
setImportWalletDialog(false);
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
setInvalidMnemonicError((error.message as string).toUpperCase())
|
||||||
|
setToastVisible(true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -194,6 +202,16 @@ const HomeScreen = () => {
|
|||||||
hideDialog={hideResetDialog}
|
hideDialog={hideResetDialog}
|
||||||
onConfirm={confirmResetWallet}
|
onConfirm={confirmResetWallet}
|
||||||
/>
|
/>
|
||||||
|
<Portal>
|
||||||
|
<Snackbar
|
||||||
|
open={toastVisible}
|
||||||
|
autoHideDuration={3000}
|
||||||
|
message={invalidMnemonicError}
|
||||||
|
onClose={() => setToastVisible(false)}
|
||||||
|
anchorOrigin={{ horizontal: 'center', vertical: 'bottom' }}
|
||||||
|
ContentProps={{ style: { backgroundColor: 'red', color: 'white'} }}
|
||||||
|
/>
|
||||||
|
</Portal>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -30,9 +30,9 @@ const createWallet = async (
|
|||||||
recoveryPhrase?: string,
|
recoveryPhrase?: string,
|
||||||
): Promise<string> => {
|
): Promise<string> => {
|
||||||
const mnemonic = recoveryPhrase ? recoveryPhrase : utils.entropyToMnemonic(utils.randomBytes(16));
|
const mnemonic = recoveryPhrase ? recoveryPhrase : utils.entropyToMnemonic(utils.randomBytes(16));
|
||||||
await setInternetCredentials('mnemonicServer', 'mnemonic', mnemonic);
|
|
||||||
|
|
||||||
const hdNode = HDNode.fromMnemonic(mnemonic);
|
const hdNode = HDNode.fromMnemonic(mnemonic);
|
||||||
|
await setInternetCredentials('mnemonicServer', 'mnemonic', mnemonic);
|
||||||
|
|
||||||
await createWalletFromMnemonic(networksData, hdNode, mnemonic);
|
await createWalletFromMnemonic(networksData, hdNode, mnemonic);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user