Skip to content

Commit

Permalink
Merge pull request #30 from polkawallet-io/deve0221
Browse files Browse the repository at this point in the history
proposals&voting&referendums
  • Loading branch information
0xthreebody authored Feb 22, 2019
2 parents 976b08e + 1a1937f commit bc02218
Show file tree
Hide file tree
Showing 10 changed files with 473 additions and 42 deletions.
2 changes: 2 additions & 0 deletions App.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import Unnominate from './src/code/Staking/secondary/unnominate'
import Preferences from './src/code/Staking/secondary/preferences'
import Change_Password from './src/code/Profile/secondary/Change/Change_Password'
import Change_Name from './src/code/Profile/secondary/Change/Change_Name'
import NayorAye from './src/code/Democracy/secondary/NayorAye'



Expand Down Expand Up @@ -56,6 +57,7 @@ const Polkawallet_App = StackNavigator({
Preferences:{screen:Preferences,navigationOptions:{header:null}},
Change_Password:{screen:Change_Password,navigationOptions:{header:null}},
Change_Name:{screen:Change_Name,navigationOptions:{header:null}},
NayorAye:{screen:NayorAye,navigationOptions:{header:null}},

})

Expand Down
3 changes: 2 additions & 1 deletion src/code/Assetes/secondary/right_menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ export default class New extends Component {
this.props.rootStore.stateStore.isvalidators=1
}
})
if (nominating!=null&&String(nominating)!='5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUppTZ')
if (String(nominating)!=''&&String(nominating)!='5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUppTZ')
{
console.warn(String(nominating))
this.props.rootStore.stateStore.StakingState=3
}
if(this.props.rootStore.stateStore.StakingState!=2&&this.props.rootStore.stateStore.StakingState!=3){
Expand Down
13 changes: 10 additions & 3 deletions src/code/Democracy/Democracy.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default class IntegralMall extends Component {
referendumCount:'0',
referendumActive:0,
referendums:[],
proposalsNum:0
}
}
componentWillMount(){
Expand All @@ -47,6 +48,9 @@ export default class IntegralMall extends Component {
await api.query.democracy.referendumCount((result)=>{
this.props.rootStore.stateStore.referendumCount=JSON.stringify(result)
})
await api.query.democracy.publicProps((result)=>{
this.setState({proposalsNum:result.length})
})
//查询referendums中referendumActive
await api.derive.democracy.referendums((result)=>{
this.setState({
Expand Down Expand Up @@ -76,23 +80,26 @@ export default class IntegralMall extends Component {
</Text>
</TouchableOpacity>
<TouchableOpacity
style={{justifyContent:'center',alignItems:'center',height:ScreenHeight/20,width:ScreenWidth*0.49,borderWidth:1,borderColor:'#0076ff',borderTopRightRadius:8,borderBottomRightRadius:8,backgroundColor:this.state.Toptitle!=1?'#0076ff':'white'}}
style={{flexDirection:'row',justifyContent:'center',alignItems:'center',height:ScreenHeight/20,width:ScreenWidth*0.49,borderWidth:1,borderColor:'#0076ff',borderTopRightRadius:8,borderBottomRightRadius:8,backgroundColor:this.state.Toptitle!=1?'#0076ff':'white'}}
onPress={()=>{
this.setState({
Toptitle:2
})
}}
>
<Text style={{color:this.state.Toptitle!=1?'white':'#0076ff',fontSize:ScreenWidth/23.44,marginRight:ScreenWidth/28.85}}>
<Text style={{color:this.state.Toptitle!=1?'white':'#0076ff',fontSize:ScreenWidth/23.44}}>
{'proposals('+this.state.publicPropCount+')'}
</Text>
<Text style={{color:'#fd75a3',fontSize:ScreenWidth/23.44}}>
{"+"+this.state.proposalsNum}
</Text>
</TouchableOpacity>
</View>
{(this.state.Toptitle==1)
?
<ScrollView>
<View/>
<Referendums/>
<Referendums p={this.props}/>
</ScrollView>
:
<ScrollView>
Expand Down
86 changes: 73 additions & 13 deletions src/code/Democracy/proposals.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from 'react-native';
import Api from '@polkadot/api/promise';
import WsProvider from '@polkadot/rpc-provider/ws';
import { Method } from '@polkadot/types';

let ScreenWidth = Dimensions.get("screen").width;
let ScreenHeight = Dimensions.get("screen").height;
Expand All @@ -20,52 +21,111 @@ const Proposals=[
{name:'councilVoting.setCooloffPeriod',time:'30',number:51,depositors:'5rgjhfdkjgbfdkjvbcvbkdjvbdfghjsdffd',balance:19.999,Actives_Nofixed:[{key:'who:Address',value:'5rgjhfdkjgbfdkjvbcvbkdjvbdfghjsdffd'},{key:'free:Compact<Balance>',value:18000},{key:'reserved:Compact<Balance>',value:180000}]},
]
import { observer, inject } from "mobx-react";
import { async } from 'rxjs/internal/scheduler/async';
@inject('rootStore')
@observer
export default class Polkawallet extends Component {
constructor(props){
super(props)
this.state={
publicProps:[],
Actives_Nofixed:[],
Actives_Nofixedvalue:[],
Actives_Title:[],
votingCountdown:0,
launchCountdown:0,
Index:[],
votingState:[],
balances:[],
}
this.balances=this.balances.bind(this)
}
balances(){
(async()=>{
const api = await Api.create(new WsProvider(this.props.rootStore.stateStore.ENDPOINT));
launchPeriod = await api.query.democracy.launchPeriod()

await api.derive.chain.bestNumber((bestNumber)=>{
launchCountdown = launchPeriod - bestNumber.mod(launchPeriod).addn(1)
this.setState({launchCountdown:launchCountdown})
})
await api.query.democracy.publicProps((result)=>{
this.setState({publicProps:[],Actives_Nofixed:[],Actives_Nofixedvalue:[],Actives_Title:[],Index:[],balances:[]})
result.map((item,index)=>{
if (item) {
let {meta, method, section } = Method.findFunction(item[1].callIndex)
this.state.Actives_Title.push({section:section,method:method})
this.state.Actives_Nofixedvalue.push(item[1].args)
this.state.Actives_Nofixed.push(meta.arguments)
this.state.publicProps.push(item)
this.state.Index.push(item[0])
}
this.setState({})
})
})
for(i=0;i<this.state.Index.length;i++){
balance = await api.query.democracy.depositOf(this.state.Index[i])
this.state.balances.push(JSON.parse(balance)[0])
this.setState({})
}
})();
}
componentWillMount(){
(async()=>{
const api = await Api.create(new WsProvider(this.props.rootStore.stateStore.ENDPOINT));

launchPeriod = await api.query.democracy.launchPeriod()

await api.derive.chain.bestNumber((bestNumber)=>{
launchCountdown = launchPeriod - bestNumber.mod(launchPeriod).addn(1)
this.setState({launchCountdown:launchCountdown})
})
await api.query.democracy.publicProps((result)=>{

this.balances()
})
})();
}
render() {
return (
<View style={{flex:1}}>
{
Proposals.map((item,index)=>{
this.state.publicProps[0]==null
?
<View style={{marginTop:ScreenHeight/15,flex:1,justifyContent:'center',alignItems:'center'}}>
<Text style={{fontSize:ScreenWidth/25,color:'#696969'}}>no available proposals</Text>
</View>
:

this.state.publicProps.map((item,index)=>{
return(
<View style={{margin:ScreenWidth/150,borderWidth:1,borderColor:'#D3D3D3',borderRadius:ScreenWidth/100}} key={index}>
<View style={{borderRadius:ScreenHeight/200,height:ScreenHeight/30,flexDirection:'row',alignItems:'center'}}>
<Text style={{marginLeft:ScreenWidth/40,fontSize:ScreenWidth/30}}>{item.name}</Text>
<Text style={{marginLeft:ScreenWidth/40,fontSize:ScreenWidth/30}}>{this.state.Actives_Title[index].section+'.'+this.state.Actives_Title[index].method}</Text>
{/* 时间 */}
<Image
style={{marginLeft:ScreenWidth/40,height:ScreenHeight/50,width:ScreenHeight/50,resizeMode:'contain'}}
source={require('../../images/Democracy/time.png')}
/>
<Text style={{fontWeight:'500',marginLeft:ScreenWidth/80,color:'#90BD5B',fontSize:ScreenWidth/35}}>{item.time}</Text>
<Text style={{fontWeight:'500',marginLeft:ScreenWidth/80,color:'#90BD5B',fontSize:ScreenWidth/35}}>{this.state.launchCountdown}</Text>
<Text style={{fontWeight:'500',color:'#90BD5B',fontSize:ScreenWidth/40}}> {' blocks launch'}</Text>
<View style={{flex:1}}></View>
<Text style={{marginRight:ScreenWidth/70,fontSize:ScreenWidth/26}}>#{item.number}</Text>
<Text style={{marginRight:ScreenWidth/70,fontSize:ScreenWidth/26}}>{'#'+item[0]}</Text>
</View>
<View style={{width:ScreenWidth,flexDirection:'row'}}>
{/* 不确定个数 */}
<View style={{width:ScreenWidth/2-0.5}}>
{
item.Actives_Nofixed.map((itemNo,indexNo)=>{
{
this.state.Actives_Nofixed[index].map((itemNo,indexNo)=>{
return(
<View style={{marginLeft:ScreenWidth/30,marginTop:ScreenHeight/70}} key={indexNo}>
<Text style={{color:'#696969',fontSize:ScreenWidth/40}}>{itemNo.key}</Text>
<Text style={{color:'#696969',fontSize:ScreenWidth/30}}>{itemNo.name+' : '+itemNo.type}</Text>
<View style={{borderRadius:ScreenHeight/200,borderWidth:1,borderColor:'#C0C0C0',marginTop:ScreenHeight/100,justifyContent:'center',width:ScreenWidth/2.3,height:ScreenHeight/30,backgroundColor:'#DCDCDC',color:'#666666'}}>
<Text
style={{width:ScreenWidth/3.2,marginLeft:ScreenWidth/40,color:'#666666',fontSize:ScreenWidth/30}}
ellipsizeMode={"middle"}
numberOfLines={1}
>
{itemNo.value}
{String(this.state.Actives_Nofixedvalue[index][indexNo])}
</Text>
</View>
</View>
Expand All @@ -79,26 +139,26 @@ export default class Polkawallet extends Component {
{/* 确定个数 */}
<View style={{width:ScreenWidth/2-0.5}}>
<View style={{marginLeft:ScreenWidth/30,marginTop:ScreenHeight/70}}>
<Text style={{color:'#696969',fontSize:ScreenWidth/40}}>depositors</Text>
<Text style={{color:'#696969',fontSize:ScreenWidth/30}}>depositors</Text>
<View style={{borderRadius:ScreenHeight/200,borderWidth:1,borderColor:'#C0C0C0',marginTop:ScreenHeight/100,justifyContent:'center',width:ScreenWidth/2.3,height:ScreenHeight/30,backgroundColor:'#DCDCDC',color:'#666666'}}>
<Text
style={{width:ScreenWidth/3.2,marginLeft:ScreenWidth/40,color:'#666666',fontSize:ScreenWidth/30}}
ellipsizeMode={"middle"}
numberOfLines={1}
>
{item.depositors}
{String(item[2])}
</Text>
</View>
</View>
<View style={{marginLeft:ScreenWidth/30,marginTop:ScreenHeight/70}}>
<Text style={{color:'#696969',fontSize:ScreenWidth/40}}>balance</Text>
<Text style={{color:'#696969',fontSize:ScreenWidth/30}}>balance</Text>
<View style={{borderRadius:ScreenHeight/200,borderWidth:1,borderColor:'#C0C0C0',marginTop:ScreenHeight/100,justifyContent:'center',width:ScreenWidth/2.3,height:ScreenHeight/30,backgroundColor:'#DCDCDC',color:'#666666'}}>
<Text
style={{width:ScreenWidth/3.2,marginLeft:ScreenWidth/40,color:'#666666',fontSize:ScreenWidth/30}}
ellipsizeMode={"middle"}
numberOfLines={1}
>
{item.balance}
{String(this.state.balances[index])}
</Text>
</View>
</View>
Expand Down
2 changes: 1 addition & 1 deletion src/code/Democracy/referendums.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default class Polkawallet extends Component {
{
(this.state.title==1)
?
<Active/>
<Active p={this.props.p}/>
:
(this.state.title==2)
?
Expand Down
Loading

0 comments on commit bc02218

Please sign in to comment.