mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-11-28 01:52:56 +03:00
add SBD convert
This commit is contained in:
parent
c54c3c661e
commit
f3b735a139
@ -12,7 +12,7 @@ import styles from './walletDetailsStyles';
|
||||
|
||||
const WalletDetailsView = ({ walletData, intl, navigate, isShowDropdowns }) => {
|
||||
const steemDropdown = ['purchase_estm', 'transfer_token', 'transfer_to_saving', 'powerUp'];
|
||||
const sbdDropdown = ['purchase_estm', 'transfer_token', 'transfer_to_saving'];
|
||||
const sbdDropdown = ['purchase_estm', 'transfer_token', 'transfer_to_saving', 'convert'];
|
||||
const savingSteemDropdown = ['withdraw_steem'];
|
||||
const savingSbdDropdown = ['withdraw_sbd'];
|
||||
const steemPowerDropdown = ['delegate', 'power_down'];
|
||||
|
@ -410,10 +410,12 @@
|
||||
"information": "Are you sure to transfer funds?",
|
||||
"amount_desc": "Balance",
|
||||
"memo_desc": "This memo is public",
|
||||
"convert_desc": "Convert takes 3.5 days and NOT recommended IF SBD price is higher than $1",
|
||||
"to_placeholder": "Username",
|
||||
"memo_placeholder": "Enter your notes here",
|
||||
"transfer_token": "Transfer",
|
||||
"purchase_estm": "Purchase ESTM",
|
||||
"convert": "Convert SBD to STEEM",
|
||||
"points": "Gift ESTM to someone",
|
||||
"transfer_to_saving": "Transfer To Saving",
|
||||
"powerUp": "Power Up",
|
||||
|
@ -22,7 +22,7 @@ import { getEstimatedAmount } from '../utils/vote';
|
||||
import ROUTES from '../constants/routeNames';
|
||||
|
||||
const STEEM_DROPDOWN = ['purchase_estm', 'transfer_token', 'transfer_to_saving', 'powerUp'];
|
||||
const SBD_DROPDOWN = ['purchase_estm', 'transfer_token', 'transfer_to_saving'];
|
||||
const SBD_DROPDOWN = ['purchase_estm', 'transfer_token', 'transfer_to_saving', 'convert'];
|
||||
const SAVING_STEEM_DROPDOWN = ['withdraw_steem'];
|
||||
const SAVING_SBD_DROPDOWN = ['withdraw_sbd'];
|
||||
const STEEM_POWER_DROPDOWN = ['delegate', 'power_down'];
|
||||
@ -242,7 +242,9 @@ const WalletContainer = ({
|
||||
balance = Math.round(walletData.balance * 1000) / 1000;
|
||||
}
|
||||
if (
|
||||
(transferType === 'transfer_token' || transferType === 'purchase_estm') &&
|
||||
(transferType === 'transfer_token' ||
|
||||
transferType === 'convert' ||
|
||||
transferType === 'purchase_estm') &&
|
||||
fundType === 'SBD'
|
||||
) {
|
||||
balance = Math.round(walletData.sbdBalance * 1000) / 1000;
|
||||
|
@ -7,6 +7,7 @@ import get from 'lodash/get';
|
||||
import {
|
||||
lookupAccounts,
|
||||
transferToken,
|
||||
convert,
|
||||
transferFromSavings,
|
||||
transferToSavings,
|
||||
transferToVesting,
|
||||
@ -77,7 +78,9 @@ class TransferContainer extends Component {
|
||||
balance = account[0].balance.replace(fundType, '');
|
||||
}
|
||||
if (
|
||||
(transferType === 'purchase_estm' || transferType === 'transfer_token') &&
|
||||
(transferType === 'purchase_estm' ||
|
||||
transferType === 'convert' ||
|
||||
transferType === 'transfer_token') &&
|
||||
fundType === 'SBD'
|
||||
) {
|
||||
balance = account[0].sbd_balance.replace(fundType, '');
|
||||
@ -141,6 +144,10 @@ class TransferContainer extends Component {
|
||||
case 'purchase_estm':
|
||||
func = transferToken;
|
||||
break;
|
||||
case 'convert':
|
||||
func = convert;
|
||||
data.requestId = new Date().getTime() >>> 0;
|
||||
break;
|
||||
case 'transfer_to_saving':
|
||||
func = transferToSavings;
|
||||
break;
|
||||
|
@ -565,6 +565,41 @@ export const transferToken = (currentAccount, pin, data) => {
|
||||
return Promise.reject(new Error('Check private key permission!'));
|
||||
};
|
||||
|
||||
export const convert = (currentAccount, pin, data) => {
|
||||
const digitPinCode = getDigitPinCode(pin);
|
||||
const key = getAnyPrivateKey({ activeKey: get(currentAccount, 'local.activeKey') }, digitPinCode);
|
||||
|
||||
if (key) {
|
||||
const privateKey = PrivateKey.fromString(key);
|
||||
|
||||
const args = [
|
||||
[
|
||||
'convert',
|
||||
{
|
||||
owner: get(data, 'from'),
|
||||
amount: get(data, 'amount'),
|
||||
requestid: get(data, 'requestId'),
|
||||
},
|
||||
],
|
||||
];
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
client.broadcast
|
||||
.sendOperations(args, privateKey)
|
||||
.then(result => {
|
||||
if (result) {
|
||||
resolve(result);
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return Promise.reject(new Error('Check private key permission!'));
|
||||
};
|
||||
|
||||
export const transferToSavings = (currentAccount, pin, data) => {
|
||||
const digitPinCode = getDigitPinCode(pin);
|
||||
const key = getAnyPrivateKey({ activeKey: get(currentAccount, 'local.activeKey') }, digitPinCode);
|
||||
|
@ -26,6 +26,7 @@ const Transfer = ({ navigation }) => (
|
||||
switch (transferType) {
|
||||
case 'transfer_token':
|
||||
case 'purchase_estm':
|
||||
case 'convert':
|
||||
case 'transfer_to_saving':
|
||||
case 'powerUp':
|
||||
case 'points':
|
||||
|
@ -38,11 +38,14 @@ class TransferView extends Component {
|
||||
? props.currentAccountName
|
||||
: props.transferType === 'purchase_estm'
|
||||
? 'esteem.app'
|
||||
: props.transferType === 'convert'
|
||||
? props.currentAccountName
|
||||
: '',
|
||||
amount: '',
|
||||
memo: props.transferType === 'purchase_estm' ? 'estm-purchase' : '',
|
||||
isUsernameValid: !!(
|
||||
props.transferType === 'purchase_estm' ||
|
||||
props.transferType === 'convert' ||
|
||||
props.transferType === 'powerUp' ||
|
||||
props.transferType === 'withdraw_steem' ||
|
||||
(props.transferType === 'withdraw_steem' && props.currentAccountName)
|
||||
@ -132,10 +135,13 @@ class TransferView extends Component {
|
||||
);
|
||||
|
||||
_handleOnDropdownChange = value => {
|
||||
const { fetchBalance } = this.props;
|
||||
const { fetchBalance, transferType } = this.props;
|
||||
|
||||
fetchBalance(value);
|
||||
this.setState({ from: value });
|
||||
if (transferType === 'convert') {
|
||||
this.setState({ destination: value });
|
||||
}
|
||||
};
|
||||
|
||||
_renderDescription = text => <Text style={styles.description}>{text}</Text>;
|
||||
@ -198,16 +204,18 @@ class TransferView extends Component {
|
||||
label={intl.formatMessage({ id: 'transfer.from' })}
|
||||
rightComponent={() => this._renderDropdown(accounts, currentAccountName)}
|
||||
/>
|
||||
<TransferFormItem
|
||||
label={intl.formatMessage({ id: 'transfer.to' })}
|
||||
rightComponent={() =>
|
||||
this._renderInput(
|
||||
intl.formatMessage({ id: 'transfer.to_placeholder' }),
|
||||
'destination',
|
||||
'default',
|
||||
)
|
||||
}
|
||||
/>
|
||||
{transferType !== 'convert' && (
|
||||
<TransferFormItem
|
||||
label={intl.formatMessage({ id: 'transfer.to' })}
|
||||
rightComponent={() =>
|
||||
this._renderInput(
|
||||
intl.formatMessage({ id: 'transfer.to_placeholder' }),
|
||||
'destination',
|
||||
'default',
|
||||
)
|
||||
}
|
||||
/>
|
||||
)}
|
||||
<TransferFormItem
|
||||
label={intl.formatMessage({ id: 'transfer.amount' })}
|
||||
rightComponent={() =>
|
||||
@ -229,9 +237,7 @@ class TransferView extends Component {
|
||||
</TouchableOpacity>
|
||||
)}
|
||||
/>
|
||||
{(transferType === 'points' ||
|
||||
transferType === 'transfer_token' ||
|
||||
transferType === 'purchase_estm') && (
|
||||
{(transferType === 'points' || transferType === 'transfer_token') && (
|
||||
<TransferFormItem
|
||||
label={intl.formatMessage({ id: 'transfer.memo' })}
|
||||
rightComponent={() =>
|
||||
@ -244,15 +250,20 @@ class TransferView extends Component {
|
||||
}
|
||||
/>
|
||||
)}
|
||||
{(transferType === 'points' ||
|
||||
transferType === 'transfer_token' ||
|
||||
transferType === 'purchase_estm') && (
|
||||
{(transferType === 'points' || transferType === 'transfer_token') && (
|
||||
<TransferFormItem
|
||||
rightComponent={() =>
|
||||
this._renderDescription(intl.formatMessage({ id: 'transfer.memo_desc' }))
|
||||
}
|
||||
/>
|
||||
)}
|
||||
{transferType === 'convert' && (
|
||||
<TransferFormItem
|
||||
rightComponent={() =>
|
||||
this._renderDescription(intl.formatMessage({ id: 'transfer.convert_desc' }))
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</View>
|
||||
<View style={styles.bottomContent}>
|
||||
<MainButton
|
||||
|
Loading…
Reference in New Issue
Block a user