Skip to content

Commit 5b0b16f

Browse files
committed
add comment lines to explain funnctions
1 parent d8acd34 commit 5b0b16f

File tree

8 files changed

+53
-27
lines changed

8 files changed

+53
-27
lines changed

App.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ export default class App extends Component {
2323
this.checkWallet();
2424
}
2525

26+
/**
27+
* @method to check wallet in Localstorage
28+
*/
2629
async checkWallet() {
2730
try {
2831
const value = await AsyncStorage.getItem('account');

src/containers/Browser/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import React, { Component } from 'react';
22
import { View, Text, SafeAreaView } from 'react-native';
33

4-
class SendETH extends Component {
4+
/**
5+
* @class DAppBrowser
6+
*/
7+
class DAppBrowser extends Component {
58
constructor(props) {
69
super(props);
710
this.state = {
@@ -17,4 +20,4 @@ class SendETH extends Component {
1720
}
1821
}
1922

20-
export default SendETH;
23+
export default DAppBrowser;

src/containers/CreateWallet/index.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/containers/ETHWallet/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import React, { Component } from 'react';
22
import { View, Text, SafeAreaView, AsyncStorage } from 'react-native';
33
import QRCode from 'react-native-qrcode-svg';
44

5+
/**
6+
* @class ETH Wallet
7+
*/
58
class ETHWallet extends Component {
69
constructor(props) {
710
super(props);
@@ -12,6 +15,9 @@ class ETHWallet extends Component {
1215
};
1316
}
1417

18+
/**
19+
* @method to get wallet from localstorage
20+
*/
1521
async componentDidMount() {
1622
let wallet = await AsyncStorage.getItem('account');
1723
wallet = JSON.parse(wallet);

src/containers/Home/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ class Home extends Component {
4848
this.checkWallet();
4949
}
5050

51+
/**
52+
* @method to check wallet in localstorage
53+
*/
5154
async checkWallet() {
5255
try {
5356
const value = await AsyncStorage.getItem('account');
@@ -63,6 +66,9 @@ class Home extends Component {
6366
}
6467
}
6568

69+
/**
70+
* @method to fetch balance of wallet
71+
*/
6672
async getETHBalance() {
6773
let balance = await web3.eth.getBalance(this.state.account.address);
6874
balance = web3.utils.fromWei(balance, 'ether');

src/containers/SendETH/index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ class SendEther extends Component {
4444
this.checkWallet();
4545
}
4646

47+
/**
48+
* @method to check wallet in localstorage
49+
*/
4750
async checkWallet() {
4851
try {
4952
const value = await AsyncStorage.getItem('account');
@@ -59,6 +62,9 @@ class SendEther extends Component {
5962
}
6063
}
6164

65+
/**
66+
* @method to fetch balance of wallet
67+
*/
6268
async getETHBalance() {
6369
let balance = await web3.eth.getBalance(this.state.account.address);
6470
balance = web3.utils.fromWei(balance, 'ether');
@@ -67,8 +73,12 @@ class SendEther extends Component {
6773
await this.setState({ ETHBalance: Number(balance).toFixed(3) });
6874
}
6975

76+
/**
77+
* @method to transfer Ether
78+
*/
7079
async transferEther() {
7180
await this.setState({ dialogVisible: false })
81+
// ETH address validation
7282
if (this.state.receiver === undefined || this.state.receiver.length !== 42 || web3.utils.isAddress(this.state.receiver) === false ) {
7383
Alert.alert(
7484
'Wrong Ethereum Address!',
@@ -100,6 +110,7 @@ class SendEther extends Component {
100110
};
101111

102112
let tx = new EthereumTx(rawTransaction);
113+
// sign transaction with private key
103114
tx.sign(privateKey);
104115
let serializedTx = tx.serialize();
105116

@@ -111,6 +122,7 @@ class SendEther extends Component {
111122
]
112123
);
113124

125+
// Send signed transaction to Ethereum blockchain
114126
web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex')).then(result => {
115127
console.log(result);
116128

@@ -122,7 +134,6 @@ class SendEther extends Component {
122134
]
123135
);
124136
}).catch(error => {
125-
console.log(typeof error);
126137
console.log(error);
127138
this.setState({ error, receiver: undefined });
128139

src/containers/Settings/index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,23 @@ class Settings extends Component {
1212
super(props);
1313
this.state = {
1414
};
15-
this.showWallet = this.showWallet.bind(this);
15+
this.copyToClipboard = this.copyToClipboard.bind(this);
1616
this.deleteWallet = this.deleteWallet.bind(this);
1717
}
1818

19-
async showWallet() {
19+
/**
20+
* @method to export the private key by copying it to Clipboard
21+
*/
22+
async copyToClipboard() {
2023
let wallet = await AsyncStorage.getItem('account');
2124
wallet = JSON.parse(wallet);
2225
Clipboard.setString(wallet.privateKey);
2326
alert('Your private key is copied to the clipboard.');
2427
}
2528

29+
/**
30+
* @method to delete whole information(includes wallet)
31+
*/
2632
async deleteWallet() {
2733
await AsyncStorage.removeItem('account');
2834
const resetAction = StackActions.reset({
@@ -35,7 +41,7 @@ class Settings extends Component {
3541
render() {
3642
return (
3743
<View style={styles.container}>
38-
<TouchableOpacity style={{ width: '100%', alignSelf: 'center' }} onPress={() => { this.showWallet() }}>
44+
<TouchableOpacity style={{ width: '100%', alignSelf: 'center' }} onPress={() => { this.copyToClipboard() }}>
3945
<Card.Body style={styles.card}>
4046
<View style={{ paddingVertical: 20 }} >
4147
<Text style={{ color: '#fff', fontSize: 20, textAlign: 'center', fontWeight: 'bold' }}> Backup Wallet </Text>

src/containers/Welcome/index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,21 @@ class Welcome extends Component {
2727

2828
componentDidMount() {
2929
console.log(this.props);
30-
//AsyncStorage.clear();
3130
}
3231

32+
/**
33+
* @method to create new Ethereum wallet
34+
*/
3335
createWallet = async () => {
3436
const account = await web3.eth.accounts.create();
3537
console.log(account);
3638
await this.setState({ account });
3739
this.storeData();
3840
}
3941

42+
/**
43+
* @method to store wallet info in localstorage
44+
*/
4045
storeData = async () => {
4146
try {
4247
await AsyncStorage.setItem('account', JSON.stringify(this.state.account));
@@ -47,6 +52,9 @@ class Welcome extends Component {
4752
}
4853
};
4954

55+
/**
56+
* @method to retrieve wallet info from localstorage
57+
*/
5058
async retrieveData() {
5159
try {
5260
const value = await AsyncStorage.getItem('account');
@@ -56,6 +64,9 @@ class Welcome extends Component {
5664
}
5765
};
5866

67+
/**
68+
* @method to restore Ethereum wallet from private key
69+
*/
5970
async restoreWallet() {
6071
console.log(this.state);
6172

0 commit comments

Comments
 (0)