Merge pull request #650 from esteemapp/feature/ePoint

ePoint System Implemented
This commit is contained in:
uğur erdal 2019-03-03 22:17:34 +03:00 committed by GitHub
commit 1963a5eedf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 141 additions and 6 deletions

View File

@ -4,6 +4,9 @@ import {
} from 'react-native';
import { injectIntl } from 'react-intl';
// Providers
import { userActivity } from '../../../providers/esteem/ePoint';
// Utils
import { getTimeFromNow } from '../../../utils/time';
@ -36,6 +39,13 @@ class PostDisplayView extends PureComponent {
}
// Component Life Cycles
componentDidMount() {
const { currentAccount, isLoggedIn } = this.props;
if (isLoggedIn && currentAccount && currentAccount.name) {
userActivity(currentAccount.name, 10);
}
}
// Component Functions
_handleOnScroll = (event) => {

11
src/config/ePoint.js Normal file
View File

@ -0,0 +1,11 @@
import axios from 'axios';
import Config from 'react-native-config';
const search = axios.create({
baseURL: Config.BACKEND_URL,
headers: {
'User-Agent': Config.USER_AGENT,
},
});
export default search;

View File

@ -0,0 +1,69 @@
import ePointApi from '../../config/ePoint';
export const userActivity = (username, type, blockNumber = '', transactionNumber = '') => {
const params = { username, type };
if (blockNumber) {
params.blockNumber = blockNumber;
}
if (transactionNumber) {
params.transactionNumber = transactionNumber;
}
try {
return ePointApi.post('/usr-activity', params).then(res => res.data);
} catch (error) {
return null;
}
};
export const transfer = (sender, receiver, amount) => new Promise((resolve, reject) => {
ePointApi
.post('/transfer', {
se: sender,
re: receiver,
am: amount,
})
.then((res) => {
resolve(res.data);
})
.catch((error) => {
reject(error);
});
});
export const getUser = username => new Promise((resolve, reject) => {
ePointApi
.get(`/users/:${username}`)
.then((res) => {
resolve(res.data);
})
.catch((error) => {
reject(error);
});
});
export const getUserPoints = username => new Promise((resolve, reject) => {
ePointApi
.get(`/users/:${username}/points`)
.then((res) => {
resolve(res.data);
})
.catch((error) => {
reject(error);
});
});
export const claim = username => new Promise((resolve, reject) => {
ePointApi
.put('/claim', {
us: `${username}`,
})
.then((res) => {
resolve(res.data);
})
.catch((error) => {
reject(error);
});
});

View File

@ -4,7 +4,7 @@ import Config from 'react-native-config';
import { getServer } from '../../realm/realm';
import { getUnreadActivityCount } from '../esteem/esteem';
import { userActivity } from '../esteem/ePoint';
// Utils
import { decryptKey } from '../../utils/crypto';
import { parsePosts, parsePost, parseComments } from '../../utils/postParser';
@ -376,14 +376,21 @@ export const getPostWithComments = async (user, permlink) => {
return [post, comments];
};
// export const getAccountRC = username => client.call('rc_api', 'find_rc_accounts', { accounts: [username] });
/**
* @method upvote upvote a content
* @param vote vote object(author, permlink, voter, weight)
* @param postingKey private posting key
*/
export const vote = async (currentAccount, pin, author, permlink, weight) => {
export const vote = (account, pin, author, permlink, weight) => _vote(
account, pin, author, permlink, weight,
)
.then((resp) => {
userActivity(account.username, 120, resp.block_num, resp.id);
return resp;
});
const _vote = async (currentAccount, pin, author, permlink, weight) => {
const digitPinCode = getDigitPinCode(pin);
const key = getAnyPrivateKey(currentAccount.local, digitPinCode);
@ -631,11 +638,41 @@ export const getTrendingTags = async (tag) => {
}
};
export const postContent = (
account,
pin,
parentAuthor,
parentPermlink,
permlink,
title,
body,
jsonMetadata,
options = null,
voteWeight = null,
) => _postContent(
account,
pin,
parentAuthor,
parentPermlink,
permlink,
title,
body,
jsonMetadata,
options,
voteWeight,
).then((resp) => {
if (options) {
const t = title ? 100 : 110;
userActivity(account.username, t, resp.block_num, resp.id);
}
return resp;
});
/**
* @method postComment post a comment/reply
* @param comment comment object { author, permlink, ... }
*/
export const postContent = async (
const _postContent = async (
account,
pin,
parentAuthor,
@ -742,7 +779,15 @@ export const postContent = async (
};
// Re-blog
export const reblog = async (account, pinCode, author, permlink) => {
// TODO: remove pinCode
export const reblog = (account, pinCode, author, permlink) => _reblog(
account, pinCode, author, permlink,
).then((resp) => {
userActivity(account.name, 130, resp.block_num, resp.id);
return resp;
});
const _reblog = async (account, pinCode, author, permlink) => {
const pin = getDigitPinCode(pinCode);
const key = getAnyPrivateKey(account.local, pin);