mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-11-22 23:28:56 +03:00
transfer tokens, profile view
This commit is contained in:
parent
16608cab1f
commit
3c6c2c5ceb
@ -29,12 +29,43 @@ export const getAccount = user => {
|
||||
export const getUser = async user => {
|
||||
try {
|
||||
let account = await client.database.getAccounts([user]);
|
||||
// get global properties to calculate Steem Power
|
||||
let global_properties = await client.database.getDynamicGlobalProperties();
|
||||
|
||||
// calculate Steem Power (own, received, delegated)
|
||||
account[0].steem_power = vestToSteem(
|
||||
account[0].vesting_shares,
|
||||
global_properties.total_vesting_shares,
|
||||
global_properties.total_vesting_fund_steem
|
||||
).toFixed(0);
|
||||
account[0].received_steem_power = vestToSteem(
|
||||
account[0].received_vesting_shares,
|
||||
global_properties.total_vesting_shares,
|
||||
global_properties.total_vesting_fund_steem
|
||||
).toFixed(0);
|
||||
account[0].delegated_steem_power = vestToSteem(
|
||||
account[0].delegated_vesting_shares,
|
||||
global_properties.total_vesting_shares,
|
||||
global_properties.total_vesting_fund_steem
|
||||
).toFixed(0);
|
||||
|
||||
return account[0];
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
};
|
||||
|
||||
export const vestToSteem = (
|
||||
vestingShares,
|
||||
totalVestingShares,
|
||||
totalVestingFundSteem
|
||||
) => {
|
||||
return (
|
||||
parseFloat(totalVestingFundSteem) *
|
||||
(parseFloat(vestingShares) / parseFloat(totalVestingShares))
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* @method getFollows get account data
|
||||
* @param user username
|
||||
@ -60,6 +91,8 @@ export const getFollows = user => {
|
||||
export const getPosts = async (by, query, user) => {
|
||||
try {
|
||||
let posts = await client.database.getDiscussions(by, query);
|
||||
console.log("comments");
|
||||
console.log(posts);
|
||||
posts = await parsePosts(posts, user);
|
||||
return posts;
|
||||
} catch (error) {
|
||||
@ -67,6 +100,17 @@ export const getPosts = async (by, query, user) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const getUserComments = async query => {
|
||||
try {
|
||||
let comments = await client.database.getDiscussions("comments", query);
|
||||
comments = parseComments(comments);
|
||||
console.log(comments);
|
||||
return comments;
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @method getUser get user data
|
||||
* @param user post author
|
||||
@ -187,3 +231,19 @@ export const postComment = (comment, postingKey) => {
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const transferToken = (data, activeKey) => {
|
||||
let key = PrivateKey.fromString(activeKey);
|
||||
return new Promise((resolve, reject) => {
|
||||
client.broadcast
|
||||
.transfer(data, key)
|
||||
.then(result => {
|
||||
console.log(result);
|
||||
resolve(result);
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
@ -1,4 +1,5 @@
|
||||
import * as React from 'react';
|
||||
import React from "react";
|
||||
import { StatusBar } from "react-native";
|
||||
import {
|
||||
Container,
|
||||
Header,
|
||||
@ -8,16 +9,16 @@ import {
|
||||
Button,
|
||||
Icon,
|
||||
Title,
|
||||
} from 'native-base';
|
||||
} from "native-base";
|
||||
|
||||
class NotificationPage extends React.Component {
|
||||
static navigationOptions = {
|
||||
title: 'Notifications',
|
||||
title: "Notifications",
|
||||
};
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Container>
|
||||
<Container style={{ top: StatusBar.currentHeight }}>
|
||||
<Header>
|
||||
<Left>
|
||||
<Button transparent>
|
||||
|
@ -1,6 +1,11 @@
|
||||
/* eslint-disable no-unused-vars */
|
||||
import React from "react";
|
||||
import { StatusBar, Dimensions } from "react-native";
|
||||
import {
|
||||
StatusBar,
|
||||
Dimensions,
|
||||
FlatList,
|
||||
ActivityIndicator,
|
||||
} from "react-native";
|
||||
|
||||
import moment from "moment";
|
||||
import FastImage from "react-native-fast-image";
|
||||
@ -8,7 +13,8 @@ import FastImage from "react-native-fast-image";
|
||||
import ScrollableTabView from "react-native-scrollable-tab-view";
|
||||
import CustomTabBar from "../home/FeedTabs";
|
||||
import DiscoverPage from "../discover/Discover";
|
||||
import { getUser, getFollows } from "../../providers/steem/Dsteem";
|
||||
import PostCard from "../../components/post-card/PostCard";
|
||||
import Comment from "../../components/comment/Comment";
|
||||
|
||||
import {
|
||||
Content,
|
||||
@ -23,18 +29,33 @@ import {
|
||||
Icon,
|
||||
Title,
|
||||
Text,
|
||||
Container,
|
||||
} from "native-base";
|
||||
|
||||
import { getUserData, getAuthStatus } from "../../realm/Realm";
|
||||
import {
|
||||
getUser,
|
||||
getFollows,
|
||||
getPosts,
|
||||
getUserComments,
|
||||
getUserReplies,
|
||||
} from "../../providers/steem/Dsteem";
|
||||
import store from "../../redux/store/Store";
|
||||
import styles from "../../styles/profile.styles";
|
||||
import HotPage from "../home/hot";
|
||||
/* eslint-enable no-unused-vars */
|
||||
|
||||
class ProfilePage extends React.Component {
|
||||
constructor() {
|
||||
super();
|
||||
this.getBlog = this.getBlog.bind(this);
|
||||
this.getMore = this.getMore.bind(this);
|
||||
this.getComments = this.getComments.bind(this);
|
||||
this.state = {
|
||||
user: [],
|
||||
posts: [],
|
||||
commments: [],
|
||||
replies: [],
|
||||
about: {},
|
||||
follows: {},
|
||||
isLoggedIn: false,
|
||||
@ -63,48 +84,94 @@ class ProfilePage extends React.Component {
|
||||
|
||||
user = await getUser(userData[0].username);
|
||||
about = JSON.parse(user.json_metadata);
|
||||
this.setState({
|
||||
user: user,
|
||||
isLoggedIn: isLoggedIn,
|
||||
follows: follows,
|
||||
about: about.profile,
|
||||
});
|
||||
this.setState(
|
||||
{
|
||||
user: user,
|
||||
isLoggedIn: isLoggedIn,
|
||||
follows: follows,
|
||||
about: about.profile,
|
||||
},
|
||||
() => {
|
||||
this.getBlog(userData[0].username);
|
||||
this.getComments(userData[0].username);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
renderFooter = () => {
|
||||
if (!this.state.loading == false) return null;
|
||||
|
||||
return (
|
||||
<View style={{ marginVertical: 20 }}>
|
||||
<ActivityIndicator animating size="large" />
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
getBlog = user => {
|
||||
this.setState({ loading: true });
|
||||
getPosts("blog", { tag: user, limit: 10 }, user)
|
||||
.then(result => {
|
||||
this.setState({
|
||||
isReady: true,
|
||||
posts: result,
|
||||
start_author: result[result.length - 1].author,
|
||||
start_permlink: result[result.length - 1].permlink,
|
||||
refreshing: false,
|
||||
loading: false,
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
alert(err);
|
||||
});
|
||||
};
|
||||
|
||||
getMore = async () => {
|
||||
console.log("get more");
|
||||
await getPosts(
|
||||
"blog",
|
||||
{
|
||||
tag: this.state.user.name,
|
||||
limit: 10,
|
||||
start_author: this.state.start_author,
|
||||
start_permlink: this.state.start_permlink,
|
||||
},
|
||||
this.state.user.name
|
||||
).then(result => {
|
||||
console.log(result);
|
||||
let posts = result;
|
||||
posts.shift();
|
||||
this.setState({
|
||||
posts: [...this.state.posts, ...posts],
|
||||
start_author: result[result.length - 1].author,
|
||||
start_permlink: result[result.length - 1].permlink,
|
||||
loading: false,
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
getComments = async user => {
|
||||
await getUserComments({ start_author: user, limit: 10 })
|
||||
.then(result => {
|
||||
this.setState({
|
||||
isReady: true,
|
||||
commments: result,
|
||||
refreshing: false,
|
||||
loading: false,
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
};
|
||||
|
||||
render() {
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
{this.state.isLoggedIn ? (
|
||||
<View style={{ flex: 1 }}>
|
||||
<Header
|
||||
style={{
|
||||
backgroundColor: "transparent",
|
||||
position: "absolute",
|
||||
top: StatusBar.currentHeight,
|
||||
}}
|
||||
>
|
||||
<Left>
|
||||
<Button transparent>
|
||||
<Icon name="menu" />
|
||||
</Button>
|
||||
</Left>
|
||||
<Body>
|
||||
<Title>{this.state.user.name}</Title>
|
||||
</Body>
|
||||
<Right>
|
||||
<Button transparent>
|
||||
<Icon name="search" />
|
||||
</Button>
|
||||
<Button transparent>
|
||||
<Icon name="heart" />
|
||||
</Button>
|
||||
<Button transparent>
|
||||
<Icon name="more" />
|
||||
</Button>
|
||||
</Right>
|
||||
</Header>
|
||||
<Content style={styles.content}>
|
||||
<View style={styles.content}>
|
||||
<FastImage
|
||||
style={styles.cover}
|
||||
source={{
|
||||
@ -181,35 +248,112 @@ class ProfilePage extends React.Component {
|
||||
</View>
|
||||
</CardItem>
|
||||
</Card>
|
||||
<View>
|
||||
<ScrollableTabView
|
||||
style={styles.tabs}
|
||||
renderTabBar={() => (
|
||||
<CustomTabBar
|
||||
style={styles.tabbar}
|
||||
tabUnderlineDefaultWidth={30} // default containerWidth / (numberOfTabs * 4)
|
||||
tabUnderlineScaleX={3} // default 3
|
||||
activeColor={"#222"}
|
||||
inactiveColor={"#222"}
|
||||
</View>
|
||||
<ScrollableTabView
|
||||
style={styles.tabs}
|
||||
style={{ flex: 1 }}
|
||||
renderTabBar={() => (
|
||||
<CustomTabBar
|
||||
style={styles.tabbar}
|
||||
tabUnderlineDefaultWidth={30} // default containerWidth / (numberOfTabs * 4)
|
||||
tabUnderlineScaleX={3} // default 3
|
||||
activeColor={"#222"}
|
||||
inactiveColor={"#222"}
|
||||
/>
|
||||
)}
|
||||
>
|
||||
<View tabLabel="Blog" style={styles.tabbarItem}>
|
||||
<FlatList
|
||||
data={this.state.posts}
|
||||
showsVerticalScrollIndicator={false}
|
||||
renderItem={({ item }) => (
|
||||
<PostCard
|
||||
style={{ shadowColor: "white" }}
|
||||
navigation={this.props.navigation}
|
||||
content={item}
|
||||
user={this.state.user}
|
||||
isLoggedIn={true}
|
||||
/>
|
||||
)}
|
||||
>
|
||||
<View tabLabel="Blog" />
|
||||
<View
|
||||
tabLabel="Comments"
|
||||
style={styles.tabbarItem}
|
||||
/>
|
||||
<View
|
||||
tabLabel="Replies"
|
||||
style={styles.tabbarItem}
|
||||
/>
|
||||
<View
|
||||
tabLabel="Wallet"
|
||||
style={styles.tabbarItem}
|
||||
/>
|
||||
</ScrollableTabView>
|
||||
keyExtractor={(post, index) =>
|
||||
index.toString()
|
||||
}
|
||||
onEndReached={info => {
|
||||
if (this.state.loading == false) {
|
||||
console.log(info);
|
||||
this.getMore();
|
||||
}
|
||||
}}
|
||||
onEndThreshold={0}
|
||||
bounces={false}
|
||||
ListFooterComponent={this.renderFooter}
|
||||
/>
|
||||
</View>
|
||||
</Content>
|
||||
|
||||
<View tabLabel="Comments" style={styles.tabbarItem}>
|
||||
<FlatList
|
||||
data={this.state.commments}
|
||||
showsVerticalScrollIndicator={false}
|
||||
renderItem={({ item }) => (
|
||||
<Comment
|
||||
comment={item}
|
||||
navigation={this.props.navigation}
|
||||
isLoggedIn={true}
|
||||
user={this.state.user}
|
||||
/>
|
||||
)}
|
||||
keyExtractor={(post, index) =>
|
||||
index.toString()
|
||||
}
|
||||
onEndThreshold={0}
|
||||
bounces={false}
|
||||
ListFooterComponent={this.renderFooter}
|
||||
/>
|
||||
</View>
|
||||
<View
|
||||
tabLabel="Replies"
|
||||
style={styles.tabbarItem}
|
||||
/>
|
||||
<View tabLabel="Wallet" style={styles.tabbarItem}>
|
||||
<Card>
|
||||
<Text>
|
||||
STEEM Balance: {this.state.user.balance}
|
||||
</Text>
|
||||
</Card>
|
||||
<Card>
|
||||
<Text>
|
||||
SBD Balance:{" "}
|
||||
{this.state.user.sbd_balance}
|
||||
</Text>
|
||||
</Card>
|
||||
<Card>
|
||||
<Text>
|
||||
STEEM Power:{" "}
|
||||
{this.state.user.steem_power} SP
|
||||
</Text>
|
||||
<Text>
|
||||
Received STEEM Power:{" "}
|
||||
{this.state.user.received_steem_power}{" "}
|
||||
SP
|
||||
</Text>
|
||||
<Text>
|
||||
Delegated Power Power:{" "}
|
||||
{this.state.user.delegated_steem_power}{" "}
|
||||
SP
|
||||
</Text>
|
||||
</Card>
|
||||
<Card>
|
||||
<Text>
|
||||
Saving STEEM Balance:{" "}
|
||||
{this.state.user.savings_balance}
|
||||
</Text>
|
||||
<Text>
|
||||
Saving STEEM Balance:{" "}
|
||||
{this.state.user.savings_sbd_balance}
|
||||
</Text>
|
||||
</Card>
|
||||
</View>
|
||||
</ScrollableTabView>
|
||||
</View>
|
||||
) : (
|
||||
<View>
|
||||
|
@ -330,7 +330,7 @@ class SinglePostPage extends React.Component {
|
||||
}
|
||||
/>
|
||||
)}
|
||||
keyExtractor={item => item.permlink.toString()}
|
||||
keyExtractor={item => item.id.toString()}
|
||||
/>
|
||||
) : (
|
||||
<Card
|
||||
|
@ -1,4 +1,5 @@
|
||||
import * as React from 'react';
|
||||
import React from "react";
|
||||
import { StatusBar, Text, Picker } from "react-native";
|
||||
import {
|
||||
Container,
|
||||
Header,
|
||||
@ -8,16 +9,79 @@ import {
|
||||
Button,
|
||||
Icon,
|
||||
Title,
|
||||
} from 'native-base';
|
||||
Content,
|
||||
Card,
|
||||
Input,
|
||||
Form,
|
||||
} from "native-base";
|
||||
import { getUserData, getAuthStatus } from "../../realm/Realm";
|
||||
import { getUser, transferToken } from "../../providers/steem/Dsteem";
|
||||
import { decryptKey } from "../../utils/Crypto";
|
||||
|
||||
class WalletPage extends React.Component {
|
||||
static navigationOptions = {
|
||||
title: 'Wallet',
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
receiver: "",
|
||||
amount: "",
|
||||
asset: "STEEM",
|
||||
memo: "",
|
||||
user: {},
|
||||
};
|
||||
}
|
||||
async componentWillMount() {
|
||||
let isLoggedIn;
|
||||
let user;
|
||||
let userData;
|
||||
|
||||
await getAuthStatus().then(res => {
|
||||
isLoggedIn = res;
|
||||
});
|
||||
|
||||
if (isLoggedIn == true) {
|
||||
await getUserData().then(res => {
|
||||
userData = Array.from(res);
|
||||
});
|
||||
|
||||
user = await getUser(userData[0].username);
|
||||
|
||||
this.setState({
|
||||
user: user,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
sendSteem = async () => {
|
||||
let userData;
|
||||
let activeKey;
|
||||
|
||||
transferData = {
|
||||
from: this.state.user.name,
|
||||
to: this.state.receiver,
|
||||
amount: this.state.amount + " " + this.state.asset,
|
||||
memo: this.state.memo,
|
||||
};
|
||||
|
||||
await getUserData()
|
||||
.then(result => {
|
||||
userData = Array.from(result);
|
||||
activeKey = userData[0].activeKey;
|
||||
console.log(userData);
|
||||
console.log(activeKey);
|
||||
})
|
||||
.then(() => {
|
||||
activeKey = decryptKey(activeKey, "pinCode");
|
||||
transferToken(transferData, activeKey);
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
});
|
||||
};
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Container>
|
||||
<Container style={{ top: StatusBar.currentHeight }}>
|
||||
<Header>
|
||||
<Left>
|
||||
<Button transparent>
|
||||
@ -27,18 +91,77 @@ class WalletPage extends React.Component {
|
||||
<Body>
|
||||
<Title>Wallet</Title>
|
||||
</Body>
|
||||
<Right>
|
||||
<Button transparent>
|
||||
<Icon name="search" />
|
||||
</Button>
|
||||
<Button transparent>
|
||||
<Icon name="heart" />
|
||||
</Button>
|
||||
<Button transparent>
|
||||
<Icon name="more" />
|
||||
</Button>
|
||||
</Right>
|
||||
<Right />
|
||||
</Header>
|
||||
<Content>
|
||||
<Card>
|
||||
<Text>STEEM Balance: {this.state.user.balance}</Text>
|
||||
</Card>
|
||||
<Card>
|
||||
<Text>SBD Balance: {this.state.user.sbd_balance}</Text>
|
||||
</Card>
|
||||
<Card>
|
||||
<Text>
|
||||
STEEM Power: {this.state.user.steem_power} SP
|
||||
</Text>
|
||||
<Text>
|
||||
Received STEEM Power:{" "}
|
||||
{this.state.user.received_steem_power} SP
|
||||
</Text>
|
||||
<Text>
|
||||
Delegated Power Power:{" "}
|
||||
{this.state.user.delegated_steem_power} SP
|
||||
</Text>
|
||||
</Card>
|
||||
<Card>
|
||||
<Text>
|
||||
Saving STEEM Balance:{" "}
|
||||
{this.state.user.savings_balance}
|
||||
</Text>
|
||||
<Text>
|
||||
Saving STEEM Balance:{" "}
|
||||
{this.state.user.savings_sbd_balance}
|
||||
</Text>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<Input
|
||||
autoCapitalize="none"
|
||||
placeholder="Recipient"
|
||||
onChangeText={user =>
|
||||
this.setState({ receiver: user })
|
||||
}
|
||||
value={this.state.receiver}
|
||||
/>
|
||||
<Input
|
||||
placeholder="amount"
|
||||
onChangeText={amount =>
|
||||
this.setState({ amount: amount })
|
||||
}
|
||||
value={this.state.amount}
|
||||
/>
|
||||
<Input
|
||||
placeholder="memo"
|
||||
onChangeText={memo => this.setState({ memo: memo })}
|
||||
value={this.state.memo}
|
||||
/>
|
||||
<Picker
|
||||
note
|
||||
mode="dropdown"
|
||||
style={{ width: 120 }}
|
||||
selectedValue={this.state.asset}
|
||||
onValueChange={(itemValue, itemIndex) =>
|
||||
this.setState({ asset: itemValue })
|
||||
}
|
||||
>
|
||||
<Picker.Item label="STEEM" value="STEEM" />
|
||||
<Picker.Item label="SBD" value="SBD" />
|
||||
</Picker>
|
||||
<Button onPress={this.sendSteem} style={{ margin: 10 }}>
|
||||
<Text style={{ color: "white" }}>Send</Text>
|
||||
</Button>
|
||||
</Card>
|
||||
</Content>
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ const styles = createStyle({
|
||||
top: StatusBar.currentHeight,
|
||||
},
|
||||
content: {
|
||||
flex: 1,
|
||||
backgroundColor: "#f9f9f9",
|
||||
},
|
||||
cover: {
|
||||
|
Loading…
Reference in New Issue
Block a user