From f11020a2c4d72cd3520f998704d40ed42300fbba Mon Sep 17 00:00:00 2001 From: u-e Date: Fri, 14 Jun 2019 01:04:42 +0300 Subject: [PATCH] wip on transfer func --- .../points/container/pointsContainer.js | 7 +++- src/config/locales/en-US.json | 1 + src/providers/esteem/ePoint.js | 35 +++++++++++++++++++ src/providers/steem/dsteem.js | 4 +-- .../transfer/container/transferContainer.js | 14 +++++--- src/utils/points.js | 0 6 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 src/utils/points.js diff --git a/src/components/points/container/pointsContainer.js b/src/components/points/container/pointsContainer.js index 2239c2b9d..6dfb539a6 100644 --- a/src/components/points/container/pointsContainer.js +++ b/src/components/points/container/pointsContainer.js @@ -62,11 +62,16 @@ class PointsContainer extends Component { _handleOnPressTransfer = () => { const { dispatch } = this.props; + const { userPoints } = this.state; dispatch( openPinCodeModal({ navigateTo: ROUTES.SCREENS.TRANSFER, - navigateParams: { transferType: '', fundType: '', balance: '' }, + navigateParams: { + transferType: 'points', + fundType: 'ESTM', + balance: Math.round(get(userPoints, 'points') * 1000) / 1000, + }, }), ); }; diff --git a/src/config/locales/en-US.json b/src/config/locales/en-US.json index 50f123737..cd2fbc4fd 100644 --- a/src/config/locales/en-US.json +++ b/src/config/locales/en-US.json @@ -283,6 +283,7 @@ "to_placeholder": "Username", "memo_placeholder": "Enter your notes here", "transfer_token": "Transfer", + "points": "Points Transfer", "transfer_to_saving": "Transfer To Saving", "powerUp": "Power Up", "withdraw_to_saving": "Withdraw To Saving", diff --git a/src/providers/esteem/ePoint.js b/src/providers/esteem/ePoint.js index 823e9e5b5..9a4657bb0 100644 --- a/src/providers/esteem/ePoint.js +++ b/src/providers/esteem/ePoint.js @@ -1,6 +1,12 @@ import { Alert } from 'react-native'; +import { Client, PrivateKey } from 'dsteem'; import ePointApi from '../../config/ePoint'; +// Utils +import { decryptKey } from '../../utils/crypto'; + +const client = new Client(getItem('server', 'https://api.steemit.com')); + export const userActivity = (us, ty, bl = '', tx = '') => new Promise(resolve => { const params = { us, ty }; @@ -39,6 +45,35 @@ export const transfer = (sender, receiver, amount) => }); }); +export const transferPoint = (account, pin, to, amount, memo) => { + const { username: from } = account; + + const json = JSON.stringify({ + sender: from, + receiver: to, + amount, + memo, + }); + + if (account.type === 's' || true) { + const key = decryptKey(account.keys.active, pin); + const privateKey = PrivateKey.fromString(key); + + const op = { + id: 'esteem_point_transfer', + json, + required_auths: [from], + required_posting_auths: [], + }; + + return Client.broadcast.json(op, privateKey); + } + + if (account.type === 'sc') { + return sctTransferPoint(from, json); + } +}; + export const getUser = username => new Promise(resolve => { ePointApi diff --git a/src/providers/steem/dsteem.js b/src/providers/steem/dsteem.js index d7f7f6767..d268c07e8 100644 --- a/src/providers/steem/dsteem.js +++ b/src/providers/steem/dsteem.js @@ -514,7 +514,7 @@ export const upvoteAmount = async input => { return estimated; }; -export const transfer_token = (currentAccount, pin, data) => { +export const transferToken = (currentAccount, pin, data) => { const digitPinCode = getDigitPinCode(pin); const key = getAnyPrivateKey({ activeKey: currentAccount.local.activeKey }, digitPinCode); @@ -545,7 +545,7 @@ export const transfer_token = (currentAccount, pin, data) => { return Promise.reject(new Error('You dont have permission!')); }; -export const transfer_to_savings = (currentAccount, pin, data) => { +export const transferToSavings = (currentAccount, pin, data) => { const digitPinCode = getDigitPinCode(pin); const key = getAnyPrivateKey({ activeKey: currentAccount.local.activeKey }, digitPinCode); diff --git a/src/screens/transfer/container/transferContainer.js b/src/screens/transfer/container/transferContainer.js index 04a287f2f..c2311b24f 100644 --- a/src/screens/transfer/container/transferContainer.js +++ b/src/screens/transfer/container/transferContainer.js @@ -5,9 +5,9 @@ import { injectIntl } from 'react-intl'; // Services and Actions import { lookupAccounts, - transfer_token, + transferToken, transferFromSavings, - transfer_to_savings, + transferToSavings, transferToVesting, getAccount, } from '../../../providers/steem/dsteem'; @@ -55,6 +55,9 @@ class TransferContainer extends Component { case 'SBD': balance = account[0].sbd_balance.replace(fundType, ''); break; + case 'ESTM': + balance = navigation.getParam('balance', ''); + break; default: break; } @@ -90,10 +93,10 @@ class TransferContainer extends Component { switch (transferType) { case 'transfer_token': - func = transfer_token; + func = transferToken; break; case 'transfer_to_saving': - func = transfer_to_savings; + func = transferToSavings; break; case 'powerUp': func = transferToVesting; @@ -102,6 +105,9 @@ class TransferContainer extends Component { func = transferFromSavings; data.requestId = new Date().getTime() >>> 0; break; + case 'points': + alert('sss'); + break; default: break; diff --git a/src/utils/points.js b/src/utils/points.js new file mode 100644 index 000000000..e69de29bb