11import React from 'react' ;
22require ( 'semantic-ui-css/semantic.min.css' ) ;
3- const { generateMnemonic, mnemonicToSeed } = require ( 'bip39' )
3+ const { generateMnemonic } = require ( 'bip39' )
44import { Icon , List , Label , Header , Segment , Divider , Button } from 'semantic-ui-react' ;
55import { Bond , TransformBond } from 'oo7' ;
66import { ReactiveComponent , If , Rspan } from 'oo7-react' ;
7- import { calls , runtime , chain , system , runtimeUp , ss58Encode } from 'oo7-substrate' ;
7+ import { calls , runtime , chain , system , runtimeUp , ss58Encode , addressBook , secretStore } from 'oo7-substrate' ;
88import Identicon from 'polkadot-identicon' ;
99import { AccountIdBond , SignerBond } from './AccountIdBond.jsx' ;
1010import { BalanceBond } from './BalanceBond.jsx' ;
1111import { InputBond } from './InputBond.jsx' ;
1212import { TransactButton } from './TransactButton.jsx' ;
1313import { StakingStatusLabel } from './StakingStatusLabel' ;
1414import { WalletList } from './WalletList' ;
15+ import { AddressBookList } from './AddressBookList' ;
1516import { TransformBondButton } from './TransformBondButton' ;
1617import { Pretty } from './Pretty' ;
1718
@@ -21,6 +22,8 @@ export class App extends ReactiveComponent {
2122
2223 // For debug only.
2324 window . runtime = runtime ;
25+ window . secretStore = secretStore ;
26+ window . addressBook = addressBook ;
2427 window . chain = chain ;
2528 window . calls = calls ;
2629 window . that = this ;
@@ -30,10 +33,11 @@ export class App extends ReactiveComponent {
3033 this . destination = new Bond ;
3134 this . staker = new Bond ;
3235 this . nomination = new Bond ;
36+ this . nick = new Bond ;
37+ this . lookup = new Bond ;
3338 this . name = new Bond ;
3439 this . seed = new Bond ;
35- this . seed . trigger ( generateMnemonic ( ) )
36- this . seedAccount = this . seed . map ( secretStore ( ) . accountFromSeed )
40+ this . seedAccount = this . seed . map ( s => s ? secretStore ( ) . accountFromSeed ( s ) : undefined )
3741 this . seedAccount . use ( )
3842 }
3943
@@ -72,6 +76,7 @@ export class App extends ReactiveComponent {
7276 bond = { this . seed }
7377 reversible
7478 placeholder = 'Some seed for this key'
79+ validator = { n => n || null }
7580 action = { < Button content = "Another" onClick = { ( ) => this . seed . trigger ( generateMnemonic ( ) ) } /> }
7681 iconPosition = 'left'
7782 icon = { < i style = { { opacity : 1 } } className = 'icon' > < Identicon account = { this . seedAccount } size = { 28 } style = { { marginTop : '5px' } } /> </ i > }
@@ -95,6 +100,61 @@ export class App extends ReactiveComponent {
95100 </ div >
96101 </ Segment >
97102 < Divider hidden />
103+ < Segment style = { { margin : '1em' } } padded >
104+ < Header as = 'h2' >
105+ < Icon name = 'search' />
106+ < Header . Content >
107+ Inspect
108+ < Header . Subheader > Inspect the status of any account on the network</ Header . Subheader >
109+ </ Header . Content >
110+ </ Header >
111+ < div style = { { paddingBottom : '1em' } } >
112+ < div style = { { fontSize : 'small' } } > lookup account</ div >
113+ < AccountIdBond bond = { this . lookup } />
114+ < If condition = { this . lookup . ready ( ) } then = { < div >
115+ < Label > Balance
116+ < Label . Detail >
117+ < Pretty value = { runtime . balances . balance ( this . lookup ) } />
118+ </ Label . Detail >
119+ </ Label >
120+ < Label > Nonce
121+ < Label . Detail >
122+ < Pretty value = { runtime . system . accountNonce ( this . lookup ) } />
123+ </ Label . Detail >
124+ </ Label >
125+ < StakingStatusLabel id = { this . lookup } />
126+ < If condition = { runtime . balances . tryIndex ( this . lookup , null ) . map ( x => x !== null ) } then = {
127+ < Label > Short-form
128+ < Label . Detail >
129+ < Rspan > { runtime . balances . tryIndex ( this . lookup ) . map ( ss58Encode ) } </ Rspan >
130+ </ Label . Detail >
131+ </ Label >
132+ } />
133+ < Label > Address
134+ < Label . Detail >
135+ < Pretty value = { this . lookup } />
136+ </ Label . Detail >
137+ </ Label >
138+ </ div > } />
139+ </ div >
140+ < div style = { { paddingBottom : '1em' } } >
141+ < div style = { { fontSize : 'small' } } > name</ div >
142+ < InputBond
143+ bond = { this . nick }
144+ placeholder = 'A name for this address'
145+ validator = { n => { console . log ( n ) ; return n ? addressBook ( ) . map ( ss => ss . byName [ n ] ? null : n ) : null } }
146+ action = { < TransformBondButton
147+ content = 'Add'
148+ transform = { ( name , account ) => { addressBook ( ) . submit ( account , name ) ; return true } }
149+ args = { [ this . nick , this . lookup ] }
150+ /> }
151+ />
152+ </ div >
153+ < div style = { { paddingBottom : '1em' } } >
154+ < AddressBookList />
155+ </ div >
156+ </ Segment >
157+ < Divider hidden />
98158 < Segment style = { { margin : '1em' } } padded >
99159 < Header as = 'h2' >
100160 < Icon name = 'send' />
@@ -138,7 +198,6 @@ export class App extends ReactiveComponent {
138198 content = "Send"
139199 icon = 'send'
140200 tx = { {
141- longevity : true ,
142201 sender : runtime . balances . tryIndex ( this . source ) ,
143202 call : calls . balances . transfer ( runtime . balances . tryIndex ( this . destination ) , this . amount )
144203 } }
@@ -173,7 +232,7 @@ export class App extends ReactiveComponent {
173232
174233 < div style = { { paddingBottom : '1em' } } >
175234 < div style = { { fontSize : 'small' } } > nominated account</ div >
176- < SignerBond bond = { this . nomination } />
235+ < AccountIdBond bond = { this . nomination } />
177236 < If condition = { this . nomination . ready ( ) } then = { < span >
178237 < Label > Balance
179238 < Label . Detail >
@@ -225,10 +284,10 @@ export class App extends ReactiveComponent {
225284 icon = "thumbs down"
226285 tx = { {
227286 sender : runtime . balances . tryIndex ( this . staker ) ,
228- call : calls . staking . unnominate ( runtime . staking . nominationIndex ( this . nomination , this . staker ) )
287+ call : calls . staking . unnominate ( runtime . staking . nominationIndex ( this . staker ) )
229288 } }
230289 negative
231- enabled = { runtime . staking . nominationIndex ( this . nomination , this . staker ) . map ( i => i !== - 1 ) . default ( false ) }
290+ enabled = { runtime . staking . nominationIndex ( this . staker ) . map ( i => i !== - 1 ) . default ( false ) }
232291 />
233292 </ div >
234293 </ Segment >
0 commit comments