Skip to content

Commit

Permalink
feat: adds mnemonic import
Browse files Browse the repository at this point in the history
  • Loading branch information
ganchoradkov committed Dec 12, 2024
1 parent bfa890a commit 90bf650
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
19 changes: 17 additions & 2 deletions wallets/rn_cli_wallet/src/screens/Settings/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {useSnapshot} from 'valtio';
import {useEffect, useState} from 'react';
import {Text, View, Alert, ScrollView} from 'react-native';
import {Text, View, Alert, ScrollView, DevSettings} from 'react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
import Clipboard from '@react-native-clipboard/clipboard';
import {getVersion, getBuildNumber} from 'react-native-device-info';

import {eip155Wallets} from '@/utils/EIP155WalletUtil';
import {eip155Wallets, replaceMnemonic} from '@/utils/EIP155WalletUtil';
import SettingsStore from '@/store/SettingsStore';
import {Card} from '@/components/Card';
import {useTheme} from '@/hooks/useTheme';
Expand Down Expand Up @@ -34,6 +34,20 @@ export default function Settings({navigation}: Props) {
Alert.alert('Value copied to clipboard');
};

const onAddNewAccount = () => {
console.log('Add new account');
Alert.prompt('Enter mnemonic', '', text => {
replaceMnemonic(text)
.then(() => {
Alert.alert('Success', 'Mnemonic replaced, reloading the app...');
DevSettings.reload();
})
.catch(e => {
Alert.alert('Error', e.message);
});
});
};

return (
<ScrollView
style={[styles.container]}
Expand All @@ -53,6 +67,7 @@ export default function Settings({navigation}: Props) {
}
value={eip155Wallets[eip155Address].getMnemonic()}
/>
<Card title="Add new account" onPress={onAddNewAccount} />
</View>
<Text style={[styles.subtitle, {color: Theme['fg-100']}]}>Device</Text>
<View style={styles.sectionContainer}>
Expand Down
6 changes: 5 additions & 1 deletion wallets/rn_cli_wallet/src/utils/EIP155WalletUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,18 @@ export async function createOrRestoreEIP155Wallet() {
[address2]: wallet2,
};
eip155Addresses = Object.keys(eip155Wallets);
console.log('eip155Wallets:', eip155Wallets);

return {
eip155Wallets,
eip155Addresses,
};
}

export async function replaceMnemonic(mnemonic: string) {
const wallet = EIP155Lib.init({mnemonic});
await AsyncStorage.setItem('EIP155_MNEMONIC_1', wallet.getMnemonic());
}

export async function calculateEip155Gas(transaction: any, chainId: string) {
console.log('calculateEip155Gas:', chainId);
const chainData = PresetsUtil.getChainData(parseChainId(chainId));
Expand Down

0 comments on commit 90bf650

Please sign in to comment.