Skip to content

Commit

Permalink
Merge pull request #90 from polkawallet-io/develop0308
Browse files Browse the repository at this point in the history
referendums&proposals&andriod_balances&transfer
  • Loading branch information
0xthreebody authored Mar 8, 2019
2 parents 7a73ec3 + fb20b10 commit 76fd704
Show file tree
Hide file tree
Showing 14 changed files with 307 additions and 68 deletions.
63 changes: 63 additions & 0 deletions android/app/src/main/assets/tpl.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ios/Polkawallet/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.11</string>
<string>1.12</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
54 changes: 49 additions & 5 deletions src/code/Assets/Assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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)
}


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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()
}

Expand Down
76 changes: 69 additions & 7 deletions src/code/Assets/secondary/Create_Account.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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 {
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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;i<this.props.rootStore.stateStore.StakingOption.series[0].data.length;i++)
{
if(this.props.rootStore.stateStore.StakingOption.series[0].data[i]>max){
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<this.props.rootStore.stateStore.StakingOption.series[0].data.length;i++)
{
this.props.rootStore.stateStore.StakingOption.series[0].data[i]=(this.props.rootStore.stateStore.StakingOption.series[0].data[i]/Number(Math.pow(10,power))).toFixed(3)

}
this.props.rootStore.stateStore.StakingOption.title.text = 'Staking slash record, Unit ( '+unit+' )'
}
).catch()
})()

}
Save_Account(){
if(this.state.password==''||this.state.passwordErepeat == '')
{
Expand Down Expand Up @@ -225,6 +285,7 @@ export default class Polkawallet extends Component {
this.props.rootStore.stateStore.balanceIndex=(index)
}
})
this.unit()
this.props.navigation.navigate('Backup_Account',{key:this.state.key})

}else{
Expand All @@ -243,6 +304,7 @@ export default class Polkawallet extends Component {
this.props.rootStore.stateStore.balanceIndex=(index)
}
})
this.unit()
this.props.navigation.navigate('Backup_Account',{key:this.state.key,address:this.state.address})
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/code/Assets/secondary/Transfer/transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,16 @@ import {
{
if(this.state.address==''&&this.props.rootStore.stateStore.transfer_address==0&&this.props.rootStore.stateStore.iscamera==0){alert('Please enter address')}
else{
if(this.state.balance<this.state.value*this.state.multiple){
alert('Lack of balance')
}else{
this.props.rootStore.stateStore.value=new BN(this.state.value*this.state.multiple)
// if(this.state.balance<this.state.value*this.state.multiple){
// alert('Lack of balance')
// }else{
this.props.rootStore.stateStore.value=String(this.state.value*this.state.multiple)
this.props.rootStore.stateStore.inaddress=(this.props.rootStore.stateStore.isaddresses==0&&this.props.rootStore.stateStore.iscamera==0)?this.state.address:this.props.rootStore.stateStore.t_address
this.props.rootStore.stateStore.isaddresses=0
this.props.rootStore.stateStore.transfer_address=0
this.props.rootStore.stateStore.iscamera=0
this.props.navigation.navigate('Make_transfer')
}
// }
}
}
ChangeAddress(changeAddress){
Expand Down
54 changes: 54 additions & 0 deletions src/code/Assets/secondary/right_menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
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";

let ScreenWidth = Dimensions.get("screen").width;
let ScreenHeight = Dimensions.get("screen").height;
Expand All @@ -29,6 +31,7 @@ export default class New extends Component {
this.Create_Account=this.Create_Account.bind(this)
this.Switch_Account=this.Switch_Account.bind(this)
this.camera=this.camera.bind(this)
this.unit=this.unit.bind(this)

}
camera(){
Expand All @@ -45,6 +48,55 @@ export default class New extends Component {
})
this.props.p.navigation.navigate('Create_Account')
}
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;i<this.props.rootStore.stateStore.StakingOption.series[0].data.length;i++)
{
if(this.props.rootStore.stateStore.StakingOption.series[0].data[i]>max){
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<this.props.rootStore.stateStore.StakingOption.series[0].data.length;i++)
{
this.props.rootStore.stateStore.StakingOption.series[0].data[i]=(this.props.rootStore.stateStore.StakingOption.series[0].data[i]/Number(Math.pow(10,power))).toFixed(3)

}
this.props.rootStore.stateStore.StakingOption.title.text = 'Staking slash record, Unit ( '+unit+' )'
}
).catch()
})()
}
Switch_Account(){
// Query Balance
(async()=>{
Expand Down Expand Up @@ -143,6 +195,8 @@ export default class New extends Component {
this.props.rootStore.stateStore.transactions=JSON.parse(result._bodyInit)
}
).catch()

this.unit()
}
componentWillMount(){

Expand Down
Loading

0 comments on commit 76fd704

Please sign in to comment.