forked from cerc-io/laconic-wallet
Remove configured networks on reset (#105)
This commit is contained in:
parent
cd03fb6e84
commit
1172e67f5f
@ -26,7 +26,7 @@ const SelectNetworkType = ({
|
|||||||
<Text
|
<Text
|
||||||
style={{
|
style={{
|
||||||
fontWeight: 'bold',
|
fontWeight: 'bold',
|
||||||
marginBottom: 10,
|
marginVertical: 10,
|
||||||
}}>
|
}}>
|
||||||
Select Network Type
|
Select Network Type
|
||||||
</Text>
|
</Text>
|
||||||
|
@ -32,7 +32,8 @@ const HomeScreen = () => {
|
|||||||
const { accounts, setAccounts, currentIndex, setCurrentIndex } =
|
const { accounts, setAccounts, currentIndex, setCurrentIndex } =
|
||||||
useAccounts();
|
useAccounts();
|
||||||
|
|
||||||
const { networksData, selectedNetwork, setSelectedNetwork } = useNetworks();
|
const { networksData, selectedNetwork, setSelectedNetwork, setNetworksData } =
|
||||||
|
useNetworks();
|
||||||
const { setActiveSessions } = useWalletConnect();
|
const { setActiveSessions } = useWalletConnect();
|
||||||
|
|
||||||
const navigation =
|
const navigation =
|
||||||
@ -86,15 +87,21 @@ const HomeScreen = () => {
|
|||||||
fetchAccounts();
|
fetchAccounts();
|
||||||
setWalletDialog(true);
|
setWalletDialog(true);
|
||||||
setPhrase(mnemonic);
|
setPhrase(mnemonic);
|
||||||
|
setSelectedNetwork(networksData[0]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const confirmResetWallet = async () => {
|
const confirmResetWallet = useCallback(async () => {
|
||||||
await resetWallet();
|
const updatedNetworks = networksData.filter(
|
||||||
|
networkData => networkData.isDefault,
|
||||||
|
);
|
||||||
|
setNetworksData(updatedNetworks);
|
||||||
|
setSelectedNetwork(undefined);
|
||||||
setIsWalletCreated(false);
|
setIsWalletCreated(false);
|
||||||
setIsWalletCreating(false);
|
setIsWalletCreating(false);
|
||||||
setAccounts([]);
|
setAccounts([]);
|
||||||
setCurrentIndex(0);
|
setCurrentIndex(0);
|
||||||
|
await resetWallet(updatedNetworks);
|
||||||
const sessions = web3wallet!.getActiveSessions();
|
const sessions = web3wallet!.getActiveSessions();
|
||||||
|
|
||||||
Object.keys(sessions).forEach(async sessionId => {
|
Object.keys(sessions).forEach(async sessionId => {
|
||||||
@ -106,7 +113,14 @@ const HomeScreen = () => {
|
|||||||
setActiveSessions({});
|
setActiveSessions({});
|
||||||
|
|
||||||
hideResetDialog();
|
hideResetDialog();
|
||||||
};
|
}, [
|
||||||
|
networksData,
|
||||||
|
setAccounts,
|
||||||
|
setActiveSessions,
|
||||||
|
setCurrentIndex,
|
||||||
|
setNetworksData,
|
||||||
|
setSelectedNetwork,
|
||||||
|
]);
|
||||||
|
|
||||||
const updateNetwork = (networkData: NetworksDataState) => {
|
const updateNetwork = (networkData: NetworksDataState) => {
|
||||||
setSelectedNetwork(networkData);
|
setSelectedNetwork(networkData);
|
||||||
@ -128,7 +142,7 @@ const HomeScreen = () => {
|
|||||||
<Text style={styles.LoadingText}>Loading...</Text>
|
<Text style={styles.LoadingText}>Loading...</Text>
|
||||||
<ActivityIndicator size="large" color="#0000ff" />
|
<ActivityIndicator size="large" color="#0000ff" />
|
||||||
</View>
|
</View>
|
||||||
) : isWalletCreated ? (
|
) : isWalletCreated && selectedNetwork ? (
|
||||||
<>
|
<>
|
||||||
<NetworkDropdown updateNetwork={updateNetwork} />
|
<NetworkDropdown updateNetwork={updateNetwork} />
|
||||||
<View style={styles.accountComponent}>
|
<View style={styles.accountComponent}>
|
||||||
|
@ -186,13 +186,13 @@ const retrieveAccounts = async (
|
|||||||
`accountIndices/${currentNetworkData.namespace}:${currentNetworkData.chainId}`,
|
`accountIndices/${currentNetworkData.namespace}:${currentNetworkData.chainId}`,
|
||||||
);
|
);
|
||||||
const accountIndices = accountIndicesServer && accountIndicesServer.password;
|
const accountIndices = accountIndicesServer && accountIndicesServer.password;
|
||||||
|
const loadedAccounts =
|
||||||
const loadedAccounts = accountIndices
|
accountIndices !== false
|
||||||
? await retrieveAccountsForNetwork(
|
? await retrieveAccountsForNetwork(
|
||||||
`${currentNetworkData.namespace}:${currentNetworkData.chainId}`,
|
`${currentNetworkData.namespace}:${currentNetworkData.chainId}`,
|
||||||
accountIndices,
|
accountIndices,
|
||||||
)
|
)
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
return loadedAccounts;
|
return loadedAccounts;
|
||||||
};
|
};
|
||||||
@ -225,12 +225,13 @@ const retrieveSingleAccount = async (
|
|||||||
return loadedAccounts.find(account => account.address === address);
|
return loadedAccounts.find(account => account.address === address);
|
||||||
};
|
};
|
||||||
|
|
||||||
const resetWallet = async () => {
|
const resetWallet = async (networks: NetworksDataState[]) => {
|
||||||
try {
|
try {
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
resetInternetCredentials('mnemonicServer'),
|
resetInternetCredentials('mnemonicServer'),
|
||||||
resetKeyServers(EIP155),
|
resetKeyServers(EIP155),
|
||||||
resetKeyServers(COSMOS),
|
resetKeyServers(COSMOS),
|
||||||
|
setInternetCredentials('networks', '_', JSON.stringify(networks)),
|
||||||
]);
|
]);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error resetting wallet:', error);
|
console.error('Error resetting wallet:', error);
|
||||||
|
Loading…
Reference in New Issue
Block a user