Skip to content

Commit

Permalink
Closes #249 - Balance is only calculated if there is not wallet balan…
Browse files Browse the repository at this point in the history
…ce yet calculated, flat list refresh now calls a function with all this calculation logic
  • Loading branch information
chrisfenos committed Oct 9, 2018
1 parent 0199f9e commit 62b4dbf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/reducers/wallet/Wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const initialState = {
wallets: [], //Contains all the encrypted HD Wallet
tempWalletName: null,
tokens: [],
walletBalance: {},
walletBalance: null,
tokenBalances: {},
walletTokens: [],
isFetching: null,
Expand Down
25 changes: 18 additions & 7 deletions src/screens/main/portfolio/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,20 @@ class Portfolio extends Component {
* The Balance (soon to be Wallet) reducer then updates state -> { ...state, walletBalance: walletBalanceObject, tokenBalances: individualTokens };
*/
async componentDidMount() {
if (this.props.walletBalance == null) {
await this.balanceCalculations();
} else {
await this.setState({
walletBalance: this.props.walletBalance,
tokenPrices: this.props.tokenBalances,
tokenAmounts: this.props.tokenBalances,
});
this.showTokens();
}
}

balanceCalculations = async () => {
const { tokenSymbolString, tokenBalances } = await this.formatTokens(this.state.data);
console.log('token balance in mount', tokenBalances);

await this.props.fetchCoinData(tokenSymbolString);
await this.props.calculateWalletBalance(tokenBalances, this.props.tokenConversions); //amount of tokens and symbol -> token balance, conversions -> matrix of prices
await this.setState({
Expand All @@ -67,7 +78,6 @@ class Portfolio extends Component {
});
this.showTokens();
}

/**
* tokens are passed into the function where their symbols and addresses are parsed out and stored in an array,
* which is then passed to processAllTokenBalances. The return is the concatenated string of symbols in wallet, and the amount
Expand Down Expand Up @@ -148,13 +158,12 @@ class Portfolio extends Component {
<View style={ styles.listItemValueComponent }>
<Text style={styles.listItemCryptoValue}>
{
tokenAmounts == null ? 0 : tokenAmounts.amount
tokenAmounts == null ? 0 : tokenAmounts.amount
}
</Text>
<Text style={styles.listItemFiatValue}>
{
tokenAmounts == null ? 'NA' : (tokenPriceInfo)[this.props.currencyOptions[this.state.currencyIndex]]

tokenAmounts == null ? 'NA' : (tokenPriceInfo)[this.props.currencyOptions[this.state.currencyIndex]]
}
</Text>
</View>
Expand All @@ -166,7 +175,9 @@ class Portfolio extends Component {
);
}

handleListRefresh = () => {}
handleListRefresh = async () => {
await this.balanceCalculations();
}

handleCurrencyTouch = async () => {
let currentIndex = this.state.currencyIndex;
Expand Down

0 comments on commit 62b4dbf

Please sign in to comment.