Repository: busyorg/busy
Pull request #960 (2017-10-31 14:58:20)

Add loadingGlobalProperties to wallet reducer
* https://github.com/busyorg/busy/issues/959

Fixes # .
 https://github.com/busyorg/busy/issues/959

Changes:
- Add loadingGlobalProperties to reducer, and pass it through to UserWalletSummary for displaying SP. Since SP relies on global properties



Patch:
diff --git a/src/reducers.js b/src/reducers.js
index b40ee29d..c4e99de2 100644
--- a/src/reducers.js
+++ b/src/reducers.js
@@ -102,3 +102,5 @@ export const getUsersEstAccountsValues = state =>
   fromWallet.getUsersEstAccountsValues(state.wallet);
 export const getLoadingEstAccountValue = state =>
   fromWallet.getLoadingEstAccountValue(state.wallet);
+export const getLoadingGlobalProperties = state =>
+  fromWallet.getLoadingGlobalProperties(state.wallet);
diff --git a/src/user/UserWallet.js b/src/user/UserWallet.js
index eb2f2e53..6ed53c8f 100644
--- a/src/user/UserWallet.js
+++ b/src/user/UserWallet.js
@@ -16,6 +16,7 @@ import {
   getUsersTransactionsLoading,
   getUsersEstAccountsValues,
   getLoadingEstAccountValue,
+  getLoadingGlobalProperties,
 } from '../reducers';
 import {
   getGlobalProperties,
@@ -37,6 +38,7 @@ import { getAccountWithFollowingCount } from './usersActions';
     usersTransactionsLoading: getUsersTransactionsLoading(state),
     usersEstAccountsValues: getUsersEstAccountsValues(state),
     loadingEstAccountValue: getLoadingEstAccountValue(state),
+    loadingGlobalProperties: getLoadingGlobalProperties(state),
   }),
   {
     getGlobalProperties,
@@ -59,6 +61,7 @@ class Wallet extends Component {
     usersEstAccountsValues: PropTypes.shape().isRequired,
     usersTransactionsLoading: PropTypes.bool.isRequired,
     loadingEstAccountValue: PropTypes.bool.isRequired,
+    loadingGlobalProperties: PropTypes.bool.isRequired,
     isCurrentUser: PropTypes.bool,
     authenticatedUserName: PropTypes.string,
   };
@@ -115,6 +118,7 @@ class Wallet extends Component {
       totalVestingShares,
       totalVestingFundSteem,
       loadingEstAccountValue,
+      loadingGlobalProperties,
       usersTransactions,
       usersTransactionsLoading,
       usersEstAccountsValues,
@@ -131,6 +135,7 @@ class Wallet extends Component {
           loadingEstAccountValue={loadingEstAccountValue}
           totalVestingShares={totalVestingShares}
           totalVestingFundSteem={totalVestingFundSteem}
+          loadingGlobalProperties={loadingGlobalProperties}
         />
         {transactions.length === 0 && usersTransactionsLoading
           ? <Loading style={{ marginTop: '20px' }} />
diff --git a/src/wallet/UserWalletSummary.js b/src/wallet/UserWalletSummary.js
index 66af0651..cf6b5a03 100644
--- a/src/wallet/UserWalletSummary.js
+++ b/src/wallet/UserWalletSummary.js
@@ -48,6 +48,7 @@ const UserWalletSummary = ({
   totalVestingShares,
   totalVestingFundSteem,
   loadingEstAccountValue,
+  loadingGlobalProperties,
 }) => (
   <div className="UserWalletSummary">
     <div className="UserWalletSummary__item">
@@ -67,7 +68,7 @@ const UserWalletSummary = ({
         <FormattedMessage id="steem_power" defaultMessage="Steem Power" />
       </div>
       <div className="UserWalletSummary__value">
-        {loading
+        {loading || loadingGlobalProperties
           ? <Loading />
           : <span>
             <FormattedNumber
@@ -130,6 +131,7 @@ UserWalletSummary.propTypes = {
   totalVestingFundSteem: PropTypes.string.isRequired,
   loading: PropTypes.bool,
   loadingEstAccountValue: PropTypes.bool,
+  loadingGlobalProperties: PropTypes.bool.isRequired,
 };
 
 UserWalletSummary.defaultProps = {
diff --git a/src/wallet/walletReducer.js b/src/wallet/walletReducer.js
index d95a37be..830f5f36 100644
--- a/src/wallet/walletReducer.js
+++ b/src/wallet/walletReducer.js
@@ -9,6 +9,7 @@ const initialState = {
   usersEstAccountsValues: {},
   usersTransactionsLoading: true,
   loadingEstAccountValue: true,
+  loadingGlobalProperties: true,
 };
 
 export default function walletReducer(state = initialState, action) {
@@ -24,11 +25,23 @@ export default function walletReducer(state = initialState, action) {
         ...state,
         transferVisible: false,
       };
+    case walletActions.GET_GLOBAL_PROPERTIES.START:
+      return {
+        ...state,
+        loadingGlobalProperties: true,
+      };
     case walletActions.GET_GLOBAL_PROPERTIES.SUCCESS: {
       return {
         ...state,
         totalVestingFundSteem: action.payload.total_vesting_fund_steem,
         totalVestingShares: action.payload.total_vesting_shares,
+        loadingGlobalProperties: false,
+      };
+    }
+    case walletActions.GET_GLOBAL_PROPERTIES.ERROR: {
+      return {
+        ...state,
+        loadingGlobalProperties: false,
       };
     }
     case walletActions.GET_USER_TRANSACTIONS.START:
@@ -77,3 +90,4 @@ export const getUsersTransactions = state => state.usersTransactions;
 export const getUsersEstAccountsValues = state => state.usersEstAccountsValues;
 export const getUsersTransactionsLoading = state => state.usersTransactionsLoading;
 export const getLoadingEstAccountValue = state => state.loadingEstAccountValue;
+export const getLoadingGlobalProperties = state => state.loadingGlobalProperties;


Test patch:
diff --git a/src/wallet/__tests__/walletReducer.js b/src/wallet/__tests__/walletReducer.js
index 48c3029a..493471e2 100644
--- a/src/wallet/__tests__/walletReducer.js
+++ b/src/wallet/__tests__/walletReducer.js
@@ -8,6 +8,7 @@ const reducerInitialState = {
   usersEstAccountsValues: {},
   usersTransactionsLoading: true,
   loadingEstAccountValue: true,
+  loadingGlobalProperties: true,
 };
 
 describe('walletReducer', () => {