Merge pull request #97 from esteemapp/wallet-data

Wallet data
This commit is contained in:
Feruz M 2018-11-10 21:37:58 +02:00 committed by GitHub
commit fb6d403691
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 200 additions and 46 deletions

55
package-lock.json generated
View File

@ -1486,6 +1486,15 @@
"resolved": "https://registry.npmjs.org/aws4/-/aws4-1.8.0.tgz",
"integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ=="
},
"axios": {
"version": "0.18.0",
"resolved": "http://registry.npmjs.org/axios/-/axios-0.18.0.tgz",
"integrity": "sha1-MtU+SFHv3AoRmTts0AB4nXDAUQI=",
"requires": {
"follow-redirects": "^1.3.0",
"is-buffer": "^1.1.5"
}
},
"axobject-query": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-2.0.1.tgz",
@ -4207,6 +4216,24 @@
"lodash": "^4.0.0"
}
},
"follow-redirects": {
"version": "1.5.9",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.9.tgz",
"integrity": "sha512-Bh65EZI/RU8nx0wbYF9shkFZlqLP+6WT/5FnA3cE/djNSuKNHJEinGGZgu/cQEkeeb2GdFOgenAmn8qaqYke2w==",
"requires": {
"debug": "=3.1.0"
},
"dependencies": {
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"requires": {
"ms": "2.0.0"
}
}
}
},
"for-in": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz",
@ -4325,12 +4352,14 @@
"balanced-match": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c="
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=",
"optional": true
},
"brace-expansion": {
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
"optional": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
@ -4345,17 +4374,20 @@
"code-point-at": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz",
"integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c="
"integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=",
"optional": true
},
"concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=",
"optional": true
},
"console-control-strings": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz",
"integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4="
"integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=",
"optional": true
},
"core-util-is": {
"version": "1.0.2",
@ -4472,7 +4504,8 @@
"inherits": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=",
"optional": true
},
"ini": {
"version": "1.3.5",
@ -4484,6 +4517,7 @@
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz",
"integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=",
"optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
@ -4498,6 +4532,7 @@
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
"optional": true,
"requires": {
"brace-expansion": "^1.1.7"
}
@ -4505,12 +4540,14 @@
"minimist": {
"version": "0.0.8",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0="
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=",
"optional": true
},
"minipass": {
"version": "2.2.4",
"resolved": "https://registry.npmjs.org/minipass/-/minipass-2.2.4.tgz",
"integrity": "sha512-hzXIWWet/BzWhYs2b+u7dRHlruXhwdgvlTMDKC6Cb1U7ps6Ac6yQlR39xsbjWJE377YTCtKwIXIpJ5oP+j5y8g==",
"optional": true,
"requires": {
"safe-buffer": "^5.1.1",
"yallist": "^3.0.0"
@ -4529,6 +4566,7 @@
"version": "0.5.1",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
"optional": true,
"requires": {
"minimist": "0.0.8"
}
@ -4609,7 +4647,8 @@
"number-is-nan": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz",
"integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0="
"integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=",
"optional": true
},
"object-assign": {
"version": "4.1.1",
@ -4621,6 +4660,7 @@
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
"optional": true,
"requires": {
"wrappy": "1"
}
@ -4742,6 +4782,7 @@
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
"integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=",
"optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",

View File

@ -23,6 +23,7 @@
"@babel/runtime": "^7.1.2",
"@esteemapp/react-native-scrollable-tab-view": "^0.8.2",
"@esteemapp/react-native-tags": "^1.3.1",
"axios": "^0.18.0",
"crypto-js": "^3.1.9-1",
"dsteem": "^0.10.1",
"lodash": "^4.17.11",
@ -62,13 +63,13 @@
"eslint-plugin-jsx-a11y": "^6.1.1",
"eslint-plugin-react": "^7.11.1",
"jest": "23.6.0",
"lint-staged": "^7.2.0",
"metro-react-native-babel-preset": "0.47.0",
"prettier": "^1.14.3",
"prettier-eslint": "^8.8.2",
"react-test-renderer": "16.6.0-alpha.8af6728",
"redux-logger": "^3.0.6",
"redux-devtools-extension": "^2.13.5",
"lint-staged": "^7.2.0"
"redux-logger": "^3.0.6"
},
"lint-staged": {
"*.js": [

View File

@ -1,38 +1,83 @@
import React, { Component } from 'react';
// import { connect } from "react-redux";
// Services and Actions
import { globalProps, getFeedHistory } from '../../../providers/steem/dsteem';
// Middleware
// Constants
// Utilities
import parseToken from '../../../utils/parseToken';
import parseDate from '../../../utils/parseDate';
import { vestsToSp } from '../../../utils/conversions';
// Component
import { WalletView } from '..';
/*
* Props Name Description Value
*@props --> props name here description here Value Type Here
*
*/
* Props Name Description Value
*@props --> props name here description here Value Type Here
*
*/
class WalletContainer extends Component {
constructor(props) {
super(props);
this.state = {};
this.state = {
walletData: {},
};
}
// Component Life Cycle Functions
async componentWillMount() {
const { user } = this.props;
console.log('user :', user);
const walletData = {};
walletData.rewardSteemBalance = parseToken(user.reward_steem_balance);
walletData.rewardSbdBalance = parseToken(user.reward_sbd_balance);
walletData.rewardVestingSteem = parseToken(user.reward_vesting_steem);
walletData.hasUnclaimedRewards = walletData.rewardSteemBalance > 0
|| walletData.rewardSbdBalance > 0
|| walletData.rewardVestingSteem > 0;
walletData.balance = parseToken(user.balance);
walletData.vestingShares = parseToken(user.vesting_shares);
walletData.vestingSharesDelegated = parseToken(user.delegated_vesting_shares);
walletData.vestingSharesReceived = parseToken(user.received_vesting_shares);
walletData.vestingSharesTotal = walletData.vestingShares
- walletData.vestingSharesDelegated
+ walletData.vestingSharesReceived;
walletData.sbdBalance = parseToken(user.sbd_balance);
walletData.savingBalance = parseToken(user.savings_balance);
walletData.savingBalanceSbd = parseToken(user.savings_sbd_balance);
const global = await globalProps();
const feedHistory = await getFeedHistory();
walletData.steemPerMVests = (parseToken(global.total_vesting_fund_steem) / parseToken(global.total_vesting_shares)) * 1e6;
walletData.estimatedValue = vestsToSp(walletData.vestingShares, walletData.steemPerMVests)
* parseToken(feedHistory.current_median_history.base)
+ walletData.balance * parseToken(feedHistory.current_median_history.base)
+ walletData.sbdBalance;
walletData.showPowerDown = user.next_vesting_withdrawal !== '1969-12-31T23:59:59';
walletData.nextVestingWithdrawal = parseDate(user.next_vesting_withdrawal);
this.setState({ walletData });
}
// Component Functions
render() {
// eslint-disable-next-line
//const {} = this.props;
const { walletData } = this.state;
return <WalletView {...this.props} />;
return <WalletView {...this.props} walletData={walletData} />;
}
}

View File

@ -15,9 +15,9 @@ import styles from './walletStyles';
class WalletView extends Component {
/* Props
* ------------------------------------------------
* @prop { type } name - Description....
*/
* ------------------------------------------------
* @prop { type } name - Description....
*/
constructor(props) {
super(props);
@ -29,7 +29,7 @@ class WalletView extends Component {
// Component Functions
render() {
const { user } = this.props;
const { user, walletData } = this.props;
return (
<View style={styles.container}>
@ -41,18 +41,36 @@ class WalletView extends Component {
defaultTitle="Unclaimed rewards"
expanded
>
<MainButton style={styles.mainButton} height={50} onPress={this._handleOnPressLogin}>
<View style={styles.mainButtonWrapper}>
<Text style={styles.mainButtonText}>18.323 STEEM 1.916 SBD 150.167 SP</Text>
<View style={styles.mainIconWrapper}>
<Ionicons name="md-add" color="#357ce6" size={23} />
</View>
</View>
</MainButton>
{walletData.rewardSteemBalance > 0
&& walletData.rewardSbdBalance > 0
&& walletData.rewardVestingSteem > 0 && (
<MainButton
style={styles.mainButton}
height={50}
onPress={this._handleOnPressLogin}
>
<View style={styles.mainButtonWrapper}>
<Text style={styles.mainButtonText}>
{walletData.rewardSteemBalance
? `${Math.round(walletData.rewardSteemBalance * 1000) / 1000} STEEM`
: ''}
{walletData.rewardSbdBalance
? ` ${Math.round(walletData.rewardSbdBalance * 1000) / 1000} SDB`
: ''}
{walletData.rewardVestingSteem
? ` ${Math.round(walletData.rewardVestingSteem * 1000) / 1000} SP`
: ''}
</Text>
<View style={styles.mainIconWrapper}>
<Ionicons name="md-add" color="#357ce6" size={23} />
</View>
</View>
</MainButton>
)}
</CollapsibleCard>
<CollapsibleCard titleColor="#788187" title="Wallet Details" expanded>
<WalletDetails balance={user.balance} />
<WalletDetails walletData={walletData} />
</CollapsibleCard>
<Transaction />

View File

@ -5,15 +5,19 @@ import { View } from 'react-native';
// Components
import { GrayWrapper, WalletLineItem } from '../../basicUIElements';
// Utilities
import { vestsToSp } from '../../../utils/conversions';
// Styles
// eslint-disable-next-line
import styles from './walletDetailsStyles';
class WalletDetailsView extends Component {
/* Props
* ------------------------------------------------
* @prop { type } name - Description....
*/
* ------------------------------------------------
* @prop { type } name - Description....
*/
constructor(props) {
super(props);
@ -25,7 +29,7 @@ class WalletDetailsView extends Component {
// Component Functions
render() {
const { balance } = this.props;
const { walletData } = this.props;
return (
<View>
@ -33,30 +37,63 @@ class WalletDetailsView extends Component {
text="Steem"
textColor="#3c4449"
iconName="ios-information-circle-outline"
rightText={balance}
rightText={`${Math.round(walletData.estimatedValue * 1000) / 1000} STEEM`}
isBoldText
/>
<GrayWrapper>
<WalletLineItem
text="Steem"
text="Steem Power"
textColor="#3c4449"
iconName="ios-information-circle-outline"
rightText="18,891.867 STEEM"
rightText={`${Math.round(vestsToSp(walletData.vestingShares, walletData.steemPerMVests) * 1000) / 1000} SP`}
tightTextColor="red"
isBoldText
/>
<WalletLineItem rightText="- 15,088.108 SP" />
<WalletLineItem rightText="+ 504,787.529 SP" />
<WalletLineItem rightText="= 508,591.288 SP" rightTextColor="#357ce6" />
{walletData.vestingSharesDelegated > 0 && (
<WalletLineItem
rightText={`- ${Math.round(vestsToSp(
walletData.vestingSharesDelegated,
walletData.steemPerMVests,
) * 1000) / 1000} SP`}
/>
)}
{walletData.vestingSharesReceived > 0 && (
<WalletLineItem
rightText={`+ ${Math.round(vestsToSp(
walletData.vestingSharesReceived,
walletData.steemPerMVests,
) * 1000) / 1000} SP`}
/>
)}
{(walletData.vestingSharesDelegated > 0 || walletData.vestingSharesReceived > 0) && (
<WalletLineItem
rightText={`= ${Math.round(vestsToSp(
walletData.vestingSharesTotal,
walletData.steemPerMVests,
) * 1000) / 1000} SP`}
rightTextColor="#357ce6"
/>
)}
</GrayWrapper>
<WalletLineItem
text="Net power down is in 6 days"
textColor="#788187"
isThin
text="Steem Dollars"
textColor="#3c4449"
iconName="ios-information-circle-outline"
rightText={`$${Math.round(walletData.sbdBalance * 1000) / 1000}`}
isBoldText
/>
<GrayWrapper>
<WalletLineItem
text="Savings"
textColor="#3c4449"
iconName="ios-information-circle-outline"
rightText={`${Math.round(walletData.savingBalance * 1000) / 1000} STEEM`}
isBoldText
/>
<WalletLineItem rightText={`$${Math.round(walletData.savingBalanceSbd * 1000) / 1000}`} />
</GrayWrapper>
</View>
);
}

View File

@ -436,8 +436,18 @@ export const delegate = (data, activeKey) => {
export const globalProps = async () => {
try {
const global_properties = await client.database.getDynamicGlobalProperties();
return global_properties;
const globalProperties = await client.database.getDynamicGlobalProperties();
return globalProperties;
} catch (error) {
console.log(error);
return error;
}
};
export const getFeedHistory = async () => {
try {
const feedHistory = await client.database.call('get_feed_history');
return feedHistory;
} catch (error) {
console.log(error);
return error;

View File

@ -148,7 +148,7 @@ class ProfileScreen extends Component {
)}
</View>
<View
tabLabel={user && user.balance ? `$${user && parseToken(user.balance)}` : 'Wallet'}
tabLabel="Wallet"
>
<Wallet user={user} />
</View>

1
src/utils/conversions.js Normal file
View File

@ -0,0 +1 @@
export const vestsToSp = (vests, steemPerMVests) => (vests / 1e6) * steemPerMVests;

1
src/utils/parseDate.js Normal file
View File

@ -0,0 +1 @@
export default d => new Date(`${d}.000Z`);