From fb20b10dcb39aa31151a22a4b4507f9c43394466 Mon Sep 17 00:00:00 2001 From: zx870076178 <870076178@qq.com> Date: Fri, 8 Mar 2019 17:52:41 +0800 Subject: [PATCH] referendums&proposals&andriod_balances&transfer --- android/app/src/main/assets/tpl.html | 63 ++++++++++++++ ios/Polkawallet/Info.plist | 2 +- package.json | 2 +- src/code/Assets/Assets.js | 54 ++++++++++-- src/code/Assets/secondary/Create_Account.js | 76 +++++++++++++++-- .../Assets/secondary/Transfer/transfer.js | 10 +-- src/code/Assets/secondary/right_menu.js | 54 ++++++++++++ src/code/Democracy/referendums/Active.js | 83 +++++++++++-------- src/code/Democracy/secondary/NayorAye.js | 16 ++-- src/code/Profile/secondary/About.js | 2 +- src/code/Profile/secondary/Settings.js | 4 +- .../Profile/secondary/Settings/Gesture.js | 1 + src/code/Staking/Staking.js | 6 +- src/code/Staking/secondary/unnominate.js | 2 +- 14 files changed, 307 insertions(+), 68 deletions(-) create mode 100644 android/app/src/main/assets/tpl.html diff --git a/android/app/src/main/assets/tpl.html b/android/app/src/main/assets/tpl.html new file mode 100644 index 00000000..ca20a315 --- /dev/null +++ b/android/app/src/main/assets/tpl.html @@ -0,0 +1,63 @@ + + + + + echarts + + + + + + + +
+ + diff --git a/ios/Polkawallet/Info.plist b/ios/Polkawallet/Info.plist index 817d265c..e80b190e 100644 --- a/ios/Polkawallet/Info.plist +++ b/ios/Polkawallet/Info.plist @@ -21,7 +21,7 @@ CFBundleSignature ???? CFBundleVersion - 1.11 + 1.12 LSRequiresIPhoneOS NSAppTransportSecurity diff --git a/package.json b/package.json index 573e9bc8..63f17ca3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "Polkawallet", - "version": "0.1.0", + "version": "0.1.1", "private": true, "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start", diff --git a/src/code/Assets/Assets.js b/src/code/Assets/Assets.js index 317876b2..9d39c310 100644 --- a/src/code/Assets/Assets.js +++ b/src/code/Assets/Assets.js @@ -10,7 +10,9 @@ import { TouchableOpacity, RefreshControl, SafeAreaView, - StatusBar + StatusBar, + AsyncStorage, + AppState } from 'react-native'; import Identicon from 'polkadot-identicon-react-native'; import moment from "moment/moment"; @@ -46,6 +48,7 @@ export default class Assets extends Component { this.Coin_details=this.Coin_details.bind(this) this.refresh=this.refresh.bind(this) this.Loading=this.Loading.bind(this) + this.handleAppStateChange=this.handleAppStateChange.bind(this) } @@ -111,11 +114,28 @@ export default class Assets extends Component { this.props.rootStore.stateStore.Accounts=[{account:'NeedCreate',address:'xxxxxxxxxxxxxxxxxxxxxxxxxxx'}] this.props.rootStore.stateStore.balances=[{address:'xxxxxxxxxxxxxxxxxxxxxxxxxxx',balance:0}] if (Platform.OS === 'android') { + //android //android for(var o in result){ this.props.rootStore.stateStore.Accounts.push({account:JSON.parse(result[o]).meta.name,address:JSON.parse(result[o]).address}) this.props.rootStore.stateStore.Account++ this.props.rootStore.stateStore.Accountnum++ + //创建查询每个账户的进程 + (async()=>{ + let _address = o + const api = await Api.create(new WsProvider(this.props.rootStore.stateStore.ENDPOINT)); + await api.query.balances.freeBalance(_address,(balance)=>{ + this.props.rootStore.stateStore.have=0 + this.props.rootStore.stateStore.balances.map((item,index)=>{ + if(item.address!=_address){}else{ + this.props.rootStore.stateStore.have=1 + this.props.rootStore.stateStore.balances[index].balance=balance + } + }) + if(this.props.rootStore.stateStore.have==0){ + this.props.rootStore.stateStore.balances.push({address:_address,balance:balance})} + }) + })() } }else{ //ios @@ -161,6 +181,7 @@ export default class Assets extends Component { this.props.rootStore.stateStore.balances.map((item,index)=>{ if(item.address == this.props.rootStore.stateStore.Accounts[this.props.rootStore.stateStore.Account].address){ this.props.rootStore.stateStore.balanceIndex=(index) + } }) // balance = await api.query.balances.freeBalance(this.props.rootStore.stateStore.Accounts[this.props.rootStore.stateStore.Account].address); @@ -214,13 +235,10 @@ export default class Assets extends Component { myDate=new Date() blockdate = await api.query.timestamp.now() lastBlockTime=Number(myDate)-Number(blockdate) - // console.warn(blockdate) if(lastBlockTime>120000){ a=192,b=192,c=192 - }else if(lastBlockTime<6000){ - a=0;b=255;c=0; }else{ - colorPara = (lastBlockTime / 1000 - 6) * (255 / 60) + colorPara = (lastBlockTime / 1000) * (255 / 18) a=0; b=255; c=0; @@ -313,7 +331,33 @@ export default class Assets extends Component { },2000) } + handleAppStateChange(appState){ + if(appState=='background'&&this.props.rootStore.stateStore.GestureState==2){ + this.props.navigation.navigate('Gesture') + } + } componentWillMount(){ + setInterval(()=>{ + this.props.rootStore.stateStore.balances.map((item,index)=>{ + if(item.address == this.props.rootStore.stateStore.Accounts[this.props.rootStore.stateStore.Account].address){ + this.props.rootStore.stateStore.balanceIndex=(index) + } + }) + // alert(this.props.rootStore.stateStore.balances[this.props.rootStore.stateStore.balanceIndex].address) + },5000) + AppState.addEventListener('change', this.handleAppStateChange) + AsyncStorage.getItem('Gesture').then( + (result)=>{ + if(result==null){ + this.props.rootStore.stateStore.GestureState=0 + }else{ + this.props.rootStore.stateStore.GestureState=2 + this.props.navigation.navigate('Gesture') + } + this.props.rootStore.stateStore.Gesture=result + } + ) + this.Loading() } diff --git a/src/code/Assets/secondary/Create_Account.js b/src/code/Assets/secondary/Create_Account.js index e87e13c7..471a8d59 100644 --- a/src/code/Assets/secondary/Create_Account.js +++ b/src/code/Assets/secondary/Create_Account.js @@ -18,6 +18,7 @@ import Identicon from 'polkadot-identicon-react-native'; import Api from '@polkadot/api/promise'; import WsProvider from '@polkadot/rpc-provider/ws'; import formatBalance from '../../../util/formatBalance' +import moment from "moment/moment"; import SInfo from 'react-native-sensitive-info'; import Keyring from '@polkadot/keyring' @@ -30,6 +31,7 @@ let ScreenWidth = Dimensions.get("screen").width; let ScreenHeight = Dimensions.get("screen").height; let Platform = require('Platform'); import { observer, inject } from "mobx-react"; +import { async } from 'rxjs/internal/scheduler/async'; @inject('rootStore') @observer export default class Polkawallet extends Component { @@ -61,15 +63,23 @@ export default class Polkawallet extends Component { this.Modify_way=this.Modify_way.bind(this) this.Reset=this.Reset.bind(this) this.onChangpasswordErepeat = this.onChangpasswordErepeat.bind(this) + this.unit=this.unit.bind(this) } componentWillMount(){ - let key = mnemonicGenerate() - this.pair = keyring.addFromMnemonic(key) - this.setState({ - key:key, - address:this.pair.address() - }) - + (async()=>{ + let key = mnemonicGenerate() + this.pair = keyring.addFromMnemonic(key) + this.setState({ + key:key, + address:this.pair.address() + }) + const api = await Api.create(new WsProvider(this.props.rootStore.stateStore.ENDPOINT)); + const props = await api.rpc.system.properties(); + formatBalance.setDefaults({ + decimals: props.get('tokenDecimals'), + unit: props.get('tokenSymbol') + }); + })() } Modify_way(){ this.setState({ @@ -187,6 +197,56 @@ export default class Polkawallet extends Component { }) } } + unit(){ + (async()=>{ + const api = await Api.create(new WsProvider(this.props.rootStore.stateStore.ENDPOINT)); + const props = await api.rpc.system.properties(); + formatBalance.setDefaults({ + decimals: props.get('tokenDecimals'), + unit: props.get('tokenSymbol') + }); + //获取本地账户staking折线图数据 + REQUEST_URL ='http://107.173.250.124:8080/staking_chart_alexander' + map = { + method:'POST' + } + privateHeaders = { + 'Content-Type':'application/json' + } + map.headers = privateHeaders; + map.follow = 20; + map.timeout = 0; + map.body = '{"user_address":"'+this.props.rootStore.stateStore.Accounts[this.props.rootStore.stateStore.Account].address+'","UTCdate":"'+moment((new Date()).getTime()).format('YYYY-MM-DD HH:mm:ss')+'"}'; + // map.body = '{"user_address":"'+'5Enp67VYwLviZWuyf2XfM5mJXgTWHaa45podYXhUhDCUeQUM'+'","UTCdate":"'+moment((new Date()).getTime()).format('YYYY-MM-DD HH:mm:ss')+'"}'; + fetch(REQUEST_URL,map).then( + (result)=>{ + this.props.rootStore.stateStore.StakingOption.xAxis.data=[] + this.props.rootStore.stateStore.StakingOption.series[0].data=[] + JSON.parse(result._bodyInit).map((item,index)=>{ + this.props.rootStore.stateStore.StakingOption.xAxis.data.push(item.time.substring(5,7)+'/'+item.time.substring(8,10)) + this.props.rootStore.stateStore.StakingOption.series[0].data.push(item.slash_balance) + }) + max=0 + for(i=0;imax){ + max=this.props.rootStore.stateStore.StakingOption.series[0].data[i] + } + } + power = formatBalance.calcSi(String(max),formatBalance.getDefaults().decimals).power+formatBalance.getDefaults().decimals + unit = formatBalance.calcSi(String(max),formatBalance.getDefaults().decimals).text + + for(i=0;i{ + const api = await Api.create(new WsProvider(this.props.rootStore.stateStore.ENDPOINT)); + const props = await api.rpc.system.properties(); + formatBalance.setDefaults({ + decimals: props.get('tokenDecimals'), + unit: props.get('tokenSymbol') + }); + //获取本地账户staking折线图数据 + REQUEST_URL ='http://107.173.250.124:8080/staking_chart_alexander' + map = { + method:'POST' + } + privateHeaders = { + 'Content-Type':'application/json' + } + map.headers = privateHeaders; + map.follow = 20; + map.timeout = 0; + map.body = '{"user_address":"'+this.props.rootStore.stateStore.Accounts[this.props.rootStore.stateStore.Account].address+'","UTCdate":"'+moment((new Date()).getTime()).format('YYYY-MM-DD HH:mm:ss')+'"}'; + // map.body = '{"user_address":"'+'5Enp67VYwLviZWuyf2XfM5mJXgTWHaa45podYXhUhDCUeQUM'+'","UTCdate":"'+moment((new Date()).getTime()).format('YYYY-MM-DD HH:mm:ss')+'"}'; + fetch(REQUEST_URL,map).then( + (result)=>{ + this.props.rootStore.stateStore.StakingOption.xAxis.data=[] + this.props.rootStore.stateStore.StakingOption.series[0].data=[] + JSON.parse(result._bodyInit).map((item,index)=>{ + this.props.rootStore.stateStore.StakingOption.xAxis.data.push(item.time.substring(5,7)+'/'+item.time.substring(8,10)) + this.props.rootStore.stateStore.StakingOption.series[0].data.push(item.slash_balance) + }) + max=0 + for(i=0;imax){ + max=this.props.rootStore.stateStore.StakingOption.series[0].data[i] + } + } + power = formatBalance.calcSi(String(max),formatBalance.getDefaults().decimals).power+formatBalance.getDefaults().decimals + unit = formatBalance.calcSi(String(max),formatBalance.getDefaults().decimals).text + + for(i=0;i{ @@ -143,6 +195,8 @@ export default class New extends Component { this.props.rootStore.stateStore.transactions=JSON.parse(result._bodyInit) } ).catch() + + this.unit() } componentWillMount(){ diff --git a/src/code/Democracy/referendums/Active.js b/src/code/Democracy/referendums/Active.js index 2a88a911..85c398ee 100644 --- a/src/code/Democracy/referendums/Active.js +++ b/src/code/Democracy/referendums/Active.js @@ -41,6 +41,8 @@ export default class Polkawallet extends Component { this.votingState=this.votingState.bind(this) this.Nay=this.Nay.bind(this) this.Aye=this.Aye.bind(this) + this.NayNumber=this.NayNumber.bind(this) + this.AyeNumber=this.AyeNumber.bind(this) } Nay(votingState){ let balance = 0 @@ -51,6 +53,15 @@ export default class Polkawallet extends Component { } return balance } + NayNumber(votingState){ + let NayNumber = 0 + for(i=0;i{ this.state.votingState = [] @@ -151,26 +171,11 @@ export default class Polkawallet extends Component { this.state.votingState[i].msg = result } } - // alert(JSON.stringify(this.state.votingState)) this.setState({}) }) - // alert(JSON.stringify(this.state.votingState)) })() - - // this.votingState() }) - // alert(JSON.stringify(this.state.votingState)) }) - // console.warn(this.state.votingIndex) - // for(i=0;i{ - // alert(typeof(this.state.votingIndex[i])) - // console.warn(result) - // this.state.votingState.push(result); - // this.setState({}) - // }) - // } - // console.warn(this.state.votingState) })() } @@ -216,25 +221,35 @@ export default class Polkawallet extends Component { }) } {/* threshold */} - - {'Threshold: '+item.threshold} - - - - {'Aye '+formatBalance(this.Aye(this.state.votingState[index]))} - {(this.Aye(this.state.votingState[index])/(this.Aye(this.state.votingState[index])+this.Nay(this.state.votingState[index]))*100).toFixed(2)+'%'} - {'('+item.aye+')'} - - {'Nay '+formatBalance(this.Nay(this.state.votingState[index]))} - {(this.Nay(this.state.votingState[index])/(this.Aye(this.state.votingState[index])+this.Nay(this.state.votingState[index]))*100).toFixed(2)+'%'} - {'('+item.nay+')'} - + + { + (this.Aye(this.state.votingState[index])==0) + ? + + : + + + {'Threshold: '+item.threshold} + + + + {'Aye '+formatBalance(this.Aye(this.state.votingState[index]))} + {(this.Aye(this.state.votingState[index])/(this.Aye(this.state.votingState[index])+this.Nay(this.state.votingState[index]))*100).toFixed(2)+'%'} + {'('+this.AyeNumber(this.state.votingState[index])+')'} + + {'Nay '+formatBalance(this.Nay(this.state.votingState[index]))} + {(this.Nay(this.state.votingState[index])/(this.Aye(this.state.votingState[index])+this.Nay(this.state.votingState[index]))*100).toFixed(2)+'%'} + {'('+this.NayNumber(this.state.votingState[index])+')'} + + + } + - - + + @@ -182,7 +182,7 @@ import { {this.state.onlyone==0? @@ -192,7 +192,7 @@ import { : @@ -205,6 +205,7 @@ import { or + - Version: 0.1.0 + Version: 0.1.1 ); diff --git a/src/code/Profile/secondary/Settings.js b/src/code/Profile/secondary/Settings.js index aae63019..9d6d809e 100644 --- a/src/code/Profile/secondary/Settings.js +++ b/src/code/Profile/secondary/Settings.js @@ -112,7 +112,7 @@ export default class New extends Component { } {/* Gesture */} - {/* Gesture @@ -121,7 +121,7 @@ export default class New extends Component { value={this.state.Gesture}//默认状态 onValueChange={(e) => this.Gesture(e)} //当状态值发生变化值回调 /> - */} + {/* Fingerprint */} {/* diff --git a/src/code/Profile/secondary/Settings/Gesture.js b/src/code/Profile/secondary/Settings/Gesture.js index 077a3713..ad73b107 100644 --- a/src/code/Profile/secondary/Settings/Gesture.js +++ b/src/code/Profile/secondary/Settings/Gesture.js @@ -59,6 +59,7 @@ export default class Gesture_Test1 extends Component{ status: 'right', message: 'Password is correct.' }); + setTimeout(()=>{this.props.navigation.navigate('Tabbed_Navigation')},500) }else{ this.setState({ status: 'wrong', diff --git a/src/code/Staking/Staking.js b/src/code/Staking/Staking.js index 06875300..211fbe42 100644 --- a/src/code/Staking/Staking.js +++ b/src/code/Staking/Staking.js @@ -97,7 +97,6 @@ export default class IntegralMall extends Component { loding(){ (async()=>{ const api = await Api.create(new WsProvider(this.props.rootStore.stateStore.ENDPOINT)); - //查询all [validatorCount,sessionLength,eraLength] = await Promise.all([ api.query.staking.validatorCount(), @@ -136,8 +135,6 @@ export default class IntegralMall extends Component { } sumnominatorsBalance.push(sum) } - - //查询Staking状态 this.state.intentions.filter((address) =>{ if(this.props.rootStore.stateStore.Accounts[this.props.rootStore.stateStore.Account].address.includes(address)){ @@ -208,7 +205,6 @@ export default class IntegralMall extends Component { this.props.rootStore.stateStore.StakingState=1 } },1000) - //实时监控 setInterval(async()=>{ @@ -299,7 +295,7 @@ export default class IntegralMall extends Component { sumnominatorsBalance2: sumnominatorsBalance2 }) } - },30000) + },5000) // 找出Next up _intentions=[] diff --git a/src/code/Staking/secondary/unnominate.js b/src/code/Staking/secondary/unnominate.js index 1ec721ae..1fea2d4c 100644 --- a/src/code/Staking/secondary/unnominate.js +++ b/src/code/Staking/secondary/unnominate.js @@ -108,7 +108,7 @@ import { set } from 'mobx'; 'Nominate success', [ {text: 'OK', onPress: () => { - this.props.rootStore.stateStore.StakingState=1 + this.props.rootStore.stateStore.StakingState=0 this.setState({ isModal:false })