fixed other steemconnect endpoints

This commit is contained in:
ue 2018-12-10 16:08:59 +03:00
parent b959cc73ac
commit e380ab3d74
11 changed files with 167 additions and 139 deletions

View File

@ -25,15 +25,16 @@ class PostCardContainer extends Component {
}
_handleOnUserPress = (username) => {
const { navigation } = this.props;
navigation.navigate({
routeName: ROUTES.SCREENS.PROFILE,
params: {
username,
},
key: username,
});
const { navigation, currentAccount } = this.props;
if (currentAccount.name !== username) {
navigation.navigate({
routeName: ROUTES.SCREENS.PROFILE,
params: {
username,
},
key: username,
});
}
};
_handleOnContentPress = (author, permlink) => {

View File

@ -25,29 +25,24 @@ class PostHeaderDescription extends Component {
// Component Functions
_handleOnUserPress = (username) => {
const { navigation } = this.props;
const { navigation, profileOnPress } = this.props;
navigation.navigate({
routeName: ROUTES.SCREENS.PROFILE,
params: {
username,
},
key: username + Math.random() * 100,
});
if (profileOnPress) {
profileOnPress(username);
} else {
navigation.navigate({
routeName: ROUTES.SCREENS.PROFILE,
params: {
username,
},
key: username,
});
}
};
render() {
const {
date,
avatar,
name,
reputation,
size,
tag,
profileOnPress,
tagOnPress,
isHideImage,
dropdownComponent,
date, avatar, name, reputation, size, tag, tagOnPress, isHideImage,
} = this.props;
const _reputationText = `(${reputation})`;
@ -63,7 +58,7 @@ class PostHeaderDescription extends Component {
<View style={styles.container}>
<TouchableOpacity
style={styles.avatarNameWrapper}
onPress={() => (profileOnPress ? profileOnPress(name) : this._handleOnUserPress(name))}
onPress={() => this._handleOnUserPress(name)}
>
{_avatar && (
<FastImage

View File

@ -124,6 +124,7 @@ export const loginWithSC2 = async (accessToken) => {
.then(() => {
setUserData(userData)
.then(() => {
account.account.username = account.account.name;
resolve({ ...account.account, accessToken });
})
.catch((error) => {

View File

@ -1,6 +1,5 @@
import { Client, PrivateKey } from 'dsteem';
import steemConnect from 'steemconnect';
import sc2 from './steemConnectAPI';
import { getServer } from '../../realm/realm';
import { getUnreadActivityCount } from '../esteem/esteem';
@ -8,7 +7,7 @@ import { getUnreadActivityCount } from '../esteem/esteem';
import { decryptKey } from '../../utils/crypto';
import { getDigitPinCode } from './auth';
import {
parsePosts, parsePost, parseComments, parsePostsSummary,
parsePosts, parsePost, parseComments,
} from '../../utils/postParser';
import { getName, getAvatar } from '../../utils/user';
@ -409,6 +408,7 @@ export const transferToken = (data, activeKey) => {
export const followUser = async (currentAccount, data) => {
const digitPinCode = await getDigitPinCode();
if (currentAccount.local.authType === AUTH_TYPE.MASTER_KEY) {
const key = decryptKey(currentAccount.local.postingKey, digitPinCode);
const privateKey = PrivateKey.fromString(key);
@ -490,14 +490,11 @@ export const unfollowUser = async (currentAccount, data) => {
};
export const delegate = (data, activeKey) => {
let key;
try {
key = PrivateKey.fromString(activeKey);
} catch (error) {}
const privateKey = PrivateKey.fromString(activeKey);
return new Promise((resolve, reject) => {
client.broadcast
.delegateVestingShares(data, key)
.delegateVestingShares(data, privateKey)
.then((result) => {
resolve(result);
})
@ -526,10 +523,7 @@ export const getFeedHistory = async () => {
};
export const transferToVesting = (data, activeKey) => {
let key;
try {
key = PrivateKey.fromString(activeKey);
} catch (error) {}
const privateKey = PrivateKey.fromString(activeKey);
const op = [
'transfer_to_vesting',
@ -542,7 +536,7 @@ export const transferToVesting = (data, activeKey) => {
return new Promise((resolve, reject) => {
client.broadcast
.sendOperations([op], key)
.sendOperations([op], privateKey)
.then((result) => {
resolve(result);
})
@ -553,11 +547,7 @@ export const transferToVesting = (data, activeKey) => {
};
export const withdrawVesting = (data, activeKey) => {
let key;
try {
key = PrivateKey.fromString(activeKey);
} catch (error) {}
const privateKey = PrivateKey.fromString(activeKey);
const op = [
'withdraw_vesting',
{
@ -568,57 +558,7 @@ export const withdrawVesting = (data, activeKey) => {
return new Promise((resolve, reject) => {
client.broadcast
.sendOperations([op], key)
.then((result) => {
resolve(result);
})
.catch((error) => {
reject(error);
});
});
};
export const postContent = (data, postingKey) => {
let key;
try {
key = PrivateKey.fromString(postingKey);
} catch (error) {}
const post = {
author: data.author,
body: data.body,
parent_author: '',
parent_permlink: data.tags[0],
permlink: data.permlink,
title: data.title,
json_metadata: JSON.stringify({
app: 'esteem/2.0.0-mobile',
community: 'esteem.app',
tags: data.tags,
}),
};
const op = {
author: data.author,
permlink: data.permlink,
max_accepted_payout: '1000000.000 SBD',
percent_steem_dollars: 10000,
allow_votes: true,
allow_curation_rewards: true,
extensions: [
[
0,
{
beneficiaries: [{ account: 'esteemapp', weight: 1000 }],
},
],
],
};
return new Promise((resolve, reject) => {
client.broadcast
.commentWithOptions(post, op, key)
.sendOperations([op], privateKey)
.then((result) => {
resolve(result);
})
@ -641,7 +581,7 @@ export const lookupAccounts = async (username) => {
* @method postComment post a comment/reply
* @param comment comment object { author, permlink, ... }
*/
export const postComment = async (
export const postContent = async (
account,
digitPinCode,
parentAuthor,
@ -744,25 +684,40 @@ export const postComment = async (
}
};
// Re-blog
export const reblog = async (account, author, permlink) => {
const pin = await getDigitPinCode();
const key = decryptKey(account.local.postingKey, pin);
const privateKey = PrivateKey.fromString(key);
const follower = account.name;
const json = {
id: 'follow',
json: JSON.stringify([
'reblog',
{
account: follower,
author,
permlink,
},
]),
required_auths: [],
required_posting_auths: [follower],
};
if (account.local.authType === AUTH_TYPE.MASTER_KEY) {
const key = decryptKey(account.local.postingKey, pin);
const privateKey = PrivateKey.fromString(key);
const follower = account.name;
return client.broadcast.json(json, privateKey);
const json = {
id: 'follow',
json: JSON.stringify([
'reblog',
{
account: follower,
author,
permlink,
},
]),
required_auths: [],
required_posting_auths: [follower],
};
return client.broadcast.json(json, privateKey);
}
if (account.local.authType === AUTH_TYPE.STEEM_CONNECT) {
const token = decryptKey(account.local.accessToken, pin);
const api = steemConnect.Initialize({
accessToken: token,
});
const follower = account.name;
return api.reblog(follower, author, permlink);
}
};

View File

@ -90,6 +90,15 @@ export const getUserData = () => new Promise((resolve, reject) => {
}
});
export const getSelectedUser = username => new Promise((resolve, reject) => {
try {
const user = realm.objects(USER_SCHEMA).filtered('username = $0', username);
resolve(user);
} catch (error) {
reject(error);
}
});
export const getUserDataWithUsername = (username) => {
try {
const user = Array.from(realm.objects(USER_SCHEMA).filtered('username = $0', username));
@ -399,7 +408,7 @@ export const getPushTokenSaved = () => new Promise((resolve, reject) => {
resolve(false);
}
if (application[0].isPushTokenSaved) {
resolve((application[0].isPushTokenSaved));
resolve(application[0].isPushTokenSaved);
} else {
resolve(false);
}
@ -436,7 +445,7 @@ export const getExistUser = () => new Promise((resolve, reject) => {
resolve(false);
}
if (application[0].isExistUser) {
resolve((application[0].isExistUser));
resolve(application[0].isExistUser);
} else {
resolve(false);
}

View File

@ -1,12 +1,11 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Alert } from 'react-native';
import ImagePicker from 'react-native-image-crop-picker';
// Services and Actions
// import { Buffer } from 'buffer';
import { uploadImage } from '../../../providers/esteem/esteem';
import { postContent, postComment } from '../../../providers/steem/dsteem';
import { postContent } from '../../../providers/steem/dsteem';
import { setDraftPost, getDraftPost } from '../../../realm/realm';
import { getDigitPinCode } from '../../../providers/steem/auth';
@ -19,10 +18,11 @@ import { default as ROUTES } from '../../../constants/routeNames';
import {
generatePermlink,
generateReplyPermlink,
makeJsonMetadataReply,
makeJsonMetadata,
makeOptions,
extractMetadata,
makeJsonMetadataReply,
} from '../../../utils/editor';
import { decryptKey } from '../../../utils/crypto';
// import { generateSignature } from '../../../utils/image';
// Component
import EditorScreen from '../screen/editorScreen';
@ -205,25 +205,32 @@ class EditorContainer extends Component {
if (currentAccount) {
this.setState({ isPostSending: true });
const meta = extractMetadata(fields.body);
const jsonMeta = makeJsonMetadata(meta, fields.tags);
const permlink = generatePermlink(fields.title);
const digitPinCode = await getDigitPinCode();
const author = currentAccount.name;
const options = makeOptions(author, permlink);
const parentPermlink = fields.tags[0];
const postingKey = decryptKey(currentAccount.local.postingKey, digitPinCode);
const post = {
...fields,
await postContent(
currentAccount,
digitPinCode,
'',
parentPermlink,
permlink,
author: currentAccount.name,
};
postContent(post, postingKey)
fields.title,
fields.body,
jsonMeta,
options,
0,
)
.then((result) => {
Alert.alert('Success', 'Your reply has been submitted!');
navigation.navigate(ROUTES.SCREENS.HOME);
alert('Your post succesfully shared');
navigation.goBack();
})
.catch((error) => {
Alert.alert('Failed!', 'Your reply failed to submit!');
alert(`Opps! there is a problem${error}`);
this.setState({ isPostSending: false });
});
}
@ -245,13 +252,13 @@ class EditorContainer extends Component {
const parentAuthor = post.author;
const parentPermlink = post.permlink;
await postComment(
await postContent(
currentAccount,
digitPinCode,
parentAuthor,
parentPermlink,
permlink,
'',
fields.title || '',
fields.body,
jsonMeta,
options,
@ -274,7 +281,7 @@ class EditorContainer extends Component {
if (isReply) {
this._submitReply(form.fields);
} else {
this._submitPost(form);
this._submitPost(form.fields);
}
};

View File

@ -64,7 +64,7 @@ class HomeScreen extends PureComponent {
<Posts
filterOptions={_filterOptions}
getFor="feed"
tag={tag || currentAccount.username}
tag={tag || currentAccount.name}
/>
</View>
<View

View File

@ -90,7 +90,6 @@ class LoginScreen extends Component {
_handleOnModalToggle = () => {
const { isModalOpen } = this.state;
console.log('isModalOpen :', isModalOpen);
this.setState({ isModalOpen: !isModalOpen });
}

View File

@ -7,9 +7,9 @@ import { setUserDataWithPinCode, verifyPinCode } from '../../../providers/steem/
// Actions & Services
import { closePinCodeModal } from '../../../redux/actions/applicationActions';
import { getExistUser, setExistUser } from '../../../realm/realm';
import { getExistUser, setExistUser, getUserData } from '../../../realm/realm';
import { updateCurrentAccount } from '../../../redux/actions/accountAction';
import {formatAccount } from "../../../utils/user";
import { PinCodeScreen } from '..';
class PinCodeContainer extends Component {

View File

@ -65,3 +65,55 @@ export const makeJsonMetadataReply = tags => ({
format: 'markdown+html',
community: 'esteem.app',
});
export const makeJsonMetadata = (meta, tags) => Object.assign({}, meta, {
tags,
app: 'esteem/2.0.0-mobile',
format: 'markdown+html',
community: 'esteem.app',
});
export const extractMetadata = (body) => {
const urlReg = /(\b(https?|ftp):\/\/[A-Z0-9+&@#/%?=~_|!:,.;-]*[-A-Z0-9+&@#/%=~_|])/gim;
const userReg = /(^|\s)(@[a-z][-.a-z\d]+[a-z\d])/gim;
const imgReg = /(https?:\/\/.*\.(?:png|jpg|jpeg|gif))/gim;
const out = {};
const mUrls = body.match(urlReg);
const mUsers = body.match(userReg);
const matchedImages = [];
const matchedLinks = [];
const matchedUsers = [];
if (mUrls) {
for (let i = 0; i < mUrls.length; i++) {
const ind = mUrls[i].match(imgReg);
if (ind) {
matchedImages.push(mUrls[i]);
} else {
matchedLinks.push(mUrls[i]);
}
}
}
if (matchedLinks.length) {
out.links = matchedLinks;
}
if (matchedImages.length) {
out.image = matchedImages;
}
if (mUsers) {
for (let i = 0; i < mUsers.length; i++) {
matchedUsers.push(mUsers[i].trim().substring(1));
}
}
if (matchedUsers.length) {
out.users = matchedUsers;
}
return out;
};

View File

@ -1,3 +1,5 @@
import { getUserDataWithUsername } from '../realm/realm';
export const getReputation = (input) => {
if (input === 0) {
return 25;
@ -36,3 +38,10 @@ export const getAvatar = about => {
}
return null;
};
// export const formatAccount = account => {
// getUserDataWithUsername(account).then(response => {
// if (response.length > 0) {
// }
// });
// };