diff --git a/src/components/walletDetails/view/walletDetailsView.js b/src/components/walletDetails/view/walletDetailsView.js index 922ac8e8c..02d6bb98c 100644 --- a/src/components/walletDetails/view/walletDetailsView.js +++ b/src/components/walletDetails/view/walletDetailsView.js @@ -5,17 +5,22 @@ import { View } from 'react-native'; import { GrayWrapper, WalletLineItem } from '../../basicUIElements'; // Utilities -import { vestsToSp } from '../../../utils/conversions'; +import { vestsToHp } from '../../../utils/conversions'; // Styles 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', 'convert']; - const savingSteemDropdown = ['withdraw_steem']; - const savingSbdDropdown = ['withdraw_sbd']; - const steemPowerDropdown = ['delegate', 'power_down']; + const hiveDropdown = [ + 'purchase_estm', + 'transfer_token', + 'transfer_to_savings', + 'transfer_to_vesting', + ]; + const hbdDropdown = ['purchase_estm', 'transfer_token', 'transfer_to_savings', 'convert']; + const savingHiveDropdown = ['withdraw_hive']; + const savingHbdDropdown = ['withdraw_hbd']; + const hivePowerDropdown = ['delegate', 'power_down']; return ( @@ -26,10 +31,8 @@ const WalletDetailsView = ({ walletData, intl, navigate, isShowDropdowns }) => { rightText={`${Math.round(walletData.balance * 1000) / 1000} HIVE`} isBoldText isHasdropdown={isShowDropdowns} - dropdownOptions={steemDropdown.map((item) => - intl.formatMessage({ id: `transfer.${item}` }), - )} - onDropdownSelect={(index) => navigate(steemDropdown[index], 'HIVE')} + dropdownOptions={hiveDropdown.map((item) => intl.formatMessage({ id: `transfer.${item}` }))} + onDropdownSelect={(index) => navigate(hiveDropdown[index], 'HIVE')} /> { isBlackText iconName="ios-information-circle-outline" rightText={`${ - Math.round(vestsToSp(walletData.vestingShares, walletData.steemPerMVests) * 1000) / 1000 + Math.round(vestsToHp(walletData.vestingShares, walletData.hivePerMVests) * 1000) / 1000 } HP`} isBoldText isHasdropdown={isShowDropdowns} - dropdownOptions={steemPowerDropdown.map((item) => + dropdownOptions={hivePowerDropdown.map((item) => intl.formatMessage({ id: `transfer.${item}` }), )} - onDropdownSelect={(a) => navigate(steemPowerDropdown[a], 'HIVE_POWER')} + onDropdownSelect={(a) => navigate(hivePowerDropdown[a], 'HIVE_POWER')} /> {walletData.vestingSharesDelegated > 0 && ( { { { })} isBlackText iconName="ios-information-circle-outline" - rightText={`$${Math.round(walletData.sbdBalance * 1000) / 1000}`} + rightText={`$${Math.round(walletData.hbdBalance * 1000) / 1000}`} isBoldText isHasdropdown={isShowDropdowns} - dropdownOptions={sbdDropdown.map((item) => intl.formatMessage({ id: `transfer.${item}` }))} - onDropdownSelect={(a) => navigate(sbdDropdown[a], 'HBD')} + dropdownOptions={hbdDropdown.map((item) => intl.formatMessage({ id: `transfer.${item}` }))} + onDropdownSelect={(a) => navigate(hbdDropdown[a], 'HBD')} /> { rightText={`${Math.round(walletData.savingBalance * 1000) / 1000} HIVE`} isBoldText isHasdropdown={isShowDropdowns} - dropdownOptions={savingSteemDropdown.map((item) => + dropdownOptions={savingHiveDropdown.map((item) => intl.formatMessage({ id: `transfer.${item}` }), )} - onDropdownSelect={(a) => navigate(savingSteemDropdown[a], 'SAVING_HIVE')} + onDropdownSelect={(a) => navigate(savingHiveDropdown[a], 'SAVING_HIVE')} /> + dropdownOptions={savingHbdDropdown.map((item) => intl.formatMessage({ id: `transfer.${item}` }), )} - onDropdownSelect={(a) => navigate(savingSbdDropdown[a], 'SAVING_HBD')} + onDropdownSelect={(a) => navigate(savingHbdDropdown[a], 'SAVING_HBD')} /> {walletData.showPowerDown && ( diff --git a/src/config/locales/en-US.json b/src/config/locales/en-US.json index bb78b000b..2378c72ed 100644 --- a/src/config/locales/en-US.json +++ b/src/config/locales/en-US.json @@ -5,7 +5,7 @@ "comment_benefactor_reward": "Benefactor Reward", "claim_reward_balance": "Claim Reward ", "transfer": "Transfer", - "transfer_to_vesting": "To Vesting", + "power_up": "To Vesting", "transfer_from_savings": "From Savings", "withdraw_vesting": "Power Down", "fill_order": "Fill Order", @@ -62,14 +62,14 @@ "purchase_estm": "GET POINTS", "points": "Gift Points to someone", "transfer_to_saving": "To Saving", - "powerUp": "Power Up", + "transfer_to_vesting": "Power Up", "withdraw_to_saving": "Withdraw Saving", "steemconnect_title": "Hivesigner Transfer", "next": "NEXT", "delegate": "Delegate", "power_down": "Power Down", - "withdraw_steem": "Withdraw HIVE", - "withdraw_sbd": "Withdraw HBD", + "withdraw_hive": "Withdraw HIVE", + "withdraw_hbd": "Withdraw HBD", "transfer_to_savings": "To Savings", "convert": "Convert", "escrow_transfer": "Escrow Transfer", @@ -85,21 +85,21 @@ "title": "Points", "buy": "GET POINTS" }, - "savingsteem": { + "savinghive": { "title": "HIVE Savings" }, - "savingsbd": { + "savinghbd": { "title": "HBD Savings" }, - "steem": { + "hive": { "title": "HIVE", "buy": "GET HIVE" }, - "sbd": { + "hbd": { "title": "HBD", "buy": "GET HBD" }, - "steem_power": { + "hive_power": { "title": "HIVE POWER" }, "btc": { @@ -162,11 +162,11 @@ "follow_communities": "Join some communities to fill your feed", "havent_commented": "haven't commented anything yet", "havent_posted": "haven't posted anything yet", - "steem_power": "Hive Power", + "hive_power": "Hive Power", "next_power_text": "Next power down is in", "days": "days", "day": "day", - "steem_dollars": "Hive Dollars", + "hive_dollars": "Hive Dollars", "savings": "Savings", "edit": { "display_name": "Display Name", @@ -511,8 +511,8 @@ "purchase_estm": "Purchase Points", "convert": "Convert HBD to HIVE", "points": "Gift Points to someone", - "transfer_to_saving": "Transfer To Saving", - "powerUp": "Power Up", + "transfer_to_savings": "Transfer To Saving", + "transfer_to_vesting": "Power Up", "withdraw_to_saving": "Withdraw To Saving", "steemconnect_title": "Hivesigner Transfer", "estimated_weekly": "Estimated Weekly", @@ -525,10 +525,11 @@ "next": "NEXT", "delegate": "Delegate", "power_down": "Power Down", - "withdraw_steem": "Withdraw HIVE", - "withdraw_sbd": "Withdraw HIVE Dollar", + "withdraw_hive": "Withdraw HIVE", + "withdraw_hbd": "Withdraw HIVE Dollar", "incoming_funds": "Incoming Funds", "stop": "Stop", + "sc_power_down_error": "This feature is not implemented for Hivesigner login, yet", "address_view": "View address" }, "boost": { diff --git a/src/containers/transferContainer.js b/src/containers/transferContainer.js index ab9411530..8b03c938e 100644 --- a/src/containers/transferContainer.js +++ b/src/containers/transferContainer.js @@ -85,18 +85,18 @@ class TransferContainer extends Component { transferType === 'transfer_token') && fundType === 'HBD' ) { - balance = account[0].sbd_balance.replace(fundType, ''); + balance = account[0].hbd_balance.replace(fundType, ''); } if (transferType === 'points' && fundType === 'ESTM') { this._getUserPointsBalance(username); } - if (transferType === 'transfer_to_saving' && fundType === 'HIVE') { + if (transferType === 'transfer_to_savings' && fundType === 'HIVE') { balance = account[0].balance.replace(fundType, ''); } - if (transferType === 'transfer_to_saving' && fundType === 'HBD') { - balance = account[0].sbd_balance.replace(fundType, ''); + if (transferType === 'transfer_to_savings' && fundType === 'HBD') { + balance = account[0].hbd_balance.replace(fundType, ''); } - if (transferType === 'powerUp' && fundType === 'HIVE') { + if (transferType === 'transfer_to_vesting' && fundType === 'HIVE') { balance = account[0].balance.replace(fundType, ''); } if (transferType === 'address_view' && fundType === 'BTC') { @@ -142,7 +142,6 @@ class TransferContainer extends Component { } data.amount = `${data.amount} ${fundType}`; - switch (transferType) { case 'transfer_token': func = transferToken; @@ -154,17 +153,17 @@ class TransferContainer extends Component { func = convert; data.requestId = new Date().getTime() >>> 0; break; - case 'transfer_to_saving': + case 'transfer_to_savings': func = transferToSavings; break; - case 'powerUp': + case 'transfer_to_vesting': func = transferToVesting; break; - case 'withdraw_steem' || 'withdraw_hive': + case 'withdraw_hive': func = transferFromSavings; data.requestId = new Date().getTime() >>> 0; break; - case 'withdraw_sbd' || 'withdraw_hbd': + case 'withdraw_hbd': func = transferFromSavings; data.requestId = new Date().getTime() >>> 0; break; @@ -222,7 +221,7 @@ class TransferContainer extends Component { }; render() { - const { accounts, navigation, children, steemPerMVests, currentAccount } = this.props; + const { accounts, navigation, children, hivePerMVests, currentAccount } = this.props; const { balance, fundType, selectedAccount, tokenAddress } = this.state; const transferType = navigation.getParam('transferType', ''); @@ -236,7 +235,7 @@ class TransferContainer extends Component { fundType, transferType, selectedAccount, - steemPerMVests, + hivePerMVests, fetchBalance: this.fetchBalance, getAccountsWithUsername: this._getAccountsWithUsername, transferToAccount: this._transferToAccount, @@ -253,7 +252,7 @@ const mapStateToProps = (state) => ({ accounts: state.account.otherAccounts, currentAccount: state.account.currentAccount, pinCode: state.application.pin, - steemPerMVests: state.account.globalProps.steemPerMVests, + hivePerMVests: state.account.globalProps.hivePerMVests, }); export default connect(mapStateToProps)(injectIntl(TransferContainer)); diff --git a/src/containers/walletContainer.js b/src/containers/walletContainer.js index b923df5a8..42bf5f65b 100644 --- a/src/containers/walletContainer.js +++ b/src/containers/walletContainer.js @@ -5,7 +5,7 @@ import { useIntl } from 'react-intl'; import get from 'lodash/get'; import { toastNotification } from '../redux/actions/uiAction'; -// Dsteem +// dhive import { getAccount, claimRewardBalance, getBtcAddress } from '../providers/hive/dhive'; // Actions @@ -14,18 +14,23 @@ import { openPinCodeModal } from '../redux/actions/applicationActions'; // Utils import { groomingWalletData, groomingTransactionData, transferTypes } from '../utils/wallet'; import parseToken from '../utils/parseToken'; -import { vestsToSp } from '../utils/conversions'; +import { vestsToHp } from '../utils/conversions'; import { navigate } from '../navigation/service'; import { getEstimatedAmount } from '../utils/vote'; // Constants import ROUTES from '../constants/routeNames'; -const HIVE_DROPDOWN = ['purchase_estm', 'transfer_token', 'transfer_to_saving', 'powerUp']; +const HIVE_DROPDOWN = [ + 'purchase_estm', + 'transfer_token', + 'transfer_to_savings', + 'transfer_to_vesting', +]; const BTC_DROPDOWN = ['transfer_token']; -const HBD_DROPDOWN = ['purchase_estm', 'transfer_token', 'transfer_to_saving', 'convert']; -const SAVING_HIVE_DROPDOWN = ['withdraw_steem']; -const SAVING_HBD_DROPDOWN = ['withdraw_sbd']; +const HBD_DROPDOWN = ['purchase_estm', 'transfer_token', 'transfer_to_savings', 'convert']; +const SAVING_HIVE_DROPDOWN = ['withdraw_hive']; +const SAVING_HBD_DROPDOWN = ['withdraw_hbd']; const HIVE_POWER_DROPDOWN = ['delegate', 'power_down']; const WalletContainer = ({ @@ -36,7 +41,7 @@ const WalletContainer = ({ pinCode, selectedUser, setEstimatedWalletValue, - steemPerMVests, + hivePerMVests, isPinCodeOpen, currency, }) => { @@ -45,18 +50,18 @@ const WalletContainer = ({ const [refreshing, setRefreshing] = useState(false); const [walletData, setWalletData] = useState(null); const [userActivities, setUserActivities] = useState([]); - const [sbdBalance, setSbdBalance] = useState(0); + const [hbdBalance, setHbdBalance] = useState(0); const [tokenBalance, setTokenBalance] = useState(0); const [tokenAddress, setTokenAddress] = useState(''); - const [steemBalance, setSteemBalance] = useState(0); - const [spBalance, setSpBalance] = useState(0); - const [steemSavingBalance, setSteemSavingBalance] = useState(0); - const [sbdSavingBalance, setSbdSavingBalance] = useState(0); + const [hiveBalance, setHiveBalance] = useState(0); + const [hpBalance, setHpBalance] = useState(0); + const [hiveSavingBalance, setHiveSavingBalance] = useState(0); + const [hbdSavingBalance, setHbdSavingBalance] = useState(0); const [estimatedValue, setEstimatedValue] = useState(0); - const [estimatedSteemValue, setEstimatedSteemValue] = useState(0); - const [estimatedSbdValue, setEstimatedSbdValue] = useState(0); + const [estimatedHiveValue, setEstimatedHiveValue] = useState(0); + const [estimatedHbdValue, setEstimatedHbdValue] = useState(0); const [estimatedTokenValue, setEstimatedTokenValue] = useState(0); - const [estimatedSpValue, setEstimatedSpValue] = useState(0); + const [estimatedHpValue, setEstimatedHpValue] = useState(0); const [unclaimedBalance, setUnclaimedBalance] = useState(''); const [estimatedAmount, setEstimatedAmount] = useState(0); const [delegationsAmount, setDelegationsAmount] = useState(0); @@ -78,41 +83,41 @@ const WalletContainer = ({ ); setTransferHistory(_transferHistory); - setSbdBalance(Math.round(get(walletData, 'sbdBalance', 0) * 1000) / 1000); + setHbdBalance(Math.round(get(walletData, 'hbdBalance', 0) * 1000) / 1000); setTokenBalance(Math.round(get(walletData, 'tokenBalance', 0) * 1000) / 1000); setTokenAddress(get(walletData, 'tokenAddress', '')); - setSteemBalance(Math.round(get(walletData, 'balance', 0) * 1000) / 1000); - setSteemSavingBalance(Math.round(get(walletData, 'savingBalance', 0) * 1000) / 1000); - setSbdSavingBalance(Math.round(get(walletData, 'savingBalanceSbd', 0) * 1000) / 1000); - setSpBalance( + setHiveBalance(Math.round(get(walletData, 'balance', 0) * 1000) / 1000); + setHiveSavingBalance(Math.round(get(walletData, 'savingBalance', 0) * 1000) / 1000); + setHbdSavingBalance(Math.round(get(walletData, 'savingBalanceHbd', 0) * 1000) / 1000); + setHpBalance( Math.round( - vestsToSp(get(walletData, 'vestingShares', 0), get(walletData, 'steemPerMVests', 0)) * 1000, + vestsToHp(get(walletData, 'vestingShares', 0), get(walletData, 'hivePerMVests', 0)) * 1000, ) / 1000, ); setEstimatedValue(get(walletData, 'estimatedValue', 0)); - setEstimatedSteemValue(get(walletData, 'estimatedSteemValue', 0)); - setEstimatedSbdValue(get(walletData, 'estimatedSbdValue', 0)); + setEstimatedHiveValue(get(walletData, 'estimatedHiveValue', 0)); + setEstimatedHbdValue(get(walletData, 'estimatedHbdValue', 0)); setEstimatedTokenValue(get(walletData, 'estimatedTokenValue', 0)); - setEstimatedSpValue(get(walletData, 'estimatedSpValue', 0)); + setEstimatedHpValue(get(walletData, 'estimatedHpValue', 0)); setDelegationsAmount( - vestsToSp( + vestsToHp( get(walletData, 'vestingSharesReceived', 0) - get(walletData, 'vestingSharesDelegated', 0), - get(walletData, 'steemPerMVests', 0), + get(walletData, 'hivePerMVests', 0), ).toFixed(3), ); if ( - get(walletData, 'rewardSteemBalance', 0) || - get(walletData, 'rewardSbdBalance', 0) || - get(walletData, 'rewardVestingSteem', 0) + get(walletData, 'rewardHiveBalance', 0) || + get(walletData, 'rewardHbdBalance', 0) || + get(walletData, 'rewardVestingHive', 0) ) { const getBalance = (val, cur) => (val ? Math.round(val * 1000) / 1000 + cur : ''); setUnclaimedBalance( - `${getBalance(get(walletData, 'rewardSteemBalance', 0), ' HIVE')} ${getBalance( - get(walletData, 'rewardSbdBalance', 0), + `${getBalance(get(walletData, 'rewardHiveBalance', 0), ' HIVE')} ${getBalance( + get(walletData, 'rewardHbdBalance', 0), ' HBD', - )} ${getBalance(get(walletData, 'rewardVestingSteem', 0), ' HP')}`, + )} ${getBalance(get(walletData, 'rewardVestingHive', 0), ' HP')}`, ); } }, [userActivities, walletData]); @@ -127,19 +132,19 @@ const WalletContainer = ({ setIsLoading(false); setUserActivities( get(_walletData, 'transactions', []).map((item) => - groomingTransactionData(item, steemPerMVests), + groomingTransactionData(item, hivePerMVests), ), ); setEstimatedWalletValue && setEstimatedWalletValue(_walletData.estimatedValue); const getBalance = (val, cur) => (val ? Math.round(val * 1000) / 1000 + cur : ''); setUnclaimedBalance( - `${getBalance(get(_walletData, 'rewardSteemBalance', 0), ' HIVE')} ${getBalance( - get(_walletData, 'rewardSbdBalance', 0), + `${getBalance(get(_walletData, 'rewardHiveBalance', 0), ' HIVE')} ${getBalance( + get(_walletData, 'rewardHbdBalance', 0), ' HBD', - )} ${getBalance(get(_walletData, 'rewardVestingSteem', 0), ' HP')}`, + )} ${getBalance(get(_walletData, 'rewardVestingHive', 0), ' HP')}`, ); }, - [globalProps, setEstimatedWalletValue, steemPerMVests], + [globalProps, setEstimatedWalletValue, hivePerMVests], ); const _isHasUnclaimedRewards = (account) => { @@ -164,11 +169,11 @@ const WalletContainer = ({ isHasUnclaimedRewards = _isHasUnclaimedRewards(account[0]); if (isHasUnclaimedRewards) { const { - reward_hive_balance: steemBal, - reward_hbd_balance: sbdBal, + reward_hive_balance: hiveBal, + reward_hbd_balance: hbdBal, reward_vesting_balance: vestingBal, } = account[0]; - return claimRewardBalance(currentAccount, pinCode, steemBal, sbdBal, vestingBal); + return claimRewardBalance(currentAccount, pinCode, hiveBal, hbdBal, vestingBal); } setIsClaiming(false); }) @@ -238,19 +243,13 @@ const WalletContainer = ({ transferType === 'purchase_estm') && fundType === 'HBD' ) { - balance = Math.round(walletData.sbdBalance * 1000) / 1000; + balance = Math.round(walletData.hbdBalance * 1000) / 1000; } - if ( - (transferType === 'withdraw_steem' || transferType === 'withdraw_hive') && - fundType === 'HIVE' - ) { + if (transferType === 'withdraw_hive' && fundType === 'HIVE') { balance = Math.round(walletData.savingBalance * 1000) / 1000; } - if ( - (transferType === 'withdraw_sbd' || transferType === 'withdraw_hbd') && - fundType === 'HBD' - ) { - balance = Math.round(walletData.savingBalanceSbd * 1000) / 1000; + if (transferType === 'withdraw_hbd' && fundType === 'HBD') { + balance = Math.round(walletData.savingBalanceHbd * 1000) / 1000; } if (isPinCodeOpen) { @@ -285,29 +284,29 @@ const WalletContainer = ({ selectedUsername: get(selectedUser, 'name', ''), isLoading, walletData, - steemPerMVests, + hivePerMVests, userActivities, transferHistory, - steemBalance, - spBalance, - sbdBalance, + hiveBalance, + hpBalance, + hbdBalance, tokenBalance, getTokenAddress, - steemSavingBalance, - sbdSavingBalance, + hiveSavingBalance, + hbdSavingBalance, estimatedValue, - estimatedSteemValue, - estimatedSbdValue, + estimatedHiveValue, + estimatedHbdValue, estimatedTokenValue, - estimatedSpValue, + estimatedHpValue, delegationsAmount, navigate: _navigate, - steemDropdown: HIVE_DROPDOWN, - sbdDropdown: HBD_DROPDOWN, + hiveDropdown: HIVE_DROPDOWN, + hbdDropdown: HBD_DROPDOWN, btcDropdown: BTC_DROPDOWN, - savingSteemDropdown: SAVING_HIVE_DROPDOWN, - savingSbdDropdown: SAVING_HBD_DROPDOWN, - steemPowerDropdown: HIVE_POWER_DROPDOWN, + savingHiveDropdown: SAVING_HIVE_DROPDOWN, + savingHbdDropdown: SAVING_HBD_DROPDOWN, + hivePowerDropdown: HIVE_POWER_DROPDOWN, unclaimedBalance: unclaimedBalance && unclaimedBalance.trim(), estimatedAmount, }) @@ -319,7 +318,7 @@ const mapStateToProps = (state) => ({ pinCode: state.application.pin, globalProps: state.account.globalProps, currency: state.application.currency.currency, - steemPerMVests: state.account.globalProps.steemPerMVests, + hivePerMVests: state.account.globalProps.hivePerMVests, isPinCodeOpen: state.application.isPinCodeOpen, }); diff --git a/src/providers/hive/dhive.js b/src/providers/hive/dhive.js index 3b879e337..2cde3a7c1 100644 --- a/src/providers/hive/dhive.js +++ b/src/providers/hive/dhive.js @@ -78,29 +78,27 @@ export const fetchGlobalProps = async () => { globalDynamic = await getDynamicGlobalProperties(); await setCache('globalDynamic', globalDynamic); feedHistory = await getFeedHistory(); - await setCache('feedHistory', feedHistory); rewardFund = await getRewardFund(); - await setCache('rewardFund', rewardFund); } catch (e) { return; } - const steemPerMVests = + const hivePerMVests = (parseToken(get(globalDynamic, 'total_vesting_fund_hive')) / parseToken(get(globalDynamic, 'total_vesting_shares'))) * 1e6; - const sbdPrintRate = get(globalDynamic, 'hbd_print_rate'); + const hbdPrintRate = get(globalDynamic, 'hbd_print_rate'); const base = parseAsset(get(feedHistory, 'current_median_history.base')).amount; const quote = parseAsset(get(feedHistory, 'current_median_history.quote')).amount; const fundRecentClaims = get(rewardFund, 'recent_claims'); const fundRewardBalance = parseToken(get(rewardFund, 'reward_balance')); const globalProps = { - steemPerMVests, + hivePerMVests, base, quote, fundRecentClaims, fundRewardBalance, - sbdPrintRate, + hbdPrintRate, }; return globalProps; @@ -186,7 +184,12 @@ export const getUser = async (user, loggedIn = true) => { return null; } - const globalProperties = getCache('globalDynamic'); + let globalProperties; + try { + globalProperties = await getDynamicGlobalProperties(); + } catch (error) { + globalProperties = getCache('globalDynamic'); + } const rcPower = (user && @@ -1357,7 +1360,7 @@ const _reblog = async (account, pinCode, author, permlink) => { ); }; -export const claimRewardBalance = (account, pinCode, rewardSteem, rewardSbd, rewardVests) => { +export const claimRewardBalance = (account, pinCode, rewardHive, rewardHbd, rewardVests) => { const pin = getDigitPinCode(pinCode); const key = getAnyPrivateKey(get(account, 'local'), pin); @@ -1367,7 +1370,7 @@ export const claimRewardBalance = (account, pinCode, rewardSteem, rewardSbd, rew accessToken: token, }); - return api.claimRewardBalance(get(account, 'name'), rewardSteem, rewardSbd, rewardVests); + return api.claimRewardBalance(get(account, 'name'), rewardHive, rewardHbd, rewardVests); } if (key) { @@ -1378,8 +1381,8 @@ export const claimRewardBalance = (account, pinCode, rewardSteem, rewardSbd, rew 'claim_reward_balance', { account: account.name, - reward_hive: rewardSteem, - reward_hbd: rewardSbd, + reward_hive: rewardHive, + reward_hbd: rewardHbd, reward_vests: rewardVests, }, ], diff --git a/src/screens/transfer/index.js b/src/screens/transfer/index.js index 6dca69694..2018830a4 100644 --- a/src/screens/transfer/index.js +++ b/src/screens/transfer/index.js @@ -21,18 +21,18 @@ const Transfer = ({ navigation }) => ( handleOnModalClose, accountType, currentAccountName, - steemPerMVests, + hivePerMVests, setWithdrawVestingRoute, }) => { switch (transferType) { case 'transfer_token': case 'purchase_estm': case 'convert': - case 'transfer_to_saving': - case 'powerUp': + case 'transfer_to_savings': + case 'transfer_to_vesting': case 'points': - case 'withdraw_steem': - case 'withdraw_sbd': + case 'withdraw_hive': + case 'withdraw_hbd': return ( ( transferToAccount={transferToAccount} accountType={accountType} handleOnModalClose={handleOnModalClose} - steemPerMVests={steemPerMVests} + hivePerMVests={hivePerMVests} /> ); case 'power_down': @@ -77,7 +77,7 @@ const Transfer = ({ navigation }) => ( accountType={accountType} currentAccountName={currentAccountName} selectedAccount={selectedAccount} - steemPerMVests={steemPerMVests} + hivePerMVests={hivePerMVests} setWithdrawVestingRoute={setWithdrawVestingRoute} /> ); diff --git a/src/screens/transfer/screen/delegateScreen.js b/src/screens/transfer/screen/delegateScreen.js index 928685781..2b04542e1 100644 --- a/src/screens/transfer/screen/delegateScreen.js +++ b/src/screens/transfer/screen/delegateScreen.js @@ -24,7 +24,7 @@ import { import parseToken from '../../../utils/parseToken'; import { isEmptyDate } from '../../../utils/time'; -import { vestsToSp } from '../../../utils/conversions'; +import { vestsToHp } from '../../../utils/conversions'; // Styles import styles from './transferStyles'; @@ -138,11 +138,11 @@ class DelegateScreen extends Component { currentAccountName, selectedAccount, handleOnModalClose, - steemPerMVests, + hivePerMVests, + accountType, } = this.props; const { amount, isTransfering, from, destination, steemConnectTransfer } = this.state; let availableVestingShares = 0; - if (!isEmptyDate(get(selectedAccount, 'next_vesting_withdrawal'))) { // powering down availableVestingShares = @@ -162,7 +162,7 @@ class DelegateScreen extends Component { fixedAmount, )}`; - const spCalculated = vestsToSp(amount, steemPerMVests); + const spCalculated = vestsToHp(amount, hivePerMVests); return ( diff --git a/src/screens/transfer/screen/powerDownScreen.js b/src/screens/transfer/screen/powerDownScreen.js index ceb4414a3..63be9de32 100644 --- a/src/screens/transfer/screen/powerDownScreen.js +++ b/src/screens/transfer/screen/powerDownScreen.js @@ -24,7 +24,7 @@ import WithdrawAccountModal from './withdrawAccountModal'; import parseToken from '../../../utils/parseToken'; import parseDate from '../../../utils/parseDate'; -import { vestsToSp } from '../../../utils/conversions'; +import { vestsToHp } from '../../../utils/conversions'; import { isEmptyDate } from '../../../utils/time'; import styles from './transferStyles'; @@ -80,6 +80,7 @@ class PowerDownView extends Component { intl.formatMessage({ id: 'alert.warning' }), intl.formatMessage({ id: 'transfer.sc_power_down_error' }), ); + this.setState({ steemConnectTransfer: true, isTransfering: false }); } else { transferToAccount(from, destinationAccounts, amount, ''); } @@ -198,7 +199,7 @@ class PowerDownView extends Component { getAccountsWithUsername, transferType, currentAccountName, - steemPerMVests, + hivePerMVests, } = this.props; const { amount, isTransfering, isOpenWithdrawAccount } = this.state; let poweringDownVests = 0; @@ -210,7 +211,7 @@ class PowerDownView extends Component { if (poweringDown) { poweringDownVests = parseToken(get(selectedAccount, 'vesting_withdraw_rate')); - poweringDownFund = vestsToSp(poweringDownVests, steemPerMVests).toFixed(3); + poweringDownFund = vestsToHp(poweringDownVests, hivePerMVests).toFixed(3); } else { availableVestingShares = parseToken(get(selectedAccount, 'vesting_shares')) - @@ -219,7 +220,7 @@ class PowerDownView extends Component { parseToken(get(selectedAccount, 'delegated_vesting_shares')); } - const spCalculated = vestsToSp(amount, steemPerMVests); + const spCalculated = vestsToHp(amount, hivePerMVests); const fundPerWeek = Math.round((spCalculated / 13) * 1000) / 1000; return ( diff --git a/src/screens/transfer/screen/transferScreen.js b/src/screens/transfer/screen/transferScreen.js index ff3e630dd..ee3ab2ae8 100644 --- a/src/screens/transfer/screen/transferScreen.js +++ b/src/screens/transfer/screen/transferScreen.js @@ -1,4 +1,4 @@ -import React, { Fragment, Component } from 'react'; +import React, { Fragment, Component, useState, useRef, useEffect } from 'react'; import { Text, View, ScrollView, TouchableOpacity } from 'react-native'; import { WebView } from 'react-native-webview'; import ActionSheet from 'react-native-actionsheet'; @@ -21,96 +21,98 @@ import { import styles from './transferStyles'; -/* Props - * ------------------------------------------------ - * @prop { type } name - Description.... - */ +const TransferView = ({ + currentAccountName, + transferType, + getAccountsWithUsername, + balance, + transferToAccount, + accountType, + accounts, + intl, + handleOnModalClose, + fundType, + selectedAccount, + fetchBalance, +}) => { + const [from, setFrom] = useState(currentAccountName); + const [destination, setDestination] = useState( + transferType === 'transfer_to_vesting' || + transferType === 'transfer_to_savings' || + transferType === 'withdraw_vesting' || + transferType === 'withdraw_hive' || + transferType === 'withdraw_hbd' || + transferType === 'convert' + ? currentAccountName + : transferType === 'purchase_estm' + ? 'esteem.app' + : '', + ); + const [amount, setAmount] = useState(''); + const [memo, setMemo] = useState(transferType === 'purchase_estm' ? 'estm-purchase' : ''); + const [isUsernameValid, setIsUsernameValid] = useState( + !!( + transferType === 'purchase_estm' || + transferType === 'transfer_to_vesting' || + transferType === 'transfer_to_savings' || + transferType === 'withdraw_vesting' || + transferType === 'withdraw_hive' || + transferType === 'withdraw_hbd' || + (transferType === 'convert' && currentAccountName) + ), + ); + const [hsTransfer, setHsTransfer] = useState(false); + const [isTransfering, setIsTransfering] = useState(false); + const confirm = useRef(null); -class TransferView extends Component { - constructor(props) { - super(props); - this.state = { - from: props.currentAccountName, - destination: - props.transferType === 'powerUp' || - props.transferType === 'withdraw_steem' || - props.transferType === 'withdraw_steem' - ? 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) - ), - steemConnectTransfer: false, - isTransfering: false, - }; - } - - // Component Life Cycles - - // Component Functions - _setState = (key, value) => { - const { getAccountsWithUsername, balance } = this.props; - - if (key) { - switch (key) { - case 'destination': - getAccountsWithUsername(value).then((res) => { - const isValid = res.includes(value); - - this.setState({ isUsernameValid: isValid }); - }); - this.setState({ [key]: value }); - break; - case 'amount': - if (parseFloat(Number(value)) <= parseFloat(balance)) { - this.setState({ [key]: value }); - } - break; - - default: - this.setState({ [key]: value }); - break; - } - } - }; - - _handleTransferAction = () => { - const { transferToAccount, accountType } = this.props; - const { from, destination, amount, memo } = this.state; - - this.setState({ isTransfering: true }); + //useEffect(() => { + //}, []); + const _handleTransferAction = () => { + setIsTransfering(true); if (accountType === AUTH_TYPE.STEEM_CONNECT) { - this.setState({ steemConnectTransfer: true }); + setHsTransfer(true); } else { transferToAccount(from, destination, amount, memo); } }; - _handleOnAmountChange = (state, amount) => { - let _amount = amount.toString(); + const _handleOnChange = (state, val) => { + let _amount = val.toString(); if (_amount.includes(',')) { - _amount = amount.replace(',', '.'); + _amount = val.replace(',', '.'); } + if (state === 'amount') { + if (parseFloat(Number(_amount)) <= parseFloat(balance)) { + setAmount(_amount); + } + } + if (state === 'destination') { + getAccountsWithUsername(val).then((res) => { + const isValid = res.includes(val); - this._setState(state, _amount); + setIsUsernameValid(isValid); + }); + setDestination(_amount); + } + if (state === 'memo') { + setMemo(_amount); + } }; - _renderInput = (placeholder, state, keyboardType, isTextArea) => ( + const _renderInput = (placeholder, state, keyboardType, isTextArea) => ( this._handleOnAmountChange(state, amount)} - value={this.state[state]} + onChangeText={(amount) => _handleOnChange(state, amount)} + value={ + state === 'destination' + ? destination + : state === 'amount' + ? amount + : state === 'memo' + ? memo + : '' + } placeholder={placeholder} placeholderTextColor="#c1c5c7" autoCapitalize="none" @@ -119,8 +121,7 @@ class TransferView extends Component { keyboardType={keyboardType} /> ); - - _renderDropdown = (accounts, currentAccountName) => ( + const _renderDropdown = (accounts, currentAccountName) => ( item.username)} defaultText={currentAccountName} selectedOptionIndex={accounts.findIndex((item) => item.username === currentAccountName)} - onSelect={(index, value) => this._handleOnDropdownChange(value)} + onSelect={(index, value) => _handleOnDropdownChange(value)} /> ); - _handleOnDropdownChange = (value) => { - const { fetchBalance, transferType } = this.props; - + const _handleOnDropdownChange = (value) => { fetchBalance(value); - this.setState({ from: value }); + setFrom(value); if (transferType === 'convert') { - this.setState({ destination: value }); + setDestination(value); } }; - _renderDescription = (text) => {text}; - - render() { - const { - accounts, - intl, - handleOnModalClose, - balance, - fundType, - transferType, - currentAccountName, - selectedAccount, - } = this.props; - const { - destination, - isUsernameValid, - amount, - steemConnectTransfer, - memo, - isTransfering, - from, - } = this.state; - let path; - + const _renderDescription = (text) => {text}; + let path; + if (hsTransfer) { if (transferType === 'points') { const json = JSON.stringify({ sender: get(selectedAccount, 'name'), @@ -181,129 +159,148 @@ class TransferView extends Component { )}%22%5D&required_posting_auths=%5B%5D&id=esteem_point_transfer&json=${encodeURIComponent( json, )}`; + } else if (transferType === 'transfer_to_savings') { + path = `sign/transfer_to_savings?from=${currentAccountName}&to=${destination}&amount=${encodeURIComponent( + `${amount} ${fundType}`, + )}&memo=${encodeURIComponent(memo)}`; + } else if (transferType === 'delegate_vesting_shares') { + path = `sign/delegate_vesting_shares?delegator=${currentAccountName}&delegatee=${destination}&vesting_shares=${encodeURIComponent( + `${amount} ${fundType}`, + )}`; + } else if (transferType === 'transfer_to_vesting') { + path = `sign/transfer_to_vesting?from=${currentAccountName}&to=${destination}&amount=${encodeURIComponent( + `${amount} ${fundType}`, + )}`; + } else if (transferType === 'withdraw_hive' || transferType === 'withdraw_hbd') { + path = `sign/transfer_from_savings?from=${currentAccountName}&to=${destination}&amount=${encodeURIComponent( + `${amount} ${fundType}`, + )}&request_id=${new Date().getTime() >>> 0}`; + } else if (transferType === 'convert') { + path = `sign/convert?owner=${currentAccountName}&amount=${encodeURIComponent( + `${amount} ${fundType}`, + )}&requestid=${new Date().getTime() >>> 0}`; + } else if (transferType === 'withdraw_vesting') { + path = `sign/withdraw_vesting?account=${currentAccountName}&vesting_shares=${encodeURIComponent( + `${amount} ${fundType}`, + )}`; } else { - path = `sign/transfer?from=${ - accounts[0].username - }&to=${destination}&amount=${encodeURIComponent( + path = `sign/transfer?from=${currentAccountName}&to=${destination}&amount=${encodeURIComponent( `${amount} ${fundType}`, )}&memo=${encodeURIComponent(memo)}`; } - - return ( - - - - - - - - - - + } + return ( + + + + + + + + + + + _renderDropdown(accounts, currentAccountName)} + /> + {transferType !== 'convert' && ( this._renderDropdown(accounts, currentAccountName)} - /> - {transferType !== 'convert' && ( - - this._renderInput( - intl.formatMessage({ id: 'transfer.to_placeholder' }), - 'destination', - 'default', - ) - } - /> - )} - - this._renderInput( - intl.formatMessage({ id: 'transfer.amount' }), - 'amount', - 'numeric', + _renderInput( + intl.formatMessage({ id: 'transfer.to_placeholder' }), + 'destination', + 'default', ) } /> + )} + + _renderInput(intl.formatMessage({ id: 'transfer.amount' }), 'amount', 'numeric') + } + /> + ( + _handleOnChange('amount', balance)}> + {_renderDescription( + `${intl.formatMessage({ + id: 'transfer.amount_desc', + })} ${balance} ${fundType === 'ESTM' ? 'Points' : fundType}`, + )} + + )} + /> + {(transferType === 'points' || + transferType === 'transfer_token' || + transferType === 'transfer_to_savings') && ( ( - this._handleOnAmountChange('amount', balance)}> - {this._renderDescription( - `${intl.formatMessage({ - id: 'transfer.amount_desc', - })} ${balance} ${fundType === 'ESTM' ? 'Points' : fundType}`, - )} - - )} + label={intl.formatMessage({ id: 'transfer.memo' })} + rightComponent={() => + _renderInput( + intl.formatMessage({ id: 'transfer.memo_placeholder' }), + 'memo', + 'default', + true, + ) + } /> - {(transferType === 'points' || transferType === 'transfer_token') && ( - - this._renderInput( - intl.formatMessage({ id: 'transfer.memo_placeholder' }), - 'memo', - 'default', - true, - ) - } - /> - )} - {(transferType === 'points' || transferType === 'transfer_token') && ( - - this._renderDescription(intl.formatMessage({ id: 'transfer.memo_desc' })) - } - /> - )} - {transferType === 'convert' && ( - - this._renderDescription(intl.formatMessage({ id: 'transfer.convert_desc' })) - } - /> - )} - - - = 0.001 && isUsernameValid)} - onPress={() => this.ActionSheet.show()} - isLoading={isTransfering} - > - {intl.formatMessage({ id: 'transfer.next' })} - - - - - (this.ActionSheet = o)} - options={[ - intl.formatMessage({ id: 'alert.confirm' }), - intl.formatMessage({ id: 'alert.cancel' }), - ]} - title={intl.formatMessage({ id: 'transfer.information' })} - cancelButtonIndex={1} - destructiveButtonIndex={0} - onPress={(index) => { - index === 0 ? this._handleTransferAction() : null; - }} - /> - {path && ( - - - - )} - - ); - } -} + )} + {(transferType === 'points' || transferType === 'transfer_token') && ( + + _renderDescription(intl.formatMessage({ id: 'transfer.memo_desc' })) + } + /> + )} + {transferType === 'convert' && ( + + _renderDescription(intl.formatMessage({ id: 'transfer.convert_desc' })) + } + /> + )} + + + = 0.001 && isUsernameValid)} + onPress={() => confirm.current.show()} + isLoading={isTransfering} + > + {intl.formatMessage({ id: 'transfer.next' })} + + + + + { + index === 0 ? _handleTransferAction() : null; + }} + /> + {path && ( + + + + )} + + ); +}; export default injectIntl(TransferView); diff --git a/src/screens/wallet/screen/sbdView.js b/src/screens/wallet/screen/hbdView.js similarity index 77% rename from src/screens/wallet/screen/sbdView.js rename to src/screens/wallet/screen/hbdView.js index 7e8b835de..a63b0d79a 100644 --- a/src/screens/wallet/screen/sbdView.js +++ b/src/screens/wallet/screen/hbdView.js @@ -6,7 +6,7 @@ import { WalletContainer, AccountContainer } from '../../../containers'; import globalStyles from '../../../globalStyles'; -const SbdView = ({ handleOnSelected, index, currentIndex, refreshing: reload }) => ( +const HbdView = ({ handleOnSelected, index, currentIndex, refreshing: reload }) => ( {({ currentAccount }) => ( @@ -17,12 +17,12 @@ const SbdView = ({ handleOnSelected, index, currentIndex, refreshing: reload }) handleOnWalletRefresh, refreshing, transferHistory, - sbdBalance, + hbdBalance, isLoading, - sbdSavingBalance, - estimatedSbdValue, - sbdDropdown, - savingSbdDropdown, + hbdSavingBalance, + estimatedHbdValue, + hbdDropdown, + savingHbdDropdown, navigate, }) => ( navigate(option, 'HBD')} - type="sbd" + type="hbd" currentIndex={currentIndex} showIconList={false} valueDescriptions={[ { textKey: 'estimated_value', - value: , + value: , subTextKey: 'estimated_value_desc', }, ]} @@ -58,4 +58,4 @@ const SbdView = ({ handleOnSelected, index, currentIndex, refreshing: reload }) ); -export default SbdView; +export default HbdView; diff --git a/src/screens/wallet/screen/steemView.js b/src/screens/wallet/screen/hiveView.js similarity index 75% rename from src/screens/wallet/screen/steemView.js rename to src/screens/wallet/screen/hiveView.js index 4c720aa70..a8a87494f 100644 --- a/src/screens/wallet/screen/steemView.js +++ b/src/screens/wallet/screen/hiveView.js @@ -6,7 +6,7 @@ import { WalletContainer, AccountContainer } from '../../../containers'; import globalStyles from '../../../globalStyles'; -const SteemView = ({ handleOnSelected, index, currentIndex, refreshing: reload }) => ( +const HiveView = ({ handleOnSelected, index, currentIndex, refreshing: reload }) => ( {({ currentAccount }) => ( @@ -17,12 +17,12 @@ const SteemView = ({ handleOnSelected, index, currentIndex, refreshing: reload } handleOnWalletRefresh, refreshing, transferHistory, - steemBalance, + hiveBalance, isLoading, - steemSavingBalance, - estimatedSteemValue, - steemDropdown, - savingSteemDropdown, + hiveSavingBalance, + estimatedHiveValue, + hiveDropdown, + savingHiveDropdown, navigate, }) => ( navigate(option, 'HIVE')} - type="steem" + type="hive" currentIndex={currentIndex} showIconList={false} valueDescriptions={[ { textKey: 'estimated_value', - value: , + value: , subTextKey: 'estimated_value_desc', }, ]} @@ -62,4 +62,4 @@ const SteemView = ({ handleOnSelected, index, currentIndex, refreshing: reload } ); -export default SteemView; +export default HiveView; diff --git a/src/screens/wallet/screen/spView.js b/src/screens/wallet/screen/hpView.js similarity index 87% rename from src/screens/wallet/screen/spView.js rename to src/screens/wallet/screen/hpView.js index bf29217ec..1c1cc5f8e 100644 --- a/src/screens/wallet/screen/spView.js +++ b/src/screens/wallet/screen/hpView.js @@ -6,7 +6,7 @@ import { WalletContainer, AccountContainer } from '../../../containers'; import globalStyles from '../../../globalStyles'; -const SpView = ({ handleOnSelected, index, currentIndex, refreshing: reload }) => ( +const HpView = ({ handleOnSelected, index, currentIndex, refreshing: reload }) => ( {({ currentAccount }) => ( @@ -17,11 +17,11 @@ const SpView = ({ handleOnSelected, index, currentIndex, refreshing: reload }) = handleOnWalletRefresh, refreshing, userActivities, - spBalance, + hpBalance, isLoading, - estimatedSpValue, + estimatedHpValue, delegationsAmount, - steemPowerDropdown, + hivePowerDropdown, unclaimedBalance, navigate, estimatedAmount, @@ -39,10 +39,10 @@ const SpView = ({ handleOnSelected, index, currentIndex, refreshing: reload }) = unclaimedBalance={unclaimedBalance} showBuyButton={unclaimedBalance.length > 0} userBalance={[ - { balance: spBalance, nameKey: 'steem_power', options: steemPowerDropdown }, + { balance: hpBalance, nameKey: 'hive_power', options: hivePowerDropdown }, ]} handleOnDropdownSelected={(option) => navigate(option, 'HIVE_POWER')} - type="steem_power" + type="hive_power" currentIndex={currentIndex} showIconList={false} valueDescriptions={[ @@ -57,7 +57,7 @@ const SpView = ({ handleOnSelected, index, currentIndex, refreshing: reload }) = }, { textKey: 'estimated_value', - value: , + value: , }, { textKey: 'estimated_amount', @@ -72,4 +72,4 @@ const SpView = ({ handleOnSelected, index, currentIndex, refreshing: reload }) = ); -export default SpView; +export default HpView; diff --git a/src/screens/wallet/screen/walletScreen.js b/src/screens/wallet/screen/walletScreen.js index 16b60e5c9..1961756af 100644 --- a/src/screens/wallet/screen/walletScreen.js +++ b/src/screens/wallet/screen/walletScreen.js @@ -9,9 +9,9 @@ import { LoggedInContainer } from '../../../containers'; // Components import { Header, Transaction, HorizontalIconList } from '../../../components'; import EstmView from './estmView'; -import SteemView from './steemView'; -import SpView from './spView'; -import SbdView from './sbdView'; +import HiveView from './hiveView'; +import HpView from './hpView'; +import HbdView from './hbdView'; // Styles import globalStyles from '../../../globalStyles'; @@ -62,19 +62,19 @@ const WalletScreen = () => { refreshing={refreshing} currentIndex={currentIndex} /> - - - { - if (!vests || !steemPerMVests) { +export const vestsToHp = (vests, hivePerMVests) => { + if (!vests || !hivePerMVests) { return 0; } - return (vests / 1e6) * steemPerMVests; + return (vests / 1e6) * hivePerMVests; }; export const vestsToRshares = (vests, votingPower, votePerc) => { diff --git a/src/utils/manaBar.js b/src/utils/manaBar.js index 1f5d34ba3..d98d00460 100644 --- a/src/utils/manaBar.js +++ b/src/utils/manaBar.js @@ -5,13 +5,13 @@ const PERIOD = 432000; export const getVotingPower = (account) => { const { vp_manabar } = account; - const { percentage } = vp_manabar; + const { percentage } = vp_manabar || 0; return percentage / 100 || 0; }; export const getRcPower = (account) => { const { rc_manabar } = account; - const { percentage } = rc_manabar; + const { percentage } = rc_manabar || 0; return percentage / 100 || 0; }; diff --git a/src/utils/wallet.js b/src/utils/wallet.js index c6f6d5f09..5a94aeff8 100644 --- a/src/utils/wallet.js +++ b/src/utils/wallet.js @@ -1,7 +1,7 @@ import get from 'lodash/get'; import parseDate from './parseDate'; import parseToken from './parseToken'; -import { vestsToSp } from './conversions'; +import { vestsToHp } from './conversions'; import { getFeedHistory, getAccount, getAccountHistory } from '../providers/hive/dhive'; import { getCurrencyTokenRate } from '../providers/ecency/ecency'; @@ -27,8 +27,8 @@ export const transferTypes = [ 'fill_vesting_withdraw', ]; -export const groomingTransactionData = (transaction, steemPerMVests) => { - if (!transaction || !steemPerMVests) { +export const groomingTransactionData = (transaction, hivePerMVests) => { + if (!transaction || !hivePerMVests) { return []; } @@ -50,7 +50,7 @@ export const groomingTransactionData = (transaction, steemPerMVests) => { const { reward } = opData; const { comment_author: commentAuthor, comment_permlink: commentPermlink } = opData; - result.value = `${vestsToSp(parseToken(reward), steemPerMVests) + result.value = `${vestsToHp(parseToken(reward), hivePerMVests) .toFixed(3) .replace(',', '.')} HP`; result.details = commentAuthor ? `@${commentAuthor}/${commentPermlink}` : null; @@ -58,21 +58,21 @@ export const groomingTransactionData = (transaction, steemPerMVests) => { case 'author_reward': case 'comment_benefactor_reward': let { - sbd_payout: sbdPayout = opData.hbd_payout, - steem_payout: steemPayout = opData.hive_payout, + hbd_payout: hbdPayout, + hive_payout: hivePayout, vesting_payout: vestingPayout, } = opData; const { author, permlink } = opData; - sbdPayout = parseToken(sbdPayout).toFixed(3).replace(',', '.'); - steemPayout = parseToken(steemPayout).toFixed(3).replace(',', '.'); - vestingPayout = vestsToSp(parseToken(vestingPayout), steemPerMVests) + hbdPayout = parseToken(hbdPayout).toFixed(3).replace(',', '.'); + hivePayout = parseToken(hivePayout).toFixed(3).replace(',', '.'); + vestingPayout = vestsToHp(parseToken(vestingPayout), hivePerMVests) .toFixed(3) .replace(',', '.'); - result.value = `${sbdPayout > 0 ? `${sbdPayout} HBD` : ''} ${ - steemPayout > 0 ? `${steemPayout} HIVE` : '' + result.value = `${hbdPayout > 0 ? `${hbdPayout} HBD` : ''} ${ + hivePayout > 0 ? `${hivePayout} HIVE` : '' } ${vestingPayout > 0 ? `${vestingPayout} HP` : ''}`; result.details = author && permlink ? `@${author}/${permlink}` : null; @@ -81,14 +81,14 @@ export const groomingTransactionData = (transaction, steemPerMVests) => { } break; case 'claim_reward_balance': - let { reward_hbd: rewardSdb, reward_hive: rewardSteem, reward_vests: rewardVests } = opData; + let { reward_hbd: rewardHdb, reward_hive: rewardHive, reward_vests: rewardVests } = opData; - rewardSdb = parseToken(rewardSdb).toFixed(3).replace(',', '.'); - rewardSteem = parseToken(rewardSteem).toFixed(3).replace(',', '.'); - rewardVests = vestsToSp(parseToken(rewardVests), steemPerMVests).toFixed(3).replace(',', '.'); + rewardHdb = parseToken(rewardHdb).toFixed(3).replace(',', '.'); + rewardHive = parseToken(rewardHive).toFixed(3).replace(',', '.'); + rewardVests = vestsToHp(parseToken(rewardVests), hivePerMVests).toFixed(3).replace(',', '.'); - result.value = `${rewardSdb > 0 ? `${rewardSdb} HBD` : ''} ${ - rewardSteem > 0 ? `${rewardSteem} HIVE` : '' + result.value = `${rewardHdb > 0 ? `${rewardHdb} HBD` : ''} ${ + rewardHive > 0 ? `${rewardHive} HIVE` : '' } ${rewardVests > 0 ? `${rewardVests} HP` : ''}`; break; case 'transfer': @@ -107,9 +107,7 @@ export const groomingTransactionData = (transaction, steemPerMVests) => { let { vesting_shares: opVestingShares } = opData; opVestingShares = parseToken(opVestingShares); - result.value = `${vestsToSp(opVestingShares, steemPerMVests) - .toFixed(3) - .replace(',', '.')} HP`; + result.value = `${vestsToHp(opVestingShares, hivePerMVests).toFixed(3).replace(',', '.')} HP`; result.icon = 'attach-money'; result.details = acc ? `@${acc}` : null; break; @@ -188,47 +186,47 @@ export const groomingWalletData = async (user, globalProps, userCurrency) => { const [userdata] = state; // TODO: move them to utils these so big for a lifecycle function - walletData.rewardSteemBalance = parseToken(userdata.reward_hive_balance); - walletData.rewardSbdBalance = parseToken(userdata.reward_hbd_balance); - walletData.rewardVestingSteem = parseToken(userdata.reward_vesting_hive); + walletData.rewardHiveBalance = parseToken(userdata.reward_hive_balance); + walletData.rewardHbdBalance = parseToken(userdata.reward_hbd_balance); + walletData.rewardVestingHive = parseToken(userdata.reward_vesting_hive); walletData.hasUnclaimedRewards = - walletData.rewardSteemBalance > 0 || - walletData.rewardSbdBalance > 0 || - walletData.rewardVestingSteem > 0; + walletData.rewardHiveBalance > 0 || + walletData.rewardHbdBalance > 0 || + walletData.rewardVestingHive > 0; walletData.balance = parseToken(userdata.balance); walletData.vestingShares = parseToken(userdata.vesting_shares); walletData.vestingSharesDelegated = parseToken(userdata.delegated_vesting_shares); walletData.vestingSharesReceived = parseToken(userdata.received_vesting_shares); walletData.vestingSharesTotal = walletData.vestingShares - walletData.vestingSharesDelegated + walletData.vestingSharesReceived; - walletData.sbdBalance = parseToken(userdata.hbd_balance); + walletData.hbdBalance = parseToken(userdata.hbd_balance); walletData.savingBalance = parseToken(userdata.savings_balance); - walletData.savingBalanceSbd = parseToken(userdata.savings_hbd_balance); + walletData.savingBalanceHbd = parseToken(userdata.savings_hbd_balance); const feedHistory = await getFeedHistory(); const base = parseToken(feedHistory.current_median_history.base); const quote = parseToken(feedHistory.current_median_history.quote); - walletData.steemPerMVests = globalProps.steemPerMVests; + walletData.hivePerMVests = globalProps.hivePerMVests; - const pricePerSteem = base / quote; + const pricePerHive = base / quote; - const totalSteem = - vestsToSp(walletData.vestingShares, walletData.steemPerMVests) + + const totalHive = + vestsToHp(walletData.vestingShares, walletData.hivePerMVests) + walletData.balance + walletData.savingBalance; - const totalSbd = walletData.sbdBalance + walletData.savingBalanceSbd; + const totalHbd = walletData.hbdBalance + walletData.savingBalanceHbd; - walletData.estimatedValue = totalSteem * pricePerSteem + totalSbd; + walletData.estimatedValue = totalHive * pricePerHive + totalHbd; - const ppSbd = await getCurrencyTokenRate(userCurrency, 'hbd'); - const ppSteem = await getCurrencyTokenRate(userCurrency, 'hive'); + const ppHbd = await getCurrencyTokenRate(userCurrency, 'hbd'); + const ppHive = await getCurrencyTokenRate(userCurrency, 'hive'); - walletData.estimatedSteemValue = (walletData.balance + walletData.savingBalance) * ppSteem; - walletData.estimatedSbdValue = totalSbd * ppSbd; - walletData.estimatedSpValue = - vestsToSp(walletData.vestingShares, walletData.steemPerMVests) * ppSteem; + walletData.estimatedHiveValue = (walletData.balance + walletData.savingBalance) * ppHive; + walletData.estimatedHbdValue = totalHbd * ppHbd; + walletData.estimatedHpValue = + vestsToHp(walletData.vestingShares, walletData.hivePerMVests) * ppHive; walletData.showPowerDown = userdata.next_vesting_withdrawal !== '1969-12-31T23:59:59'; const timeDiff = Math.abs(parseDate(userdata.next_vesting_withdrawal) - new Date());