Skip to content

Commit

Permalink
add comment lines to explain funnctions
Browse files Browse the repository at this point in the history
  • Loading branch information
hsyndeniz committed Apr 13, 2019
1 parent d8acd34 commit 5b0b16f
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 27 deletions.
3 changes: 3 additions & 0 deletions App.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export default class App extends Component {
this.checkWallet();
}

/**
* @method to check wallet in Localstorage
*/
async checkWallet() {
try {
const value = await AsyncStorage.getItem('account');
Expand Down
7 changes: 5 additions & 2 deletions src/containers/Browser/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import React, { Component } from 'react';
import { View, Text, SafeAreaView } from 'react-native';

class SendETH extends Component {
/**
* @class DAppBrowser
*/
class DAppBrowser extends Component {
constructor(props) {
super(props);
this.state = {
Expand All @@ -17,4 +20,4 @@ class SendETH extends Component {
}
}

export default SendETH;
export default DAppBrowser;
20 changes: 0 additions & 20 deletions src/containers/CreateWallet/index.js

This file was deleted.

6 changes: 6 additions & 0 deletions src/containers/ETHWallet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import React, { Component } from 'react';
import { View, Text, SafeAreaView, AsyncStorage } from 'react-native';
import QRCode from 'react-native-qrcode-svg';

/**
* @class ETH Wallet
*/
class ETHWallet extends Component {
constructor(props) {
super(props);
Expand All @@ -12,6 +15,9 @@ class ETHWallet extends Component {
};
}

/**
* @method to get wallet from localstorage
*/
async componentDidMount() {
let wallet = await AsyncStorage.getItem('account');
wallet = JSON.parse(wallet);
Expand Down
6 changes: 6 additions & 0 deletions src/containers/Home/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class Home extends Component {
this.checkWallet();
}

/**
* @method to check wallet in localstorage
*/
async checkWallet() {
try {
const value = await AsyncStorage.getItem('account');
Expand All @@ -63,6 +66,9 @@ class Home extends Component {
}
}

/**
* @method to fetch balance of wallet
*/
async getETHBalance() {
let balance = await web3.eth.getBalance(this.state.account.address);
balance = web3.utils.fromWei(balance, 'ether');
Expand Down
13 changes: 12 additions & 1 deletion src/containers/SendETH/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class SendEther extends Component {
this.checkWallet();
}

/**
* @method to check wallet in localstorage
*/
async checkWallet() {
try {
const value = await AsyncStorage.getItem('account');
Expand All @@ -59,6 +62,9 @@ class SendEther extends Component {
}
}

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

/**
* @method to transfer Ether
*/
async transferEther() {
await this.setState({ dialogVisible: false })
// ETH address validation
if (this.state.receiver === undefined || this.state.receiver.length !== 42 || web3.utils.isAddress(this.state.receiver) === false ) {
Alert.alert(
'Wrong Ethereum Address!',
Expand Down Expand Up @@ -100,6 +110,7 @@ class SendEther extends Component {
};

let tx = new EthereumTx(rawTransaction);
// sign transaction with private key
tx.sign(privateKey);
let serializedTx = tx.serialize();

Expand All @@ -111,6 +122,7 @@ class SendEther extends Component {
]
);

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

Expand All @@ -122,7 +134,6 @@ class SendEther extends Component {
]
);
}).catch(error => {
console.log(typeof error);
console.log(error);
this.setState({ error, receiver: undefined });

Expand Down
12 changes: 9 additions & 3 deletions src/containers/Settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,23 @@ class Settings extends Component {
super(props);
this.state = {
};
this.showWallet = this.showWallet.bind(this);
this.copyToClipboard = this.copyToClipboard.bind(this);
this.deleteWallet = this.deleteWallet.bind(this);
}

async showWallet() {
/**
* @method to export the private key by copying it to Clipboard
*/
async copyToClipboard() {
let wallet = await AsyncStorage.getItem('account');
wallet = JSON.parse(wallet);
Clipboard.setString(wallet.privateKey);
alert('Your private key is copied to the clipboard.');
}

/**
* @method to delete whole information(includes wallet)
*/
async deleteWallet() {
await AsyncStorage.removeItem('account');
const resetAction = StackActions.reset({
Expand All @@ -35,7 +41,7 @@ class Settings extends Component {
render() {
return (
<View style={styles.container}>
<TouchableOpacity style={{ width: '100%', alignSelf: 'center' }} onPress={() => { this.showWallet() }}>
<TouchableOpacity style={{ width: '100%', alignSelf: 'center' }} onPress={() => { this.copyToClipboard() }}>
<Card.Body style={styles.card}>
<View style={{ paddingVertical: 20 }} >
<Text style={{ color: '#fff', fontSize: 20, textAlign: 'center', fontWeight: 'bold' }}> Backup Wallet </Text>
Expand Down
13 changes: 12 additions & 1 deletion src/containers/Welcome/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,21 @@ class Welcome extends Component {

componentDidMount() {
console.log(this.props);
//AsyncStorage.clear();
}

/**
* @method to create new Ethereum wallet
*/
createWallet = async () => {
const account = await web3.eth.accounts.create();
console.log(account);
await this.setState({ account });
this.storeData();
}

/**
* @method to store wallet info in localstorage
*/
storeData = async () => {
try {
await AsyncStorage.setItem('account', JSON.stringify(this.state.account));
Expand All @@ -47,6 +52,9 @@ class Welcome extends Component {
}
};

/**
* @method to retrieve wallet info from localstorage
*/
async retrieveData() {
try {
const value = await AsyncStorage.getItem('account');
Expand All @@ -56,6 +64,9 @@ class Welcome extends Component {
}
};

/**
* @method to restore Ethereum wallet from private key
*/
async restoreWallet() {
console.log(this.state);

Expand Down

0 comments on commit 5b0b16f

Please sign in to comment.