From 42c008f51aaa25fe7ca244352a121e872939872f Mon Sep 17 00:00:00 2001 From: StevenJNPearce Date: Thu, 11 Apr 2019 02:37:33 +0800 Subject: [PATCH] add option for 24 word mnemonic --- src/code/Assets/secondary/Create_Account.js | 50 +++++++++++++-------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/src/code/Assets/secondary/Create_Account.js b/src/code/Assets/secondary/Create_Account.js index c51f1625..694405cc 100644 --- a/src/code/Assets/secondary/Create_Account.js +++ b/src/code/Assets/secondary/Create_Account.js @@ -86,23 +86,30 @@ export default class Polkawallet extends Component { isModel:false, way:this.state.way_change, }) + let key; if(this.state.way_change == 'Keystore'){ this.setState({ key:'', address:'' }) + return; + }else if(this.state.way_change === 'Mnemonic'){ + key = mnemonicGenerate() + }else if(this.state.way_change === 'Mnemonic24'){ + key = mnemonicGenerate(24) + }else{ - let key = this.state.way_change=='Mnemonic'?mnemonicGenerate():u8aToHex(randomAsU8a()) - this.pair = keyring.addFromMnemonic(key) - this.setState({ - key:key, - address:this.pair.address() - }) + key = u8aToHex(randomAsU8a()) } + this.pair = keyring.addFromMnemonic(key) + this.setState({ + key:key, + address:this.pair.address() + }) } onChangekey(Changekey){ - if(this.state.way=='Mnemonic') + if(this.state.way=='Mnemonic' || 'Mnemonic24') { // alert('1') this.pair = keyring.addFromMnemonic(Changekey) @@ -181,21 +188,27 @@ export default class Polkawallet extends Component { } Reset(){ - if(this.state.way=='Keystore'){ + let key; + if(this.state.way == 'Keystore'){ this.setState({ key:'', address:'', - balance:0 + balance: 0 }) - + return; + }else if(this.state.way === 'Mnemonic'){ + key = mnemonicGenerate() + }else if(this.state.way === 'Mnemonic24'){ + key = mnemonicGenerate(24) + }else{ - let key = this.state.way=='Mnemonic'?mnemonicGenerate():u8aToHex(randomAsU8a()) - this.pair = keyring.addFromMnemonic(key) - this.setState({ - key:key, - address:this.pair.address() - }) + key = u8aToHex(randomAsU8a()) } + this.pair = keyring.addFromMnemonic(key) + this.setState({ + key:key, + address:this.pair.address() + }) } unit(){ (async()=>{ @@ -386,7 +399,7 @@ export default class Polkawallet extends Component { {/* 密钥 */} - create from mnemonic,seed or import keystore + Create from mnemonic,seed or import keystore {/* 选择方式 */} { @@ -649,7 +662,8 @@ export default class Polkawallet extends Component { onValueChange={(value) => this.setState({way_change: value})} androidmode = {'dropdown'} > - + +