Commit 3c1b9305 authored by Marek Kotewicz's avatar Marek Kotewicz
Browse files

add account view

parent 1d3adc87
......@@ -7,6 +7,9 @@
"test": "jest"
},
"dependencies": {
"debounce": "^1.0.0",
"elliptic": "^6.3.2",
"js-sha3": "^0.5.7",
"react": "^15.4.2",
"react-native": "0.40.0",
"react-native-camera": "^0.5.1",
......
import { ec } from 'elliptic'
import { keccak_256 } from 'js-sha3'
var secp = new ec('secp256k1')
export function keypairFromPhrase(phrase) {
var seed = keccak_256.array(phrase);
var kp;
for (var i = 0; i <= 16384 || !toAddress(kp = secp.keyFromPrivate(seed)).startsWith('00'); ++i)
seed = keccak_256.array(seed)
return kp
}
export function toAddress(kp) { return keccak_256(kp.getPublic('buffer').slice(1)).substr(24); }
......@@ -31,7 +31,7 @@ export default class NewAccountInput extends Component {
this.props.onChangeText(text)
}}
value={this.state.text}
maxLength={100}
maxLength={240}
/>
)
}
......
export const ADD_ACCOUNT = 'ACCOUNT_ACTION_ADD_ACCOUNT'
......@@ -3,7 +3,7 @@ import { connect } from 'react-redux'
import AccountsList from '../components/AccountsList'
const Accounts = connect(state => ({
accounts: state.accounts
accounts: state.accounts.map(account => account.address)
}))(AccountsList)
export default Accounts
import React, { Component } from 'react'
import { View, Text, StyleSheet } from 'react-native'
import { View, Text, Button, StyleSheet } from 'react-native'
import debounce from 'debounce'
import NewAccountInput from '../components/NewAccountInput'
import { words } from '../actions/random'
import { keypairFromPhrase, toAddress } from '../actions/crypto'
//const addAccount = (dispatch) => {
//return {
//onAddAccount: (keypair) => {
//}
//}
//}
export default class NewAccount extends Component {
constructor(props) {
super(props)
const seed = words()
this.state = {
seed: seed,
keypair: keypairFromPhrase(seed),
}
}
render() {
var self = this;
return (
<View style={styles.view}>
<NewAccountInput seed={words()} onChangeText={() => {}}/>
<NewAccountInput seed={this.state.seed} onChangeText={
debounce((text) => self.setState({keypair: keypairFromPhrase(text)}), 100)
}/>
<Text>0x{toAddress(this.state.keypair)}</Text>
<Button
onPress={() => {}}
title="Add Account"
color="#841584"
accessibilityLabel="Press to add new account"
/>
</View>
)
}
......
const initialAccounts = [
'0xb794f5ea0ba39494ce839613fffba74279579268',
'0xe853c56864a2ebe4576a807d26fdc4a0ada51919',
'0x53d284357ec70ce289d6d64134dfac8e511c8a3d',
'0xd56d423cdc0e437babbdff79c4fa38904ff8d128'
]
import { ADD_ACCOUNT } from '../constants/AccountActions'
const initialAccounts = [{
address: '0xb794f5ea0ba39494ce839613fffba74279579268',
}, {
address: '0xe853c56864a2ebe4576a807d26fdc4a0ada51919',
}, {
address: '0x53d284357ec70ce289d6d64134dfac8e511c8a3d',
}, {
address: '0xd56d423cdc0e437babbdff79c4fa38904ff8d128'
}]
export default function accounts(state = initialAccounts, action) {
return state
switch (action.type) {
case ADD_ACCOUNT:
return [
...state,
{
address: action.address
}
]
default:
return state
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment