From 69a6f5fd5f8d9f0c457d838e0b979767d06b9d17 Mon Sep 17 00:00:00 2001 From: u-e Date: Fri, 1 Mar 2019 00:10:24 +0300 Subject: [PATCH 1/2] added endpoint urls added arch created get put post and implemented --- .../postView/view/postDisplayView.js | 8 +++ src/config/ePoint.js | 11 ++++ src/providers/esteem/ePoint.js | 65 +++++++++++++++++++ src/providers/steem/dsteem.js | 52 +++++++++++++-- 4 files changed, 130 insertions(+), 6 deletions(-) create mode 100644 src/config/ePoint.js create mode 100644 src/providers/esteem/ePoint.js diff --git a/src/components/postView/view/postDisplayView.js b/src/components/postView/view/postDisplayView.js index 6aa463e00..140866f90 100644 --- a/src/components/postView/view/postDisplayView.js +++ b/src/components/postView/view/postDisplayView.js @@ -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,11 @@ class PostDisplayView extends PureComponent { } // Component Life Cycles + componentDidMount() { + const { currentAccount, isLoggedIn } = this.props; + + userActivity(currentAccount.name, 10); + } // Component Functions _handleOnScroll = (event) => { diff --git a/src/config/ePoint.js b/src/config/ePoint.js new file mode 100644 index 000000000..6581bb9b1 --- /dev/null +++ b/src/config/ePoint.js @@ -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; diff --git a/src/providers/esteem/ePoint.js b/src/providers/esteem/ePoint.js new file mode 100644 index 000000000..64c5f5891 --- /dev/null +++ b/src/providers/esteem/ePoint.js @@ -0,0 +1,65 @@ +import ePointApi from '../../config/ePoint'; + +export const userActivity = (us, ty, bl = '', tx = '') => { + const params = { us, ty }; + + if (bl) { + params.bl = bl; + } + + if (tx) { + params.tx = tx; + } + + return ePointApi.post('/usr-activity', params).then(res => res.data); +}; + +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); + }); +}); diff --git a/src/providers/steem/dsteem.js b/src/providers/steem/dsteem.js index 0ce0147f4..26bfc03ed 100644 --- a/src/providers/steem/dsteem.js +++ b/src/providers/steem/dsteem.js @@ -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,18 @@ 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 +635,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 +776,13 @@ export const postContent = async ( }; // Re-blog -export const reblog = async (account, pinCode, author, permlink) => { + +export const reblog = (account, pinCode, author, permlink) => _reblog(account, pin, 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); From 6951dcde2661a5a5fd9b36b9da1b4c5eb3f372c9 Mon Sep 17 00:00:00 2001 From: u-e Date: Sun, 3 Mar 2019 22:15:23 +0300 Subject: [PATCH 2/2] ficed comments --- .../postView/view/postDisplayView.js | 4 +++- src/providers/esteem/ePoint.js | 18 +++++++++++------- src/providers/steem/dsteem.js | 17 +++++++++++------ 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/components/postView/view/postDisplayView.js b/src/components/postView/view/postDisplayView.js index 140866f90..67f8038f0 100644 --- a/src/components/postView/view/postDisplayView.js +++ b/src/components/postView/view/postDisplayView.js @@ -42,7 +42,9 @@ class PostDisplayView extends PureComponent { componentDidMount() { const { currentAccount, isLoggedIn } = this.props; - userActivity(currentAccount.name, 10); + if (isLoggedIn && currentAccount && currentAccount.name) { + userActivity(currentAccount.name, 10); + } } // Component Functions diff --git a/src/providers/esteem/ePoint.js b/src/providers/esteem/ePoint.js index 64c5f5891..a726f298e 100644 --- a/src/providers/esteem/ePoint.js +++ b/src/providers/esteem/ePoint.js @@ -1,17 +1,21 @@ import ePointApi from '../../config/ePoint'; -export const userActivity = (us, ty, bl = '', tx = '') => { - const params = { us, ty }; +export const userActivity = (username, type, blockNumber = '', transactionNumber = '') => { + const params = { username, type }; - if (bl) { - params.bl = bl; + if (blockNumber) { + params.blockNumber = blockNumber; } - if (tx) { - params.tx = tx; + if (transactionNumber) { + params.transactionNumber = transactionNumber; } - return ePointApi.post('/usr-activity', params).then(res => res.data); + 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) => { diff --git a/src/providers/steem/dsteem.js b/src/providers/steem/dsteem.js index 26bfc03ed..263125f19 100644 --- a/src/providers/steem/dsteem.js +++ b/src/providers/steem/dsteem.js @@ -382,10 +382,13 @@ export const getPostWithComments = async (user, permlink) => { * @param postingKey private posting key */ -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; -}); +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); @@ -776,8 +779,10 @@ const _postContent = async ( }; // Re-blog - -export const reblog = (account, pinCode, author, permlink) => _reblog(account, pin, author, permlink).then((resp) => { +// 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; });