Working on transfer feature

This commit is contained in:
Mustafa Buyukcelebi 2019-04-23 11:47:12 +03:00
parent 94860059df
commit 8f4467ca8f
8 changed files with 149 additions and 74 deletions

View File

@ -9,3 +9,4 @@ PODS_BUILD_DIR = ${BUILD_DIR}
PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
PODS_PODFILE_DIR_PATH = ${SRCROOT}/.
PODS_ROOT = ${SRCROOT}/Pods
USER_HEADER_SEARCH_PATHS = $(inherited) $(SRCROOT)/FLAnimatedImage/FLAnimatedImage

View File

@ -9,3 +9,4 @@ PODS_BUILD_DIR = ${BUILD_DIR}
PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
PODS_PODFILE_DIR_PATH = ${SRCROOT}/.
PODS_ROOT = ${SRCROOT}/Pods
USER_HEADER_SEARCH_PATHS = $(inherited) $(SRCROOT)/FLAnimatedImage/FLAnimatedImage

View File

@ -8,3 +8,4 @@ PODS_BUILD_DIR = ${BUILD_DIR}
PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
PODS_PODFILE_DIR_PATH = ${SRCROOT}/.
PODS_ROOT = ${SRCROOT}/Pods
USER_HEADER_SEARCH_PATHS = $(inherited) $(SRCROOT)/FLAnimatedImage/FLAnimatedImage

View File

@ -8,3 +8,4 @@ PODS_BUILD_DIR = ${BUILD_DIR}
PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
PODS_PODFILE_DIR_PATH = ${SRCROOT}/.
PODS_ROOT = ${SRCROOT}/Pods
USER_HEADER_SEARCH_PATHS = $(inherited) $(SRCROOT)/FLAnimatedImage/FLAnimatedImage

View File

@ -27,10 +27,15 @@ class WalletContainer extends PureComponent {
// Component Functions
_navigate = () => {
const { dispatch, setPinCodeState } = this.props;
const { dispatch, setPinCodeState, navigation } = this.props;
setPinCodeState({ navigateTo: ROUTES.SCREENS.TRANSFER });
dispatch(openPinCodeModal());
navigation.navigate(ROUTES.SCREENS.TRANSFER, {
transferType: 'transferToSaving',
fundType: 'STEEM',
});
// setPinCodeState({ navigateTo: ROUTES.SCREENS.TRANSFER, navigateParams: {transferType: 'sbd'} });
// dispatch(openPinCodeModal());
};
render() {

View File

@ -463,52 +463,15 @@ export const transferToken = (currentAccount, pin, data) => {
const digitPinCode = getDigitPinCode(pin);
const key = getAnyPrivateKey({ activeKey: currentAccount.local.activeKey }, digitPinCode);
if (currentAccount.local.authType === AUTH_TYPE.STEEM_CONNECT) {
const token = decryptKey(currentAccount.local.accessToken, digitPinCode);
console.log('currentAccount.local :', currentAccount.local);
console.log('token :', token);
const api = steemConnect.Initialize({
accessToken: token,
});
console.log('api :', api);
const opArr = [];
const e = [
'transfer',
{
from: data.from,
to: data.destination,
amount: {
amount: data.amount,
precision: 3,
nai: '@@000000021',
},
memo: 'Thanks for all the fish.',
},
];
opArr.push(e);
console.log('opArr :', opArr);
api
.broadcast(opArr)
.then(res => console.log('res1111111 :', res))
.catch(err => console.log('err1111111 :', Object.keys(err), err.name, err.error, err.error_description));
return api.broadcast(opArr);
}
if (key) {
const privateKey = PrivateKey.fromString(key);
const args = {
from: data.from,
to: data.destination,
amount: `${data.amount} STEEM`,
amount: data.amount,
memo: data.memo,
};
console.log('args :', args);
console.log('privateKey :', privateKey);
console.log('key :', key);
return new Promise((resolve, reject) => {
client.broadcast
.transfer(args, privateKey)
@ -524,6 +487,101 @@ export const transferToken = (currentAccount, pin, data) => {
return Promise.reject(new Error('You dont have permission!'));
};
export const transferToSavings = (currentAccount, pin, data) => {
const digitPinCode = getDigitPinCode(pin);
const key = getAnyPrivateKey({ activeKey: currentAccount.local.activeKey }, digitPinCode);
if (key) {
const privateKey = PrivateKey.fromString(key);
const args = [
'transfer_to_savings',
{
from: data.from,
to: data.destination,
amount: data.amount,
memo: data.memo,
},
];
console.log('args :', args);
return new Promise((resolve, reject) => {
client.broadcast
.sendOperations(args, privateKey)
.then((result) => {
resolve(result);
})
.catch((err) => {
reject(err);
});
});
}
return Promise.reject(new Error('You dont have permission!'));
};
export const transferFromSavings = (currentAccount, pin, data) => {
const digitPinCode = getDigitPinCode(pin);
const key = getAnyPrivateKey({ activeKey: currentAccount.local.activeKey }, digitPinCode);
if (key) {
const privateKey = PrivateKey.fromString(key);
const args = [
'transfer_from_savings',
{
from: data.from,
to: data.destination,
amount: data.amount,
memo: data.memo,
request_id: data.requestId,
},
];
return new Promise((resolve, reject) => {
client.broadcast
.sendOperations(args, privateKey)
.then((result) => {
resolve(result);
})
.catch((err) => {
reject(err);
});
});
}
return Promise.reject(new Error('You dont have permission!'));
};
export const transferToVesting = (currentAccount, pin, data) => {
const digitPinCode = getDigitPinCode(pin);
const key = getAnyPrivateKey({ activeKey: currentAccount.local.activeKey }, digitPinCode);
if (key) {
const privateKey = PrivateKey.fromString(key);
const args = [
'transfer_to_vesting',
{
from: data.from,
to: data.destination,
amount: data.amount,
},
];
return new Promise((resolve, reject) => {
client.broadcast
.sendOperations(args, privateKey)
.then((result) => {
resolve(result);
})
.catch((err) => {
reject(err);
});
});
}
return Promise.reject(new Error('You dont have permission!'));
};
export const followUser = async (currentAccount, pin, data) => {
const digitPinCode = getDigitPinCode(pin);
const key = getAnyPrivateKey(currentAccount.local, digitPinCode);
@ -628,30 +686,6 @@ export const delegate = (data, activeKey) => {
});
};
export const transferToVesting = (data, activeKey) => {
const privateKey = PrivateKey.fromString(activeKey);
const op = [
'transfer_to_vesting',
{
from: data.from,
to: data.to,
amount: data.amount,
},
];
return new Promise((resolve, reject) => {
client.broadcast
.sendOperations([op], privateKey)
.then((result) => {
resolve(result);
})
.catch((error) => {
reject(error);
});
});
};
export const withdrawVesting = (data, activeKey) => {
const privateKey = PrivateKey.fromString(activeKey);
const op = [

View File

@ -127,12 +127,7 @@ export const unFollow = data => new Promise((resolve, reject) => {
*/
export const claimRewards = data => new Promise((resolve, reject) => {
steemConnect
.claimRewardBalance(
data.account,
data.rewardSteem,
data.rewardSBD,
data.VESTS,
)
.claimRewardBalance(data.account, data.rewardSteem, data.rewardSBD, data.VESTS)
.then((result) => {
resolve(result);
})

View File

@ -2,7 +2,13 @@ import React, { Component } from 'react';
import { connect } from 'react-redux';
// Services and Actions
import { lookupAccounts, transferToken } from '../../../providers/steem/dsteem';
import {
lookupAccounts,
transferToken,
transferFromSavings,
transferToSavings,
transferToVesting,
} from '../../../providers/steem/dsteem';
import { toastNotification } from '../../../redux/actions/uiAction';
// Middleware
@ -39,6 +45,10 @@ class ExampleContainer extends Component {
currentAccount, pinCode, navigation, dispatch,
} = this.props;
const transferType = navigation.getParam('transferType', '');
const fundType = navigation.getParam('fundType', '');
let func;
const data = {
from,
destination,
@ -46,12 +56,39 @@ class ExampleContainer extends Component {
memo,
};
transferToken(currentAccount, pinCode, data)
switch (transferType) {
case 'transferToken':
func = transferToken;
data.amount = `${data.amount} ${fundType}`;
break;
case 'transferToSaving':
func = transferToSavings;
data.amount = `${data.amount} ${fundType}`;
break;
case 'powerUp':
func = transferToVesting;
break;
case 'withdrawToSaving':
func = transferFromSavings;
data.requestId = new Date().getTime() >>> 0;
data.amount = `${data.amount} ${fundType}`;
break;
default:
break;
}
console.log('func :', func);
return func(currentAccount, pinCode, data)
.then((res) => {
console.log('res :', res);
dispatch(toastNotification('Successfull'));
navigation.goBack();
})
.catch(err => dispatch(toastNotification(err)));
.catch((err) => {
console.log('err :', err);
dispatch(toastNotification(err.message));
});
};
_handleOnModalClose = () => {